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