text: !function(){"use strict";function e(){this.filterResults=[],this.filterLimit=20}e.prototype.bindEventHandlers=function(){$("#admins").on("submit","#filter-admins form",function(e){e.preventDefault();e=$("#filter-admins .key").val();$("#filter-admins .selected").removeClass("selected"),this.resetForm(),this.filter(e)}.bind(this)),$("#admins").on("click","#filter-admins .clear",function(){this.filter(""),$("#filter-admins .key").val(""),this.resetForm()}.bind(this)),$("#admins").on("click",".admin-row",function(e){var i,a;$("#filter-admins .filter").prop("disabled")?$("#filter-admins .results").css("color","#AAA"):(i=$(e.currentTarget).attr("data-id"),a=this.filterResults.find(function(e){return Number(e.id)===Number(i)}),this.display(a),$("#filter-admins .selected").removeClass("selected"),$(e.currentTarget).addClass("selected"),$("#edit-admin, #delete-admin").prop("disabled",!1))}.bind(this)),$("#admins").on("click","#add-admin",function(){this.resetForm(),$("#admins .add-edit-delete-group").hide(),$("#admins .save-cancel-group").show(),$("#admins .record-details").find("input, textarea").prop("disabled",!1),$("#admins .record-details").find("select").prop("disabled",!1),$("#admin-password, #admin-password-confirm").addClass("required"),$("#filter-admins button").prop("disabled",!0),$("#filter-admins .results").css("color","#AAA")}.bind(this)),$("#admins").on("click","#edit-admin",function(){$("#admins .add-edit-delete-group").hide(),$("#admins .save-cancel-group").show(),$("#admins .record-details").find("input, textarea").prop("disabled",!1),$("#admins .record-details").find("select").prop("disabled",!1),$("#admin-password, #admin-password-confirm").removeClass("required"),$("#filter-admins button").prop("disabled",!0),$("#filter-admins .results").css("color","#AAA")}),$("#admins").on("click","#delete-admin",function(){var e=$("#admin-id").val(),i=[{text:EALang.cancel,click:function(){$("#message-box").dialog("close")}},{text:EALang.delete,click:function(){this.delete(e),$("#message-box").dialog("close")}.bind(this)}];GeneralFunctions.displayMessageBox(EALang.delete_admin,EALang.delete_record_prompt,i)}.bind(this)),$("#admins").on("click","#save-admin",function(){var e={first_name:$("#admin-first-name").val(),last_name:$("#admin-last-name").val(),email:$("#admin-email").val(),mobile_number:$("#admin-mobile-number").val(),phone_number:$("#admin-phone-number").val(),address:$("#admin-address").val(),city:$("#admin-city").val(),state:$("#admin-state").val(),zip_code:$("#admin-zip-code").val(),notes:$("#admin-notes").val(),timezone:$("#admin-timezone").val(),settings:{username:$("#admin-username").val(),notifications:$("#admin-notifications").prop("checked"),calendar_view:$("#admin-calendar-view").val()}};""!==$("#admin-password").val()&&(e.settings.password=$("#admin-password").val()),""!==$("#admin-id").val()&&(e.id=$("#admin-id").val()),this.validate()&&this.save(e)}.bind(this)),$("#admins").on("click","#cancel-admin",function(){var e=$("#admin-id").val();this.resetForm(),e&&this.select(e,!0)}.bind(this))},e.prototype.unbindEventHandlers=function(){$("#admins").off("submit","#filter-admins form").off("click","#filter-admins .clear").off("click",".admin-row").off("click","#add-admin").off("click","#edit-admin").off("click","#delete-admin").off("click","#save-admin").off("click","#cancel-admin")},e.prototype.save=function(e){var i=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_save_admin",e={csrfToken:GlobalVariables.csrfToken,admin:JSON.stringify(e)};$.post(i,e).done(function(e){Backend.displayNotification(EALang.admin_saved),this.resetForm(),$("#filter-admins .key").val(""),this.filter("",e.id,!0)}.bind(this))},e.prototype.delete=function(e){var i=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_delete_admin",e={csrfToken:GlobalVariables.csrfToken,admin_id:e};$.post(i,e).done(function(e){Backend.displayNotification(EALang.admin_deleted),this.resetForm(),this.filter($("#filter-admins .key").val())}.bind(this))},e.prototype.validate=function(){$("#admins .has-error").removeClass("has-error");try{var a=!1;if($("#admins .required").each(function(e,i){$(i).val()||($(i).closest(".form-group").addClass("has-error"),a=!0)}),a)throw new Error("Fields with * are  required.");if($("#admin-password").val()!==$("#admin-password-confirm").val())throw $("#admin-password, #admin-password-confirm").closest(".form-group").addClass("has-error"),new Error(EALang.passwords_mismatch);if($("#admin-password").val().length<BackendUsers.MIN_PASSWORD_LENGTH&&""!==$("#admin-password").val())throw $("#admin-password, #admin-password-confirm").closest(".form-group").addClass("has-error"),new Error(EALang.password_length_notice.replace("$number",BackendUsers.MIN_PASSWORD_LENGTH));if(!GeneralFunctions.validateEmail($("#admin-email").val()))throw $("#admin-email").closest(".form-group").addClass("has-error"),new Error(EALang.invalid_email);if("true"===$("#admin-username").attr("already-exists"))throw $("#admin-username").closest(".form-group").addClass("has-error"),new Error(EALang.username_already_exists);return!0}catch(e){return $("#admins .form-message").addClass("alert-danger").text(e.message).show(),!1}},e.prototype.resetForm=function(){$("#filter-admins .selected").removeClass("selected"),$("#filter-admins button").prop("disabled",!1),$("#filter-admins .results").css("color",""),$("#admins .add-edit-delete-group").show(),$("#admins .save-cancel-group").hide(),$("#admins .record-details").find("input, select, textarea").val("").prop("disabled",!0),$("#admins .record-details #admin-calendar-view").val("default"),$("#admins .record-details #admin-timezone").val("UTC"),$("#edit-admin, #delete-admin").prop("disabled",!0),$("#admins .has-error").removeClass("has-error"),$("#admins .form-message").hide()},e.prototype.display=function(e){$("#admin-id").val(e.id),$("#admin-first-name").val(e.first_name),$("#admin-last-name").val(e.last_name),$("#admin-email").val(e.email),$("#admin-mobile-number").val(e.mobile_number),$("#admin-phone-number").val(e.phone_number),$("#admin-address").val(e.address),$("#admin-city").val(e.city),$("#admin-state").val(e.state),$("#admin-zip-code").val(e.zip_code),$("#admin-notes").val(e.notes),$("#admin-timezone").val(e.timezone),$("#admin-username").val(e.settings.username),$("#admin-calendar-view").val(e.settings.calendar_view),$("#admin-notifications").prop("checked",Boolean(Number(e.settings.notifications)))},e.prototype.filter=function(i,a,n){n=n||!1;var e=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_filter_admins",s={csrfToken:GlobalVariables.csrfToken,key:i,limit:this.filterLimit};$.post(e,s).done(function(e){this.filterResults=e,$("#filter-admins .results").empty(),e.forEach(function(e){$("#filter-admins .results").append(this.getFilterHtml(e)).append($("<hr/>"))}.bind(this)),e.length?e.length===this.filterLimit&&$("<button/>",{type:"button",class:"btn btn-block btn-outline-secondary load-more text-center",text:EALang.load_more,click:function(){this.filterLimit+=20,this.filter(i,a,n)}.bind(this)}).appendTo("#filter-admins .results"):$("#filter-admins .results").append($("<em/>",{text:EALang.no_records_found})),a&&this.select(a,n)}.bind(this))},e.prototype.getFilterHtml=function(e){var i=e.first_name+" "+e.last_name,a=e.email,a=e.mobile_number?a+", "+e.mobile_number:a;return a=e.phone_number?a+", "+e.phone_number:a,$("<div/>",{class:"admin-row entry","data-id":e.id,html:[$("<strong/>",{text:i}),$("<br/>"),$("<span/>",{text:a}),$("<br/>")]})},e.prototype.select=function(i,e){e=e||!1,$("#filter-admins .selected").removeClass("selected"),$('#filter-admins .admin-row[data-id="'+i+'"]').addClass("selected"),e&&(e=this.filterResults.find(function(e){return Number(e.id)===Number(i)}),this.display(e),$("#edit-admin, #delete-admin").prop("disabled",!1))},window.AdminsHelper=e}();