summaryrefslogtreecommitdiff
blob: d84ab77cae69fd75dec8465468b045410d07d6a6 (plain)
1
function WMP_PAGE_DETAILS(){var e=this;this.type="wmp_pageedit";this.form;this.DOMDoc;this.send_btn;this.init=function(){WMPJSInterface=window.parent.WMPJSInterface;this.send_btn=jQuery("#"+this.type+"_send_btn",this.DOMDoc).get(0);this.form=this.DOMDoc.getElementById(this.type+"_form");this.addButtonsActions();if(this.form==null){return}this.initValidation()};this.initValidation=function(){this.validator=jQuery("#"+this.form.id,this.DOMDoc).validate({rules:{wmp_pageedit_content:{required:true},messages:{wmp_pageedit_content:{required:"The content is required"}}},errorPlacement:function(t,n){var r=n[0].id.split("_");var i=r.length>1?r[r.length-1]:r[0];var s=jQuery("#error_"+i+"_container",e.DOMDoc);t.appendTo(s)},errorElement:"span"})};this.addButtonsActions=function(){jQuery(this.send_btn).unbind("click");jQuery(this.send_btn).bind("click",function(){e.disableButton(this);e.validate()});e.enableButton(this.send_btn)};this.enableButton=function(e){jQuery(e).css("cursor","pointer");jQuery(e).animate({opacity:1},100)};this.disableButton=function(e){jQuery(e).unbind("click");jQuery(e).animate({opacity:.4},100);jQuery(e).css("cursor","default")};this.scrollToError=function(t){var n=jQuery("html,body",e.DOMDoc);var r=parseInt(jQuery("html,body").scrollTop())||parseInt(jQuery("body").scrollTop());var i=n.get(0).clientHeight;var s=parseInt(n.offset().top);if(t<r){jQuery(n).animate({scrollTop:t-20},1e3)}else if(t>r+i){jQuery(n).animate({scrollTop:r+i},1e3)}};this.validate=function(){jQuery(this.form).validate().form();var t=[];for(var n in this.validator.invalid){var r=jQuery(this.form[n]);t.push(r.offset().top)}if(t.length==0){this.sendData()}else{t.sort(function(e,t){return e-t});e.scrollToError(t[0]);e.addButtonsActions()}};this.submitForm=function(){return WMPJSInterface.AjaxUpload.dosubmit(e.form,{onStart:e.startUploadingData,onComplete:e.completeUploadingData})};this.sendData=function(){jQuery("#"+this.form.id,this.DOMDoc).unbind("submit");jQuery("#"+this.form.id,this.DOMDoc).bind("submit",function(){e.submitForm()});jQuery("#"+this.form.id,this.DOMDoc).submit();e.disableButton(e.send_btn)};this.startUploadingData=function(){WMPJSInterface.Preloader.start();setTimeout(function(){var t=e.form.elements;nElems=t.length;for(j=0;j<nElems;j++){t[j].disabled=true}},300);return true};this.completeUploadingData=function(t){jQuery("#"+e.form.id,e.DOMDoc).unbind("submit");jQuery("#"+e.form.id,e.DOMDoc).bind("submit",function(){return false});WMPJSInterface.Preloader.remove(100);t=Boolean(Number(String(t)));if(t==true){var n="Your page has been successfully modified!";WMPJSInterface.Loader.display({message:n})}else{var n="There was an error. Please reload the page and try again.";WMPJSInterface.Loader.display({message:n})}setTimeout(function(){var t=e.form.elements;nElems=t.length;for(j=0;j<nElems;j++){t[j].disabled=false}},300);e.addButtonsActions()}}