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