2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-02-28 01:27:14 +01:00
|
|
|
import {localstorage} from "./localstorage";
|
|
|
|
import * as notifications from "./notifications";
|
2021-03-25 22:35:45 +01:00
|
|
|
import {page_params} from "./page_params";
|
2021-02-28 21:30:08 +01:00
|
|
|
import * as unread_ops from "./unread_ops";
|
2021-02-28 01:27:14 +01:00
|
|
|
import * as unread_ui from "./unread_ui";
|
|
|
|
import * as util from "./util";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
2021-02-28 01:27:14 +01:00
|
|
|
export function resize_app() {
|
2019-11-02 00:06:25 +01:00
|
|
|
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).
|
2020-07-15 00:34:28 +02:00
|
|
|
const frb_top =
|
2020-10-07 09:17:30 +02:00
|
|
|
panels_height +
|
|
|
|
$(".header").height() +
|
|
|
|
Number.parseInt($(".header").css("paddingBottom"), 10);
|
2020-05-27 23:00:51 +02:00
|
|
|
$("#floating_recipient_bar").css("top", frb_top + "px");
|
2021-02-28 01:27:14 +01:00
|
|
|
}
|
2017-10-13 00:13:51 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const show_step = function ($process, step) {
|
2020-07-15 00:34:28 +02: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) {
|
2020-10-07 11:38:36 +02:00
|
|
|
return $process.find("[data-step]: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.
|
2020-12-22 11:26:39 +01:00
|
|
|
if (localstorage.supported() && 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
|
|
|
|
2021-02-28 01:27:14 +01:00
|
|
|
export function check_profile_incomplete() {
|
2020-03-26 08:15:26 +01:00
|
|
|
if (!page_params.is_admin) {
|
2021-03-04 19:28:02 +01:00
|
|
|
return false;
|
2020-03-26 08:15:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2020-07-15 00:34:28 +02:00
|
|
|
if (
|
|
|
|
page_params.realm_description === "" ||
|
2021-03-04 19:15:12 +01:00
|
|
|
/^Organization imported from [A-Za-z]+[!.]$/.test(page_params.realm_description)
|
2020-07-15 00:34:28 +02:00
|
|
|
) {
|
2021-03-04 19:28:02 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function show_profile_incomplete(is_profile_incomplete) {
|
|
|
|
if (is_profile_incomplete) {
|
2020-03-26 08:15:26 +01:00
|
|
|
$("[data-process='profile-incomplete']").show();
|
|
|
|
} else {
|
|
|
|
$("[data-process='profile-incomplete']").hide();
|
|
|
|
}
|
2021-02-28 01:27:14 +01:00
|
|
|
}
|
2020-03-26 08:15:26 +01:00
|
|
|
|
2021-02-28 01:27:14 +01:00
|
|
|
export function initialize() {
|
2020-03-26 20:49:28 +01:00
|
|
|
const ls = localstorage();
|
|
|
|
if (page_params.insecure_desktop_app) {
|
2021-02-28 01:27:14 +01:00
|
|
|
open($("[data-process='insecure-desktop-app']"));
|
2020-03-26 20:49:28 +01:00
|
|
|
} 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.
|
2021-02-28 01:27:14 +01:00
|
|
|
open($("[data-process='email-server']"));
|
2020-03-26 20:49:28 +01:00
|
|
|
} else if (should_show_notifications(ls)) {
|
2021-02-28 01:27:14 +01:00
|
|
|
open($("[data-process='notifications']"));
|
2020-03-28 19:33:46 +01:00
|
|
|
} else if (unread_ui.should_display_bankruptcy_banner()) {
|
2021-02-28 01:27:14 +01:00
|
|
|
open($("[data-process='bankruptcy']"));
|
2021-03-04 19:28:02 +01:00
|
|
|
} else if (check_profile_incomplete()) {
|
|
|
|
open($("[data-process='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();
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".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-08-10 19:36:07 +02:00
|
|
|
|
|
|
|
// Treat Enter with links in the panels UI focused like a click.,
|
|
|
|
$("#panels").on("keyup", ".alert-link[role=button]", function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
if (e.key === "Enter") {
|
|
|
|
$(this).click();
|
|
|
|
}
|
|
|
|
});
|
2021-02-28 01:27:14 +01:00
|
|
|
}
|
2017-09-23 11:27:18 +02:00
|
|
|
|
2021-02-28 01:27:14 +01:00
|
|
|
export function open($process) {
|
2020-03-26 20:49:28 +01:00
|
|
|
$("[data-process]").hide();
|
|
|
|
$process.show();
|
|
|
|
resize_app();
|
2021-02-28 01:27:14 +01:00
|
|
|
}
|