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