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                                                 allowDecimals : false,
1189                                                 decimalPrecision : 0,
1190                                                 xns : Roo.form,
1191                                                 minValue : 0
1192                                             },
1193                                             '|xns' : 'Roo.grid',
1194                                             xtype : 'GridEditor',
1195                                             xns : Roo.grid,
1196                                             items : [
1197
1198                                             ]
1199
1200                                         },
1201                                         '|xns' : 'Roo.grid',
1202                                         xtype : 'ColumnModel',
1203                                         align : 'right',
1204                                         header : 'Qty',
1205                                         width : 100,
1206                                         renderer : function(v) { return String.format('{0}', v); },
1207                                         xns : Roo.grid,
1208                                         dataIndex : 'bomitem_qtyper',
1209                                         items : [
1210
1211                                         ]
1212
1213                                     }
1214                         ],
1215                         listeners : {
1216                                 beforeedit : function (e)
1217                                    {
1218                                        Roo.log('before');
1219                                        Roo.log(e);
1220                                        if(e.field != 'ipshead_ipsitem_price'){
1221                                            return false;
1222                                        }
1223                                        
1224                                    },
1225                                 render : function() 
1226                                    {
1227                                        _this.partsgrid = this; 
1228                                        //_this.dialog = Pman.Dialog.FILL_IN
1229                                        if (_this.partspanel.active) {
1230                                           this.footer.onClick('first');
1231                                        }
1232                                    },
1233                                 afteredit : function (e)
1234                                    {
1235                                        Roo.log('after');
1236                                        Roo.log(e);
1237                                        if(e.originalValue == e.value){
1238                                            return false;
1239                                        }
1240                                        return false;
1241                                        
1242                                        
1243                                        var id = _this.form.findField('item_id').getValue() * 1;
1244                                        if(id < 1){
1245                                            return false;
1246                                        }
1247                                        
1248                                        new Pman.Request({
1249                                            method : 'POST',
1250                                            url : baseURL + '/Roo/ipsiteminfo',
1251                                            mask : 'Saving',
1252                                            params : {
1253                                                ipsitem_ipshead_id : e.record.data.ipshead_id,
1254                                                ipsitem_item_id : id,
1255                                                ipsitem_price : e.record.data.ipshead_ipsitem_price,
1256                                                ipsitem_id : e.record.data.ipshead_ipsitem_id
1257                                            }
1258                                        
1259                                        });
1260                                            
1261                                             
1262                                            
1263                                            
1264                                    }
1265                         },
1266                         items : [
1267
1268                         ]
1269
1270                     },
1271                     '|xns' : 'Roo',
1272                     background : true,
1273                     region : 'center',
1274                     fitToframe : true,
1275                     title : "Item Parts",
1276                     xtype : 'GridPanel',
1277                     fitContainer : true,
1278                     xns : Roo,
1279                     tableName : 'bomitem',
1280                     listeners : {
1281                         activate : function() {
1282                                _this.partspanel = this;
1283                                
1284                                try { if (MODULE.isBuilder) {
1285                                    return;
1286                                } } catch(e) { }
1287                                
1288                                var id = _this.form.findField('item_id').getValue() * 1;
1289                                if (id < 1) {
1290                                    Roo.MessageBox.alert("Save First", "Save the item first, before adding parts");
1291                                    _this.dialog.layout.getRegion('center').showPanel(0);
1292                                    return;
1293                                }
1294                                
1295                                var type = _this.form.findField('item_type').getValue();
1296                                
1297                                if(!type.length || type != 'K'){
1298                                    Roo.MessageBox.alert("Error", "Can't add parts to non-kit item");
1299                                    _this.dialog.layout.getRegion('center').showPanel(0);
1300                                    return;
1301                                }
1302                                
1303                                if (_this.partsgrid) {
1304                                    _this.partsgrid.footer.onClick('first');
1305                                
1306                                 }
1307                            }
1308                     },
1309                     items : [
1310
1311                     ]
1312
1313                 },
1314                 {
1315                     grid : {
1316                         dataSource : {
1317                             reader : {
1318                                 '|xns' : 'Roo.data',
1319                                 id : 'id',
1320                                 root : 'data',
1321                                 xtype : 'JsonReader',
1322                                 fields : [
1323                                     {
1324                                         'name': 'id',
1325                                         'type': 'int'
1326                                     },
1327                                     {
1328                                         'name': 'filename',
1329                                         'type': 'string'
1330                                     },
1331                                     {
1332                                         'name': 'ontable',
1333                                         'type': 'string'
1334                                     },
1335                                     {
1336                                         'name': 'onid',
1337                                         'type': 'int'
1338                                     },
1339                                     {
1340                                         'name': 'mimetype',
1341                                         'type': 'string'
1342                                     },
1343                                     {
1344                                         'name': 'width',
1345                                         'type': 'int'
1346                                     },
1347                                     {
1348                                         'name': 'height',
1349                                         'type': 'int'
1350                                     },
1351                                     {
1352                                         'name': 'filesize',
1353                                         'type': 'int'
1354                                     },
1355                                     {
1356                                         'name': 'displayorder',
1357                                         'type': 'int'
1358                                     },
1359                                     {
1360                                         'name': 'language',
1361                                         'type': 'string'
1362                                     },
1363                                     {
1364                                         'name': 'parent_image_id',
1365                                         'type': 'int'
1366                                     },
1367                                     {
1368                                         'name': 'created',
1369                                         'type': 'date',
1370                                         'dateFormat' : 'Y-m-d H:i:s'
1371                                     },
1372                                     {
1373                                         'name': 'imgtype',
1374                                         'type': 'string'
1375                                     },
1376                                     {
1377                                         'name': 'linkurl',
1378                                         'type': 'string'
1379                                     },
1380                                     {
1381                                         'name': 'descript',
1382                                         'type': 'string'
1383                                     },
1384                                     {
1385                                         'name': 'title',
1386                                         'type': 'string'
1387                                     }
1388                                 ],
1389                                 xns : Roo.data,
1390                                 totalProperty : 'total'
1391                             },
1392                             proxy : {
1393                                 '|xns' : 'Roo.data',
1394                                 url : baseURL + '/Roo/Images.php',
1395                                 xtype : 'HttpProxy',
1396                                 method : 'GET',
1397                                 xns : Roo.data
1398                             },
1399                             '|xns' : 'Roo.data',
1400                             xtype : 'Store',
1401                             remoteSort : true,
1402                             sortInfo : { field: 'created' , direction: 'DESC' },
1403                             xns : Roo.data,
1404                             listeners : {
1405                                 beforeload : function (_self, o)
1406                                    {
1407                                        o.params = o.params || {};
1408                                        
1409                                        var id = _this.form.findField('item_id').getValue();
1410                                        
1411                                        if(id * 1 < 1){
1412                                            return false;
1413                                        }
1414                                        
1415                                        o.params.onid = id;
1416                                        o.params.ontable = 'item';
1417                                        
1418                                    }
1419                             },
1420                             items : [
1421
1422                             ]
1423
1424                         },
1425                         footer : {
1426                             '|xns' : 'Roo',
1427                             pageSize : 25,
1428                             xtype : 'PagingToolbar',
1429                             emptyMsg : "No Images found",
1430                             xns : Roo,
1431                             displayInfo : true,
1432                             displayMsg : "Displaying Images  {0} - {1} of {2}"
1433                         },
1434                         toolbar : {
1435                             '|xns' : 'Roo',
1436                             xtype : 'Toolbar',
1437                             xns : Roo,
1438                             items : [
1439                                 {
1440                                     '|xns' : 'Roo.Toolbar',
1441                                     text : "Add",
1442                                     xtype : 'Button',
1443                                     cls : 'x-btn-text-icon',
1444                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
1445                                     xns : Roo.Toolbar,
1446                                     listeners : {
1447                                         click : function()
1448                                            {
1449                                                Pman.Dialog.Image.show({
1450                                                    id : 0, 
1451                                                    ontable: 'item',
1452                                                    onid: _this.form.findField('item_id').getValue() * 1,
1453                                                    imgtype : ''
1454                                                }, function(data){
1455                                                    if (!data) { return; } 
1456                                                    _this.grid.footer.onClick('first');
1457                                                }); 
1458                                            
1459                                            }
1460                                     }
1461                                 },
1462                                 {
1463                                     '|xns' : 'Roo.Toolbar',
1464                                     text : "Delete",
1465                                     xtype : 'Button',
1466                                     cls : 'x-btn-text-icon',
1467                                     icon : rootURL + '/Pman/templates/images/trash.gif',
1468                                     xns : Roo.Toolbar,
1469                                     listeners : {
1470                                         click : function()
1471                                            {
1472                                                Pman.genericDelete(_this, 'Images'); 
1473                                            }
1474                                     }
1475                                 }
1476                             ]
1477
1478                         },
1479                         '|xns' : 'Roo.grid',
1480                         autoExpandColumn : 'id',
1481                         xtype : 'Grid',
1482                         loadMask : true,
1483                         xns : Roo.grid,
1484                         colModel : [
1485                                  {
1486                                         '|xns' : 'Roo.grid',
1487                                         xtype : 'ColumnModel',
1488                                         sortable : true,
1489                                         header : 'Created',
1490                                         width : 200,
1491                                         renderer : function(v,x,r) {
1492                                                return String.format('{0}<br/><i>{1}</i><br/>{2}<br/><i>{3}x{4}</i>',
1493                                                     v.format('d/M/Y'), r.data.mimetype, r.data.filename,
1494                                             r.data.width, r.data.height
1495                                             ); 
1496                                         },
1497                                         xns : Roo.grid,
1498                                         dataIndex : 'created'
1499                                     },
1500 {
1501                                         '|xns' : 'Roo.grid',
1502                                         xtype : 'ColumnModel',
1503                                         width : 100,
1504                                         header : 'Image',
1505                                         renderer : function(v,x,r) { return String.format('<img src="{0}/Images/Thumb/100/{1}/{2}" height="100">', baseURL, v, r.data.filename); },
1506                                         xns : Roo.grid,
1507                                         dataIndex : 'id'
1508                                     }
1509                         ],
1510                         listeners : {
1511                                 rowdblclick : function (_self, rowIndex, e)
1512                                    {
1513                                      
1514                                       var s =  _self.getDataSource().getAt(rowIndex);
1515                                       new Pman.Download({
1516                                            url : baseURL + '/Images/Download/' + s.data.id
1517                                        });
1518                                       
1519                                    },
1520                                 render : function() { 
1521                                        _this.grid = this; 
1522                                    
1523                                        if (_this.panel.active) {
1524                                           this.footer.onClick('first');
1525                                        }
1526                                    }
1527                         },
1528                         items : [
1529
1530                         ]
1531
1532                     },
1533                     '|xns' : 'Roo',
1534                     region : 'center',
1535                     fitToframe : true,
1536                     background : true,
1537                     title : "Reference Files",
1538                     xtype : 'GridPanel',
1539                     fitContainer : true,
1540                     xns : Roo,
1541                     tableName : 'Images',
1542                     listeners : {
1543                         activate : function() {
1544                                _this.panel = this;
1545                                
1546                                try { if (MODULE.isBuilder) {
1547                                    return;
1548                                } } catch(e) { }
1549                                
1550                                var id = _this.form.findField('item_id').getValue() * 1;
1551                                if (id < 1) {
1552                                    Roo.MessageBox.alert("Save First", "Save the item first, before adding image");
1553                                    _this.dialog.layout.getRegion('center').showPanel(0);
1554                                    return;
1555                                }
1556                                
1557                                if (_this.grid) {
1558                                    _this.grid.footer.onClick('first');
1559                                
1560                                 }
1561                            }
1562                     },
1563                     items : [
1564
1565                     ]
1566
1567                 },
1568                 {
1569                     grid : {
1570                         dataSource : {
1571                             proxy : {
1572                                 '|xns' : 'Roo.data',
1573                                 url : baseURL + '/Roo/ipshead.php',
1574                                 method : 'GET',
1575                                 xtype : 'HttpProxy',
1576                                 xns : Roo.data
1577                             },
1578                             reader : {
1579                                 '|xns' : 'Roo.data',
1580                                 id : 'ipshead_id',
1581                                 root : 'data',
1582                                 xtype : 'JsonReader',
1583                                 fields : [
1584                                     {
1585                                         'name': 'ipshead_id',
1586                                         'type': 'int'
1587                                     },
1588                                     {
1589                                         'name': 'ipshead_name',
1590                                         'type': 'string'
1591                                     }
1592                                 ],
1593                                 xns : Roo.data,
1594                                 totalProperty : 'total'
1595                             },
1596                             '|xns' : 'Roo.data',
1597                             xtype : 'Store',
1598                             remoteSort : true,
1599                             sortInfo : { field : 'ipshead_id', direction: 'ASC' },
1600                             xns : Roo.data,
1601                             listeners : {
1602                                 beforeload : function (_self, o)
1603                                    {
1604                                       o.params = o.params || {};
1605                                       
1606                                       var id  = _this.form.findField('item_id').getValue() * 1;
1607                                       if(id < 1){
1608                                            return false;
1609                                       }
1610                                       
1611                                       o.params._with_item = id;
1612                                    }
1613                             },
1614                             items : [
1615
1616                             ]
1617
1618                         },
1619                         footer : {
1620                             '|xns' : 'Roo',
1621                             pageSize : 50,
1622                             xtype : 'PagingToolbar',
1623                             emptyMsg : "Nothing found",
1624                             xns : Roo,
1625                             displayMsg : "Displaying records {0} - {1} of {2}",
1626                             displayInfo : true
1627                         },
1628                         '|xns' : 'Roo.grid',
1629                         autoExpandColumn : 'ipshead_descrip',
1630                         xtype : 'EditorGrid',
1631                         loadMask : true,
1632                         clicksToEdit : 1,
1633                         xns : Roo.grid,
1634                         colModel : [
1635                                  {
1636                                         '|xns' : 'Roo.grid',
1637                                         xtype : 'ColumnModel',
1638                                         width : 150,
1639                                         header : 'Name',
1640                                         renderer : function(v) { return String.format('{0}', v); },
1641                                         xns : Roo.grid,
1642                                         dataIndex : 'ipshead_name'
1643                                     },
1644 {
1645                                         '|xns' : 'Roo.grid',
1646                                         xtype : 'ColumnModel',
1647                                         width : 150,
1648                                         header : 'Description',
1649                                         renderer : function(v) { return String.format('{0}', v); },
1650                                         xns : Roo.grid,
1651                                         dataIndex : 'ipshead_descrip'
1652                                     },
1653 {
1654                                         '|xns' : 'Roo.grid',
1655                                         xtype : 'ColumnModel',
1656                                         width : 100,
1657                                         header : 'Currency',
1658                                         renderer : function(v) { return String.format('{0}', v); },
1659                                         xns : Roo.grid,
1660                                         dataIndex : 'ipshead_curr_id_curr_name'
1661                                     },
1662 {
1663                                         editor : {
1664                                             field : {
1665                                                 '|xns' : 'Roo.form',
1666                                                 xtype : 'NumberField',
1667                                                 cls : 'align-right',
1668                                                 decimalPrecision : 2,
1669                                                 xns : Roo.form
1670                                             },
1671                                             '|xns' : 'Roo.grid',
1672                                             xtype : 'GridEditor',
1673                                             xns : Roo.grid,
1674                                             items : [
1675
1676                                             ]
1677
1678                                         },
1679                                         '|xns' : 'Roo.grid',
1680                                         align : 'right',
1681                                         xtype : 'ColumnModel',
1682                                         header : 'Price',
1683                                         width : 120,
1684                                         renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v*1,2)); },
1685                                         xns : Roo.grid,
1686                                         dataIndex : 'ipshead_ipsitem_price',
1687                                         items : [
1688
1689                                         ]
1690
1691                                     }
1692                         ],
1693                         listeners : {
1694                                 beforeedit : function (e)
1695                                    {
1696                                        if(e.field != 'ipshead_ipsitem_price'){
1697                                            return false;
1698                                        }
1699                                        
1700                                    },
1701                                 render : function() 
1702                                    {
1703                                        _this.lgrid = this; 
1704                                        //_this.dialog = Pman.Dialog.FILL_IN
1705                                        if (_this.lpanel.active) {
1706                                           this.footer.onClick('first');
1707                                        }
1708                                    },
1709                                 afteredit : function (e)
1710                                    {
1711                                        if(e.originalValue == e.value){
1712                                            return false;
1713                                        }
1714                                        
1715                                        var id = _this.form.findField('item_id').getValue() * 1;
1716                                        if(id < 1){
1717                                            return false;
1718                                        }
1719                                        
1720                                        new Pman.Request({
1721                                            method : 'POST',
1722                                            url : baseURL + '/Roo/ipsiteminfo',
1723                                            mask : 'Saving',
1724                                            params : {
1725                                                ipsitem_ipshead_id : e.record.data.ipshead_id,
1726                                                ipsitem_item_id : id,
1727                                                ipsitem_price : e.record.data.ipshead_ipsitem_price,
1728                                                ipsitem_id : e.record.data.ipshead_ipsitem_id
1729                                            }
1730                                        
1731                                        });
1732                                            
1733                                             
1734                                            
1735                                            
1736                                    }
1737                         },
1738                         items : [
1739
1740                         ]
1741
1742                     },
1743                     '|xns' : 'Roo',
1744                     region : 'center',
1745                     fitToframe : true,
1746                     background : true,
1747                     title : "Price List",
1748                     xtype : 'GridPanel',
1749                     fitContainer : true,
1750                     xns : Roo,
1751                     tableName : 'ipshead',
1752                     listeners : {
1753                         activate : function() {
1754                                _this.lpanel = this;
1755                                
1756                                try { if (MODULE.isBuilder) {
1757                                    return;
1758                                } } catch(e) { }
1759                                
1760                                var id = _this.form.findField('item_id').getValue() * 1;
1761                                if (id < 1) {
1762                                    Roo.MessageBox.alert("Save First", "Save the item first, before adding image");
1763                                    _this.dialog.layout.getRegion('center').showPanel(0);
1764                                    return;
1765                                }
1766                                
1767                                if (_this.lgrid) {
1768                                    _this.lgrid.footer.onClick('first');
1769                                
1770                                 }
1771                            }
1772                     },
1773                     items : [
1774
1775                     ]
1776
1777                 },
1778                 {
1779                     grid : {
1780                         dataSource : {
1781                             proxy : {
1782                                 '|xns' : 'Roo.data',
1783                                 url : baseURL + '/Roo/itemsrc.php',
1784                                 xtype : 'HttpProxy',
1785                                 method : 'GET',
1786                                 xns : Roo.data
1787                             },
1788                             reader : {
1789                                 '|xns' : 'Roo.data',
1790                                 id : 'id',
1791                                 root : 'data',
1792                                 xtype : 'JsonReader',
1793                                 xns : Roo.data,
1794                                 fields : [
1795                                     {
1796                                         'name': 'itemsrc_id',
1797                                         'type': 'int'
1798                                     },
1799                                     {
1800                                         'name': 'itemsrc_item_id',
1801                                         'type': 'int'
1802                                     },
1803                                     {
1804                                         'name': 'itemsrc_item_id',
1805                                         'type': 'int'
1806                                     },
1807                                     {
1808                                         'name': 'itemsrc_vend_id',
1809                                         'type': 'int'
1810                                     },
1811                                     {
1812                                         'name': 'itemsrc_vend_id',
1813                                         'type': 'int'
1814                                     },
1815                                     {
1816                                         'name': 'itemsrc_vend_item_number',
1817                                         'type': 'string'
1818                                     },
1819                                     {
1820                                         'name': 'itemsrc_vend_item_descrip',
1821                                         'type': 'string'
1822                                     },
1823                                     {
1824                                         'name': 'itemsrc_comments',
1825                                         'type': 'string'
1826                                     },
1827                                     {
1828                                         'name': 'itemsrc_vend_uom',
1829                                         'type': 'string'
1830                                     },
1831                                     {
1832                                         'name': 'itemsrc_invvendoruomratio',
1833                                         'type': 'float'
1834                                     },
1835                                     {
1836                                         'name': 'itemsrc_minordqty',
1837                                         'type': 'float'
1838                                     },
1839                                     {
1840                                         'name': 'itemsrc_multordqty',
1841                                         'type': 'float'
1842                                     },
1843                                     {
1844                                         'name': 'itemsrc_leadtime',
1845                                         'type': 'int'
1846                                     },
1847                                     {
1848                                         'name': 'itemsrc_ranking',
1849                                         'type': 'int'
1850                                     },
1851                                     {
1852                                         'name': 'itemsrc_active',
1853                                         'type': 'int'
1854                                     },
1855                                     {
1856                                         'name': 'itemsrc_manuf_name',
1857                                         'type': 'string'
1858                                     },
1859                                     {
1860                                         'name': 'itemsrc_manuf_item_number',
1861                                         'type': 'string'
1862                                     },
1863                                     {
1864                                         'name': 'itemsrc_manuf_item_descrip',
1865                                         'type': 'string'
1866                                     },
1867                                     {
1868                                         'name': 'itemsrc_default',
1869                                         'type': 'int'
1870                                     },
1871                                     {
1872                                         'name': 'itemsrc_upccode',
1873                                         'type': 'string'
1874                                     }
1875                                 ],
1876                                 totalProperty : 'total'
1877                             },
1878                             '|xns' : 'Roo.data',
1879                             xtype : 'Store',
1880                             remoteSort : true,
1881                             sortInfo : { field : 'itemsrc_vend_id_vend_name', direction: 'ASC' },
1882                             xns : Roo.data,
1883                             listeners : {
1884                                 update : function (_self, record, operation)
1885                                    {
1886                                        Roo.log(operation);
1887                                          Roo.log(record);
1888                                       
1889                                        if (operation != 'commit') {
1890                                            return;
1891                                        }
1892                                        if (record.data.itemsrc_vend_id * 1 < 1) {
1893                                            return; // do not save.
1894                                        }
1895                                        if (record.data.itemsrc_id * 1 < 0) {
1896                                            return; // do not save. -- updating at present...
1897                                        }
1898                                        
1899                                        var p = Roo.apply({}, record.data);
1900                                        record.set('itemsrc_id', -1);    
1901                                        
1902                                        new Pman.Request({
1903                                            url : baseURL + '/Roo/Itemsrc',
1904                                            params : p,
1905                                            method : 'POST',
1906                                            success: function(res) {
1907                                                if (record.data.itemsrc_id *1  < 1) { 
1908                                                    record.set('itemsrc_id', res.data.itemsrc_id);
1909                                                }
1910                                            }
1911                                        });
1912                                        
1913                                        
1914                                    },
1915                                 beforeload : function (_self, o)
1916                                    {
1917                                        
1918                                        var id = 1 * _this.form.findField('item_id').getValue();
1919                                        if (!id) {
1920                                            this.removeAll();
1921                                            return false;
1922                                        }
1923                                        o.params.itemsrc_item_id = id;
1924                                    }
1925                             },
1926                             items : [
1927
1928                             ]
1929
1930                         },
1931                         footer : {
1932                             '|xns' : 'Roo',
1933                             pageSize : 25,
1934                             xtype : 'PagingToolbar',
1935                             emptyMsg : "No itemsrc found",
1936                             xns : Roo,
1937                             displayInfo : true,
1938                             displayMsg : "Displaying itemsrc{0} - {1} of {2}"
1939                         },
1940                         toolbar : {
1941                             '|xns' : 'Roo',
1942                             xtype : 'Toolbar',
1943                             xns : Roo,
1944                             items : [
1945                                 {
1946                                     '|xns' : 'Roo.Toolbar',
1947                                     text : "Add",
1948                                     xtype : 'Button',
1949                                     cls : 'x-btn-text-icon',
1950                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
1951                                     xns : Roo.Toolbar,
1952                                     listeners : {
1953                                         click : function()
1954                                            {
1955                                                 
1956                                                Roo.log("add presed");
1957                                                 
1958                                                // work out last 
1959                                                var grid = _this.itemsrcgrid;
1960                                                 
1961                                                // uses form defaults or last row value.
1962                                                var nr = grid.ds.reader.newRow({
1963                                                         itemsrc_id : 0,
1964                                                    itemsrc_item_id : _this.form.findField('item_id').getValue(),
1965                                            
1966                                                     itemsrc_vend_id : 0,
1967                                                     itemsrc_vend_item_number : '',
1968                                                     itemsrc_vend_item_descrip : '',
1969                                                     itemsrc_comments           : '',
1970                                                     itemsrc_vend_uom  :           'EA',
1971                                                     itemsrc_invvendoruomratio : 1.0,
1972                                                     itemsrc_minordqty        : 0,
1973                                                     itemsrc_multordqty        : 0,
1974                                                     itemsrc_leadtime         :  30,
1975                                                     itemsrc_ranking         :   0,
1976                                                     itemsrc_active          :   true,
1977                                                     itemsrc_manuf_name       :  '',
1978                                                     itemsrc_manuf_item_number : '',
1979                                                     itemsrc_manuf_item_descrip: '',
1980                                                     itemsrc_default          : true,
1981                                                     itemsrc_upccode    : ''
1982                                                                    
1983                                                });
1984                                                grid.stopEditing();
1985                                                grid.ds.insert(0, nr); 
1986                                                grid.startEditing(0, 0); // type..
1987                                            
1988                                            }
1989                                     }
1990                                 }
1991                             ]
1992
1993                         },
1994                         '|xns' : 'Roo.grid',
1995                         autoExpandColumn : 'itemsrc_comments',
1996                         xtype : 'EditorGrid',
1997                         loadMask : true,
1998                         clicksToEdit : 1,
1999                         xns : Roo.grid,
2000                         colModel : [
2001                                  {
2002                                         editor : {
2003                                             field : {
2004                                                 store : {
2005                                                     proxy : {
2006                                                         '|xns' : 'Roo.data',
2007                                                         url : baseURL + '/Roo/vendinfo.php',
2008                                                         xtype : 'HttpProxy',
2009                                                         method : 'GET',
2010                                                         xns : Roo.data
2011                                                     },
2012                                                     reader : {
2013                                                         '|xns' : 'Roo.data',
2014                                                         id : 'id',
2015                                                         root : 'data',
2016                                                         xtype : 'JsonReader',
2017                                                         xns : Roo.data,
2018                                                         fields : [{"name":"id","type":"int"},{"name":"vend_name","type":"string"}],
2019                                                         totalProperty : 'total'
2020                                                     },
2021                                                     '|xns' : 'Roo.data',
2022                                                     xtype : 'Store',
2023                                                     remoteSort : true,
2024                                                     xns : Roo.data,
2025                                                     sortInfo : { direction : 'ASC', field: 'id' },
2026                                                     listeners : {
2027                                                         beforeload : function (_self, o){
2028                                                                o.params = o.params || {};
2029                                                                // set more here
2030                                                            }
2031                                                     },
2032                                                     items : [
2033
2034                                                     ]
2035
2036                                                 },
2037                                                 '|xns' : 'Roo.form',
2038                                                 listWidth : 400,
2039                                                 triggerAction : 'all',
2040                                                 forceSelection : true,
2041                                                 selectOnFocus : true,
2042                                                 pageSize : 20,
2043                                                 displayField : 'vend_name',
2044                                                 emptyText : "Select Vendor",
2045                                                 hiddenName : 'itemsrc_vend_id',
2046                                                 minChars : 2,
2047                                                 valueField : 'vend_id',
2048                                                 xtype : 'ComboBox',
2049                                                 allowBlank : false,
2050                                                 typeAhead : true,
2051                                                 editable : true,
2052                                                 width : 300,
2053                                                 xns : Roo.form,
2054                                                 name : 'itemsrc_vend_id_vend_name',
2055                                                 qtip : "Select vendinfo",
2056                                                 queryParam : 'q[search]',
2057                                                 tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{vend_name}</b> </div>',
2058                                                 loadingText : "Searching...",
2059                                                 items : [
2060
2061                                                 ]
2062
2063                                             },
2064                                             '|xns' : 'Roo.grid',
2065                                             xtype : 'GridEditor',
2066                                             xns : Roo.grid,
2067                                             items : [
2068
2069                                             ]
2070
2071                                         },
2072                                         '|xns' : 'Roo.grid',
2073                                         xtype : 'ColumnModel',
2074                                         width : 120,
2075                                         header : 'Vendor',
2076                                         renderer : function(v,x,r) { return String.format('{0}', r.data.itemsrc_vend_id_vend_name); },
2077                                         xns : Roo.grid,
2078                                         dataIndex : 'itemsrc_vend_id',
2079                                         items : [
2080
2081                                         ]
2082
2083                                     },
2084 {
2085                                         editor : {
2086                                             field : {
2087                                                 '|xns' : 'Roo.form',
2088                                                 xtype : 'TextField',
2089                                                 xns : Roo.form
2090                                             },
2091                                             '|xns' : 'Roo.grid',
2092                                             xtype : 'GridEditor',
2093                                             xns : Roo.grid,
2094                                             items : [
2095
2096                                             ]
2097
2098                                         },
2099                                         '|xns' : 'Roo.grid',
2100                                         xtype : 'ColumnModel',
2101                                         width : 100,
2102                                         header : 'Vendor Ref#',
2103                                         renderer : function(v) { return String.format('{0}', v); },
2104                                         xns : Roo.grid,
2105                                         dataIndex : 'itemsrc_vend_item_number',
2106                                         items : [
2107
2108                                         ]
2109
2110                                     },
2111 {
2112                                         editor : {
2113                                             field : {
2114                                                 '|xns' : 'Roo.form',
2115                                                 xtype : 'TextField',
2116                                                 xns : Roo.form
2117                                             },
2118                                             '|xns' : 'Roo.grid',
2119                                             xtype : 'GridEditor',
2120                                             xns : Roo.grid,
2121                                             items : [
2122
2123                                             ]
2124
2125                                         },
2126                                         '|xns' : 'Roo.grid',
2127                                         xtype : 'ColumnModel',
2128                                         width : 200,
2129                                         header : 'Comments',
2130                                         renderer : function(v) { return String.format('{0}', v); },
2131                                         xns : Roo.grid,
2132                                         dataIndex : 'itemsrc_comments',
2133                                         items : [
2134
2135                                         ]
2136
2137                                     },
2138 {
2139                                         '|xns' : 'Roo.grid',
2140                                         xtype : 'ColumnModel',
2141                                         width : 50,
2142                                         header : 'UOM',
2143                                         renderer : function(v) { return String.format('{0}', v); },
2144                                         xns : Roo.grid,
2145                                         dataIndex : 'itemsrc_vend_uom'
2146                                     },
2147 {
2148                                         editor : {
2149                                             field : {
2150                                                 '|xns' : 'Roo.form',
2151                                                 minValue : 0,
2152                                                 xtype : 'NumberField',
2153                                                 decimalPrecision : 0,
2154                                                 xns : Roo.form
2155                                             },
2156                                             '|xns' : 'Roo.grid',
2157                                             xtype : 'GridEditor',
2158                                             xns : Roo.grid,
2159                                             items : [
2160
2161                                             ]
2162
2163                                         },
2164                                         '|xns' : 'Roo.grid',
2165                                         align : 'right',
2166                                         xtype : 'ColumnModel',
2167                                         header : 'Min Qty',
2168                                         width : 50,
2169                                         renderer : function(v) { return String.format('{0}', v); },
2170                                         xns : Roo.grid,
2171                                         dataIndex : 'itemsrc_minordqty',
2172                                         items : [
2173
2174                                         ]
2175
2176                                     },
2177 {
2178                                         editor : {
2179                                             field : {
2180                                                 '|xns' : 'Roo.form',
2181                                                 minValue : 0,
2182                                                 xtype : 'NumberField',
2183                                                 decimalPrecision : 0,
2184                                                 xns : Roo.form
2185                                             },
2186                                             '|xns' : 'Roo.grid',
2187                                             xtype : 'GridEditor',
2188                                             xns : Roo.grid,
2189                                             items : [
2190
2191                                             ]
2192
2193                                         },
2194                                         '|xns' : 'Roo.grid',
2195                                         align : 'right',
2196                                         xtype : 'ColumnModel',
2197                                         header : 'Lead time',
2198                                         width : 75,
2199                                         renderer : function(v) { return String.format('{0}', v); },
2200                                         xns : Roo.grid,
2201                                         dataIndex : 'itemsrc_leadtime',
2202                                         items : [
2203
2204                                         ]
2205
2206                                     },
2207 {
2208                                         '|xns' : 'Roo.grid',
2209                                         xtype : 'ColumnModel',
2210                                         width : 50,
2211                                         header : 'Active',
2212                                         renderer : function(v) { return String.format('{0}', v); },
2213                                         xns : Roo.grid,
2214                                         dataIndex : 'itemsrc_active'
2215                                     }
2216                         ],
2217                         listeners : {
2218                                 rowdblclick : function (_self, rowIndex, e)
2219                                    {
2220                                        if (!_this.dialog) return;
2221                                        _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
2222                                            _this.grid.footer.onClick('first');
2223                                        }); 
2224                                    },
2225                                 render : function() 
2226                                    {
2227                                        _this.itemsrcgrid = this; 
2228                                        //_this.dialog = Pman.Dialog.FILL_IN
2229                                        
2230                                    },
2231                                 afteredit : function (e)
2232                                    {
2233                                        e.record.commit();
2234                                    }
2235                         },
2236                         items : [
2237
2238                         ]
2239
2240                     },
2241                     '|xns' : 'Roo',
2242                     region : 'center',
2243                     fitToframe : true,
2244                     background : true,
2245                     title : "Suppliers",
2246                     xtype : 'GridPanel',
2247                     fitContainer : true,
2248                     xns : Roo,
2249                     tableName : 'itemsrc',
2250                     listeners : {
2251                         activate : function() {
2252                                _this.itemsrcpanel = this;
2253                                if (_this.itemsrcgrid) {
2254                                    _this.itemsrcgrid.footer.onClick('first');
2255                                }
2256                            }
2257                     },
2258                     items : [
2259
2260                     ]
2261
2262                 },
2263                 {
2264                     grid : {
2265                         dataSource : {
2266                             proxy : {
2267                                 '|xns' : 'Roo.data',
2268                                 url : baseURL + '/Roo/events.php',
2269                                 method : 'GET',
2270                                 xtype : 'HttpProxy',
2271                                 xns : Roo.data
2272                             },
2273                             reader : {
2274                                 '|xns' : 'Roo.data',
2275                                 id : 'id',
2276                                 root : 'data',
2277                                 xtype : 'JsonReader',
2278                                 fields : [
2279                                     {
2280                                         'name': 'event_when',
2281                                         'type': 'date'
2282                                     },
2283                                     {
2284                                         'name': 'action',
2285                                         'type': 'string'
2286                                     },
2287                                     {
2288                                         'name': 'ipaddr',
2289                                         'type': 'string'
2290                                     },
2291                                     {
2292                                         'name': 'person_id_name',
2293                                         'type': 'string'
2294                                     },
2295                                     {
2296                                         'name': 'remarks',
2297                                         'type': 'string'
2298                                     }
2299                                 ],
2300                                 xns : Roo.data,
2301                                 totalProperty : 'total'
2302                             },
2303                             '|xns' : 'Roo.data',
2304                             xtype : 'Store',
2305                             remoteSort : true,
2306                             sortInfo : { field : 'event_when', direction: 'DESC' },
2307                             xns : Roo.data,
2308                             listeners : {
2309                                 beforeload : function (_self, options)
2310                                    {
2311                                        options.params = options.params || {};
2312                                        
2313                                        options.params.on_table = 'item';
2314                                        options.params.on_id = _this.form.findField('item_id').getValue();
2315                                    }
2316                             },
2317                             items : [
2318
2319                             ]
2320
2321                         },
2322                         footer : {
2323                             '|xns' : 'Roo',
2324                             pageSize : 25,
2325                             xtype : 'PagingToolbar',
2326                             emptyMsg : "No Events found",
2327                             xns : Roo,
2328                             displayMsg : "Displaying events{0} - {1} of {2}",
2329                             displayInfo : true
2330                         },
2331                         '|xns' : 'Roo.grid',
2332                         autoExpandColumn : 'remarks',
2333                         xtype : 'Grid',
2334                         loadMask : true,
2335                         xns : Roo.grid,
2336                         colModel : [
2337                                  {
2338                                         '|xns' : 'Roo.grid',
2339                                         xtype : 'ColumnModel',
2340                                         width : 120,
2341                                         header : 'Changed',
2342                                         renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y H:i:s') : ''); },
2343                                         xns : Roo.grid,
2344                                         dataIndex : 'event_when'
2345                                     },
2346 {
2347                                         '|xns' : 'Roo.grid',
2348                                         xtype : 'ColumnModel',
2349                                         width : 200,
2350                                         header : 'Action',
2351                                         renderer : function(v,x,r) { return String.format('{0} - {1}', v, r.data.on_table); },
2352                                         xns : Roo.grid,
2353                                         dataIndex : 'action'
2354                                     },
2355 {
2356                                         '|xns' : 'Roo.grid',
2357                                         xtype : 'ColumnModel',
2358                                         width : 200,
2359                                         header : 'IP Address',
2360                                         renderer : function(v) { return String.format('{0}', v); },
2361                                         xns : Roo.grid,
2362                                         dataIndex : 'ipaddr'
2363                                     },
2364 {
2365                                         '|xns' : 'Roo.grid',
2366                                         xtype : 'ColumnModel',
2367                                         width : 75,
2368                                         header : 'Who',
2369                                         renderer : function(v) { return String.format('{0}', v); },
2370                                         xns : Roo.grid,
2371                                         dataIndex : 'person_id_name'
2372                                     },
2373 {
2374                                         '|xns' : 'Roo.grid',
2375                                         xtype : 'ColumnModel',
2376                                         width : 200,
2377                                         header : 'Notes',
2378                                         renderer : function(v) { return String.format('{0}', v); },
2379                                         xns : Roo.grid,
2380                                         dataIndex : 'remarks'
2381                                     }
2382                         ],
2383                         listeners : {
2384                                 render : function() 
2385                                    {
2386                                        _this.hgrid = this; 
2387                                        if (_this.hpanel.active) {
2388                                           this.footer.onClick('first');
2389                                        }
2390                                    }
2391                         },
2392                         items : [
2393
2394                         ]
2395
2396                     },
2397                     '|xns' : 'Roo',
2398                     region : 'center',
2399                     fitToframe : true,
2400                     background : true,
2401                     title : "History",
2402                     xtype : 'GridPanel',
2403                     fitContainer : true,
2404                     xns : Roo,
2405                     tableName : 'events',
2406                     listeners : {
2407                         activate : function() {
2408                                _this.hpanel = this;
2409                                if (_this.hgrid) {
2410                                    _this.hgrid.footer.onClick('first');
2411                                }
2412                            }
2413                     },
2414                     items : [
2415
2416                     ]
2417
2418                 }
2419             ]
2420
2421         });
2422     }
2423 };