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