!function(e){var a=new function(){var a=this;a.width=ko.observable(e("#main").outerWidth()),a.message={save:function(){a.message.loading||a.message.hasErrors()||e.ajax({url:"../../admin/alert/messages/update",data:e.param({sendername:a.message.format.sendername(),senderaddress:a.message.format.senderaddress(),contenttype:Menu.getSelectedValues(a.message.format.contenttype.menu(),"id"),maxevents:Menu.getSelectedValues(a.message.format.maxevents.menu(),"id"),flushinterval:Menu.getSelectedValues(a.message.queue.flushinterval.menu(),"id")},!0),type:"POST",dataType:"json",timeout:3e4,error:MMONIT.error.json})},hasErrors:function(){return!a.message.format.senderaddress.isValid()},loading:!0,format:{sendername:ko.observable().extend({maxLength:255}),senderaddress:ko.observable().extend({required:!0,maxLength:255}),subjectsingle:ko.observable(),subjectmulti:ko.observable(),txtheader:ko.observable(),txtbody:ko.observable(),txtfooter:ko.observable(),htmlheader:ko.observable(),htmlbody:ko.observable(),htmlfooter:ko.observable(),contenttype:{menu:ko.observableArray(Menu.JSONToMenu([{id:"0",name:"Multipart"},{id:"1",name:"Plain text"},{id:"2",name:"HTML"}])),select:function(e){Menu.select(a.message.format.contenttype.menu(),e.id),a.message.save()}},maxsize:{menu:ko.observableArray(Menu.JSONToMenu([{id:"524288",name:"500 kB"},{id:"1048576",name:"1 MB"},{id:"2097152",name:"2 MB"},{id:"3145728",name:"3 MB"},{id:"4194304",name:"4 MB"},{id:"5242880",name:"5 MB"}])),select:function(e){Menu.select(a.message.format.maxsize.menu(),e.id),a.message.save()}},maxevents:{menu:ko.observableArray(Menu.JSONToMenu([{id:"20",name:"20"},{id:"50",name:"50"},{id:"100",name:"100"},{id:"200",name:"200"},{id:"500",name:"500"},{id:"1000",name:"1000"}])),select:function(e){Menu.select(a.message.format.maxevents.menu(),e.id),a.message.save()}}},queue:{flushinterval:{menu:ko.observableArray(Menu.JSONToMenu([{id:"1",name:"None"},{id:"30",name:"30 seconds"},{id:"60",name:"1 minute"},{id:"300",name:"5 minutes"},{id:"900",name:"15 minutes"}])),select:function(e){Menu.select(a.message.queue.flushinterval.menu(),e.id),a.message.save()}}}},a.message.format.sendername.subscribe(a.message.save),a.message.format.senderaddress.subscribe(a.message.save),a.message.format.contenttype.label=ko.computed((function(){return Menu.getSelectedNames(a.message.format.contenttype.menu(),null)})),a.message.format.maxsize.label=ko.computed((function(){return Menu.getSelectedNames(a.message.format.maxsize.menu(),null)})),a.message.format.maxevents.label=ko.computed((function(){return Menu.getSelectedNames(a.message.format.maxevents.menu(),null)})),a.message.queue.flushinterval.label=ko.computed((function(){return Menu.getSelectedNames(a.message.queue.flushinterval.menu(),null)})),e.getJSON("../../admin/alert/messages/list",(function(e){a.message.format.sendername(e.format.sendername),a.message.format.senderaddress(e.format.senderaddress),a.message.format.subjectsingle(e.format.subjectsingle),a.message.format.subjectmulti(e.format.subjectmulti),a.message.format.txtheader(e.format.txtheader),a.message.format.txtbody(e.format.txtbody),a.message.format.txtfooter(e.format.txtfooter),a.message.format.htmlheader(e.format.htmlheader),a.message.format.htmlbody(e.format.htmlbody),a.message.format.htmlfooter(e.format.htmlfooter),Menu.select(a.message.format.contenttype.menu(),e.format.contenttype),Menu.select(a.message.format.maxsize.menu(),e.format.maxsize),Menu.select(a.message.format.maxevents.menu(),e.format.maxevents),Menu.select(a.message.queue.flushinterval.menu(),e.queue.flushinterval),a.message.loading=!1})).fail(MMONIT.error.json)};ko.validation.init({insertMessages:!1,decorateElement:!0,errorElementClass:"error"},!0),ko.applyBindings(a,document.getElementById("messageTab")),e(window).on("resize orientationchange",(function(s){a.width(e("#main").outerWidth())}))}(jQuery);