You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
3.0 KiB
JavaScript
86 lines
3.0 KiB
JavaScript
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
|
|
function openOffersAsync(routeTo, routeFrom, resolve, reject) {
|
|
app.dialog.preloader("Fetching latest deals...");
|
|
|
|
apirequest(
|
|
SETTINGS.apis.offers_services,
|
|
{},
|
|
function (resp) {
|
|
app.dialog.close();
|
|
if (resp.status == "ERROR") {
|
|
app.dialog.alert(resp.msg, "Error");
|
|
reject();
|
|
} else {
|
|
var context = {
|
|
offers: []
|
|
};
|
|
|
|
for (var i = 0; i < resp.offers.length; i++) {
|
|
if (resp.offers[i].valid === true) {
|
|
// no expiration
|
|
resp.offers[i].expires = "Limited time offer";
|
|
} else {
|
|
resp.offers[i].expires = "Expires " + formatTimestamp("l F j, Y", resp.offers[i].valid.to);
|
|
}
|
|
context.offers.push(resp.offers[i]);
|
|
}
|
|
|
|
resolve({
|
|
templateUrl: "pages/offers.html",
|
|
}, {
|
|
context: context
|
|
});
|
|
}
|
|
},
|
|
function (xhr) {
|
|
app.dialog.close();
|
|
var error = $.parseJSON(xhr.responseText);
|
|
if (error && typeof error.msg != 'undefined') {
|
|
app.dialog.alert(error.msg, "Error");
|
|
} else {
|
|
app.dialog.alert("A server or network error occurred.", "Error");
|
|
}
|
|
reject();
|
|
}, "GET");
|
|
}
|
|
|
|
function openServicesAsync(routeTo, routeFrom, resolve, reject) {
|
|
app.dialog.preloader("Just a second...");
|
|
|
|
apirequest(
|
|
SETTINGS.apis.offers_services,
|
|
{},
|
|
function (resp) {
|
|
app.dialog.close();
|
|
if (resp.status == "ERROR") {
|
|
app.dialog.alert(resp.msg, "Error");
|
|
reject();
|
|
} else {
|
|
var context = {
|
|
services: resp.services
|
|
};
|
|
|
|
resolve({
|
|
templateUrl: "pages/services.html",
|
|
}, {
|
|
context: context
|
|
});
|
|
}
|
|
},
|
|
function (xhr) {
|
|
app.dialog.close();
|
|
var error = $.parseJSON(xhr.responseText);
|
|
if (error && typeof error.msg != 'undefined') {
|
|
app.dialog.alert(error.msg, "Error");
|
|
} else {
|
|
app.dialog.alert("A server or network error occurred.", "Error");
|
|
}
|
|
reject();
|
|
}, "GET");
|
|
} |