dashboard-ui/components/accessschedule/accessschedule.js
2023-08-31 15:30:17 +02:00

1 line
2.5 KiB
JavaScript

define(["exports","./../../modules/common/globalize.js","./../../modules/dialoghelper/dialoghelper.js","./../../modules/common/datetime.js","./../../modules/emby-elements/emby-button/paper-icon-button-light.js","./../../modules/emby-elements/emby-select/emby-select.js"],function(_exports,_globalize,_dialoghelper,_datetime,_paperIconButtonLight,_embySelect){function getDisplayTime(hours){var minutes=0,pct=hours%1;return pct&&(minutes=parseInt(60*pct)),_datetime.default.getDisplayTime(new Date(2e3,1,1,hours,minutes,0,0))}function submitSchedule(context,options){var updatedSchedule={DayOfWeek:context.querySelector("#selectDay").value,StartHour:context.querySelector("#selectStart").value,EndHour:context.querySelector("#selectEnd").value};parseFloat(updatedSchedule.StartHour)>=parseFloat(updatedSchedule.EndHour)?function(options){Emby.importModule("./modules/common/dialogs/alert.js").then(function(alert){return alert(options)})}(_globalize.default.translate("ErrorMessageStartHourGreaterThanEnd")):(context.submitted=!0,options.schedule=Object.assign(options.schedule,updatedSchedule),_dialoghelper.default.close(context))}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,require(["formDialogStyle"]),_exports.default={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.default.createDialog({removeOnClose:!0,size:"small"}),html=(dlg.classList.add("formDialog"),"");html+=_globalize.default.translateDocument(template),dlg.innerHTML=html,function(context){for(var html="",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}(dlg),template=dlg,html=options.schedule,template.querySelector("#selectDay").value=html.DayOfWeek||"Sunday",template.querySelector("#selectStart").value=html.StartHour||0,template.querySelector("#selectEnd").value=html.EndHour||0,_dialoghelper.default.open(dlg),dlg.addEventListener("close",function(){dlg.submitted?resolve(options.schedule):reject()}),dlg.querySelector(".btnCancel").addEventListener("click",function(e){_dialoghelper.default.close(dlg)}),dlg.querySelector("form").addEventListener("submit",function(e){return submitSchedule(dlg,options),e.preventDefault(),!1})},xhr.send()})}}});