"use strict";!function(e){var n,a=new function(){var n=this;n.original_uname=e(document).getUrlParam("uname"),n.original_password="",n.file=null,n.fullname=ko.observable().extend({required:!0,maxLength:255}),n.uname=ko.observable().extend({required:!0,maxLength:20}),n.password=ko.observable().extend({required:!0,maxLength:55}),n.title=ko.observable(),n.email=ko.observable().extend({email:!0}),n.phone=ko.observable().extend({pattern:"^[+()0-9-]{6,40}$"}),n.mobile=ko.observable().extend({pattern:"^[+()0-9-]{6,40}$"}),n.imname=ko.observable(),n.imtype=ko.observable(),n.admin=ko.observable(!1),n.image=ko.observable(),n.isnew=ko.observable(!0),n.hasErrors=function(){return!(n.fullname.isValid()&&n.uname.isValid()&&n.password.isValid()&&n.email.isValid()&&n.phone.isValid()&&n.mobile.isValid())},n.cancel=function(){window.location="."},n.deleteUser=function(){e.post("../../admin/users/delete","uname="+n.original_uname,(function(e){window.location="."})).fail(MMONIT.error.json)},n.saveUser=function(){setTimeout("$('#button-spinner').addClass('visible')",300);var a=e("#theform").serialize(),o="../../admin/users/create";if(n.original_uname&&(a+="&uname="+encodeURIComponent(n.original_uname)+"&oldpassword="+encodeURIComponent(n.original_password),o="../../admin/users/update"),n.file){var i="id"+(new Date).getTime()+n.file.name.substr(n.file.name.lastIndexOf(".")),r=new FormData;r.append("fileid",i),r.append("uploadimage",n.file),e.ajax({url:"upload",data:r,type:"POST",cache:!1,contentType:!1,processData:!1,success:function(){e.post(o,a+"&image="+i,(function(){window.location="."})).fail(MMONIT.error.json)}}).fail(MMONIT.error.json)}else e.post(o,a,(function(){window.location="."})).fail(MMONIT.error.json)},n.original_uname?(n.original_uname=decodeURIComponent(n.original_uname),e.getJSON("../../admin/users/get?uname="+encodeURIComponent(n.original_uname),(function(e){ko.mapping.fromJS(e,{},n),n.original_password=n.password(),n.isnew(!1);var a=n.image();a=a&&a.length>0?"../../uploads/"+a:"../../img/avatar.png",document.getElementById("preview").style.background="url("+a+") no-repeat center"})).fail(MMONIT.error.json)):document.getElementById("preview").style.background="url(../../img/avatar.png) no-repeat center"};ko.bindingHandlers.selectText={init:function(n){e(n).on("click",(function(){e(this).select()}))}},ko.validation.init({insertMessages:!1,decorateElement:!0,errorElementClass:"error"}),ko.applyBindings(a),e(window).width()<768?e("#actions .btn").addClass("btn-block"):e("span.accessory input").prop("size",100),n=document.getElementById("preview"),document.getElementById("fileInput").onchange=function(o){o.preventDefault();var i=o.target.files[0];return function(n){var a=n.name.substr(n.name.lastIndexOf(".")+1).toLowerCase();-1==e.inArray(a,["gif","png","tiff","jpg","jpeg"])&&MMONIT.error.abort("File type not supported. Supported file types are gif, png, tiff, jpeg and jpg")}(i),function(e){var o=new FileReader;o.onload=function(o){a.file=e,n.style.background="url("+o.target.result+") no-repeat center"},o.readAsDataURL(e)}(i),!1}}(jQuery);