GO.calllog.MainPanel=function(b){if(!b){b={}}b.id="cl_callog_grid";var a={fields:["id","date","time","grid_time","name","company","phone","email","description"],columns:[{header:GO.lang.strDate,dataIndex:"grid_time"},{header:GO.lang.strName,dataIndex:"name"},{header:GO.lang.strCompany,dataIndex:"company"},{header:GO.lang.strPhone,dataIndex:"phone"},{header:GO.lang.strEmail,dataIndex:"email"},{header:GO.lang.strDescription,dataIndex:"description"}]};if(GO.customfields){GO.customfields.addColumns(18,a)}b.store=new GO.data.JsonStore({url:GO.settings.modules.calllog.url+"json.php",baseParams:{task:"calls"},id:"id",totalProperty:"total",root:"results",fields:a.fields,remoteSort:true});b.store.setDefaultSort("name","ASC");this.searchField=new GO.form.SearchField({store:b.store,width:320});b.view=new Ext.grid.GridView({forceFit:true,autoFill:true,emptyText:GO.lang.strNoItems});b.cm=new Ext.grid.ColumnModel({defaults:{sortable:true},columns:a.columns});var c=[{iconCls:"btn-add",text:GO.lang.cmdAdd,cls:"x-btn-text-icon",handler:function(){this.callDialog.show()},scope:this}];if(GO.settings.modules.calllog.write_permission){c.push({iconCls:"btn-delete",text:GO.lang.cmdDelete,cls:"x-btn-text-icon",handler:function(){this.deleteSelected()},scope:this})}b.tbar=new Ext.Toolbar({cls:"go-head-tb",items:[c,"-",GO.lang.strSearch+":",this.searchField]});b.sm=new Ext.grid.RowSelectionModel();b.paging=true;b.loadMask=true;GO.calllog.MainPanel.superclass.constructor.call(this,b);this.on("rowdblclick",this.rowDoubleClick,this);this.on("rowcontextmenu",this.onContextClick,this)};Ext.extend(GO.calllog.MainPanel,GO.grid.GridPanel,{afterRender:function(){GO.calllog.MainPanel.superclass.afterRender.call(this);this.store.load();if(!this.callDialog){this.callDialog=new GO.calllog.CallDialog();this.callDialog.on("save",function(){this.store.reload()},this)}},rowDoubleClick:function(c){var a=c.getSelectionModel();var b=a.getSelected();this.callDialog.show(b.data)},onContextClick:function(b,a,c){if(!this.menu){this.menu=new Ext.menu.Menu({id:"cf-calls-grid-ctx",items:[{text:GO.calllog.lang.saveAsContact,scope:this,handler:function(){var d=b.selModel.getSelected();GO.addressbook.showContactDialog();GO.addressbook.contactDialog.personalPanel.setValues(d.data)}}]})}c.stopEvent();if(GO.addressbook&&GO.settings.has_admin_permission){this.ctxRecord=this.store.getAt(a);this.menu.showAt(c.getXY())}}});GO.moduleManager.addModule("calllog",GO.calllog.MainPanel,{title:GO.calllog.lang.calllog,iconCls:"go-tab-icon-calllog"});GO.calllog.CallDialog=function(b){if(!b){b={}}this.buildForm();var a=function(){};b.layout="fit";b.title=GO.calllog.lang.call;b.modal=false;b.border=false;b.width=800;b.autoHeight=true;b.resizable=false;b.plain=true;b.shadow=false,b.closeAction="hide";b.items=this.formPanel;b.focus=a.createDelegate(this);b.buttons=[{text:GO.lang.cmdOk,handler:function(){this.submitForm(true)},scope:this},{text:GO.lang.cmdClose,handler:function(){this.hide()},scope:this}];GO.calllog.CallDialog.superclass.constructor.call(this,b);this.addEvents({save:true})};Ext.extend(GO.calllog.CallDialog,Ext.Window,{call_id:0,show:function(a){if(!this.rendered){this.render(Ext.getBody())}this.call_id=(a)?a.id:0;if(!a){a={};this.formPanel.form.reset();var b=new Date();var c=parseInt(b.format("i"));if(c>45){c="45"}else{if(c>30){c="30"}else{if(c>15){c="15"}else{c="00"}}}a.date=new Date();a.time=b.format(GO.settings.time_format)}this.formPanel.form.setValues(a);GO.calllog.CallDialog.superclass.show.call(this)},submitForm:function(a){this.formPanel.form.submit({url:GO.settings.modules.calllog.url+"json.php",params:{task:"save_call",id:this.call_id},waitMsg:GO.lang.waitMsgSave,success:function(b,c){if(c.result.id){this.call_id=c.result.id}this.fireEvent("save");if(a){this.hide()}},failure:function(c,d){var b="";if(d.failureType=="client"){b=GO.lang.strErrorsInForm}else{b=d.result.feedback}Ext.MessageBox.alert(GO.lang.strError,b)},scope:this})},buildForm:function(){this.dateField=new Ext.form.DateField({name:"date",width:100,format:GO.settings.date_format,fieldLabel:GO.lang.strDate,allowBlank:false});this.timeField=new Ext.form.TimeField({increment:15,format:GO.settings.time_format,name:"time",width:80,fieldLabel:GO.lang.strTime,autoSelect:true});var b=new Ext.form.FieldSet({title:GO.lang.strProperties,cls:"go-form-panel",anchor:"100% 100%",defaults:{anchor:"-20",labelWidth:140},defaultType:"textfield",collapsed:false,items:[this.dateField,this.timeField,{fieldLabel:GO.lang.strName,name:"name",allowBlank:false},{fieldLabel:GO.lang.strCompany,name:"company"},{fieldLabel:GO.lang.strPhone,name:"phone"},{fieldLabel:GO.lang.strEmail,name:"email",vtype:"emailAddress"},{fieldLabel:GO.lang.strDescription,name:"description",xtype:"textarea"}]});var g=[];var d=[];g.push(b);if(GO.customfields&&GO.customfields.types["18"]){for(var e=0;e<GO.customfields.types["18"].panels.length;e++){var a=GO.customfields.types["18"].panels[e];var f=[];for(var c=0;c<a.customfields.length;c++){f.push(GO.customfields.getFormField(a.customfields[c]))}b=new Ext.form.FieldSet({title:a.title,cls:"go-form-panel",anchor:"100% 100%",defaults:{anchor:"100%",labelWidth:140},defaultType:"textfield",collapsed:false,items:f});if(e%2||e==0){d.push(b)}else{g.push(b)}}}this.formPanel=new Ext.FormPanel({cls:"go-form-panel",anchor:"100% 100%",bodyStyle:"padding:10px",defaults:{anchor:"100%",border:false},autoHeight:true,waitMsgTarget:true,layout:"column",items:[{columnWidth:0.5,items:g},{columnWidth:0.5,items:d}]})}});