Ext.namespace("Waps.Products");Waps.Products=function(a){this.config=a;Ext.onReady(function(){},this)};Waps.Products.prototype={setupFields:function(){this.fields=new Array();this.fields=[{fieldLabel:"code",name:"ProductId",labelStyle:"color: #c1000f",labelSeparator:"",allowBlank:false},{fieldLabel:"title",name:"ProductName",labelStyle:"color: #c1000f",labelSeparator:"",allowBlank:false},{fieldLabel:"FlashCoordinates",name:"FlashCoordinates",allowBlank:false,xtype:"hidden",value:this.FlashCoordinates}];var a=1;Ext.each(this.config,function(b){this.fields.push({fieldLabel:b.Name,xtype:"linkedcombo",hiddenName:"Column"+a+"[]",allowBlank:false,itemId:b.Id,labelStyle:"color: #c1000f",hideLabel:false});a++},this);this.setupForm()},setupForm:function(){this.fields.push({id:"addProductPanel",xtype:"fieldset",title:"set product attributes",autoHeight:true,autoWidth:true,plugins:new Ext.ux.Plugin.RemoteComponent({url:"/index.php/ComboDataService/Type,FormComponent/recordID,0/Remote,true/fieldID,0/FormId,"}),onAdd:function(b,f,d){if(f.isFormField){var e=this.findParentByType("form");if(e){e.onAdd(b,f,d)}}},onRemove:function(d){if(d.isFormField){var b=this.findParentByType("form");if(b){b.onRemove(d)}}}});var a=new Ext.FormPanel({id:"productsForm",labelWidth:150,url:"/index.php/ProductsDataService/Type,SaveNewDataFlash",frame:true,title:"add product",autoScroll:true,bodyStyle:"padding:5px 5px 0",defaultType:"textfield",items:this.fields,buttons:[{text:"Save",handler:function(b){this.ownerCt.form.submit({success:function(d,e){alert("product added. Check XMl");d.clearInvalid();var c=Ext.getCmp("addProductPanel");c.items.each(function(f){Ext.destroy(f.container.up(".x-form-item"));this.onRemove(f);this.remove(f,true)},c);d.reset();Ext.MessageBox.alert("Hooray","action performed successfully");this.ownerCt.ownerCt.hide()},failure:function(c,d){Ext.MessageBox.alert("Eh...",d.failureType=="client"?"Please fill all the required fields!":(d.result.errorMessage||"I dont know what but something went wrong.. "))},scope:this,waitMsg:"Submitting data",waitTitle:"Please wait"})}},{text:"Cancel",handler:function(c){this.ownerCt.form.clearInvalid();var b=Ext.getCmp("addProductPanel");b.items.each(function(d){Ext.destroy(d.container.up(".x-form-item"));this.onRemove(d);this.remove(d,true)},b);this.ownerCt.form.reset();this.ownerCt.ownerCt.hide()}}]});this.ProductsWindow=new Ext.Window({layout:"fit",width:700,height:600,closeAction:"hide",items:a,modal:true,minWidth:600,containerScroll:true,maximizable:true})},showForm:function(){this.setupFields();this.ProductsWindow.show()},showEditForm:function(){param=grider.selModel.selections.keys;Ext.apply(this.ProductsWindow.items.get(0).baseParams,{recordID:param});if(param.length==0||param.length>1){Ext.MessageBox.alert("Item Check","Please select ONLY 1 record to assign/update "+this.title)}else{var a=[{fieldLabel:"code",name:"RefCode",labelStyle:"color: #c1000f",labelSeparator:"",allowBlank:false},{fieldLabel:"Product Id",name:"ProductId",allowBlank:false,xtype:"hidden"},{fieldLabel:"title",name:"ProductName",labelStyle:"color: #c1000f",labelSeparator:"",allowBlank:false}];var b=new Ext.FormPanel({labelWidth:150,url:"/index.php/ProductsDataService/Type,SaveData",frame:true,title:"edit product",autoScroll:true,bodyStyle:"padding:5px 5px 0",defaultType:"textfield",items:a,buttons:[{text:"Save",handler:function(c){this.ownerCt.form.submit({success:function(d,e){d.clearInvalid();d.reset();Ext.MessageBox.alert("Hooray","action performed successfully");this.ownerCt.ownerCt.hide();grider.store.reload()},failure:function(d,e){Ext.MessageBox.alert("Eh...",e.failureType=="client"?"Please fill all the required fields!":(e.result.errorMessage||"I dont know what but something went wrong.. "))},scope:this,waitMsg:"Submitting data",waitTitle:"Please wait"})}},{text:"Cancel",handler:function(c){this.ownerCt.form.clearInvalid();this.ownerCt.form.reset();this.ownerCt.ownerCt.hide()}}]});this.ProductsWindowEdit=new Ext.Window({layout:"fit",width:700,height:600,closeAction:"hide",items:b,modal:true,minWidth:600,containerScroll:true,maximizable:true});this.ProductsWindowEdit.show();Ext.Ajax.request({url:"/index.php/ProductsDataService/Type,RetrieveData",method:"POST",params:{recordId:param},waitMsg:"Loading",scope:this,success:function(c,d){var e=Ext.util.JSON.decode(c.responseText);returnLast=function(f,g){Iteme=f.items.get(f.items.length-1);if(g==0){return f}if(Iteme.xtype=="panel"){returnLast(Iteme)}else{return f}};Ext.each(e.data,function(g){for(x in g){var h=b;if(g[x]){for(var i=0;i<g[x].length;i++){var f=returnLast(h,i);f.insert(f.items.length,g[x][i]);var h=f.items.get(f.items.length-1);b.doLayout()}}}},this);b.add({id:"addProductPanel",xtype:"fieldset",title:"set product attributes",autoHeight:true,autoWidth:true,plugins:new Ext.ux.Plugin.RemoteComponent({url:"/index.php/ComboDataService/Type,FormComponent/recordID,0/Remote,true/fieldID,0/FormId,",mask:Ext.get(document.body),maskConfig:{msg:"remoting..."}}),onAdd:function(f,i,g){if(i.isFormField){var h=this.findParentByType("form");if(h){h.onAdd(f,i,g)}}},onRemove:function(g){if(g.isFormField){var f=this.findParentByType("form");if(f){f.onRemove(g)}}}});b.doLayout()},failure:function(c,d){Ext.MessageBox.alert("Oops","We could not load the form at this time. Please try again. <br>We know its annoying, but it happens")}})}}};Ext.onReady(function(){Ext.ux.LinkedCombo=Ext.extend(Ext.Panel,{initComponent:function(){Ext.apply(this,{layout:"form",items:{xtype:"combo",fieldLabel:this.fieldLabel?this.fieldLabel:"",hideLabel:this.hideLabel,labelWidth:150,value:this.value!=""?this.value:"",labelSeparator:"",hiddenName:this.hiddenName,store:new Ext.data.JsonStore({url:"/index.php/ComboDataService/Type,FormNameProvider2",baseParams:{FormId:0,fieldID:0,node:this.itemId},autoLoad:true,fields:["id","text","formId","leaf"]}),valueField:"id",allowBlank:false,displayField:"text",typeAhead:true,editable:false,mode:"local",triggerAction:"all",emptyText:"Select",selectOnFocus:true,loadingRemote:function(a,e){var d=a.formId;if(a.leaf){if(d==0){var c=Ext.getCmp("addProductPanel");c.items.each(function(f){Ext.destroy(f.container.up(".x-form-item"));this.onRemove(f);this.remove(f,true)},c)}else{var c=Ext.getCmp("addProductPanel");var b=c.plugins.initialConfig.url.slice(c.plugins.initialConfig.url.search("FormId")+7);if(b!=d){c.items.each(function(f){Ext.destroy(f.container.up(".x-form-item"));this.onRemove(f);this.remove(f,true)},c);c.plugins.load("/index.php/ComboDataService/Type,FormComponent/recordID,0/Remote,true/fieldID,0/FormId,"+d)}if(e){c.plugins.on("Success",function(){c.ownerCt.load({url:"/index.php/ProductsDataService/Type,getAttributes/recordId,"+param,method:"POST",waitMsg:"Loading",scope:this,success:function(f,g){this.ownerCt.setValues(a)},failure:function(f,g){Ext.MessageBox.alert("Oops","We could not load the form at this time. Please try again. <br>We know its annoying, but it happens")}},c)},c)}}}else{var c=Ext.getCmp("addProductPanel");c.items.each(function(f){Ext.destroy(f.container.up(".x-form-item"));this.onRemove(f);this.remove(f,true)},c)}},listeners:{render:{fn:function(a){a.store.on("load",function(){if(this.value){this.setValue(this.value);this.fireEvent("select",this,this.findRecord("id",this.value))}},this)}},select:{fn:function(h,c,e){var f=Ext.getCmp("productsForm");if(e==undefined){this.loadingRemote(c.data,true)}else{this.loadingRemote(c.data,false)}if(e>=0){Ext.each(this.ownerCt.items.items,function(j){if(j.xtype!="combo"){j.destroy(true);j.cascade(function(k){if(k.xtype=="combo"){f.form.items.remove(k)}})}},this);var a=this.ownerCt;a.doLayout();this.ownerCt.ownerCt.items.findIndex("id",this.ownerCt.id);var d=this.ownerCt.ownerCt.items.findIndex("id",this.ownerCt.id)+1;var g=a.getComponent(d);if(!c.data.leaf){var b={xtype:"linkedcombo",itemId:c.data.id,hiddenName:h.hiddenName,labelWidth:150,allowBlank:false};var i=new Ext.Panel({border:false,items:[b]});a.insert(d,i).show();a.doLayout();f.form.items.add(i.items.get(0).items.get(0))}}}}}}});Ext.ux.LinkedCombo.superclass.initComponent.call(this)}});Ext.reg("linkedcombo",Ext.ux.LinkedCombo)});
