2020-06-09 12:24:32 +02:00
|
|
|
exports.create_ajax_request = function (url, form_name, stripe_token = null, numeric_inputs = [], redirect_to = "/billing") {
|
2019-11-02 00:06:25 +01:00
|
|
|
const form = $("#" + form_name + "-form");
|
|
|
|
const form_loading_indicator = "#" + form_name + "_loading_indicator";
|
|
|
|
const form_input_section = "#" + form_name + "-input-section";
|
|
|
|
const form_success = "#" + form_name + "-success";
|
|
|
|
const form_error = "#" + form_name + "-error";
|
|
|
|
const form_loading = "#" + form_name + "-loading";
|
2019-01-02 09:12:19 +01:00
|
|
|
|
2020-05-22 15:42:46 +02:00
|
|
|
const zulip_limited_section = "#zulip-limited-section";
|
|
|
|
const free_trial_alert_message = "#free-trial-alert-message";
|
|
|
|
|
2019-01-02 09:12:19 +01:00
|
|
|
loading.make_indicator($(form_loading_indicator),
|
|
|
|
{text: 'Processing ...', abs_positioned: true});
|
|
|
|
$(form_input_section).hide();
|
|
|
|
$(form_error).hide();
|
|
|
|
$(form_loading).show();
|
2020-05-22 15:42:46 +02:00
|
|
|
$(zulip_limited_section).hide();
|
|
|
|
$(free_trial_alert_message).hide();
|
2019-01-02 09:12:19 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const data = {};
|
2019-01-02 09:12:19 +01:00
|
|
|
if (stripe_token) {
|
|
|
|
data.stripe_token = JSON.stringify(stripe_token.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
form.serializeArray().forEach(function (item) {
|
2020-02-08 04:04:36 +01:00
|
|
|
if (numeric_inputs.includes(item.name)) {
|
2019-01-02 09:12:19 +01:00
|
|
|
data[item.name] = item.value;
|
|
|
|
} else {
|
|
|
|
data[item.name] = JSON.stringify(item.value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$.post({
|
|
|
|
url: url,
|
|
|
|
data: data,
|
|
|
|
success: function () {
|
|
|
|
$(form_loading).hide();
|
|
|
|
$(form_error).hide();
|
|
|
|
$(form_success).show();
|
2020-02-08 04:04:36 +01:00
|
|
|
if (["autopay", "invoice"].includes(form_name)) {
|
2019-01-09 09:26:15 +01:00
|
|
|
if ("pushState" in history) {
|
|
|
|
history.pushState("", document.title, location.pathname + location.search);
|
|
|
|
} else {
|
|
|
|
location.hash = "";
|
|
|
|
}
|
|
|
|
}
|
2020-06-09 12:24:32 +02:00
|
|
|
window.location.replace(redirect_to);
|
2019-01-02 09:12:19 +01:00
|
|
|
},
|
|
|
|
error: function (xhr) {
|
|
|
|
$(form_loading).hide();
|
|
|
|
$(form_error).show().text(JSON.parse(xhr.responseText).msg);
|
|
|
|
$(form_input_section).show();
|
2020-05-22 15:42:46 +02:00
|
|
|
$(zulip_limited_section).show();
|
|
|
|
$(free_trial_alert_message).show();
|
2019-01-02 09:12:19 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.format_money = function (cents) {
|
|
|
|
// allow for small floating point errors
|
|
|
|
cents = Math.ceil(cents - 0.001);
|
2019-11-02 00:06:25 +01:00
|
|
|
let precision;
|
2019-01-02 09:12:19 +01:00
|
|
|
if (cents % 100 === 0) {
|
|
|
|
precision = 0;
|
|
|
|
} else {
|
|
|
|
precision = 2;
|
|
|
|
}
|
|
|
|
// TODO: Add commas for thousands, millions, etc.
|
|
|
|
return (cents / 100).toFixed(precision);
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.update_charged_amount = function (prices, schedule) {
|
|
|
|
$("#charged_amount").text(
|
|
|
|
exports.format_money(page_params.seat_count * prices[schedule])
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-06-09 12:24:32 +02:00
|
|
|
exports.update_discount_details = function (organization_type) {
|
|
|
|
const discount_details = {
|
|
|
|
open_source: "Open source projects are eligible for fully sponsored (free) Zulip Standard.",
|
|
|
|
research: "Academic research organizations are eligible for fully sponsored (free) Zulip Standard.",
|
|
|
|
non_profit: "Nonprofits are eligible for an 85%-100% discount.",
|
|
|
|
event: "Events are eligible for fully sponsored (free) Zulip Standard.",
|
|
|
|
education: "Education use is eligible for an 85%-100% discount.",
|
|
|
|
other: "Your organization might be eligible for a discount or sponsorship.",
|
|
|
|
};
|
|
|
|
$("#sponsorship-discount-details").text(discount_details[organization_type]);
|
|
|
|
};
|
|
|
|
|
2019-01-02 09:12:19 +01:00
|
|
|
exports.show_license_section = function (license) {
|
|
|
|
$("#license-automatic-section").hide();
|
|
|
|
$("#license-manual-section").hide();
|
|
|
|
|
|
|
|
$("#automatic_license_count").prop('disabled', true);
|
|
|
|
$("#manual_license_count").prop('disabled', true);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const section_id = "#license-" + license + "-section";
|
2019-01-02 09:12:19 +01:00
|
|
|
$(section_id).show();
|
2019-11-02 00:06:25 +01:00
|
|
|
const input_id = "#" + license + "_license_count";
|
2019-01-02 09:12:19 +01:00
|
|
|
$(input_id).prop("disabled", false);
|
|
|
|
};
|
|
|
|
|
2019-01-02 09:44:45 +01:00
|
|
|
exports.set_tab = function (page) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const hash = location.hash;
|
2019-01-02 09:44:45 +01:00
|
|
|
if (hash) {
|
|
|
|
$('#' + page + '-tabs.nav a[href="' + hash + '"]').tab('show');
|
|
|
|
$('html').scrollTop(0);
|
|
|
|
}
|
|
|
|
|
2019-02-27 12:50:03 +01:00
|
|
|
$('#' + page + '-tabs.nav-tabs a').on("click", function () {
|
2019-02-26 19:28:56 +01:00
|
|
|
location.hash = this.hash;
|
2019-01-09 11:09:15 +01:00
|
|
|
});
|
|
|
|
|
2019-02-27 12:51:01 +01:00
|
|
|
window.onhashchange = function () {
|
2019-02-26 19:28:56 +01:00
|
|
|
$('#' + page + '-tabs.nav a[href="' + location.hash + '"]').tab('show');
|
2019-01-02 09:44:45 +01:00
|
|
|
$('html').scrollTop(0);
|
2019-02-27 12:51:01 +01:00
|
|
|
};
|
2019-01-02 09:44:45 +01:00
|
|
|
};
|
|
|
|
|
2019-01-29 18:28:50 +01:00
|
|
|
exports.is_valid_input = function (elem) {
|
|
|
|
return elem[0].checkValidity();
|
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.helpers = exports;
|