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