You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
easyappointments-archive/assets/js/working_plan.min.js

1 line
10 KiB

!function(){"use strict";function t(){this.enableCancel=!1,this.enableSubmit=!1}t.prototype.setup=function(t){var e=GeneralFunctions.getWeekDayId(GlobalVariables.firstWeekday),a=GeneralFunctions.sortWeekDictionary(t,e);$(".working-plan tbody").empty(),$(".breaks tbody").empty();var r="regular"===GlobalVariables.timeFormat?"h:mm tt":"HH:mm";$.each(a,function(t,e){var a=this.convertValueToDay(t),n=GeneralFunctions.upperCaseFirstLetter(a);$("<tr/>",{html:[$("<td/>",{html:[$("<div/>",{class:"checkbox form-check",html:[$("<input/>",{class:"form-check-input",type:"checkbox",id:t}),$("<label/>",{class:"form-check-label",text:n,for:t})]})]}),$("<td/>",{html:[$("<input/>",{id:t+"-start",class:"work-start form-control input-sm"})]}),$("<td/>",{html:[$("<input/>",{id:t+"-end",class:"work-start form-control input-sm"})]})]}).appendTo(".working-plan tbody"),e?($("#"+t).prop("checked",!0),$("#"+t+"-start").val(Date.parse(e.start).toString(r).toUpperCase()),$("#"+t+"-end").val(Date.parse(e.end).toString(r).toUpperCase()),e.breaks.sort(function(t,e){return t.start.localeCompare(e.start)}),e.breaks.forEach(function(t){$("<tr/>",{html:[$("<td/>",{class:"break-day editable",text:n}),$("<td/>",{class:"break-start editable",text:Date.parse(t.start).toString(r).toUpperCase()}),$("<td/>",{class:"break-end editable",text:Date.parse(t.end).toString(r).toUpperCase()}),$("<td/>",{html:[$("<button/>",{type:"button",class:"btn btn-outline-secondary btn-sm edit-break",title:EALang.edit,html:[$("<span/>",{class:"fas fa-edit"})]}),$("<button/>",{type:"button",class:"btn btn-outline-secondary btn-sm delete-break",title:EALang.delete,html:[$("<span/>",{class:"fas fa-trash-alt"})]}),$("<button/>",{type:"button",class:"btn btn-outline-secondary btn-sm save-break d-none",title:EALang.save,html:[$("<span/>",{class:"fas fa-check-circle"})]}),$("<button/>",{type:"button",class:"btn btn-outline-secondary btn-sm cancel-break d-none",title:EALang.cancel,html:[$("<span/>",{class:"fas fa-ban"})]})]})]}).appendTo(".breaks tbody")})):($("#"+t).prop("checked",!1),$("#"+t+"-start").prop("disabled",!0),$("#"+t+"-end").prop("disabled",!0))}.bind(this)),this.editableDayCell($(".breaks .break-day")),this.editableTimeCell($(".breaks").find(".break-start, .break-end"))},t.prototype.setupWorkingPlanExceptions=function(t){for(var e in t){var a=t[e];this.renderWorkingPlanExceptionRow(e,a).appendTo(".working-plan-exceptions tbody")}},t.prototype.editableDayCell=function(t){var e={};e[EALang.sunday]=EALang.sunday,e[EALang.monday]=EALang.monday,e[EALang.tuesday]=EALang.tuesday,e[EALang.wednesday]=EALang.wednesday,e[EALang.thursday]=EALang.thursday,e[EALang.friday]=EALang.friday,e[EALang.saturday]=EALang.saturday,t.editable(function(t,e){return t},{type:"select",data:e,event:"edit",height:"30px",submit:'<button type="button" class="d-none submit-editable">Submit</button>',cancel:'<button type="button" class="d-none cancel-editable">Cancel</button>',onblur:"ignore",onreset:function(t,e){if(!this.enableCancel)return!1}.bind(this),onsubmit:function(t,e){if(!this.enableSubmit)return!1}.bind(this)})},t.prototype.editableTimeCell=function(t){t.editable(function(t,e){return t},{event:"edit",height:"30px",submit:$("<button/>",{type:"button",class:"d-none submit-editable",text:EALang.save}).get(0).outerHTML,cancel:$("<button/>",{type:"button",class:"d-none cancel-editable",text:EALang.cancel}).get(0).outerHTML,onblur:"ignore",onreset:function(t,e){if(!this.enableCancel)return!1}.bind(this),onsubmit:function(t,e){if(!this.enableSubmit)return!1}.bind(this)})},t.prototype.renderWorkingPlanExceptionRow=function(t,e){var a="regular"===GlobalVariables.timeFormat?"h:mm tt":"HH:mm";return $("<tr/>",{data:{date:t,workingPlanException:e},html:[$("<td/>",{class:"working-plan-exception-date",text:GeneralFunctions.formatDate(t,GlobalVariables.dateFormat,!1)}),$("<td/>",{class:"working-plan-exception--start",text:Date.parse(e.start).toString(a)}),$("<td/>",{class:"working-plan-exception--end",text:Date.parse(e.end).toString(a)}),$("<td/>",{html:[$("<button/>",{type:"button",class:"btn btn-outline-secondary btn-sm edit-working-plan-exception",title:EALang.edit,html:[$("<span/>",{class:"fas fa-edit"})]}),$("<button/>",{type:"button",class:"btn btn-outline-secondary btn-sm delete-working-plan-exception",title:EALang.delete,html:[$("<span/>",{class:"fas fa-trash-alt"})]})]})]})},t.prototype.bindEventHandlers=function(){$(".working-plan tbody").on("click","input:checkbox",function(){var t=$(this).attr("id");!0===$(this).prop("checked")?($("#"+t+"-start").prop("disabled",!1).val("9:00 AM"),$("#"+t+"-end").prop("disabled",!1).val("6:00 PM")):($("#"+t+"-start").prop("disabled",!0).val(""),$("#"+t+"-end").prop("disabled",!0).val(""))}),$(".add-break").on("click",function(){var t="regular"===GlobalVariables.timeFormat?"h:mm tt":"HH:mm",e=$("<tr/>",{html:[$("<td/>",{class:"break-day editable",text:EALang.sunday}),$("<td/>",{class:"break-start editable",text:Date.parse("12:00:00").toString(t)}),$("<td/>",{class:"break-end editable",text:Date.parse("14:00:00").toString(t)}),$("<td/>",{html:[$("<button/>",{type:"button",class:"btn btn-outline-secondary btn-sm edit-break",title:EALang.edit,html:[$("<span/>",{class:"fas fa-edit"})]}),$("<button/>",{type:"button",class:"btn btn-outline-secondary btn-sm delete-break",title:EALang.delete,html:[$("<span/>",{class:"fas fa-trash-alt"})]}),$("<button/>",{type:"button",class:"btn btn-outline-secondary btn-sm save-break d-none",title:EALang.save,html:[$("<span/>",{class:"fas fa-check-circle"})]}),$("<button/>",{type:"button",class:"btn btn-outline-secondary btn-sm cancel-break d-none",title:EALang.cancel,html:[$("<span/>",{class:"fas fa-ban"})]})]})]}).appendTo(".breaks tbody");this.editableDayCell(e.find(".break-day")),this.editableTimeCell(e.find(".break-start, .break-end")),e.find(".edit-break").trigger("click"),$(".add-break").prop("disabled",!0)}.bind(this)),$(document).on("click",".edit-break",function(){$(this).closest("table").find(".editable").each(function(t,e){e.reset&&e.reset()}),$(this).parent().parent().children().trigger("edit"),$(this).parent().parent().find(".break-start input, .break-end input").timepicker({timeFormat:"regular"===GlobalVariables.timeFormat?"h:mm TT":"HH:mm",currentText:EALang.now,closeText:EALang.close,timeOnlyTitle:EALang.select_time,timeText:EALang.time,hourText:EALang.hour,minuteText:EALang.minutes}),$(this).parent().parent().find(".break-day select").focus();var t=$(this).closest("tr");t.find(".edit-break, .delete-break").addClass("d-none"),t.find(".save-break, .cancel-break").removeClass("d-none"),t.find("select,input:text").addClass("form-control input-sm"),$(".add-break").prop("disabled",!0)}),$(document).on("click",".delete-break",function(){$(this).parent().parent().remove()}),$(document).on("click",".cancel-break",function(t){var e=t.target,a=$(e).closest("tr");this.enableCancel=!0,a.find(".cancel-editable").trigger("click"),this.enableCancel=!1,$(e).closest("table").find(".edit-break, .delete-break").removeClass("d-none"),a.find(".save-break, .cancel-break").addClass("d-none"),$(".add-break").prop("disabled",!1)}.bind(this)),$(document).on("click",".save-break",function(t){var e=t.target,a=$(e).closest("tr"),n=Date.parse(a.find(".break-start input").val());Date.parse(a.find(".break-end input").val())<n&&a.find(".break-end input").val(n.addHours(1).toString("regular"===GlobalVariables.timeFormat?"h:mm tt":"HH:mm")),this.enableSubmit=!0,a.find(".editable .submit-editable").trigger("click"),this.enableSubmit=!1,a.find(".save-break, .cancel-break").addClass("d-none"),$(e).closest("table").find(".edit-break, .delete-break").removeClass("d-none"),$(".add-break").prop("disabled",!1);var r=this.get();this.setup(r)}.bind(this)),$(document).on("click",".add-working-plan-exception",function(){WorkingPlanExceptionsModal.add().done(function(a,t){var n=null;$(".working-plan-exceptions tbody tr").each(function(t,e){if(a===$(e).data("date"))return n=$(e),!1});var e=this.renderWorkingPlanExceptionRow(a,t);n?n.replaceWith(e):e.appendTo(".working-plan-exceptions tbody")}.bind(this))}.bind(this)),$(document).on("click",".edit-working-plan-exception",function(t){var a=$(t.target).closest("tr"),e=a.data("date"),n=a.data("workingPlanException");WorkingPlanExceptionsModal.edit(e,n).done(function(t,e){a.replaceWith(this.renderWorkingPlanExceptionRow(t,e))}.bind(this))}.bind(this)),$(document).on("click",".delete-working-plan-exception",function(){$(this).closest("tr").remove()})},t.prototype.get=function(){var i={};return $(".working-plan input:checkbox").each(function(t,e){var r=$(e).attr("id");!0===$(e).prop("checked")?(i[r]={start:Date.parse($("#"+r+"-start").val()).toString("HH:mm"),end:Date.parse($("#"+r+"-end").val()).toString("HH:mm"),breaks:[]},$(".breaks tr").each(function(t,e){var a,n;this.convertDayToValue($(e).find(".break-day").text())===r&&(a=$(e).find(".break-start").text(),n=$(e).find(".break-end").text(),i[r].breaks.push({start:Date.parse(a).toString("HH:mm"),end:Date.parse(n).toString("HH:mm")}))}.bind(this)),i[r].breaks.sort(function(t,e){return t.start.localeCompare(e.start)})):i[r]=null}.bind(this)),i},t.prototype.getWorkingPlanExceptions=function(){var r={};return $(".working-plan-exceptions tbody tr").each(function(t,e){var a=$(e),n=a.data("date");r[n]=a.data("workingPlanException")}),r},t.prototype.timepickers=function(t){!1===(t=t||!1)?$(".working-plan input:text").timepicker({timeFormat:"regular"===GlobalVariables.timeFormat?"h:mm TT":"HH:mm",currentText:EALang.now,closeText:EALang.close,timeOnlyTitle:EALang.select_time,timeText:EALang.time,hourText:EALang.hour,minuteText:EALang.minutes,onSelect:function(t,e){var a=Date.parse($(this).parent().parent().find(".work-start").val());Date.parse($(this).parent().parent().find(".work-end").val())<a&&$(this).parent().parent().find(".work-end").val(a.addHours(1).toString("regular"===GlobalVariables.timeFormat?"h:mm tt":"HH:mm"))}}):$(".working-plan input").timepicker("destroy")},t.prototype.reset=function(){},t.prototype.convertValueToDay=function(t){switch(t){case"sunday":return EALang.sunday;case"monday":return EALang.monday;case"tuesday":return EALang.tuesday;case"wednesday":return EALang.wednesday;case"thursday":return EALang.thursday;case"friday":return EALang.friday;case"saturday":return EALang.saturday}},t.prototype.convertDayToValue=function(t){switch(t){case EALang.sunday:return"sunday";case EALang.monday:return"monday";case EALang.tuesday:return"tuesday";case EALang.wednesday:return"wednesday";case EALang.thursday:return"thursday";case EALang.friday:return"friday";case EALang.saturday:return"saturday"}},window.WorkingPlan=t}();