From 2e4591b9ae142249af2b1ed3f49c36897aae7cad Mon Sep 17 00:00:00 2001 From: grafixeyehero Date: Wed, 9 Oct 2019 18:49:41 +0300 Subject: [PATCH] accessschedule --- .../accessschedule/accessschedule.js | 96 +++++++++++++------ 1 file changed, 67 insertions(+), 29 deletions(-) diff --git a/src/components/accessschedule/accessschedule.js b/src/components/accessschedule/accessschedule.js index cce626ae78..4733522d56 100644 --- a/src/components/accessschedule/accessschedule.js +++ b/src/components/accessschedule/accessschedule.js @@ -1,19 +1,33 @@ -define(["dialogHelper", "datetime", "emby-select", "paper-icon-button-light", "formDialogStyle"], function(dialogHelper, datetime) { +define(["dialogHelper", "datetime", "emby-select", "paper-icon-button-light", "formDialogStyle"], function (dialogHelper, datetime) { "use strict"; function getDisplayTime(hours) { - var minutes = 0, - pct = hours % 1; - return pct && (minutes = parseInt(60 * pct)), datetime.getDisplayTime(new Date(2e3, 1, 1, hours, minutes, 0, 0)) + var minutes = 0; + var pct = hours % 1; + + if (pct) { + minutes = parseInt(60 * pct); + } + + return datetime.getDisplayTime(new Date(2e3, 1, 1, hours, minutes, 0, 0)); } function populateHours(context) { - for (var html = "", i = 0; i < 24; i++) html += '"; - html += '", context.querySelector("#selectStart").innerHTML = html, context.querySelector("#selectEnd").innerHTML = html + var html = ""; + + for (var i = 0; i < 24; i++) { + html += '"; + } + + html += '"; + context.querySelector("#selectStart").innerHTML = html; + context.querySelector("#selectEnd").innerHTML = html; } function loadSchedule(context, schedule) { - context.querySelector("#selectDay").value = schedule.DayOfWeek || "Sunday", context.querySelector("#selectStart").value = schedule.StartHour || 0, context.querySelector("#selectEnd").value = schedule.EndHour || 0 + context.querySelector("#selectDay").value = schedule.DayOfWeek || "Sunday"; + context.querySelector("#selectStart").value = schedule.StartHour || 0; + context.querySelector("#selectEnd").value = schedule.EndHour || 0; } function submitSchedule(context, options) { @@ -22,30 +36,54 @@ define(["dialogHelper", "datetime", "emby-select", "paper-icon-button-light", "f StartHour: context.querySelector("#selectStart").value, EndHour: context.querySelector("#selectEnd").value }; - if (parseFloat(updatedSchedule.StartHour) >= parseFloat(updatedSchedule.EndHour)) return void alert(Globalize.translate("ErrorMessageStartHourGreaterThanEnd")); - context.submitted = !0, options.schedule = Object.assign(options.schedule, updatedSchedule), dialogHelper.close(context) + + if (parseFloat(updatedSchedule.StartHour) >= parseFloat(updatedSchedule.EndHour)) { + return void alert(Globalize.translate("ErrorMessageStartHourGreaterThanEnd")); + } + + context.submitted = true; + options.schedule = Object.assign(options.schedule, updatedSchedule); + dialogHelper.close(context); } + return { - show: function(options) { - return new Promise(function(resolve, reject) { - var xhr = new XMLHttpRequest; - xhr.open("GET", "components/accessschedule/accessschedule.template.html", !0), xhr.onload = function(e) { - var template = this.response, - dlg = dialogHelper.createDialog({ - removeOnClose: !0, - size: "small" - }); + show: function (options) { + return new Promise(function (resolve, reject) { + var xhr = new XMLHttpRequest(); + xhr.open("GET", "components/accessschedule/accessschedule.template.html", true); + + xhr.onload = function (e) { + var template = this.response; + var dlg = dialogHelper.createDialog({ + removeOnClose: true, + size: "small" + }); dlg.classList.add("formDialog"); var html = ""; - html += Globalize.translateDocument(template), dlg.innerHTML = html, populateHours(dlg), loadSchedule(dlg, options.schedule), dialogHelper.open(dlg), dlg.addEventListener("close", function() { - dlg.submitted ? resolve(options.schedule) : reject() - }), dlg.querySelector(".btnCancel").addEventListener("click", function(e) { - dialogHelper.close(dlg) - }), dlg.querySelector("form").addEventListener("submit", function(e) { - return submitSchedule(dlg, options), e.preventDefault(), !1 - }) - }, xhr.send() - }) + html += Globalize.translateDocument(template); + dlg.innerHTML = html; + populateHours(dlg); + loadSchedule(dlg, options.schedule); + dialogHelper.open(dlg); + dlg.addEventListener("close", function () { + if (dlg.submitted) { + resolve(options.schedule); + } else { + reject(); + } + }); + dlg.querySelector(".btnCancel").addEventListener("click", function (e) { + dialogHelper.close(dlg); + }); + dlg.querySelector("form").addEventListener("submit", function (e) { + submitSchedule(dlg, options); + e.preventDefault(); + return false; + }); + }; + + xhr.send(); + }); } - } -}); \ No newline at end of file + }; +});