2017-09-23 11:27:18 +02:00
|
|
|
var resize_app = function () {
|
|
|
|
var panels_height = $("#panels").height();
|
|
|
|
$("body > .app").height("calc(100% - " + panels_height + "px)");
|
2017-10-13 00:13:51 +02:00
|
|
|
// the floating recipient bar is usually positioned 10px below the
|
|
|
|
// header, so add that to the panels height to get the new `top` value.
|
|
|
|
$("#floating_recipient_bar").css("top", panels_height + $(".header").height() + 10 + "px");
|
2017-09-23 11:27:18 +02:00
|
|
|
};
|
|
|
|
|
2017-10-13 00:13:51 +02:00
|
|
|
exports.resize_app = resize_app;
|
|
|
|
|
2018-01-26 22:10:30 +01:00
|
|
|
var show_step = function ($process, step) {
|
|
|
|
$process.find("[data-step]").hide().filter("[data-step=" + step + "]").show();
|
2017-09-23 11:27:18 +02:00
|
|
|
};
|
|
|
|
|
2018-01-26 22:10:30 +01:00
|
|
|
var get_step = function ($process) {
|
|
|
|
return $process.find("[data-step]").filter(":visible").data("step");
|
2017-09-23 11:27:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.initialize = function () {
|
2018-01-26 22:10:30 +01:00
|
|
|
// if email has not been set up and the user is the admin, display a warning
|
|
|
|
// to tell them to set up an email server.
|
|
|
|
if (page_params.warn_no_email === true && page_params.is_admin) {
|
2019-10-25 09:45:13 +02:00
|
|
|
exports.open($("[data-process='email-server']"));
|
2018-01-26 22:10:30 +01:00
|
|
|
} else {
|
2019-10-25 09:45:13 +02:00
|
|
|
exports.open($("[data-process='notifications']"));
|
2018-01-26 22:10:30 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.open = function ($process) {
|
2017-09-23 11:27:18 +02:00
|
|
|
var ls = localstorage();
|
|
|
|
|
2018-01-26 22:10:30 +01:00
|
|
|
$("[data-process]").hide();
|
|
|
|
|
2018-06-06 18:19:09 +02:00
|
|
|
var should_show_notifications =
|
2017-10-20 22:02:52 +02:00
|
|
|
// notifications *basically* don't work on any mobile platforms, so don't
|
|
|
|
// event show the banners. This prevents trying to access things that
|
|
|
|
// don't exist like `Notification.permission`.
|
|
|
|
!util.is_mobile() &&
|
2017-10-19 00:53:26 +02:00
|
|
|
// if permission has not been granted yet.
|
|
|
|
!notifications.granted_desktop_notifications_permission() &&
|
|
|
|
// if permission is allowed to be requested (e.g. not in "denied" state).
|
|
|
|
notifications.permission_state() !== "denied"
|
2018-06-06 18:19:09 +02:00
|
|
|
;
|
2017-09-23 11:27:18 +02:00
|
|
|
|
2018-03-18 14:36:12 +01:00
|
|
|
if (localstorage.supported()) {
|
|
|
|
// if the user said to never show banner on this computer again, it will
|
|
|
|
// be stored as `true` so we want to negate that.
|
|
|
|
should_show_notifications = should_show_notifications && !ls.get("dontAskForNotifications");
|
|
|
|
}
|
|
|
|
|
2017-09-23 11:27:18 +02:00
|
|
|
if (should_show_notifications) {
|
2018-01-26 22:10:30 +01:00
|
|
|
$process.show();
|
|
|
|
resize_app();
|
|
|
|
}
|
|
|
|
|
|
|
|
// if it is not the notifications prompt, show the error if it has been
|
|
|
|
// initialized here.
|
|
|
|
if ($process.is(":not([data-process='notifications'])")) {
|
|
|
|
$process.show();
|
2017-09-23 11:27:18 +02:00
|
|
|
resize_app();
|
|
|
|
}
|
|
|
|
|
|
|
|
$(".request-desktop-notifications").on("click", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
$(this).closest(".alert").hide();
|
|
|
|
notifications.request_desktop_notifications_permission();
|
|
|
|
resize_app();
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".reject-notifications").on("click", function () {
|
|
|
|
$(this).closest(".alert").hide();
|
|
|
|
ls.set("dontAskForNotifications", true);
|
|
|
|
resize_app();
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#panels").on("click", ".alert .close, .alert .exit", function (e) {
|
|
|
|
e.stopPropagation();
|
2018-01-26 22:10:30 +01:00
|
|
|
if (get_step($process) === 1 && $process.data("process") === "notifications") {
|
|
|
|
show_step($process, 2);
|
2017-09-23 11:27:18 +02:00
|
|
|
} else {
|
|
|
|
$(this).closest(".alert").hide();
|
|
|
|
}
|
|
|
|
resize_app();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.panels = exports;
|