mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
accessSchedule
This commit is contained in:
parent
b58af64350
commit
2cd9be9321
2 changed files with 62 additions and 53 deletions
|
@ -89,6 +89,7 @@
|
||||||
"overrides": [
|
"overrides": [
|
||||||
{
|
{
|
||||||
"test": [
|
"test": [
|
||||||
|
"src/components/accessSchedule/accessSchedule.js",
|
||||||
"src/components/actionSheet/actionSheet.js",
|
"src/components/actionSheet/actionSheet.js",
|
||||||
"src/components/autoFocuser.js",
|
"src/components/autoFocuser.js",
|
||||||
"src/components/cardbuilder/cardBuilder.js",
|
"src/components/cardbuilder/cardBuilder.js",
|
||||||
|
|
|
@ -1,9 +1,20 @@
|
||||||
define(['dialogHelper', 'datetime', 'globalize', 'emby-select', 'paper-icon-button-light', 'formDialogStyle'], function (dialogHelper, datetime, globalize) {
|
/* eslint-disable indent */
|
||||||
'use strict';
|
|
||||||
|
/**
|
||||||
|
* Module for controlling user parental control from.
|
||||||
|
* @module components/accessSchedule/accessSchedule
|
||||||
|
*/
|
||||||
|
|
||||||
|
import dialogHelper from 'dialogHelper';
|
||||||
|
import datetime from 'datetime';
|
||||||
|
import globalize from 'globalize';
|
||||||
|
import 'emby-select';
|
||||||
|
import 'paper-icon-button-light';
|
||||||
|
import 'formDialogStyle';
|
||||||
|
|
||||||
function getDisplayTime(hours) {
|
function getDisplayTime(hours) {
|
||||||
var minutes = 0;
|
let minutes = 0;
|
||||||
var pct = hours % 1;
|
const pct = hours % 1;
|
||||||
|
|
||||||
if (pct) {
|
if (pct) {
|
||||||
minutes = parseInt(60 * pct);
|
minutes = parseInt(60 * pct);
|
||||||
|
@ -13,25 +24,25 @@ define(['dialogHelper', 'datetime', 'globalize', 'emby-select', 'paper-icon-butt
|
||||||
}
|
}
|
||||||
|
|
||||||
function populateHours(context) {
|
function populateHours(context) {
|
||||||
var html = '';
|
let html = '';
|
||||||
|
|
||||||
for (var i = 0; i < 24; i++) {
|
for (let i = 0; i < 24; i++) {
|
||||||
html += '<option value="' + i + '">' + getDisplayTime(i) + '</option>';
|
html += `<option value="${i}">${getDisplayTime(i)}</option>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
html += '<option value="24">' + getDisplayTime(0) + '</option>';
|
html += `<option value="24">${getDisplayTime(0)}</option>`;
|
||||||
context.querySelector('#selectStart').innerHTML = html;
|
context.querySelector('#selectStart').innerHTML = html;
|
||||||
context.querySelector('#selectEnd').innerHTML = html;
|
context.querySelector('#selectEnd').innerHTML = html;
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadSchedule(context, schedule) {
|
function loadSchedule(context, {DayOfWeek, StartHour, EndHour}) {
|
||||||
context.querySelector('#selectDay').value = schedule.DayOfWeek || 'Sunday';
|
context.querySelector('#selectDay').value = DayOfWeek || 'Sunday';
|
||||||
context.querySelector('#selectStart').value = schedule.StartHour || 0;
|
context.querySelector('#selectStart').value = StartHour || 0;
|
||||||
context.querySelector('#selectEnd').value = schedule.EndHour || 0;
|
context.querySelector('#selectEnd').value = EndHour || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitSchedule(context, options) {
|
function submitSchedule(context, options) {
|
||||||
var updatedSchedule = {
|
const updatedSchedule = {
|
||||||
DayOfWeek: context.querySelector('#selectDay').value,
|
DayOfWeek: context.querySelector('#selectDay').value,
|
||||||
StartHour: context.querySelector('#selectStart').value,
|
StartHour: context.querySelector('#selectStart').value,
|
||||||
EndHour: context.querySelector('#selectEnd').value
|
EndHour: context.querySelector('#selectEnd').value
|
||||||
|
@ -46,44 +57,41 @@ define(['dialogHelper', 'datetime', 'globalize', 'emby-select', 'paper-icon-butt
|
||||||
dialogHelper.close(context);
|
dialogHelper.close(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
export function show(options) {
|
||||||
show: function (options) {
|
return new Promise((resolve, reject) => {
|
||||||
return new Promise(function (resolve, reject) {
|
require(['text!./components/accessSchedule/accessSchedule.template.html'], template => {
|
||||||
var xhr = new XMLHttpRequest();
|
const dlg = dialogHelper.createDialog({
|
||||||
xhr.open('GET', 'components/accessSchedule/accessSchedule.template.html', true);
|
|
||||||
|
|
||||||
xhr.onload = function (e) {
|
|
||||||
var template = this.response;
|
|
||||||
var dlg = dialogHelper.createDialog({
|
|
||||||
removeOnClose: true,
|
removeOnClose: true,
|
||||||
size: 'small'
|
size: 'small'
|
||||||
});
|
});
|
||||||
dlg.classList.add('formDialog');
|
dlg.classList.add('formDialog');
|
||||||
var html = '';
|
let html = '';
|
||||||
html += globalize.translateDocument(template);
|
html += globalize.translateDocument(template);
|
||||||
dlg.innerHTML = html;
|
dlg.innerHTML = html;
|
||||||
populateHours(dlg);
|
populateHours(dlg);
|
||||||
loadSchedule(dlg, options.schedule);
|
loadSchedule(dlg, options.schedule);
|
||||||
dialogHelper.open(dlg);
|
dialogHelper.open(dlg);
|
||||||
dlg.addEventListener('close', function () {
|
dlg.addEventListener('close', () => {
|
||||||
if (dlg.submitted) {
|
if (dlg.submitted) {
|
||||||
resolve(options.schedule);
|
resolve(options.schedule);
|
||||||
} else {
|
} else {
|
||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
dlg.querySelector('.btnCancel').addEventListener('click', function () {
|
dlg.querySelector('.btnCancel').addEventListener('click', () => {
|
||||||
dialogHelper.close(dlg);
|
dialogHelper.close(dlg);
|
||||||
});
|
});
|
||||||
dlg.querySelector('form').addEventListener('submit', function (event) {
|
dlg.querySelector('form').addEventListener('submit', event => {
|
||||||
submitSchedule(dlg, options);
|
submitSchedule(dlg, options);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
|
||||||
xhr.send();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
|
||||||
});
|
/* eslint-enable indent */
|
||||||
|
|
||||||
|
export default {
|
||||||
|
show: show
|
||||||
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue