2020-02-13 22:34:29 +01:00
|
|
|
const util = require("./util");
|
2019-11-02 00:06:25 +01:00
|
|
|
const resize_app = function () {
|
|
|
|
const panels_height = $("#panels").height();
|
2017-09-23 11:27:18 +02:00
|
|
|
$("body > .app").height("calc(100% - " + panels_height + "px)");
|
2020-05-27 23:00:51 +02:00
|
|
|
|
|
|
|
// the floating recipient bar is usually positioned right below
|
|
|
|
// the `.header` element (including padding).
|
|
|
|
const frb_top = panels_height
|
|
|
|
+ $('.header').height()
|
|
|
|
+ parseInt($(".header").css("paddingBottom"), 10);
|
|
|
|
$("#floating_recipient_bar").css("top", frb_top + "px");
|
2017-09-23 11:27:18 +02:00
|
|
|
};
|
|
|
|
|
2017-10-13 00:13:51 +02:00
|
|
|
exports.resize_app = resize_app;
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const show_step = function ($process, step) {
|
2018-01-26 22:10:30 +01:00
|
|
|
$process.find("[data-step]").hide().filter("[data-step=" + step + "]").show();
|
2017-09-23 11:27:18 +02:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const get_step = function ($process) {
|
2018-01-26 22:10:30 +01:00
|
|
|
return $process.find("[data-step]").filter(":visible").data("step");
|
2017-09-23 11:27:18 +02:00
|
|
|
};
|
|
|
|
|
2020-03-26 20:49:28 +01:00
|
|
|
function should_show_notifications(ls) {
|
|
|
|
// if the user said to never show banner on this computer again, it will
|
|
|
|
// be stored as `true` so we want to negate that.
|
|
|
|
if (localstorage.supported()) {
|
|
|
|
if (ls.get("dontAskForNotifications") === true) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-01-26 22:10:30 +01:00
|
|
|
}
|
2017-09-23 11:27:18 +02:00
|
|
|
|
2020-03-26 20:49:28 +01:00
|
|
|
return (
|
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"
|
2020-03-26 20:49:28 +01:00
|
|
|
);
|
|
|
|
}
|
2018-01-26 22:10:30 +01:00
|
|
|
|
2020-03-26 08:15:26 +01:00
|
|
|
exports.check_profile_incomplete = function () {
|
|
|
|
if (!page_params.is_admin) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Eventually, we might also check page_params.realm_icon_source,
|
|
|
|
// but it feels too aggressive to ask users to do change that
|
|
|
|
// since their organization might not have a logo yet.
|
|
|
|
if (page_params.realm_description === '' ||
|
|
|
|
page_params.realm_description.startsWith("Organization imported from")) {
|
|
|
|
$("[data-process='profile-incomplete']").show();
|
|
|
|
} else {
|
|
|
|
$("[data-process='profile-incomplete']").hide();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-03-26 20:49:28 +01:00
|
|
|
exports.initialize = function () {
|
|
|
|
const ls = localstorage();
|
|
|
|
if (page_params.insecure_desktop_app) {
|
|
|
|
exports.open($("[data-process='insecure-desktop-app']"));
|
|
|
|
} else if (page_params.warn_no_email === true && page_params.is_admin) {
|
|
|
|
// 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.
|
|
|
|
exports.open($("[data-process='email-server']"));
|
|
|
|
} else if (should_show_notifications(ls)) {
|
|
|
|
exports.open($("[data-process='notifications']"));
|
2020-03-28 19:33:46 +01:00
|
|
|
} else if (unread_ui.should_display_bankruptcy_banner()) {
|
|
|
|
exports.open($("[data-process='bankruptcy']"));
|
2020-03-26 08:15:26 +01:00
|
|
|
} else {
|
|
|
|
// TODO: This should be restructured with separate check and
|
|
|
|
// show calls.
|
|
|
|
exports.check_profile_incomplete();
|
2017-09-23 11:27:18 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 20:49:28 +01:00
|
|
|
// Configure click handlers.
|
2017-09-23 11:27:18 +02:00
|
|
|
$(".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();
|
|
|
|
});
|
|
|
|
|
2020-03-28 19:33:46 +01:00
|
|
|
$(".accept-bankruptcy").on("click", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
$(this).closest(".alert").hide();
|
|
|
|
$('.bankruptcy-loader').show();
|
2020-06-18 08:11:41 +02:00
|
|
|
setTimeout(unread_ops.mark_all_as_read, 1000);
|
2020-03-28 19:33:46 +01:00
|
|
|
resize_app();
|
|
|
|
});
|
|
|
|
|
2017-09-23 11:27:18 +02:00
|
|
|
$("#panels").on("click", ".alert .close, .alert .exit", function (e) {
|
|
|
|
e.stopPropagation();
|
2020-03-26 20:49:28 +01:00
|
|
|
const $process = $(e.target).closest("[data-process]");
|
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();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-03-26 20:49:28 +01:00
|
|
|
exports.open = function ($process) {
|
|
|
|
$("[data-process]").hide();
|
|
|
|
$process.show();
|
|
|
|
resize_app();
|
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.panels = exports;
|