Pman.Dialog.XtupleItem.bjs
[Pman.Xtuple] / Pman.Dialog.XtupleItem.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Roo.namespace('Pman.Dialog');
6
7 Pman.Dialog.XtupleItem = {
8
9     dialog : false,
10     callback:  false,
11
12     show : function(data, cb)
13     {
14         if (!this.dialog) {
15             this.create();
16         }
17
18         this.callback = cb;
19         this.data = data;
20         this.dialog.show(this.data._el);
21         if (this.form) {
22            this.form.reset();
23            this.form.setValues(data);
24            this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
25         }
26
27     },
28
29     create : function()
30     {
31         var _this = this;
32         this.dialog = Roo.factory({
33             center : {
34                 '|xns' : 'Roo',
35                 alwaysShowTabs : true,
36                 xtype : 'LayoutRegion',
37                 tabPosition : 'top',
38                 xns : Roo
39             },
40             '|xns' : 'Roo',
41             modal : true,
42             collapsible : false,
43             title : "Edit / Create item",
44             xtype : 'LayoutDialog',
45             width : 800,
46             xns : Roo,
47             closable : false,
48             resizable : false,
49             height : 550,
50             buttons : [
51                  {
52                         '|xns' : 'Roo',
53                         text : "Cancel",
54                         xtype : 'Button',
55                         xns : Roo,
56                         listeners : {
57                                 click : function (_self, e)
58                                    {
59                                        _this.dialog.hide();
60                                    }
61                         }
62                     },
63 {
64                         '|xns' : 'Roo',
65                         text : "Save",
66                         xtype : 'Button',
67                         xns : Roo,
68                         listeners : {
69                                 render : function (_self)
70                                    {
71                                        _this.saveBtn = this;
72                                    },
73                                 click : function (_self, e)
74                                    {
75                                        // do some checks?
76                                         
77                                        
78                                      //  _this.dialog.el.mask("Saving");
79                                        _this.form.doAction("submit");
80                                    
81                                    }
82                         }
83                     }
84             ],
85             listeners : {
86                 show : function (_self)
87                    {
88                         _this.dialog.layout.getRegion('center').showPanel(0);
89                    }
90             },
91             items : [
92                 {
93                     '|xns' : 'Roo',
94                     region : 'center',
95                     title : "Detail",
96                     xtype : 'ContentPanel',
97                     xns : Roo,
98                     items : [
99                         {
100                             '|xns' : 'Roo.form',
101                             url : baseURL + '/Roo/item.php',
102                             method : 'POST',
103                             style : 'margin:10px;',
104                             xtype : 'Form',
105                             labelWidth : 120,
106                             xns : Roo.form,
107                             listeners : {
108                                 actioncomplete : function(_self,action)
109                                    {
110                                        if (action.type == 'setdata') {
111                                           _this.form.findField('item_number').el.dom.readOnly = true;
112                                           _this.form.findField('item_type').disabled = true; 
113                                           
114                                           if(_this.data.item_id * 1 > 0){
115                                                
116                                                this.load({ 
117                                                    method: 'GET', 
118                                                    params: {
119                                                         '_id' : _this.data.item_id,
120                                                         '_with_itemsite' : 1,
121                                                         '_with_itemcost' : 1,
122                                                         '_with_prodcat' : 1 ,
123                                                         '_with_salesaccnt' : 1 
124                                                    }
125                                                });
126                                                return;
127                                           }
128                                           // if it's new..
129                                           _this.form.findField('item_number').el.dom.readOnly = false;
130                                           _this.form.findField('item_type').disabled = false; 
131                                           _this.form.findField('item_salesaccnt').setValue('');
132                                           
133                                           return;
134                                        }
135                                        if (action.type == 'load') {
136                                           _this.form.findField('item_type').showHide();
137                                            return;
138                                        }
139                                        if (action.type =='submit') {
140                                        
141                                            var id = _this.form.findField('item_id').getValue() * 1;
142                                            if (id < 1) {
143                                            
144                                                this.load({ 
145                                                    method: 'GET', 
146                                                    params: {
147                                                         '_id' : action.result.data.item_id,
148                                                         '_with_itemsite' : 1,
149                                                         '_with_itemcost' : 1,
150                                                         '_with_prodcat' : 1 ,
151                                                         '_with_salesaccnt' : 1 
152                                                    }
153                                                });
154                                                return;
155                                            }
156                                            _this.dialog.hide();
157                                        
158                                             if (_this.callback) {
159                                                _this.callback.call(_this, _this.form.getValues());
160                                             }
161                                             _this.form.reset();
162                                             return;
163                                        }
164                                    },
165                                 rendered : function (form)
166                                    {
167                                        _this.form= form;
168                                    }
169                             },
170                             items : [
171                                 {
172                                     '|xns' : 'Roo.form',
173                                     fieldLabel : 'SKU',
174                                     xtype : 'TextField',
175                                     allowBlank : false,
176                                     width : 200,
177                                     xns : Roo.form,
178                                     name : 'item_number'
179                                 },
180                                 {
181                                     '|xns' : 'Roo.form',
182                                     fieldLabel : 'Description',
183                                     xtype : 'TextField',
184                                     width : 400,
185                                     xns : Roo.form,
186                                     name : 'item_descrip1'
187                                 },
188                                 {
189                                     '|xns' : 'Roo.form',
190                                     fieldLabel : 'Description (2)',
191                                     xtype : 'TextField',
192                                     width : 400,
193                                     xns : Roo.form,
194                                     name : 'item_descrip2'
195                                 },
196                                 {
197                                     '|xns' : 'Roo.form',
198                                     xtype : 'Column',
199                                     labelWidth : 120,
200                                     xns : Roo.form,
201                                     items : [
202                                         {
203                                             store : {
204                                                 '|xns' : 'Roo.data',
205                                                 xtype : 'SimpleStore',
206                                                 data : [ 
207                                                     [ 'P', "Purchased (eg. a standard product)"],
208                                                     [ 'R' , "Reference (Non-Product)"],
209                                                     [ 'K', "Kit (made up of products)"]  
210                                                 ],
211                                                 fields : [  'ftype', 'fname'],
212                                                 xns : Roo.data
213                                             },
214                                             '|xns' : 'Roo.form',
215                                             listWidth : 200,
216                                             triggerAction : 'all',
217                                             fieldLabel : 'Type',
218                                             displayField : 'fname',
219                                             emptyText : "Select Type",
220                                             hiddenName : 'item_type',
221                                             valueField : 'ftype',
222                                             xtype : 'ComboBox',
223                                             allowBlank : false,
224                                             showHide : function() {
225                                             
226                                                 var it = this.getValue();
227                                                 
228                                                 var options = [ 
229                                                     'item_itemcost_id_itemcost_curr_id',
230                                                     'item_itemcost_id_itemcost_actcost',
231                                                     'item_itemsite_id_itemsite_reorderlevel',
232                                                     'item_itemsite_id_itemsite_leadtime',
233                                                     'item_itemsite_id_itemsite_location_id',
234                                                     'item_itemsite_id_itemsite_loccntrl',
235                                                     'item_itemsite_id_itemsite_stocked',
236                                                     'item_itemsite_id_itemsite_perishable',
237                                                     
238                                                     'item_itemsite_id_itemsite_safetystock',
239                                                     'item_itemsite_id_itemsite_controlmethod',
240                                                     'item_itemsite_id_itemsite_plancode_id',
241                                                     'item_itemsite_id_itemsite_costcat_id',
242                                                     'item_itemsite_id_itemsite_active',
243                                                     'item_itemsite_id_itemsite_sold'
244                                                     
245                                                 ];
246                                                 
247                                                 var r_req = [ 
248                                                     'item_listprice'
249                                                 ];
250                                                 
251                                                 var state = true;
252                                                 
253                                                 _this.standardCostFieldSet.show();
254                                                 _this.itemsiteFieldSet.show();
255                                                 _this.form.findField('_update_related').setValue(1);
256                                                 
257                                                 switch(it) {
258                                                     case 'K':
259                                                         state = false;
260                                             
261                                                         _this.form.findField('item_listprice').allowBlank = false;
262                                                         _this.form.findField('item_listprice').actionMode = 'fieldEl';
263                                                         _this.form.findField('item_listprice').hideMode = 'display';
264                                                         _this.form.findField('item_listprice').show();
265                                                                     
266                                                         break;
267                                                         
268                                                     case 'R': // refrence
269                                                         options = options.concat(r_req);
270                                                         state = false;
271                                                         _this.standardCostFieldSet.hide();
272                                                         break;
273                                                         
274                                                     case 'P': // purchased..
275                                                         options = options.concat(r_req);
276                                                         // must have
277                                                         break;
278                                                 }
279                                                 
280                                                 Roo.each(options, function(n) {
281                                                     var ff = _this.form.findField(n);
282                                                     ff.allowBlank = !state;
283                                                     ff.actionMode = 'fieldEl';
284                                                     ff.hideMode = 'display';
285                                                     state ? ff.show() : ff.hide(); 
286                                                     
287                                                 });
288                                                 
289                                                 
290                                                 if(!state){
291                                                     _this.standardCostFieldSet.hide();
292                                                     _this.itemsiteFieldSet.hide();
293                                                     _this.form.findField('_update_related').setValue(0);
294                                                 }
295                                                 
296                                               
297                                                        
298                                             },
299                                             editable : false,
300                                             width : 200,
301                                             xns : Roo.form,
302                                             mode : 'local',
303                                             name : 'item_type_name',
304                                             tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{fname}</b> </div>',
305                                             listeners : {
306                                                 beforeselect : function (combo, record, index)
307                                                    {
308                                                        (function() { combo.showHide(); }).defer(100);
309                                                    }
310                                             },
311                                             items : [
312
313                                             ]
314
315                                         },
316                                         {
317                                             store : {
318                                                 proxy : {
319                                                     '|xns' : 'Roo.data',
320                                                     url : baseURL + '/Roo/classcode.php',
321                                                     xtype : 'HttpProxy',
322                                                     method : 'GET',
323                                                     xns : Roo.data
324                                                 },
325                                                 reader : {
326                                                     '|xns' : 'Roo.data',
327                                                     id : 'id',
328                                                     root : 'data',
329                                                     xtype : 'JsonReader',
330                                                     xns : Roo.data,
331                                                     fields : [{"name":"id","type":"int"},{"name":"classcode_code","type":"string"}],
332                                                     totalProperty : 'total'
333                                                 },
334                                                 '|xns' : 'Roo.data',
335                                                 xtype : 'Store',
336                                                 remoteSort : true,
337                                                 sortInfo : { direction : 'ASC', field: 'id' },
338                                                 xns : Roo.data,
339                                                 listeners : {
340                                                         beforeload : function (_self, o){
341                                                                o.params = o.params || {};
342                                                                // set more here
343                                                            }
344                                                 },
345                                                 items : [
346
347                                                 ]
348
349                                             },
350                                             '|xns' : 'Roo.form',
351                                             listWidth : 400,
352                                             triggerAction : 'all',
353                                             fieldLabel : 'Class',
354                                             forceSelection : true,
355                                             selectOnFocus : true,
356                                             pageSize : 20,
357                                             displayField : 'classcode_code',
358                                             emptyText : "Select classcode",
359                                             hiddenName : 'item_classcode_id',
360                                             minChars : 2,
361                                             valueField : 'classcode_id',
362                                             xtype : 'ComboBox',
363                                             allowBlank : false,
364                                             typeAhead : true,
365                                             editable : false,
366                                             width : 200,
367                                             xns : Roo.form,
368                                             name : 'item_classcode_id_classcode_code',
369                                             qtip : "Select classcode",
370                                             queryParam : '',
371                                             tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{classcode_code}</b> </div>',
372                                             loadingText : "Searching...",
373                                             items : [
374
375                                             ]
376
377                                         },
378                                         {
379                                             '|xns' : 'Roo.form',
380                                             fieldLabel : 'Weight',
381                                             xtype : 'NumberField',
382                                             allowBlank : false,
383                                             allowDecimals : true,
384                                             decimalPrecision : 2,
385                                             width : 200,
386                                             xns : Roo.form,
387                                             name : 'item_prodweight'
388                                         },
389                                         {
390                                             '|xns' : 'Roo.form',
391                                             fieldLabel : 'Item comments',
392                                             xtype : 'TextArea',
393                                             width : 200,
394                                             xns : Roo.form,
395                                             name : 'item_comments',
396                                             height : 100
397                                         },
398                                         {
399                                             '|xns' : 'Roo.form',
400                                             fieldLabel : 'Item sold',
401                                             inputValue : true,
402                                             xtype : 'Checkbox',
403                                             valueOff : 0,
404                                             width : 75,
405                                             xns : Roo.form,
406                                             name : 'item_sold'
407                                         },
408                                         {
409                                             '|xns' : 'Roo.form',
410                                             fieldLabel : 'Item active',
411                                             inputValue : true,
412                                             xtype : 'Checkbox',
413                                             valueOff : 0,
414                                             width : 75,
415                                             xns : Roo.form,
416                                             name : 'item_active'
417                                         },
418                                         {
419                                             store : {
420                                                 proxy : {
421                                                     '|xns' : 'Roo.data',
422                                                     url : baseURL + '/Roo/prodcat.php',
423                                                     xtype : 'HttpProxy',
424                                                     method : 'GET',
425                                                     xns : Roo.data
426                                                 },
427                                                 reader : {
428                                                     '|xns' : 'Roo.data',
429                                                     id : 'id',
430                                                     root : 'data',
431                                                     xtype : 'JsonReader',
432                                                     xns : Roo.data,
433                                                     fields : [{"name":"id","type":"int"},{"name":"prodcat_code","type":"string"}],
434                                                     totalProperty : 'total'
435                                                 },
436                                                 '|xns' : 'Roo.data',
437                                                 xtype : 'Store',
438                                                 remoteSort : true,
439                                                 xns : Roo.data,
440                                                 sortInfo : { direction : 'ASC', field: 'id' },
441                                                 listeners : {
442                                                         beforeload : function (_self, o){
443                                                                o.params = o.params || {};
444                                                                // set more here
445                                                            }
446                                                 },
447                                                 items : [
448
449                                                 ]
450
451                                             },
452                                             '|xns' : 'Roo.form',
453                                             alwaysQuery : true,
454                                             listWidth : 400,
455                                             triggerAction : 'all',
456                                             fieldLabel : 'Product Category',
457                                             forceSelection : true,
458                                             selectOnFocus : true,
459                                             pageSize : 20,
460                                             displayField : 'prodcat_code',
461                                             emptyText : "Select Category",
462                                             hiddenName : 'item_prodcat_id',
463                                             minChars : 2,
464                                             valueField : 'prodcat_id',
465                                             xtype : 'ComboBox',
466                                             allowBlank : false,
467                                             typeAhead : true,
468                                             editable : false,
469                                             width : 200,
470                                             xns : Roo.form,
471                                             name : 'item_prodcat_id_prodcat_code',
472                                             qtip : "Select prodcat",
473                                             queryParam : '',
474                                             tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{prodcat_code}</b> </div>',
475                                             loadingText : "Searching...",
476                                             listeners : {
477                                                 add : function (combo)
478                                                    {
479                                                        Pman.Dialog.XtupleProdcat.show({prodcat_id : 0});
480                                                    },
481                                                 edit : function (combo, record)
482                                                    {
483                                                        var s = _this.form.findField('item_prodcat_id').getValue() * 1;
484                                                        if(s < 1){
485                                                            Roo.MessageBox.alert('Error','Please select a account assignment');
486                                                            return;
487                                                        }
488                                                        Pman.Dialog.XtupleProdcat.show({prodcat_id : s});
489                                                    }
490                                             },
491                                             items : [
492
493                                             ]
494
495                                         },
496                                         {
497                                             '|xns' : 'Roo.form',
498                                             fieldLabel : 'Sales Account',
499                                             xtype : 'DisplayField',
500                                             xns : Roo.form,
501                                             name : 'item_salesaccnt'
502                                         },
503                                         {
504                                             '|xns' : 'Roo.form',
505                                             fieldLabel : 'Item listprice',
506                                             xtype : 'NumberField',
507                                             width : 200,
508                                             xns : Roo.form,
509                                             name : 'item_listprice'
510                                         },
511                                         {
512                                             '|xns' : 'Roo.form',
513                                             style : 'width:320px',
514                                             xtype : 'FieldSet',
515                                             legend : "Standard Cost",
516                                             xns : Roo.form,
517                                             listeners : {
518                                                 render : function (_self)
519                                                    {
520                                                        _this.standardCostFieldSet = _self;
521                                                    }
522                                             },
523                                             items : [
524                                                 {
525                                                     store : {
526                                                         proxy : {
527                                                             '|xns' : 'Roo.data',
528                                                             url : baseURL + '/Roo/curr_symbol.php',
529                                                             xtype : 'HttpProxy',
530                                                             method : 'GET',
531                                                             xns : Roo.data
532                                                         },
533                                                         reader : {
534                                                             '|xns' : 'Roo.data',
535                                                             id : 'curr_id',
536                                                             root : 'data',
537                                                             xtype : 'JsonReader',
538                                                             xns : Roo.data,
539                                                             fields : [{"name":"curr_id","type":"int"},"curr_symbol"],
540                                                             totalProperty : 'total'
541                                                         },
542                                                         '|xns' : 'Roo.data',
543                                                         xtype : 'Store',
544                                                         remoteSort : true,
545                                                         sortInfo : { direction : 'ASC', field: 'curr_symbol' },
546                                                         xns : Roo.data,
547                                                         listeners : {
548                                                                 beforeload : function (_self, o){
549                                                                        o.params = o.params || {};
550                                                                        // set more here
551                                                                       
552                                                                    }
553                                                         },
554                                                         items : [
555
556                                                         ]
557
558                                                     },
559                                                     '|xns' : 'Roo.form',
560                                                     listWidth : 400,
561                                                     triggerAction : 'all',
562                                                     fieldLabel : 'Currency',
563                                                     forceSelection : true,
564                                                     selectOnFocus : true,
565                                                     pageSize : 20,
566                                                     displayField : 'curr_name',
567                                                     emptyText : "Select Currency",
568                                                     hiddenName : 'item_itemcost_id_itemcost_curr_id',
569                                                     minChars : 2,
570                                                     valueField : 'curr_id',
571                                                     xtype : 'ComboBox',
572                                                     allowBlank : false,
573                                                     typeAhead : true,
574                                                     editable : false,
575                                                     width : 200,
576                                                     xns : Roo.form,
577                                                     name : 'curr_name',
578                                                     qtip : "Select Currency",
579                                                     queryParam : 'query[curr_name]',
580                                                     tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{curr_name}</b> </div>',
581                                                     loadingText : "Searching...",
582                                                     items : [
583
584                                                     ]
585
586                                                 },
587                                                 {
588                                                     '|xns' : 'Roo.form',
589                                                     fieldLabel : 'Value',
590                                                     xtype : 'NumberField',
591                                                     allowBlank : false,
592                                                     width : 200,
593                                                     xns : Roo.form,
594                                                     name : 'item_itemcost_id_itemcost_actcost'
595                                                 }
596                                             ]
597
598                                         }
599                                     ]
600
601                                 },
602                                 {
603                                     '|xns' : 'Roo.form',
604                                     xtype : 'Column',
605                                     xns : Roo.form,
606                                     items : [
607                                         {
608                                             '|xns' : 'Roo.form',
609                                             xtype : 'FieldSet',
610                                             legend : "Itemsite Settings",
611                                             xns : Roo.form,
612                                             style : 'width:335px;',
613                                             labelWidth : 120,
614                                             listeners : {
615                                                 render : function (_self)
616                                                    {
617                                                        _this.itemsiteFieldSet = _self;
618                                                    }
619                                             },
620                                             items : [
621                                                 {
622                                                     '|xns' : 'Roo.form',
623                                                     fieldLabel : 'Reorder Level',
624                                                     xtype : 'NumberField',
625                                                     allowBlank : false,
626                                                     width : 200,
627                                                     xns : Roo.form,
628                                                     name : 'item_itemsite_id_itemsite_reorderlevel'
629                                                 },
630                                                 {
631                                                     '|xns' : 'Roo.form',
632                                                     fieldLabel : 'Stock Safety Level',
633                                                     xtype : 'NumberField',
634                                                     allowBlank : false,
635                                                     width : 200,
636                                                     xns : Roo.form,
637                                                     name : 'item_itemsite_id_itemsite_safetystock'
638                                                 },
639                                                 {
640                                                     '|xns' : 'Roo.form',
641                                                     fieldLabel : 'Lead time (Days)',
642                                                     xtype : 'NumberField',
643                                                     allowBlank : false,
644                                                     width : 200,
645                                                     xns : Roo.form,
646                                                     name : 'item_itemsite_id_itemsite_leadtime'
647                                                 },
648                                                 {
649                                                     store : {
650                                                         '|xns' : 'Roo.data',
651                                                         xtype : 'SimpleStore',
652                                                         data : [ 
653                                                             [ 'N', "None"],
654                                                             [ 'R' , "Regular"]
655                                                         ],
656                                                         fields : [  'ftype', 'fname'],
657                                                         xns : Roo.data
658                                                     },
659                                                     '|xns' : 'Roo.form',
660                                                     listWidth : 200,
661                                                     triggerAction : 'all',
662                                                     fieldLabel : 'Control Method',
663                                                     displayField : 'fname',
664                                                     hiddenName : 'item_itemsite_id_itemsite_controlmethod',
665                                                     valueField : 'ftype',
666                                                     xtype : 'ComboBox',
667                                                     allowBlank : false,
668                                                     editable : false,
669                                                     width : 200,
670                                                     xns : Roo.form,
671                                                     mode : 'local',
672                                                     name : 'item_itemsite_id_itemsite_controlmethod_name',
673                                                     tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{fname}</b> </div>',
674                                                     items : [
675
676                                                     ]
677
678                                                 },
679                                                 {
680                                                     store : {
681                                                         proxy : {
682                                                             '|xns' : 'Roo.data',
683                                                             url : baseURL + '/Roo/plancode.php',
684                                                             xtype : 'HttpProxy',
685                                                             method : 'GET',
686                                                             xns : Roo.data
687                                                         },
688                                                         reader : {
689                                                             '|xns' : 'Roo.data',
690                                                             id : 'id',
691                                                             root : 'data',
692                                                             xtype : 'JsonReader',
693                                                             xns : Roo.data,
694                                                             fields : [{"name":"id","type":"int"},{"name":"plancode_code","type":"string"}],
695                                                             totalProperty : 'total'
696                                                         },
697                                                         '|xns' : 'Roo.data',
698                                                         xtype : 'Store',
699                                                         remoteSort : true,
700                                                         xns : Roo.data,
701                                                         sortInfo : { direction : 'ASC', field: 'id' },
702                                                         listeners : {
703                                                                 beforeload : function (_self, o){
704                                                                        o.params = o.params || {};
705                                                                        // set more here
706                                                                    }
707                                                         },
708                                                         items : [
709
710                                                         ]
711
712                                                     },
713                                                     '|xns' : 'Roo.form',
714                                                     listWidth : 400,
715                                                     triggerAction : 'all',
716                                                     fieldLabel : 'Planner Code',
717                                                     forceSelection : true,
718                                                     selectOnFocus : true,
719                                                     pageSize : 20,
720                                                     displayField : 'plancode_name',
721                                                     emptyText : "Select plancode",
722                                                     hiddenName : 'item_itemsite_id_itemsite_plancode_id',
723                                                     minChars : 2,
724                                                     valueField : 'plancode_id',
725                                                     xtype : 'ComboBox',
726                                                     allowBlank : false,
727                                                     typeAhead : true,
728                                                     editable : false,
729                                                     width : 200,
730                                                     xns : Roo.form,
731                                                     name : 'plancode_name',
732                                                     qtip : "Select plancode",
733                                                     queryParam : '',
734                                                     tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{plancode_name}</b> </div>',
735                                                     loadingText : "Searching...",
736                                                     items : [
737
738                                                     ]
739
740                                                 },
741                                                 {
742                                                     store : {
743                                                         proxy : {
744                                                             '|xns' : 'Roo.data',
745                                                             url : baseURL + '/Roo/costcat.php',
746                                                             xtype : 'HttpProxy',
747                                                             method : 'GET',
748                                                             xns : Roo.data
749                                                         },
750                                                         reader : {
751                                                             '|xns' : 'Roo.data',
752                                                             id : 'id',
753                                                             root : 'data',
754                                                             xtype : 'JsonReader',
755                                                             xns : Roo.data,
756                                                             fields : [{"name":"id","type":"int"},{"name":"costcat_code","type":"string"}],
757                                                             totalProperty : 'total'
758                                                         },
759                                                         '|xns' : 'Roo.data',
760                                                         xtype : 'Store',
761                                                         remoteSort : true,
762                                                         xns : Roo.data,
763                                                         sortInfo : { direction : 'ASC', field: 'id' },
764                                                         listeners : {
765                                                                 beforeload : function (_self, o){
766                                                                        o.params = o.params || {};
767                                                                        // set more here
768                                                                    }
769                                                         },
770                                                         items : [
771
772                                                         ]
773
774                                                     },
775                                                     '|xns' : 'Roo.form',
776                                                     listWidth : 400,
777                                                     triggerAction : 'all',
778                                                     fieldLabel : 'Costcat',
779                                                     forceSelection : true,
780                                                     selectOnFocus : true,
781                                                     pageSize : 20,
782                                                     displayField : 'costcat_code',
783                                                     emptyText : "Select costcat",
784                                                     hiddenName : 'item_itemsite_id_itemsite_costcat_id',
785                                                     minChars : 2,
786                                                     valueField : 'costcat_id',
787                                                     xtype : 'ComboBox',
788                                                     allowBlank : false,
789                                                     typeAhead : true,
790                                                     editable : false,
791                                                     width : 200,
792                                                     xns : Roo.form,
793                                                     name : 'costcat_code',
794                                                     qtip : "Select costcat",
795                                                     queryParam : '',
796                                                     tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{costcat_code}</b> </div>',
797                                                     loadingText : "Searching...",
798                                                     items : [
799
800                                                     ]
801
802                                                 },
803                                                 {
804                                                     '|xns' : 'Roo.form',
805                                                     fieldLabel : 'Active',
806                                                     inputValue : true,
807                                                     xtype : 'Checkbox',
808                                                     valueOff : 0,
809                                                     width : 75,
810                                                     xns : Roo.form,
811                                                     name : 'item_itemsite_id_itemsite_active'
812                                                 },
813                                                 {
814                                                     '|xns' : 'Roo.form',
815                                                     fieldLabel : 'Sold',
816                                                     inputValue : true,
817                                                     xtype : 'Checkbox',
818                                                     valueOff : 0,
819                                                     width : 75,
820                                                     xns : Roo.form,
821                                                     name : 'item_itemsite_id_itemsite_sold'
822                                                 },
823                                                 {
824                                                     '|xns' : 'Roo.form',
825                                                     fieldLabel : 'Stocked',
826                                                     inputValue : true,
827                                                     xtype : 'Checkbox',
828                                                     valueOff : 0,
829                                                     width : 75,
830                                                     xns : Roo.form,
831                                                     name : 'item_itemsite_id_itemsite_stocked'
832                                                 },
833                                                 {
834                                                     '|xns' : 'Roo.form',
835                                                     fieldLabel : 'Perishable',
836                                                     inputValue : true,
837                                                     xtype : 'Checkbox',
838                                                     valueOff : 0,
839                                                     width : 75,
840                                                     xns : Roo.form,
841                                                     name : 'item_itemsite_id_itemsite_perishable'
842                                                 },
843                                                 {
844                                                     '|xns' : 'Roo.form',
845                                                     fieldLabel : 'Multi Location',
846                                                     inputValue : true,
847                                                     xtype : 'Checkbox',
848                                                     valueOff : 0,
849                                                     width : 100,
850                                                     xns : Roo.form,
851                                                     name : 'item_itemsite_id_itemsite_loccntrl'
852                                                 },
853                                                 {
854                                                     store : {
855                                                         proxy : {
856                                                             '|xns' : 'Roo.data',
857                                                             url : baseURL + '/Roo/location.php',
858                                                             method : 'GET',
859                                                             xtype : 'HttpProxy',
860                                                             xns : Roo.data
861                                                         },
862                                                         reader : {
863                                                             '|xns' : 'Roo.data',
864                                                             id : 'location_id',
865                                                             root : 'data',
866                                                             xtype : 'JsonReader',
867                                                             fields : [{"name":"location_id","type":"int"},"location_name"],
868                                                             xns : Roo.data,
869                                                             totalProperty : 'total'
870                                                         },
871                                                         '|xns' : 'Roo.data',
872                                                         xtype : 'Store',
873                                                         remoteSort : true,
874                                                         sortInfo : { direction : 'ASC', field: 'location_name' },
875                                                         xns : Roo.data,
876                                                         listeners : {
877                                                                 beforeload : function (_self, o){
878                                                                        o.params = o.params || {};
879                                                                        // set more here
880                                                                         o.params.location_netable = 1;
881                                                                         o.params._notinternalcompany = 1;
882                                                                         o.params.location_restrict = 0;
883                                                                    }
884                                                         },
885                                                         items : [
886
887                                                         ]
888
889                                                     },
890                                                     '|xns' : 'Roo.form',
891                                                     listWidth : 400,
892                                                     triggerAction : 'all',
893                                                     fieldLabel : 'Default Location',
894                                                     forceSelection : true,
895                                                     selectOnFocus : true,
896                                                     pageSize : 200,
897                                                     displayField : 'location_name',
898                                                     emptyText : "Default Location",
899                                                     hiddenName : 'item_itemsite_id_itemsite_location_id',
900                                                     minChars : 2,
901                                                     valueField : 'location_id',
902                                                     xtype : 'ComboBox',
903                                                     allowBlank : false,
904                                                     typeAhead : false,
905                                                     editable : true,
906                                                     width : 200,
907                                                     xns : Roo.form,
908                                                     name : 'location_name',
909                                                     qtip : "Select terms",
910                                                     queryParam : 'query[location_name]',
911                                                     tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{location_name}</b> </div>',
912                                                     loadingText : "Searching...",
913                                                     items : [
914
915                                                     ]
916
917                                                 }
918                                             ]
919
920                                         }
921                                     ]
922
923                                 },
924                                 {
925                                     '|xns' : 'Roo.form',
926                                     xtype : 'Hidden',
927                                     xns : Roo.form,
928                                     width : 75,
929                                     name : 'item_id'
930                                 },
931                                 {
932                                     '|xns' : 'Roo.form',
933                                     value : 1,
934                                     xtype : 'Hidden',
935                                     width : 75,
936                                     xns : Roo.form,
937                                     name : '_update_related'
938                                 }
939                             ]
940
941                         }
942                     ]
943
944                 },
945                 {
946                     grid : {
947                         toolbar : {
948                             '|xns' : 'Roo',
949                             xtype : 'Toolbar',
950                             xns : Roo,
951                             items : [
952                                 {
953                                     store : {
954                                         proxy : {
955                                             '|xns' : 'Roo.data',
956                                             url : baseURL + '/Roo/item.php',
957                                             method : 'GET',
958                                             xtype : 'HttpProxy',
959                                             xns : Roo.data
960                                         },
961                                         reader : {
962                                             '|xns' : 'Roo.data',
963                                             id : 'id',
964                                             root : 'data',
965                                             xtype : 'JsonReader',
966                                             fields : [
967                                                 {"name":"id","type":"int"},
968                                                 {"name":"item_number","type":"string"}
969                                             ],
970                                             xns : Roo.data,
971                                             totalProperty : 'total'
972                                         },
973                                         '|xns' : 'Roo.data',
974                                         xtype : 'Store',
975                                         remoteSort : true,
976                                         sortInfo : { direction : 'ASC', field: 'item_number' },
977                                         xns : Roo.data,
978                                         listeners : {
979                                                 beforeload : function (_self, o){
980                                                        o.params = o.params || {};
981                                                        
982                                                        o.params.item_active = 1;
983                                                        o.params['!item_type'] = 'K';
984                                                    }
985                                         },
986                                         items : [
987
988                                         ]
989
990                                     },
991                                     '|xns' : 'Roo.bootstrap',
992                                     alwaysQuery : true,
993                                     triggerAction : 'all',
994                                     fieldLabel : 'Item',
995                                     forceSelection : true,
996                                     selectOnFocus : true,
997                                     pageSize : 20,
998                                     displayField : 'item_number',
999                                     emptyText : "Select item",
1000                                     minChars : 2,
1001                                     valueField : 'id',
1002                                     xtype : 'ComboBox',
1003                                     allowBlank : true,
1004                                     typeAhead : true,
1005                                     editable : true,
1006                                     width : 200,
1007                                     xns : Roo.bootstrap,
1008                                     qtip : "Select item",
1009                                     queryParam : 'query[number_or_name]',
1010                                     tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{item_number}</b> </div>',
1011                                     loadingText : "Searching...",
1012                                     listeners : {
1013                                         render : function (_self)
1014                                            {
1015                                                _this.partsBox = _self;
1016                                            },
1017                                         select : function (combo, record, index)
1018                                            {
1019                                                var item_id = _this.form.findField('item_id').getValue() * 1;
1020                                                
1021                                                if(typeof(record) == 'undefined' || !record || record.data.id * 1 < 1 || item_id < 1){
1022                                                    return;
1023                                                }
1024                                                
1025                                                var err = false;
1026                                            
1027                                                _this.partsgrid.ds.each(function(d){
1028                                                    if(record.data.item_id == d.data.bomitem_item_id){
1029                                                        err = true;
1030                                                    }
1031                                                });
1032                                            
1033                                                if(err){
1034                                                    Roo.MessageBox.alert('Error', record.data.item_number + ' already exists!');
1035                                                    _this.partsBox.reset();
1036                                                    return;
1037                                                }
1038                                                
1039                                                new Pman.Request({
1040                                                    url : baseURL + '/Roo/bomitem.php',
1041                                                    method : 'POST',
1042                                                    params : {
1043                                                        bomitem_parent_item_id : item_id,
1044                                                        bomitem_item_id : record.data.item_id
1045                                                    }, 
1046                                                    success : function(res) {
1047                                                        _this.partsBox.reset();
1048                                                        _this.partsgrid.footer.onClick('first');
1049                                                    }
1050                                                }); 
1051                                            }
1052                                     },
1053                                     items : [
1054
1055                                     ]
1056
1057                                 },
1058                                 {
1059                                     '|xns' : 'Roo.Toolbar',
1060                                     xtype : 'Fill',
1061                                     xns : Roo.Toolbar
1062                                 },
1063                                 {
1064                                     '|xns' : 'Roo',
1065                                     text : "Remove",
1066                                     xtype : 'Button',
1067                                     cls : 'x-btn-text-icon',
1068                                     icon : rootURL + '/Pman/templates/images/trash.gif',
1069                                     xns : Roo,
1070                                     listeners : {
1071                                         click : function ()
1072                                            {
1073                                                var sel = _this.partsgrid.getSelectionModel().getSelectedCell();
1074                                                
1075                                                if(!sel || !sel.length){
1076                                                    Roo.MessageBox.alert("Error", "Please select a item from below list");
1077                                                    return;
1078                                                }
1079                                                
1080                                                var d = _this.partsgrid.ds.getAt(sel[0]);      
1081                                              
1082                                                if(d.data.bomitem_id * 1 < 1){
1083                                                    Roo.MessageBox.alert("Error", "Invaild selection");
1084                                                    return;
1085                                                }
1086                                                
1087                                                new Pman.Request({
1088                                                    url : baseURL + '/Roo/bomitem.php',
1089                                                    method : 'POST',
1090                                                    params : {
1091                                                        _delete : d.data.bomitem_id
1092                                                    }, 
1093                                                    success : function(res) {
1094                                                        _this.partsgrid.footer.onClick('first');
1095                                                    }
1096                                                }); 
1097                                               
1098                                            }
1099                                     }
1100                                 }
1101                             ]
1102
1103                         },
1104                         dataSource : {
1105                             proxy : {
1106                                 '|xns' : 'Roo.data',
1107                                 url : baseURL + '/Roo/bomitem.php',
1108                                 xtype : 'HttpProxy',
1109                                 method : 'GET',
1110                                 xns : Roo.data
1111                             },
1112                             reader : {
1113                                 '|xns' : 'Roo.data',
1114                                 id : 'bom_id',
1115                                 root : 'data',
1116                                 xtype : 'JsonReader',
1117                                 fields : [
1118                                     {
1119                                         'name': 'bomitem_id',
1120                                         'type': 'int'
1121                                     }
1122                                 ],
1123                                 xns : Roo.data,
1124                                 totalProperty : 'total'
1125                             },
1126                             '|xns' : 'Roo.data',
1127                             xtype : 'Store',
1128                             remoteSort : true,
1129                             sortInfo : { field : 'bomitem_item_id_item_name', direction: 'ASC' },
1130                             xns : Roo.data,
1131                             listeners : {
1132                                 beforeload : function (_self, o)
1133                                    {
1134                                       o.params = o.params || {};
1135                                       
1136                                       var id  = _this.form.findField('item_id').getValue() * 1;
1137                                       if(id < 1){
1138                                            return false;
1139                                       }
1140                                       
1141                                       o.params.bom_parent_item_id = id;
1142                                    }
1143                             },
1144                             items : [
1145
1146                             ]
1147
1148                         },
1149                         footer : {
1150                             '|xns' : 'Roo',
1151                             pageSize : 50,
1152                             xtype : 'PagingToolbar',
1153                             emptyMsg : "Nothing found",
1154                             xns : Roo,
1155                             displayMsg : "Displaying parts {0} - {1} of {2}",
1156                             displayInfo : true
1157                         },
1158                         '|xns' : 'Roo.grid',
1159                         autoExpandColumn : 'bomitem_item_id_item_descrip1',
1160                         xtype : 'EditorGrid',
1161                         loadMask : true,
1162                         clicksToEdit : 1,
1163                         xns : Roo.grid,
1164                         colModel : [
1165                                  {
1166                                         '|xns' : 'Roo.grid',
1167                                         xtype : 'ColumnModel',
1168                                         header : 'Name',
1169                                         width : 150,
1170                                         renderer : function(v) { return String.format('{0}', v); },
1171                                         xns : Roo.grid,
1172                                         dataIndex : 'bomitem_item_id_item_number'
1173                                     },
1174 {
1175                                         '|xns' : 'Roo.grid',
1176                                         xtype : 'ColumnModel',
1177                                         header : 'Description',
1178                                         width : 150,
1179                                         renderer : function(v) { return String.format('{0}', v); },
1180                                         xns : Roo.grid,
1181                                         dataIndex : 'bomitem_item_id_item_descrip1'
1182                                     },
1183 {
1184                                         editor : {
1185                                             field : {
1186                                                 '|xns' : 'Roo.form',
1187                                                 xtype : 'NumberField',
1188                                                 xns : Roo.form
1189                                             },
1190                                             '|xns' : 'Roo.grid',
1191                                             xtype : 'GridEditor',
1192                                             xns : Roo.grid,
1193                                             items : [
1194
1195                                             ]
1196
1197                                         },
1198                                         '|xns' : 'Roo.grid',
1199                                         xtype : 'ColumnModel',
1200                                         align : 'right',
1201                                         header : 'Qty',
1202                                         width : 100,
1203                                         renderer : function(v) { return String.format('{0}', v); },
1204                                         xns : Roo.grid,
1205                                         dataIndex : 'bomitem_qtyper',
1206                                         items : [
1207
1208                                         ]
1209
1210                                     }
1211                         ],
1212                         listeners : {
1213                                 beforeedit : function (e)
1214                                    {
1215                                        Roo.log('before');
1216                                        Roo.log(e);
1217                                        if(e.field != 'ipshead_ipsitem_price'){
1218                                            return false;
1219                                        }
1220                                        
1221                                    },
1222                                 render : function() 
1223                                    {
1224                                        _this.partsgrid = this; 
1225                                        //_this.dialog = Pman.Dialog.FILL_IN
1226                                        if (_this.partspanel.active) {
1227                                           this.footer.onClick('first');
1228                                        }
1229                                    },
1230                                 afteredit : function (e)
1231                                    {
1232                                        Roo.log('after');
1233                                        Roo.log(e);
1234                                        if(e.originalValue == e.value){
1235                                            return false;
1236                                        }
1237                                        return false;
1238                                        
1239                                        
1240                                        var id = _this.form.findField('item_id').getValue() * 1;
1241                                        if(id < 1){
1242                                            return false;
1243                                        }
1244                                        
1245                                        new Pman.Request({
1246                                            method : 'POST',
1247                                            url : baseURL + '/Roo/ipsiteminfo',
1248                                            mask : 'Saving',
1249                                            params : {
1250                                                ipsitem_ipshead_id : e.record.data.ipshead_id,
1251                                                ipsitem_item_id : id,
1252                                                ipsitem_price : e.record.data.ipshead_ipsitem_price,
1253                                                ipsitem_id : e.record.data.ipshead_ipsitem_id
1254                                            }
1255                                        
1256                                        });
1257                                            
1258                                             
1259                                            
1260                                            
1261                                    }
1262                         },
1263                         items : [
1264
1265                         ]
1266
1267                     },
1268                     '|xns' : 'Roo',
1269                     background : true,
1270                     region : 'center',
1271                     fitToframe : true,
1272                     title : "Item Parts",
1273                     xtype : 'GridPanel',
1274                     fitContainer : true,
1275                     xns : Roo,
1276                     tableName : 'bomitem',
1277                     listeners : {
1278                         activate : function() {
1279                                _this.partspanel = this;
1280                                
1281                                try { if (MODULE.isBuilder) {
1282                                    return;
1283                                } } catch(e) { }
1284                                
1285                                var id = _this.form.findField('item_id').getValue() * 1;
1286                                if (id < 1) {
1287                                    Roo.MessageBox.alert("Save First", "Save the item first, before adding parts");
1288                                    _this.dialog.layout.getRegion('center').showPanel(0);
1289                                    return;
1290                                }
1291                                
1292                                var type = _this.form.findField('item_type').getValue();
1293                                
1294                                if(!type.length || type != 'K'){
1295                                    Roo.MessageBox.alert("Error", "Can't add parts to non-kit item");
1296                                    _this.dialog.layout.getRegion('center').showPanel(0);
1297                                    return;
1298                                }
1299                                
1300                                if (_this.partsgrid) {
1301                                    _this.partsgrid.footer.onClick('first');
1302                                
1303                                 }
1304                            }
1305                     },
1306                     items : [
1307
1308                     ]
1309
1310                 },
1311                 {
1312                     grid : {
1313                         dataSource : {
1314                             reader : {
1315                                 '|xns' : 'Roo.data',
1316                                 id : 'id',
1317                                 root : 'data',
1318                                 xtype : 'JsonReader',
1319                                 fields : [
1320                                     {
1321                                         'name': 'id',
1322                                         'type': 'int'
1323                                     },
1324                                     {
1325                                         'name': 'filename',
1326                                         'type': 'string'
1327                                     },
1328                                     {
1329                                         'name': 'ontable',
1330                                         'type': 'string'
1331                                     },
1332                                     {
1333                                         'name': 'onid',
1334                                         'type': 'int'
1335                                     },
1336                                     {
1337                                         'name': 'mimetype',
1338                                         'type': 'string'
1339                                     },
1340                                     {
1341                                         'name': 'width',
1342                                         'type': 'int'
1343                                     },
1344                                     {
1345                                         'name': 'height',
1346                                         'type': 'int'
1347                                     },
1348                                     {
1349                                         'name': 'filesize',
1350                                         'type': 'int'
1351                                     },
1352                                     {
1353                                         'name': 'displayorder',
1354                                         'type': 'int'
1355                                     },
1356                                     {
1357                                         'name': 'language',
1358                                         'type': 'string'
1359                                     },
1360                                     {
1361                                         'name': 'parent_image_id',
1362                                         'type': 'int'
1363                                     },
1364                                     {
1365                                         'name': 'created',
1366                                         'type': 'date',
1367                                         'dateFormat' : 'Y-m-d H:i:s'
1368                                     },
1369                                     {
1370                                         'name': 'imgtype',
1371                                         'type': 'string'
1372                                     },
1373                                     {
1374                                         'name': 'linkurl',
1375                                         'type': 'string'
1376                                     },
1377                                     {
1378                                         'name': 'descript',
1379                                         'type': 'string'
1380                                     },
1381                                     {
1382                                         'name': 'title',
1383                                         'type': 'string'
1384                                     }
1385                                 ],
1386                                 xns : Roo.data,
1387                                 totalProperty : 'total'
1388                             },
1389                             proxy : {
1390                                 '|xns' : 'Roo.data',
1391                                 url : baseURL + '/Roo/Images.php',
1392                                 xtype : 'HttpProxy',
1393                                 method : 'GET',
1394                                 xns : Roo.data
1395                             },
1396                             '|xns' : 'Roo.data',
1397                             xtype : 'Store',
1398                             remoteSort : true,
1399                             sortInfo : { field: 'created' , direction: 'DESC' },
1400                             xns : Roo.data,
1401                             listeners : {
1402                                 beforeload : function (_self, o)
1403                                    {
1404                                        o.params = o.params || {};
1405                                        
1406                                        var id = _this.form.findField('item_id').getValue();
1407                                        
1408                                        if(id * 1 < 1){
1409                                            return false;
1410                                        }
1411                                        
1412                                        o.params.onid = id;
1413                                        o.params.ontable = 'item';
1414                                        
1415                                    }
1416                             },
1417                             items : [
1418
1419                             ]
1420
1421                         },
1422                         footer : {
1423                             '|xns' : 'Roo',
1424                             pageSize : 25,
1425                             xtype : 'PagingToolbar',
1426                             emptyMsg : "No Images found",
1427                             xns : Roo,
1428                             displayInfo : true,
1429                             displayMsg : "Displaying Images  {0} - {1} of {2}"
1430                         },
1431                         toolbar : {
1432                             '|xns' : 'Roo',
1433                             xtype : 'Toolbar',
1434                             xns : Roo,
1435                             items : [
1436                                 {
1437                                     '|xns' : 'Roo.Toolbar',
1438                                     text : "Add",
1439                                     xtype : 'Button',
1440                                     cls : 'x-btn-text-icon',
1441                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
1442                                     xns : Roo.Toolbar,
1443                                     listeners : {
1444                                         click : function()
1445                                            {
1446                                                Pman.Dialog.Image.show({
1447                                                    id : 0, 
1448                                                    ontable: 'item',
1449                                                    onid: _this.form.findField('item_id').getValue() * 1,
1450                                                    imgtype : ''
1451                                                }, function(data){
1452                                                    if (!data) { return; } 
1453                                                    _this.grid.footer.onClick('first');
1454                                                }); 
1455                                            
1456                                            }
1457                                     }
1458                                 },
1459                                 {
1460                                     '|xns' : 'Roo.Toolbar',
1461                                     text : "Delete",
1462                                     xtype : 'Button',
1463                                     cls : 'x-btn-text-icon',
1464                                     icon : rootURL + '/Pman/templates/images/trash.gif',
1465                                     xns : Roo.Toolbar,
1466                                     listeners : {
1467                                         click : function()
1468                                            {
1469                                                Pman.genericDelete(_this, 'Images'); 
1470                                            }
1471                                     }
1472                                 }
1473                             ]
1474
1475                         },
1476                         '|xns' : 'Roo.grid',
1477                         autoExpandColumn : 'id',
1478                         xtype : 'Grid',
1479                         loadMask : true,
1480                         xns : Roo.grid,
1481                         colModel : [
1482                                  {
1483                                         '|xns' : 'Roo.grid',
1484                                         xtype : 'ColumnModel',
1485                                         sortable : true,
1486                                         header : 'Created',
1487                                         width : 200,
1488                                         renderer : function(v,x,r) {
1489                                                return String.format('{0}<br/><i>{1}</i><br/>{2}<br/><i>{3}x{4}</i>',
1490                                                     v.format('d/M/Y'), r.data.mimetype, r.data.filename,
1491                                             r.data.width, r.data.height
1492                                             ); 
1493                                         },
1494                                         xns : Roo.grid,
1495                                         dataIndex : 'created'
1496                                     },
1497 {
1498                                         '|xns' : 'Roo.grid',
1499                                         xtype : 'ColumnModel',
1500                                         width : 100,
1501                                         header : 'Image',
1502                                         renderer : function(v,x,r) { return String.format('<img src="{0}/Images/Thumb/100/{1}/{2}" height="100">', baseURL, v, r.data.filename); },
1503                                         xns : Roo.grid,
1504                                         dataIndex : 'id'
1505                                     }
1506                         ],
1507                         listeners : {
1508                                 rowdblclick : function (_self, rowIndex, e)
1509                                    {
1510                                      
1511                                       var s =  _self.getDataSource().getAt(rowIndex);
1512                                       new Pman.Download({
1513                                            url : baseURL + '/Images/Download/' + s.data.id
1514                                        });
1515                                       
1516                                    },
1517                                 render : function() { 
1518                                        _this.grid = this; 
1519                                    
1520                                        if (_this.panel.active) {
1521                                           this.footer.onClick('first');
1522                                        }
1523                                    }
1524                         },
1525                         items : [
1526
1527                         ]
1528
1529                     },
1530                     '|xns' : 'Roo',
1531                     region : 'center',
1532                     fitToframe : true,
1533                     background : true,
1534                     title : "Reference Files",
1535                     xtype : 'GridPanel',
1536                     fitContainer : true,
1537                     xns : Roo,
1538                     tableName : 'Images',
1539                     listeners : {
1540                         activate : function() {
1541                                _this.panel = this;
1542                                
1543                                try { if (MODULE.isBuilder) {
1544                                    return;
1545                                } } catch(e) { }
1546                                
1547                                var id = _this.form.findField('item_id').getValue() * 1;
1548                                if (id < 1) {
1549                                    Roo.MessageBox.alert("Save First", "Save the item first, before adding image");
1550                                    _this.dialog.layout.getRegion('center').showPanel(0);
1551                                    return;
1552                                }
1553                                
1554                                if (_this.grid) {
1555                                    _this.grid.footer.onClick('first');
1556                                
1557                                 }
1558                            }
1559                     },
1560                     items : [
1561
1562                     ]
1563
1564                 },
1565                 {
1566                     grid : {
1567                         dataSource : {
1568                             proxy : {
1569                                 '|xns' : 'Roo.data',
1570                                 url : baseURL + '/Roo/ipshead.php',
1571                                 method : 'GET',
1572                                 xtype : 'HttpProxy',
1573                                 xns : Roo.data
1574                             },
1575                             reader : {
1576                                 '|xns' : 'Roo.data',
1577                                 id : 'ipshead_id',
1578                                 root : 'data',
1579                                 xtype : 'JsonReader',
1580                                 fields : [
1581                                     {
1582                                         'name': 'ipshead_id',
1583                                         'type': 'int'
1584                                     },
1585                                     {
1586                                         'name': 'ipshead_name',
1587                                         'type': 'string'
1588                                     }
1589                                 ],
1590                                 xns : Roo.data,
1591                                 totalProperty : 'total'
1592                             },
1593                             '|xns' : 'Roo.data',
1594                             xtype : 'Store',
1595                             remoteSort : true,
1596                             sortInfo : { field : 'ipshead_id', direction: 'ASC' },
1597                             xns : Roo.data,
1598                             listeners : {
1599                                 beforeload : function (_self, o)
1600                                    {
1601                                       o.params = o.params || {};
1602                                       
1603                                       var id  = _this.form.findField('item_id').getValue() * 1;
1604                                       if(id < 1){
1605                                            return false;
1606                                       }
1607                                       
1608                                       o.params._with_item = id;
1609                                    }
1610                             },
1611                             items : [
1612
1613                             ]
1614
1615                         },
1616                         footer : {
1617                             '|xns' : 'Roo',
1618                             pageSize : 50,
1619                             xtype : 'PagingToolbar',
1620                             emptyMsg : "Nothing found",
1621                             xns : Roo,
1622                             displayMsg : "Displaying records {0} - {1} of {2}",
1623                             displayInfo : true
1624                         },
1625                         '|xns' : 'Roo.grid',
1626                         autoExpandColumn : 'ipshead_descrip',
1627                         xtype : 'EditorGrid',
1628                         loadMask : true,
1629                         clicksToEdit : 1,
1630                         xns : Roo.grid,
1631                         colModel : [
1632                                  {
1633                                         '|xns' : 'Roo.grid',
1634                                         xtype : 'ColumnModel',
1635                                         width : 150,
1636                                         header : 'Name',
1637                                         renderer : function(v) { return String.format('{0}', v); },
1638                                         xns : Roo.grid,
1639                                         dataIndex : 'ipshead_name'
1640                                     },
1641 {
1642                                         '|xns' : 'Roo.grid',
1643                                         xtype : 'ColumnModel',
1644                                         width : 150,
1645                                         header : 'Description',
1646                                         renderer : function(v) { return String.format('{0}', v); },
1647                                         xns : Roo.grid,
1648                                         dataIndex : 'ipshead_descrip'
1649                                     },
1650 {
1651                                         '|xns' : 'Roo.grid',
1652                                         xtype : 'ColumnModel',
1653                                         width : 100,
1654                                         header : 'Currency',
1655                                         renderer : function(v) { return String.format('{0}', v); },
1656                                         xns : Roo.grid,
1657                                         dataIndex : 'ipshead_curr_id_curr_name'
1658                                     },
1659 {
1660                                         editor : {
1661                                             field : {
1662                                                 '|xns' : 'Roo.form',
1663                                                 xtype : 'NumberField',
1664                                                 cls : 'align-right',
1665                                                 decimalPrecision : 2,
1666                                                 xns : Roo.form
1667                                             },
1668                                             '|xns' : 'Roo.grid',
1669                                             xtype : 'GridEditor',
1670                                             xns : Roo.grid,
1671                                             items : [
1672
1673                                             ]
1674
1675                                         },
1676                                         '|xns' : 'Roo.grid',
1677                                         align : 'right',
1678                                         xtype : 'ColumnModel',
1679                                         header : 'Price',
1680                                         width : 120,
1681                                         renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v*1,2)); },
1682                                         xns : Roo.grid,
1683                                         dataIndex : 'ipshead_ipsitem_price',
1684                                         items : [
1685
1686                                         ]
1687
1688                                     }
1689                         ],
1690                         listeners : {
1691                                 beforeedit : function (e)
1692                                    {
1693                                        if(e.field != 'ipshead_ipsitem_price'){
1694                                            return false;
1695                                        }
1696                                        
1697                                    },
1698                                 render : function() 
1699                                    {
1700                                        _this.lgrid = this; 
1701                                        //_this.dialog = Pman.Dialog.FILL_IN
1702                                        if (_this.lpanel.active) {
1703                                           this.footer.onClick('first');
1704                                        }
1705                                    },
1706                                 afteredit : function (e)
1707                                    {
1708                                        if(e.originalValue == e.value){
1709                                            return false;
1710                                        }
1711                                        
1712                                        var id = _this.form.findField('item_id').getValue() * 1;
1713                                        if(id < 1){
1714                                            return false;
1715                                        }
1716                                        
1717                                        new Pman.Request({
1718                                            method : 'POST',
1719                                            url : baseURL + '/Roo/ipsiteminfo',
1720                                            mask : 'Saving',
1721                                            params : {
1722                                                ipsitem_ipshead_id : e.record.data.ipshead_id,
1723                                                ipsitem_item_id : id,
1724                                                ipsitem_price : e.record.data.ipshead_ipsitem_price,
1725                                                ipsitem_id : e.record.data.ipshead_ipsitem_id
1726                                            }
1727                                        
1728                                        });
1729                                            
1730                                             
1731                                            
1732                                            
1733                                    }
1734                         },
1735                         items : [
1736
1737                         ]
1738
1739                     },
1740                     '|xns' : 'Roo',
1741                     region : 'center',
1742                     fitToframe : true,
1743                     background : true,
1744                     title : "Price List",
1745                     xtype : 'GridPanel',
1746                     fitContainer : true,
1747                     xns : Roo,
1748                     tableName : 'ipshead',
1749                     listeners : {
1750                         activate : function() {
1751                                _this.lpanel = this;
1752                                
1753                                try { if (MODULE.isBuilder) {
1754                                    return;
1755                                } } catch(e) { }
1756                                
1757                                var id = _this.form.findField('item_id').getValue() * 1;
1758                                if (id < 1) {
1759                                    Roo.MessageBox.alert("Save First", "Save the item first, before adding image");
1760                                    _this.dialog.layout.getRegion('center').showPanel(0);
1761                                    return;
1762                                }
1763                                
1764                                if (_this.lgrid) {
1765                                    _this.lgrid.footer.onClick('first');
1766                                
1767                                 }
1768                            }
1769                     },
1770                     items : [
1771
1772                     ]
1773
1774                 },
1775                 {
1776                     grid : {
1777                         dataSource : {
1778                             proxy : {
1779                                 '|xns' : 'Roo.data',
1780                                 url : baseURL + '/Roo/itemsrc.php',
1781                                 xtype : 'HttpProxy',
1782                                 method : 'GET',
1783                                 xns : Roo.data
1784                             },
1785                             reader : {
1786                                 '|xns' : 'Roo.data',
1787                                 id : 'id',
1788                                 root : 'data',
1789                                 xtype : 'JsonReader',
1790                                 xns : Roo.data,
1791                                 fields : [
1792                                     {
1793                                         'name': 'itemsrc_id',
1794                                         'type': 'int'
1795                                     },
1796                                     {
1797                                         'name': 'itemsrc_item_id',
1798                                         'type': 'int'
1799                                     },
1800                                     {
1801                                         'name': 'itemsrc_item_id',
1802                                         'type': 'int'
1803                                     },
1804                                     {
1805                                         'name': 'itemsrc_vend_id',
1806                                         'type': 'int'
1807                                     },
1808                                     {
1809                                         'name': 'itemsrc_vend_id',
1810                                         'type': 'int'
1811                                     },
1812                                     {
1813                                         'name': 'itemsrc_vend_item_number',
1814                                         'type': 'string'
1815                                     },
1816                                     {
1817                                         'name': 'itemsrc_vend_item_descrip',
1818                                         'type': 'string'
1819                                     },
1820                                     {
1821                                         'name': 'itemsrc_comments',
1822                                         'type': 'string'
1823                                     },
1824                                     {
1825                                         'name': 'itemsrc_vend_uom',
1826                                         'type': 'string'
1827                                     },
1828                                     {
1829                                         'name': 'itemsrc_invvendoruomratio',
1830                                         'type': 'float'
1831                                     },
1832                                     {
1833                                         'name': 'itemsrc_minordqty',
1834                                         'type': 'float'
1835                                     },
1836                                     {
1837                                         'name': 'itemsrc_multordqty',
1838                                         'type': 'float'
1839                                     },
1840                                     {
1841                                         'name': 'itemsrc_leadtime',
1842                                         'type': 'int'
1843                                     },
1844                                     {
1845                                         'name': 'itemsrc_ranking',
1846                                         'type': 'int'
1847                                     },
1848                                     {
1849                                         'name': 'itemsrc_active',
1850                                         'type': 'int'
1851                                     },
1852                                     {
1853                                         'name': 'itemsrc_manuf_name',
1854                                         'type': 'string'
1855                                     },
1856                                     {
1857                                         'name': 'itemsrc_manuf_item_number',
1858                                         'type': 'string'
1859                                     },
1860                                     {
1861                                         'name': 'itemsrc_manuf_item_descrip',
1862                                         'type': 'string'
1863                                     },
1864                                     {
1865                                         'name': 'itemsrc_default',
1866                                         'type': 'int'
1867                                     },
1868                                     {
1869                                         'name': 'itemsrc_upccode',
1870                                         'type': 'string'
1871                                     }
1872                                 ],
1873                                 totalProperty : 'total'
1874                             },
1875                             '|xns' : 'Roo.data',
1876                             xtype : 'Store',
1877                             remoteSort : true,
1878                             sortInfo : { field : 'itemsrc_vend_id_vend_name', direction: 'ASC' },
1879                             xns : Roo.data,
1880                             listeners : {
1881                                 update : function (_self, record, operation)
1882                                    {
1883                                        Roo.log(operation);
1884                                          Roo.log(record);
1885                                       
1886                                        if (operation != 'commit') {
1887                                            return;
1888                                        }
1889                                        if (record.data.itemsrc_vend_id * 1 < 1) {
1890                                            return; // do not save.
1891                                        }
1892                                        if (record.data.itemsrc_id * 1 < 0) {
1893                                            return; // do not save. -- updating at present...
1894                                        }
1895                                        
1896                                        var p = Roo.apply({}, record.data);
1897                                        record.set('itemsrc_id', -1);    
1898                                        
1899                                        new Pman.Request({
1900                                            url : baseURL + '/Roo/Itemsrc',
1901                                            params : p,
1902                                            method : 'POST',
1903                                            success: function(res) {
1904                                                if (record.data.itemsrc_id *1  < 1) { 
1905                                                    record.set('itemsrc_id', res.data.itemsrc_id);
1906                                                }
1907                                            }
1908                                        });
1909                                        
1910                                        
1911                                    },
1912                                 beforeload : function (_self, o)
1913                                    {
1914                                        
1915                                        var id = 1 * _this.form.findField('item_id').getValue();
1916                                        if (!id) {
1917                                            this.removeAll();
1918                                            return false;
1919                                        }
1920                                        o.params.itemsrc_item_id = id;
1921                                    }
1922                             },
1923                             items : [
1924
1925                             ]
1926
1927                         },
1928                         footer : {
1929                             '|xns' : 'Roo',
1930                             pageSize : 25,
1931                             xtype : 'PagingToolbar',
1932                             emptyMsg : "No itemsrc found",
1933                             xns : Roo,
1934                             displayInfo : true,
1935                             displayMsg : "Displaying itemsrc{0} - {1} of {2}"
1936                         },
1937                         toolbar : {
1938                             '|xns' : 'Roo',
1939                             xtype : 'Toolbar',
1940                             xns : Roo,
1941                             items : [
1942                                 {
1943                                     '|xns' : 'Roo.Toolbar',
1944                                     text : "Add",
1945                                     xtype : 'Button',
1946                                     cls : 'x-btn-text-icon',
1947                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
1948                                     xns : Roo.Toolbar,
1949                                     listeners : {
1950                                         click : function()
1951                                            {
1952                                                 
1953                                                Roo.log("add presed");
1954                                                 
1955                                                // work out last 
1956                                                var grid = _this.itemsrcgrid;
1957                                                 
1958                                                // uses form defaults or last row value.
1959                                                var nr = grid.ds.reader.newRow({
1960                                                         itemsrc_id : 0,
1961                                                    itemsrc_item_id : _this.form.findField('item_id').getValue(),
1962                                            
1963                                                     itemsrc_vend_id : 0,
1964                                                     itemsrc_vend_item_number : '',
1965                                                     itemsrc_vend_item_descrip : '',
1966                                                     itemsrc_comments           : '',
1967                                                     itemsrc_vend_uom  :           'EA',
1968                                                     itemsrc_invvendoruomratio : 1.0,
1969                                                     itemsrc_minordqty        : 0,
1970                                                     itemsrc_multordqty        : 0,
1971                                                     itemsrc_leadtime         :  30,
1972                                                     itemsrc_ranking         :   0,
1973                                                     itemsrc_active          :   true,
1974                                                     itemsrc_manuf_name       :  '',
1975                                                     itemsrc_manuf_item_number : '',
1976                                                     itemsrc_manuf_item_descrip: '',
1977                                                     itemsrc_default          : true,
1978                                                     itemsrc_upccode    : ''
1979                                                                    
1980                                                });
1981                                                grid.stopEditing();
1982                                                grid.ds.insert(0, nr); 
1983                                                grid.startEditing(0, 0); // type..
1984                                            
1985                                            }
1986                                     }
1987                                 }
1988                             ]
1989
1990                         },
1991                         '|xns' : 'Roo.grid',
1992                         autoExpandColumn : 'itemsrc_comments',
1993                         xtype : 'EditorGrid',
1994                         loadMask : true,
1995                         clicksToEdit : 1,
1996                         xns : Roo.grid,
1997                         colModel : [
1998                                  {
1999                                         editor : {
2000                                             field : {
2001                                                 store : {
2002                                                     proxy : {
2003                                                         '|xns' : 'Roo.data',
2004                                                         url : baseURL + '/Roo/vendinfo.php',
2005                                                         xtype : 'HttpProxy',
2006                                                         method : 'GET',
2007                                                         xns : Roo.data
2008                                                     },
2009                                                     reader : {
2010                                                         '|xns' : 'Roo.data',
2011                                                         id : 'id',
2012                                                         root : 'data',
2013                                                         xtype : 'JsonReader',
2014                                                         xns : Roo.data,
2015                                                         fields : [{"name":"id","type":"int"},{"name":"vend_name","type":"string"}],
2016                                                         totalProperty : 'total'
2017                                                     },
2018                                                     '|xns' : 'Roo.data',
2019                                                     xtype : 'Store',
2020                                                     remoteSort : true,
2021                                                     xns : Roo.data,
2022                                                     sortInfo : { direction : 'ASC', field: 'id' },
2023                                                     listeners : {
2024                                                         beforeload : function (_self, o){
2025                                                                o.params = o.params || {};
2026                                                                // set more here
2027                                                            }
2028                                                     },
2029                                                     items : [
2030
2031                                                     ]
2032
2033                                                 },
2034                                                 '|xns' : 'Roo.form',
2035                                                 listWidth : 400,
2036                                                 triggerAction : 'all',
2037                                                 forceSelection : true,
2038                                                 selectOnFocus : true,
2039                                                 pageSize : 20,
2040                                                 displayField : 'vend_name',
2041                                                 emptyText : "Select Vendor",
2042                                                 hiddenName : 'itemsrc_vend_id',
2043                                                 minChars : 2,
2044                                                 valueField : 'vend_id',
2045                                                 xtype : 'ComboBox',
2046                                                 allowBlank : false,
2047                                                 typeAhead : true,
2048                                                 editable : true,
2049                                                 width : 300,
2050                                                 xns : Roo.form,
2051                                                 name : 'itemsrc_vend_id_vend_name',
2052                                                 qtip : "Select vendinfo",
2053                                                 queryParam : 'q[search]',
2054                                                 tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{vend_name}</b> </div>',
2055                                                 loadingText : "Searching...",
2056                                                 items : [
2057
2058                                                 ]
2059
2060                                             },
2061                                             '|xns' : 'Roo.grid',
2062                                             xtype : 'GridEditor',
2063                                             xns : Roo.grid,
2064                                             items : [
2065
2066                                             ]
2067
2068                                         },
2069                                         '|xns' : 'Roo.grid',
2070                                         xtype : 'ColumnModel',
2071                                         width : 120,
2072                                         header : 'Vendor',
2073                                         renderer : function(v,x,r) { return String.format('{0}', r.data.itemsrc_vend_id_vend_name); },
2074                                         xns : Roo.grid,
2075                                         dataIndex : 'itemsrc_vend_id',
2076                                         items : [
2077
2078                                         ]
2079
2080                                     },
2081 {
2082                                         editor : {
2083                                             field : {
2084                                                 '|xns' : 'Roo.form',
2085                                                 xtype : 'TextField',
2086                                                 xns : Roo.form
2087                                             },
2088                                             '|xns' : 'Roo.grid',
2089                                             xtype : 'GridEditor',
2090                                             xns : Roo.grid,
2091                                             items : [
2092
2093                                             ]
2094
2095                                         },
2096                                         '|xns' : 'Roo.grid',
2097                                         xtype : 'ColumnModel',
2098                                         width : 100,
2099                                         header : 'Vendor Ref#',
2100                                         renderer : function(v) { return String.format('{0}', v); },
2101                                         xns : Roo.grid,
2102                                         dataIndex : 'itemsrc_vend_item_number',
2103                                         items : [
2104
2105                                         ]
2106
2107                                     },
2108 {
2109                                         editor : {
2110                                             field : {
2111                                                 '|xns' : 'Roo.form',
2112                                                 xtype : 'TextField',
2113                                                 xns : Roo.form
2114                                             },
2115                                             '|xns' : 'Roo.grid',
2116                                             xtype : 'GridEditor',
2117                                             xns : Roo.grid,
2118                                             items : [
2119
2120                                             ]
2121
2122                                         },
2123                                         '|xns' : 'Roo.grid',
2124                                         xtype : 'ColumnModel',
2125                                         width : 200,
2126                                         header : 'Comments',
2127                                         renderer : function(v) { return String.format('{0}', v); },
2128                                         xns : Roo.grid,
2129                                         dataIndex : 'itemsrc_comments',
2130                                         items : [
2131
2132                                         ]
2133
2134                                     },
2135 {
2136                                         '|xns' : 'Roo.grid',
2137                                         xtype : 'ColumnModel',
2138                                         width : 50,
2139                                         header : 'UOM',
2140                                         renderer : function(v) { return String.format('{0}', v); },
2141                                         xns : Roo.grid,
2142                                         dataIndex : 'itemsrc_vend_uom'
2143                                     },
2144 {
2145                                         editor : {
2146                                             field : {
2147                                                 '|xns' : 'Roo.form',
2148                                                 minValue : 0,
2149                                                 xtype : 'NumberField',
2150                                                 decimalPrecision : 0,
2151                                                 xns : Roo.form
2152                                             },
2153                                             '|xns' : 'Roo.grid',
2154                                             xtype : 'GridEditor',
2155                                             xns : Roo.grid,
2156                                             items : [
2157
2158                                             ]
2159
2160                                         },
2161                                         '|xns' : 'Roo.grid',
2162                                         align : 'right',
2163                                         xtype : 'ColumnModel',
2164                                         header : 'Min Qty',
2165                                         width : 50,
2166                                         renderer : function(v) { return String.format('{0}', v); },
2167                                         xns : Roo.grid,
2168                                         dataIndex : 'itemsrc_minordqty',
2169                                         items : [
2170
2171                                         ]
2172
2173                                     },
2174 {
2175                                         editor : {
2176                                             field : {
2177                                                 '|xns' : 'Roo.form',
2178                                                 minValue : 0,
2179                                                 xtype : 'NumberField',
2180                                                 decimalPrecision : 0,
2181                                                 xns : Roo.form
2182                                             },
2183                                             '|xns' : 'Roo.grid',
2184                                             xtype : 'GridEditor',
2185                                             xns : Roo.grid,
2186                                             items : [
2187
2188                                             ]
2189
2190                                         },
2191                                         '|xns' : 'Roo.grid',
2192                                         align : 'right',
2193                                         xtype : 'ColumnModel',
2194                                         header : 'Lead time',
2195                                         width : 75,
2196                                         renderer : function(v) { return String.format('{0}', v); },
2197                                         xns : Roo.grid,
2198                                         dataIndex : 'itemsrc_leadtime',
2199                                         items : [
2200
2201                                         ]
2202
2203                                     },
2204 {
2205                                         '|xns' : 'Roo.grid',
2206                                         xtype : 'ColumnModel',
2207                                         width : 50,
2208                                         header : 'Active',
2209                                         renderer : function(v) { return String.format('{0}', v); },
2210                                         xns : Roo.grid,
2211                                         dataIndex : 'itemsrc_active'
2212                                     }
2213                         ],
2214                         listeners : {
2215                                 rowdblclick : function (_self, rowIndex, e)
2216                                    {
2217                                        if (!_this.dialog) return;
2218                                        _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
2219                                            _this.grid.footer.onClick('first');
2220                                        }); 
2221                                    },
2222                                 render : function() 
2223                                    {
2224                                        _this.itemsrcgrid = this; 
2225                                        //_this.dialog = Pman.Dialog.FILL_IN
2226                                        
2227                                    },
2228                                 afteredit : function (e)
2229                                    {
2230                                        e.record.commit();
2231                                    }
2232                         },
2233                         items : [
2234
2235                         ]
2236
2237                     },
2238                     '|xns' : 'Roo',
2239                     region : 'center',
2240                     fitToframe : true,
2241                     background : true,
2242                     title : "Suppliers",
2243                     xtype : 'GridPanel',
2244                     fitContainer : true,
2245                     xns : Roo,
2246                     tableName : 'itemsrc',
2247                     listeners : {
2248                         activate : function() {
2249                                _this.itemsrcpanel = this;
2250                                if (_this.itemsrcgrid) {
2251                                    _this.itemsrcgrid.footer.onClick('first');
2252                                }
2253                            }
2254                     },
2255                     items : [
2256
2257                     ]
2258
2259                 },
2260                 {
2261                     grid : {
2262                         dataSource : {
2263                             proxy : {
2264                                 '|xns' : 'Roo.data',
2265                                 url : baseURL + '/Roo/events.php',
2266                                 method : 'GET',
2267                                 xtype : 'HttpProxy',
2268                                 xns : Roo.data
2269                             },
2270                             reader : {
2271                                 '|xns' : 'Roo.data',
2272                                 id : 'id',
2273                                 root : 'data',
2274                                 xtype : 'JsonReader',
2275                                 fields : [
2276                                     {
2277                                         'name': 'event_when',
2278                                         'type': 'date'
2279                                     },
2280                                     {
2281                                         'name': 'action',
2282                                         'type': 'string'
2283                                     },
2284                                     {
2285                                         'name': 'ipaddr',
2286                                         'type': 'string'
2287                                     },
2288                                     {
2289                                         'name': 'person_id_name',
2290                                         'type': 'string'
2291                                     },
2292                                     {
2293                                         'name': 'remarks',
2294                                         'type': 'string'
2295                                     }
2296                                 ],
2297                                 xns : Roo.data,
2298                                 totalProperty : 'total'
2299                             },
2300                             '|xns' : 'Roo.data',
2301                             xtype : 'Store',
2302                             remoteSort : true,
2303                             sortInfo : { field : 'event_when', direction: 'DESC' },
2304                             xns : Roo.data,
2305                             listeners : {
2306                                 beforeload : function (_self, options)
2307                                    {
2308                                        options.params = options.params || {};
2309                                        
2310                                        options.params.on_table = 'item';
2311                                        options.params.on_id = _this.form.findField('item_id').getValue();
2312                                    }
2313                             },
2314                             items : [
2315
2316                             ]
2317
2318                         },
2319                         footer : {
2320                             '|xns' : 'Roo',
2321                             pageSize : 25,
2322                             xtype : 'PagingToolbar',
2323                             emptyMsg : "No Events found",
2324                             xns : Roo,
2325                             displayMsg : "Displaying events{0} - {1} of {2}",
2326                             displayInfo : true
2327                         },
2328                         '|xns' : 'Roo.grid',
2329                         autoExpandColumn : 'remarks',
2330                         xtype : 'Grid',
2331                         loadMask : true,
2332                         xns : Roo.grid,
2333                         colModel : [
2334                                  {
2335                                         '|xns' : 'Roo.grid',
2336                                         xtype : 'ColumnModel',
2337                                         width : 120,
2338                                         header : 'Changed',
2339                                         renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y H:i:s') : ''); },
2340                                         xns : Roo.grid,
2341                                         dataIndex : 'event_when'
2342                                     },
2343 {
2344                                         '|xns' : 'Roo.grid',
2345                                         xtype : 'ColumnModel',
2346                                         width : 200,
2347                                         header : 'Action',
2348                                         renderer : function(v,x,r) { return String.format('{0} - {1}', v, r.data.on_table); },
2349                                         xns : Roo.grid,
2350                                         dataIndex : 'action'
2351                                     },
2352 {
2353                                         '|xns' : 'Roo.grid',
2354                                         xtype : 'ColumnModel',
2355                                         width : 200,
2356                                         header : 'IP Address',
2357                                         renderer : function(v) { return String.format('{0}', v); },
2358                                         xns : Roo.grid,
2359                                         dataIndex : 'ipaddr'
2360                                     },
2361 {
2362                                         '|xns' : 'Roo.grid',
2363                                         xtype : 'ColumnModel',
2364                                         width : 75,
2365                                         header : 'Who',
2366                                         renderer : function(v) { return String.format('{0}', v); },
2367                                         xns : Roo.grid,
2368                                         dataIndex : 'person_id_name'
2369                                     },
2370 {
2371                                         '|xns' : 'Roo.grid',
2372                                         xtype : 'ColumnModel',
2373                                         width : 200,
2374                                         header : 'Notes',
2375                                         renderer : function(v) { return String.format('{0}', v); },
2376                                         xns : Roo.grid,
2377                                         dataIndex : 'remarks'
2378                                     }
2379                         ],
2380                         listeners : {
2381                                 render : function() 
2382                                    {
2383                                        _this.hgrid = this; 
2384                                        if (_this.hpanel.active) {
2385                                           this.footer.onClick('first');
2386                                        }
2387                                    }
2388                         },
2389                         items : [
2390
2391                         ]
2392
2393                     },
2394                     '|xns' : 'Roo',
2395                     region : 'center',
2396                     fitToframe : true,
2397                     background : true,
2398                     title : "History",
2399                     xtype : 'GridPanel',
2400                     fitContainer : true,
2401                     xns : Roo,
2402                     tableName : 'events',
2403                     listeners : {
2404                         activate : function() {
2405                                _this.hpanel = this;
2406                                if (_this.hgrid) {
2407                                    _this.hgrid.footer.onClick('first');
2408                                }
2409                            }
2410                     },
2411                     items : [
2412
2413                     ]
2414
2415                 }
2416             ]
2417
2418         });
2419     }
2420 };