Your IP : 216.73.216.240


Current Path : /home/juvelize/www/administrator/components/com_proforms/js/
Upload File :
Current File : /home/juvelize/www/administrator/components/com_proforms/js/formitems.js

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// @license: Mad4Media Javascipt License - copyright Mad4Media - Fahrettin Kutyol - All rights reserved    ++
// (re-) publishing or forking for any purpose of commercial or non-commercial use is not allowed.		   ++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
var FormItems={currentSlot:1,currentResponsiveSlot:null,showElementsStyle:null,selectAllInput:null,focus:null,focusType:"row",isDragging:false,tbody:null,editingEid:null,slotWrap:null,slotScrollNode:null,slotCount:0,leftScroll:null,rightScroll:null,isScroll:false,scrollPos:0,maxPos:0,scrollChunk:0,batchSelection:[],init:function(){console.log("FormItems Init");this.showElementsStyle=dojo.byId("showElementsStyle");this.selectAllInput=dojo.byId("selectAll");this.selectAllInput.onclick=function(_1){console.log("select all changed");FormItems.selectAllOnChange(this.checked);};var _2=dojo.query("DIV.activeSlot")[0];this.currentSlot=parseInt(_2.getAttribute("data-slot"));this.currentResponsiveSlot=parseInt(_2.getAttribute("data-responsive-slot"));this.slotSelected();this.validateSelectAll();dojo.query(".m4jSlot","m4jSlots").forEach(function(_3){_3.onclick=function(_4){var _5=dojo.query("DIV.activeSlot")[0];dojo.removeClass(_5,"activeSlot");dojo.addClass(this,"activeSlot");var _6=parseInt(this.getAttribute("data-slot"));if(_6==FormItems.currentSlot){return;}FormItems.currentSlot=_6;FormItems.currentResponsiveSlot=parseInt(this.getAttribute("data-responsive-slot"));FormItems.slotSelected();};dojo.connect(_3,"mouseover",function(_7){if(!FormItems.isDragging){this.style.cursor="";return;}if(FormItems.currentSlot==this.getAttribute("data-slot")){this.style.cursor="no-drop";FormItems.focus=null;FormItems.focusType=null;return;}this.style.cursor="crosshair";_3.enableTopInfo();FormItems.focus=this;FormItems.focusType="move";});dojo.connect(_3,"mouseout",function(_8){if(!FormItems.isDragging){return;}this.style.cursor="";_3.stopTopInfo();FormItems.focus=null;FormItems.focusType=null;this.style.boxShadow="";});dojo.connect(_3,"mouseup",function(_9){this.style.cursor="";});});dojo.query(".proformsTable input.elementSelector").forEach(function(el){el.onclick=function(_a){var tr=dojo.byId(this.getAttribute("data-tr"));if(this.checked){if(!dojo.hasClass(tr,"selectedRow")){dojo.addClass(tr,"selectedRow");}}else{dojo.removeClass(tr,"selectedRow");}FormItems.validateSelectAll();};});this.tbody=dojo.byId("proformsTbody");this.parseDropRows(this.tbody);this.parseEdits(this.tbody);this.parseCreateElements();dojo.connect(document,"mouseup",function(_b){FormItems.globalMouseUp();});if(remberSelection){dojo.forEach(remberSelection,function(_c){var _d=dojo.byId("elementSelector"+_c);if(_d){_d.click();}});}this.leftScroll=dojo.byId("tabArrowLeft");this.leftScroll.onclick=function(){FormItems.scroll(0);};this.rightScroll=dojo.byId("tabArrowRight");this.rightScroll.onclick=function(){FormItems.scroll(1);};this.slotScrollNode=dojo.byId("m4jSlots");this.slotWrap=dojo.byId("slotWrap");this.slotCount=parseInt(this.slotWrap.getAttribute("data-slot-count"));addWorkAreaExpandCallback(function(){FormItems.tabScrollInit(true);});this.tabScrollInit();},tabScrollInit:function(_e){_e=_e||false;var _f=_Dimensions(this.slotWrap);var _10=_f.width-48;console.log(_10);var _11=65;var _12=_11*this.slotCount;console.log("totalSlotWidth: "+_12);if(_12<=_10){this.leftScroll.className="off";this.rightScroll.className="off";this.isScroll=false;}else{this.leftScroll.className=(this.scrollPos==0)?"off":"";this.rightScroll.className="";this.isScroll=true;var _13=Math.floor(_10/_11);this.maxPos=Math.ceil(this.slotCount/_13)-1;this.scrollChunk=_13*_11;console.log(this);}},scroll:function(_14){if(!this.isScroll){return;}var _15=0;switch(_14){case 1:if(this.scrollPos!==this.maxPos){this.scrollPos++;_15=this.scrollPos*this.scrollChunk*-1;}else{return;}break;default:if(this.scrollPos!=0){this.scrollPos--;_15=this.scrollPos*this.scrollChunk*-1;}else{return;}break;}_15+=24;var _16=this;_fx.animToLeft(this.slotScrollNode,300,_15,function(){_16.rightScroll.className=(_16.scrollPos>=_16.maxPos)?"off":"";_16.leftScroll.className=(_16.scrollPos<=0)?"off":"";});},globalMouseUp:function(){FormItems.isDragging=false;dojo.removeClass(FormItems.tbody,"moving");document.body.style.cursor="";if(this.focus){console.log(this.focus);this.dragStop();}},slotSelected:function(){var url=formItemsURL+"&task=remember&slot="+this.currentSlot;this.xhr(url,function(_17){return;});this.showElementsStyle.innerHTML="<style type=\"text/css\">table#m4jTableList tbody tr[data-slot=\""+this.currentSlot+"\"]{display:table-row;}</style>";this.validateSelectAll();},selectAllOnChange:function(_18){dojo.query(".proformsTable input[data-slot=\""+this.currentSlot+"\"]").forEach(dojo.hitch(this,function(_19){_19.checked=_18;var tr=dojo.byId(_19.getAttribute("data-tr"));if(_19.checked){if(!dojo.hasClass(tr,"selectedRow")){dojo.addClass(tr,"selectedRow");}}else{dojo.removeClass(tr,"selectedRow");}}));},validateSelectAll:function(){var _1a=true;dojo.query(".proformsTable input[data-slot=\""+this.currentSlot+"\"]").forEach(dojo.hitch(this,function(_1b){if(!_1b.checked){_1a=false;}}));this.selectAllInput.checked=_1a;},parseDropRows:function(_1c){dojo.query("tr",_1c).forEach(dojo.hitch(this,function(row){dojo.connect(row,"mouseover",function(evt){if(!FormItems.isDragging){return;}FormItems.focus=this;FormItems.focusType="row";});dojo.connect(row,"mouseout",function(evt){if(!FormItems.isDragging){return;}FormItems.focus=null;FormItems.focusType=null;});}));dojo.query("img.moveIcon",_1c).forEach(dojo.hitch(this,function(img){img.ondragstart=function(){return false;};dojo.connect(img,"mousedown",function(evt){FormItems.dragStart(this);});}));},parseEdits:function(_1d){_1d=_1d||document.body;dojo.query("a.editFormElement",_1d).forEach(dojo.hitch(this,function(el){el.onclick=function(evt){FormItems.editingEid=this.getAttribute("data-eid");FormItems.openFieldWindow(this.href);return false;};}));},parseCreateElements:function(_1e){_1e=_1e||document.body;dojo.query("div.proformsFormElement",_1e).forEach(dojo.hitch(this,function(el){el.onclick=function(evt){var _1f=this.getAttribute("data-form");FormItems.openFieldWindow(newFormItemURL+"&slot="+FormItems.currentSlot+"&responsive_slot="+FormItems.currentResponsiveSlot+"&form="+_1f);return false;};}));},openFieldWindow:function(url){mWindow.iFrame(url,{width:980,height:1140});},dragStart:function(img){console.log(this);var eid=img.getAttribute("data-eid");var _20=dojo.byId("elementSelector"+eid);if(!_20.checked){_20.click();}this.isDragging=true;dojo.addClass(this.tbody,"moving");document.body.style.cursor="no-drop";},dragStop:function(){var _21=this.focusType;if(_21=="row"){var _22=0;var _23={};dojo.query("tr[data-slot='"+this.currentSlot+"'] input.elementSelector",this.tbody).forEach(dojo.hitch(this,function(_24){if(_24.checked){_23["selection["+_22++ +"]"]=_24.getAttribute("data-eid");}}));var _25=this.focus.getAttribute("data-eid");var url=formItemsURL+"&task=sort&destination="+_25+"&slot="+this.currentSlot;this.xhrPostData(url,_23,function(_26){FormItems.placePosition();});}else{if(_21=="move"){if(this.focus.getAttribute("data-slot")==this.currentSlot){return;}dojo.query("tr input.elementSelector",this.tbody).forEach(dojo.hitch(this,function(_27){if(_27.getAttribute("data-slot")!=this.currentSlot){_27.checked=false;}}));this.showLoadingPane();dojo.byId("proformsBatch").value=0;dojo.byId("proformsTask").value="move";dojo.byId("proformsSlot").value=this.currentSlot;dojo.byId("proformsResponsiveSlot").value=this.currentResponsiveSlot;dojo.byId("proformsDestination").value=this.focus.getAttribute("data-slot");dojo.byId("proformsResponsiveDestination").value=this.focus.getAttribute("data-responsive-slot");dojo.byId("m4jForm").submit();}}},placePosition:function(){var _28=new Array();var _29="before";dojo.query("tr[data-slot='"+this.currentSlot+"'] input.elementSelector",this.tbody).forEach(dojo.hitch(this,function(_2a){if(_2a.checked){var tr=dojo.byId(_2a.getAttribute("data-tr"));if(tr!==this.focus){dojo.place(tr,this.focus,_29);if(_29=="after"){this.focus=tr;}}else{_29="after";}_2a.click();}}));this.focus=null;},unselectAll:function(){dojo.query("tr[data-slot='"+this.currentSlot+"'] input.elementSelector",this.tbody).forEach(dojo.hitch(this,function(_2b){if(_2b.checked){_2b.click();}}));},reloadMarked:function(){mWindow.close();dojo.byId("proformsTask").value="reloadmarked";dojo.byId("proformsSlot").value=this.currentSlot;dojo.byId("m4jForm").submit();},xhr:function(url,_2c){dojo.xhrGet({url:url,preventCache:true,load:_2c,error:function(_2d){console.log("FormItems XHR error",_2d);}});},xhrPostData:function(url,_2e,_2f){dojo.xhrPost({url:url,content:_2e,preventCache:true,load:_2f,error:function(_30){console.log("FormItems XHR POST error",_30);}});},replaceNode:function(_31,_32){var _33=_31.parentNode;_33.removeChild(_31);_33.innerHTML=_32;},setActive:function(_34){this.xhr(_34.href,dojo.hitch(this,function(_35){this.replaceNode(_34,_35);}));return false;},setRequired:function(_36){this.xhr(_36.href,dojo.hitch(this,function(_37){this.replaceNode(_36,_37);}));return false;},copy:function(_38){return false;},remove:function(_39){var _3a=window.confirm(mText.askDelete);dojo.byId("proformsEid").value=_39.getAttribute("data-eid");dojo.byId("proformsTask").value="delete";dojo.byId("proformsSlot").value=this.currentSlot;dojo.byId("proformsResponsiveSlot").value=this.currentResponsiveSlot;dojo.byId("m4jForm").submit();return false;},batch:function(){var _3b=dojo.byId("batchSelectedItems");_3b.innerHTML="";this.batchSelection=[];dojo.query("tr[data-slot='"+this.currentSlot+"'] input.elementSelector",this.tbody).forEach(dojo.hitch(this,function(_3c){if(_3c.checked){this.batchSelection.push(_3c.value);}}));if(!this.batchSelection.length){return alert(mText.noitemsselected);}dojo.forEach(this.batchSelection,dojo.hitch(this,function(eid){var _3d=dojo.query("A.editFormElement[data-eid='"+eid+"']")[0];var _3e=parseInt(_3d.getAttribute("data-empty"));var _3f=!_3e?_3d.innerHTML:"[ "+dojo.byId("aliasWrap_"+eid).innerHTML+" ]";_3b.innerHTML+="<div>"+_3f+"</div>";}));console.log("SELECTED ITEMS",this.batchSelection);mWindow.fromNode("batchProcessing",{width:800,height:600});},batchProcess:function(_40){if(_40=="delete"){var _41=window.confirm(mText.askDelete);if(!_41){return;}}mWindow.close();this.showLoadingPane();dojo.query("tr input.elementSelector",this.tbody).forEach(dojo.hitch(this,function(_42){if(_42.checked&&dojo.indexOf(this.batchSelection,_42.value)===-1){_42.click();}}));dojo.byId("proformsBatch").value=1;dojo.byId("proformsBatchVerify").value=dojo.toJson(this.batchSelection);dojo.byId("proformsTask").value=_40;dojo.byId("proformsSlot").value=this.currentSlot;dojo.byId("m4jForm").submit();},showLoadingPane:function(){dojo.style("loadingPane",{display:"block"});},checkForm:function(){return true;}};dojo.addOnLoad(function(){FormItems.init();});