mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
accessschedule
This commit is contained in:
parent
3b7facd073
commit
2e4591b9ae
1 changed files with 67 additions and 29 deletions
|
@ -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";
|
"use strict";
|
||||||
|
|
||||||
function getDisplayTime(hours) {
|
function getDisplayTime(hours) {
|
||||||
var minutes = 0,
|
var minutes = 0;
|
||||||
pct = hours % 1;
|
var pct = hours % 1;
|
||||||
return pct && (minutes = parseInt(60 * pct)), datetime.getDisplayTime(new Date(2e3, 1, 1, hours, minutes, 0, 0))
|
|
||||||
|
if (pct) {
|
||||||
|
minutes = parseInt(60 * pct);
|
||||||
|
}
|
||||||
|
|
||||||
|
return datetime.getDisplayTime(new Date(2e3, 1, 1, hours, minutes, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
function populateHours(context) {
|
function populateHours(context) {
|
||||||
for (var html = "", i = 0; i < 24; i++) html += '<option value="' + i + '">' + getDisplayTime(i) + "</option>";
|
var html = "";
|
||||||
html += '<option value="24">' + getDisplayTime(0) + "</option>", context.querySelector("#selectStart").innerHTML = html, context.querySelector("#selectEnd").innerHTML = html
|
|
||||||
|
for (var i = 0; i < 24; i++) {
|
||||||
|
html += '<option value="' + i + '">' + getDisplayTime(i) + "</option>";
|
||||||
|
}
|
||||||
|
|
||||||
|
html += '<option value="24">' + getDisplayTime(0) + "</option>";
|
||||||
|
context.querySelector("#selectStart").innerHTML = html;
|
||||||
|
context.querySelector("#selectEnd").innerHTML = html;
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadSchedule(context, schedule) {
|
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) {
|
function submitSchedule(context, options) {
|
||||||
|
@ -22,30 +36,54 @@ define(["dialogHelper", "datetime", "emby-select", "paper-icon-button-light", "f
|
||||||
StartHour: context.querySelector("#selectStart").value,
|
StartHour: context.querySelector("#selectStart").value,
|
||||||
EndHour: context.querySelector("#selectEnd").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 {
|
return {
|
||||||
show: function(options) {
|
show: function (options) {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
var xhr = new XMLHttpRequest;
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.open("GET", "components/accessschedule/accessschedule.template.html", !0), xhr.onload = function(e) {
|
xhr.open("GET", "components/accessschedule/accessschedule.template.html", true);
|
||||||
var template = this.response,
|
|
||||||
dlg = dialogHelper.createDialog({
|
xhr.onload = function (e) {
|
||||||
removeOnClose: !0,
|
var template = this.response;
|
||||||
size: "small"
|
var dlg = dialogHelper.createDialog({
|
||||||
});
|
removeOnClose: true,
|
||||||
|
size: "small"
|
||||||
|
});
|
||||||
dlg.classList.add("formDialog");
|
dlg.classList.add("formDialog");
|
||||||
var html = "";
|
var html = "";
|
||||||
html += Globalize.translateDocument(template), dlg.innerHTML = html, populateHours(dlg), loadSchedule(dlg, options.schedule), dialogHelper.open(dlg), dlg.addEventListener("close", function() {
|
html += Globalize.translateDocument(template);
|
||||||
dlg.submitted ? resolve(options.schedule) : reject()
|
dlg.innerHTML = html;
|
||||||
}), dlg.querySelector(".btnCancel").addEventListener("click", function(e) {
|
populateHours(dlg);
|
||||||
dialogHelper.close(dlg)
|
loadSchedule(dlg, options.schedule);
|
||||||
}), dlg.querySelector("form").addEventListener("submit", function(e) {
|
dialogHelper.open(dlg);
|
||||||
return submitSchedule(dlg, options), e.preventDefault(), !1
|
dlg.addEventListener("close", function () {
|
||||||
})
|
if (dlg.submitted) {
|
||||||
}, xhr.send()
|
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();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue