$(document).ready((function(){function t(t){var e={};return t.parents(".panel-body").eq(0).find("input.form-control").each((function(){this.name&&("number"==this.type?(e[this.name]=parseInt($.trim(this.value)),isNaN(e[this.name])&&(this.getAttribute("data-value")?e[this.name]=parseInt(this.getAttribute("data-value")):e[this.name]=0)):e[this.name]=$.trim(this.value))})),null!=e["email_title"]&&(e["email_body"]=$("#suneditor-email_body").val()),e}function e(t){for(var e=t+"=",n=decodeURIComponent(document.cookie),a=n.split(";"),o=0;o<a.length;o++){var s=a[o];while(" "==s.charAt(0))s=s.substring(1);if(0==s.indexOf(e))return s.substring(e.length,s.length)}return""}$("#setting_tab").addClass("active"),toastr.options={positionClass:"toast-bottom-right"};var n=e("_apitoken"),a=e("asset_url"),o=a+"/api";if(!n)return toastr.error(loginLangText),"";function s(t,e,a,s){"function"==typeof a&&(s=a,a=!1);var i={Authorization:"Bearer "+n};a&&(e||(e={}),e["__tcms_model_binding"]=a),0!==t.indexOf("/")&&(t="/"+t),$.ajax({url:o+t,async:!0,type:"POST",data:e,dataType:"json",headers:i,timeout:3e4,success:function(t){s&&s(!1,t)},error:function(t){t.status&&(t.responseText?toastr.error("["+t.status+"] "+t.responseText):toastr.error("["+t.status+"] "+t.statusText)),s&&s(!0)}})}function i(t,e,a){"function"==typeof e?(a=e,e={}):e=e||{},$.ajax({url:o+"/"+t,async:!0,type:"GET",dataType:"json",data:e,headers:{Authorization:"Bearer "+n},timeout:3e4,success:function(t){a&&a(!1,t)},error:function(t){t.status&&(t.responseText?toastr.error("["+t.status+"] "+t.responseText):toastr.error("["+t.status+"] "+t.statusText)),a&&a(!0)}})}function r(e){var n=e;$("form").find("input.form-control").each((function(){"undefined"!==typeof n[this.name]&&(this.value=n[this.name])})),$("#suneditor-email_body").val("undefined"!==typeof n["email_body"]?n["email_body"]:"").trigger("change");var o=document.createElement("script");o.src=a+"/suneditor/suneditor-extension2.js",o.type="text/javascript",document.body.appendChild(o),$("form").on("submit",(function(e){e.preventDefault(),e.stopPropagation(),window["saveEditor"]();var a=$(document.activeElement);a.prop("disabled",!0).addClass("busy3");var o=t(a),i=!1;for(var r in o)if(n[r]!=o[r]){i=!0;break}return i?("undefined"!==typeof o["email_body"]&&o["email_body"]==n["email_body"]&&delete o["email_body"],s("/floor-manager/setting",o,"FloorManagerSettingModel",(function(t,e){if(a.prop("disabled",!1).removeClass("busy3"),!t&&"object"==typeof e&&e.success){for(var s in toastr.success(saveSuccessLangText),o)n[s]=o[s];d.settingChanged()}}))):a.prop("disabled",!1).removeClass("busy3"),!1}))}function u(){this.listen=function(){},this.settingChanged=function(){socketManager.emit("setting_changed",!0)}}var d=new u;i("floor-manager/setting",(function(t,e){t||r(e)}))}));