Pman.Dialog.AdminWatch.bjs
[Pman.Admin] / Pman.Tab.AdminContacts.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.Tab');
6
7 Pman.Tab.AdminContacts = new Roo.XComponent({
8
9  _strings : {
10   '99b344c8ae43e3e7213862b8f35c4e51' :"Select Company",
11   '1c76cbfe21c6f44c1d1e59d54f3e4420' :"Company",
12   'ce8ae9da5b7cd6c3df2929543a9af92d' :"Email",
13   '8444e81d652b084d70c71cd7d19ac0cf' :"Displaying Person{0} - {1} of {2}",
14   '13348442cc6a27032d2b4aa28b75a5d3' :"Search",
15   'ec211f7c20af43e742bf2570c3cb84f9' :"Add",
16   '9e727fdd3aec8274f46685441900280d' :"Project",
17   '7dce122004969d56ae2e0245cb754d35' :"Edit",
18   '4110db87ce3ac86d603d03d691616b1e' :"Drag person to add or remove from group",
19   'b47a519aebda8fdb4b59bdae6eb2bff0' :"Show No Company",
20   '1243daf593fa297e07ab03bf06d925af' :"Searching...",
21   'bcc254b55c4a1babdf1dcb82c207506b' :"Phone",
22   '9675747b5ab12d05f18518761e68a533' :"Select Companies",
23   '40bed7cf9b3d4bb3a3d7a7e3eb18c5eb' :"Person",
24   'f1174ecbbc232f948717979daf04cf08' :"No Person found",
25   'ec3249f16ee5880d4c1acb752e5c925f' :"Switch to Selected User",
26   'a93806efd0cc7a149f0f03e2b9a0f862' :"Bulk Add",
27   'f2a6c498fb90ee345d997f888fce3b18' :"Delete",
28   'a1fa27779242b4902f7ae3bdd5c6d508' :"Type",
29   '49ee3087348e8d44e1feda1917443987' :"Name",
30   'bbbabdbe1b262f75d99d62880b953be1' :"Role",
31   '4d3d769b812b6faa6b76e1a8abaece2d' :"Active",
32   'd4d25ad0a12e8d30e9d8d35230f6d1d3' :"Show Removed",
33   '9810aa2b9f44401be4bf73188ef2b67d' :"Fax"
34  },
35
36   part     :  ["Admin", "Contacts" ],
37   order    : '001-Pman.Tab.AdminContacts',
38   region   : 'center',
39   parent   : 'Pman.Tab.AdminContactsManager',
40   name     : "Pman.Tab.AdminContacts",
41   disabled : false, 
42   permname : 'Core.Person', 
43   _tree : function()
44   {
45    var _this = this;
46    var MODULE = this;
47    return {
48    xtype : 'GridPanel',
49    autoScroll : true,
50    background : false,
51    fitContainer : true,
52    fitToframe : true,
53    region : 'center',
54    tableName : 'Person',
55    title : _this._strings['40bed7cf9b3d4bb3a3d7a7e3eb18c5eb'] /* Person */,
56    listeners : {
57     activate : function() {
58          _this.panel = this;
59          if (_this.grid) {
60              _this.grid.footer.onClick('first');
61          }
62      }
63    },
64    xns : Roo,
65    '|xns' : 'Roo',
66    grid : {
67     xtype : 'Grid',
68     autoExpandColumn : 'name',
69     ddGroup : 'groupDD',
70     enableDrag : true,
71     loadMask : true,
72     listeners : {
73      cellclick : function (_self, rowIndex, columnIndex, e)
74       {
75       
76               var di = this.colModel.getDataIndex(columnIndex);
77               if (di != 'active') {
78                   return;
79               }
80                
81               var rec = _this.grid.ds.getAt(rowIndex);
82               
83               rec.set('active', rec.data.active ? 0 : 1);
84               rec.commit();
85                
86               
87       },
88      render : function() 
89       {
90           _this.grid = this; 
91           if (!_this.dialog) {
92               _this.dialog = Pman.Dialog.PersonEdit;
93               
94           }
95           //_this.dialog = Pman.Dialog.FILL_IN
96           if (_this.panel.active) {
97              this.footer.onClick('first');
98           }
99       },
100      rowdblclick : function (_self, rowIndex, e)
101       {
102           if (!_this.dialog) {
103               return;
104           }
105           _this.dialog.show( this.getDataSource().getAt(rowIndex), function() {
106               _this.grid.footer.onClick('first');
107           }); 
108       }
109     },
110     xns : Roo.grid,
111     '|xns' : 'Roo.grid',
112     footer : {
113      xtype : 'PagingToolbar',
114      displayInfo : true,
115      displayMsg : _this._strings['8444e81d652b084d70c71cd7d19ac0cf'] /* Displaying Person{0} - {1} of {2} */,
116      emptyMsg : _this._strings['f1174ecbbc232f948717979daf04cf08'] /* No Person found */,
117      pageSize : 25,
118      xns : Roo,
119      '|xns' : 'Roo',
120      items  : [
121       {
122        xtype : 'TextItem',
123        text : _this._strings['4110db87ce3ac86d603d03d691616b1e'] /* Drag person to add or remove from group */,
124        xns : Roo.Toolbar,
125        '|xns' : 'Roo.Toolbar'
126       }
127      ]
128     },
129     toolbar : {
130      xtype : 'Toolbar',
131      xns : Roo,
132      '|xns' : 'Roo',
133      items  : [
134       {
135        xtype : 'TextItem',
136        text : _this._strings['13348442cc6a27032d2b4aa28b75a5d3'] /* Search */,
137        xns : Roo.Toolbar,
138        '|xns' : 'Roo.Toolbar'
139       },
140       {
141        xtype : 'TextField',
142        listeners : {
143         render : function (_self)
144          {
145              _this.searchBox = _self;
146          },
147         show : function (_self,e)
148          {
149              if (e.getCharCode() != 13) {
150                  return;
151              }
152              _this.grid.footer.onClick('first');
153          },
154         specialkey : function (_self, e)
155          {
156            if (e.getKey() == 13) {
157              _this.grid.footer.onClick('first');
158            }
159          }
160        },
161        xns : Roo.form,
162        '|xns' : 'Roo.form'
163       },
164       {
165        xtype : 'ComboBox',
166        displayField : 'name',
167        editable : true,
168        emptyText : _this._strings['99b344c8ae43e3e7213862b8f35c4e51'] /* Select Company */,
169        forceSelection : true,
170        hiddenName : 'company_id',
171        listWidth : 400,
172        loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
173        minChars : 2,
174        name : 'company_name',
175        pageSize : 20,
176        qtip : _this._strings['9675747b5ab12d05f18518761e68a533'] /* Select Companies */,
177        queryParam : 'query[name]',
178        selectOnFocus : true,
179        tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{name}</b> </div>',
180        triggerAction : 'all',
181        typeAhead : true,
182        valueField : 'id',
183        width : 150,
184        listeners : {
185         render : function (_self)
186          {
187            _this.companyCombo = _self;
188          },
189         select : function (combo, record, index)
190          {
191             _this.grid.footer.onClick.defer(300,_this.grid.footer,[ 'first'] );
192          }
193        },
194        xns : Roo.form,
195        '|xns' : 'Roo.form',
196        store : {
197         xtype : 'Store',
198         remoteSort : true,
199         sortInfo : { direction : 'ASC', field: 'name' },
200         listeners : {
201          beforeload : function (_self, o){
202               o.params = o.params || {};
203               // set more here
204           }
205         },
206         xns : Roo.data,
207         '|xns' : 'Roo.data',
208         proxy : {
209          xtype : 'HttpProxy',
210          method : 'GET',
211          url : baseURL + '/Roo/core_company',
212          xns : Roo.data,
213          '|xns' : 'Roo.data'
214         },
215         reader : {
216          xtype : 'JsonReader',
217          fields : [{"name":"id","type":"int"},{"name":"code","type":"string"}],
218          id : 'id',
219          root : 'data',
220          totalProperty : 'total',
221          xns : Roo.data,
222          '|xns' : 'Roo.data'
223         }
224        }
225       },
226       {
227        xtype : 'Button',
228        cls : 'x-btn-icon',
229        icon : rootURL + '/Pman/templates/images/search.gif',
230        listeners : {
231         click : function (_self, e)
232          {
233          _this.grid.footer.onClick('first');
234          }
235        },
236        xns : Roo.Toolbar,
237        '|xns' : 'Roo.Toolbar'
238       },
239       {
240        xtype : 'Button',
241        cls : 'x-btn-icon',
242        icon : rootURL + '/Pman/templates/images/edit-clear.gif',
243        listeners : {
244         click : function (_self, e)
245          {
246          _this.searchBox.setValue('');
247              _this.grid.footer.onClick('first');
248          }
249        },
250        xns : Roo.Toolbar,
251        '|xns' : 'Roo.Toolbar'
252       },
253       {
254        xtype : 'Button',
255        enableToggle : true,
256        text : _this._strings['d4d25ad0a12e8d30e9d8d35230f6d1d3'] /* Show Removed */,
257        listeners : {
258         render : function (_self)
259          {
260            _this.activeButton = _self;
261          },
262         toggle : function (_self, pressed)
263          {
264             _this.grid.footer.onClick('first');
265             this.setText(pressed ? "Show Active" : "Show Removed");
266             
267             
268          }
269        },
270        xns : Roo.Toolbar,
271        '|xns' : 'Roo.Toolbar'
272       },
273       {
274        xtype : 'Button',
275        enableToggle : true,
276        text : _this._strings['b47a519aebda8fdb4b59bdae6eb2bff0'] /* Show No Company */,
277        listeners : {
278         render : function (_self)
279          {
280            _this.active_company_button = _self;
281          },
282         toggle : function (_self, pressed)
283          {
284             _this.grid.footer.onClick('first');
285             this.setText(pressed ? "Show Company" : "Show No Company");
286             
287             
288          }
289        },
290        xns : Roo.Toolbar,
291        '|xns' : 'Roo.Toolbar'
292       },
293       {
294        xtype : 'Button',
295        text : _this._strings['ec3249f16ee5880d4c1acb752e5c925f'] /* Switch to Selected User */,
296        listeners : {
297         click : function (_self, e)
298          {
299              var s = _this.grid.getSelectionModel().getSelections();
300              if(s.length != 1){
301                  Roo.MessageBox.alert("Error", "Select a Person");
302                  return;
303              }
304              
305              new Pman.Request({
306                  url : baseURL + '/Login.php',
307                  method : 'GET',
308                  params : {
309                      'switch' : s[0].data.id
310                  },
311                  success : function (){
312                      document.location = baseURL + '?ts=' + Math.random();
313                  },
314                  failure : function (d){
315                      Roo.log(d);
316                      Roo.MessageBox.alert("Error", d);
317                  }
318              });
319          }
320        },
321        xns : Roo.Toolbar,
322        '|xns' : 'Roo.Toolbar'
323       },
324       {
325        xtype : 'Fill',
326        xns : Roo.Toolbar,
327        '|xns' : 'Roo.Toolbar'
328       },
329       {
330        xtype : 'Button',
331        cls : 'x-btn-text-icon',
332        icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
333        text : _this._strings['ec211f7c20af43e742bf2570c3cb84f9'] /* Add */,
334        listeners : {
335         click : function()
336          {
337              
338              _this.dialog.show( { id : 0 } , function() {
339                  _this.grid.footer.onClick('first');
340             }); 
341          }
342        },
343        xns : Roo.Toolbar,
344        '|xns' : 'Roo.Toolbar'
345       },
346       {
347        xtype : 'Button',
348        cls : 'x-btn-text-icon',
349        icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
350        text : _this._strings['a93806efd0cc7a149f0f03e2b9a0f862'] /* Bulk Add */,
351        listeners : {
352         click : function()
353          {
354              
355              Pman.Dialog.PersonBulkAdd.show( { id : 0 } , function() {
356                  _this.grid.footer.onClick('first');
357             }); 
358          }
359        },
360        xns : Roo.Toolbar,
361        '|xns' : 'Roo.Toolbar'
362       },
363       {
364        xtype : 'Button',
365        cls : 'x-btn-text-icon',
366        icon : Roo.rootURL + 'images/default/tree/leaf.gif',
367        text : _this._strings['7dce122004969d56ae2e0245cb754d35'] /* Edit */,
368        listeners : {
369         click : function()
370          {
371              var s = _this.grid.getSelectionModel().getSelections();
372              if (!s.length || (s.length > 1))  {
373                  Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
374                  return;
375              }
376            
377              _this.dialog.show(s[0].data, function() {
378                  _this.grid.footer.onClick('first');
379              }); 
380              
381          }
382        },
383        xns : Roo.Toolbar,
384        '|xns' : 'Roo.Toolbar'
385       },
386       {
387        xtype : 'Button',
388        cls : 'x-btn-text-icon',
389        icon : rootURL + '/Pman/templates/images/trash.gif',
390        text : _this._strings['f2a6c498fb90ee345d997f888fce3b18'] /* Delete */,
391        listeners : {
392         click : function()
393          {
394               Pman.genericDelete(_this, 'Person'); 
395          }
396        },
397        xns : Roo.Toolbar,
398        '|xns' : 'Roo.Toolbar'
399       }
400      ]
401     },
402     dataSource : {
403      xtype : 'Store',
404      remoteSort : true,
405      sortInfo : { field : 'name', direction: 'ASC' },
406      listeners : {
407       beforeload : function (_self, o)
408        {
409            if(!_this.active_company_button.pressed){
410                o.params['!company_id_comptype'] = 'OWNER';
411            }
412            
413            o.params['query[search]'] = _this.searchBox.getValue();
414            
415            if (!_this.activeButton) {return; false;}
416            
417            if (_this.companyCombo &&   _this.companyCombo.getValue()) {
418                o.params.company_id =   _this.companyCombo.getValue();
419            }
420            
421            
422            o.params.active = _this.activeButton.pressed ? 0 : 1;
423            
424            if(_this.active_company_button.pressed){
425                o.params.company_id = 0;
426            }
427            
428            var c = Pman.Tab.AdminContactsManager.layout.getRegion('west').getActivePanel();
429            
430            if (!c) { 
431                return false;
432            }
433            
434            var tms = c.grid.getSelectionModel().getSelected();
435            
436            if (!tms) {
437                return false;
438            }
439            
440            if(c.tableName == 'Groups'){
441                o.params['query[in_group]'] = tms.data.id;
442                o.params['query[type]'] = 2; // group type..
443            }else{
444                o.params['query[in_country]'] = (tms.data.country*1 == -1) ? '' : tms.data.country;
445                o.params['query[in_group]'] = 0;
446                o.params['query[type]'] = 2;
447            }
448            /*
449            if (Pman.Tab.AdminContactsGroup && Pman.Tab.AdminContactsGroup.grid) {
450                
451                
452                
453            }
454            
455            if(Pman.Tab.AdminCountries && Pman.Tab.AdminCountries.grid){
456                var tms = Pman.Tab.AdminCountries.grid.getSelectionModel().getSelected();
457                
458                if (!tms) {
459                    return false;
460                }
461                
462            }
463            */
464            //o.params['query[name]'] = _this.searchBox.getValue();
465          
466        },
467       update : function (_self, record, operation)
468        {
469            if (operation != 'commit') {
470                return;
471            }
472            // only used to change active status.
473            
474            new Pman.Request({
475                url : baseURL + '/Roo/core_person',
476                method :'POST',
477                params : {
478                    id : record.data.id,
479                    active: record.data.active
480                    
481                },
482                success : function() {
483                    // do nothing
484                    
485                    _this.grid.ds.remove(record);
486                    
487                },
488                failure : function() 
489                {
490                    Roo.MessageBox.alert("Error", "saving failed", function() {
491                        _this.grid.footer.onClick('first');
492                    });
493                }
494            });
495        }
496      },
497      xns : Roo.data,
498      '|xns' : 'Roo.data',
499      proxy : {
500       xtype : 'HttpProxy',
501       method : 'GET',
502       url : baseURL + '/Roo/core_person',
503       xns : Roo.data,
504       '|xns' : 'Roo.data'
505      },
506      reader : {
507       xtype : 'JsonReader',
508       id : 'id',
509       root : 'data',
510       totalProperty : 'total',
511       xns : Roo.data,
512       '|xns' : 'Roo.data'
513      }
514     },
515     colModel : [
516      {
517       xtype : 'ColumnModel',
518       dataIndex : 'project_id_code',
519       header : _this._strings['9e727fdd3aec8274f46685441900280d'] /* Project */,
520       hidden : true,
521       renderer : function(v,x,r) { 
522             return String.format('<span qtip="{0}">{1}</span>', 
523                           r.data.project_id_name,
524                           v);
525        },
526       sortable : true,
527       width : 75,
528       xns : Roo.grid,
529       '|xns' : 'Roo.grid'
530      },
531      {
532       xtype : 'ColumnModel',
533       dataIndex : 'company_id_comptype',
534       header : _this._strings['a1fa27779242b4902f7ae3bdd5c6d508'] /* Type */,
535       renderer : function(v,x,r) {
536           if (r.data.office_id) {
537               return String.format('{0} - {1}', v, r.data.office_id_name); 
538           } 
539           return String.format('{0}', v); 
540       },
541       sortable : true,
542       width : 50,
543       xns : Roo.grid,
544       '|xns' : 'Roo.grid'
545      },
546      {
547       xtype : 'ColumnModel',
548       dataIndex : 'company_id_name',
549       header : _this._strings['1c76cbfe21c6f44c1d1e59d54f3e4420'] /* Company */,
550       renderer : function(v,x,r) {
551           if (r.data.office_id) {
552               return String.format('{0} - {1}', v, r.data.office_id_name); 
553           } 
554           return String.format('{0}', v); 
555       },
556       sortable : true,
557       width : 150,
558       xns : Roo.grid,
559       '|xns' : 'Roo.grid'
560      },
561      {
562       xtype : 'ColumnModel',
563       dataIndex : 'name',
564       header : _this._strings['49ee3087348e8d44e1feda1917443987'] /* Name */,
565       renderer : function(v) { return String.format('{0}', v); },
566       sortable : true,
567       width : 200,
568       xns : Roo.grid,
569       '|xns' : 'Roo.grid'
570      },
571      {
572       xtype : 'ColumnModel',
573       dataIndex : 'role',
574       header : _this._strings['bbbabdbe1b262f75d99d62880b953be1'] /* Role */,
575       renderer : function(v) { return String.format('{0}', v); },
576       width : 100,
577       xns : Roo.grid,
578       '|xns' : 'Roo.grid'
579      },
580      {
581       xtype : 'ColumnModel',
582       dataIndex : 'phone',
583       header : _this._strings['bcc254b55c4a1babdf1dcb82c207506b'] /* Phone */,
584       renderer : function(v) { return String.format('{0}', v); },
585       width : 100,
586       xns : Roo.grid,
587       '|xns' : 'Roo.grid'
588      },
589      {
590       xtype : 'ColumnModel',
591       dataIndex : 'fax',
592       header : _this._strings['9810aa2b9f44401be4bf73188ef2b67d'] /* Fax */,
593       renderer : function(v) { return String.format('{0}', v); },
594       width : 100,
595       xns : Roo.grid,
596       '|xns' : 'Roo.grid'
597      },
598      {
599       xtype : 'ColumnModel',
600       dataIndex : 'email',
601       header : _this._strings['ce8ae9da5b7cd6c3df2929543a9af92d'] /* Email */,
602       renderer : function(v) {
603          return (v.length && v.indexOf('@') > 0 ) ? 
604                           String.format('<a href="mailto:{0}">{0}</a>',v) : v;
605        },
606       sortable : true,
607       width : 200,
608       xns : Roo.grid,
609       '|xns' : 'Roo.grid'
610      },
611      {
612       xtype : 'ColumnModel',
613       dataIndex : 'active',
614       header : _this._strings['4d3d769b812b6faa6b76e1a8abaece2d'] /* Active */,
615       renderer : function(v) {  
616           var state = v> 0 ?  '-checked' : '';
617       
618           return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
619                       
620        },
621       width : 75,
622       xns : Roo.grid,
623       '|xns' : 'Roo.grid'
624      }
625     ]
626    }
627   };  }
628 });