Pman.Tab.AdminContacts.js
[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 Pman.Tab.AdminContacts = new Roo.XComponent({
6     part     :  ["Admin","Contacts"],
7     order    : '001-Pman.Tab.AdminContacts',
8     region   : 'center',
9     parent   : 'Pman.Tab.AdminContactsManager',
10     name     : "Pman.Tab.AdminContacts",
11     disabled : false, 
12     permname : 'Core.Person', 
13     _tree : function()
14     {
15         var _this = this;
16         var MODULE = this;
17         return {
18             xtype: 'GridPanel',
19             xns: Roo,
20             listeners : {
21                 activate : function() {
22                     _this.panel = this;
23                     if (_this.grid) {
24                         _this.grid.footer.onClick('first');
25                     }
26                 }
27             },
28             autoScroll : true,
29             background : true,
30             fitContainer : true,
31             fitToframe : true,
32             region : 'center',
33             tableName : 'Person',
34             title : "Person",
35             grid : {
36                 xtype: 'Grid',
37                 xns: Roo.grid,
38                 listeners : {
39                     render : function() 
40                     {
41                         _this.grid = this; 
42                         if (!_this.dialog) {
43                             Roo.log('iniinininin');
44                             _this.dialog = Pman.Dialog.PersonEdit;
45                             
46                         }
47                         //_this.dialog = Pman.Dialog.FILL_IN
48                         if (_this.panel.active) {
49                            this.footer.onClick('first');
50                         }
51                     },
52                     rowdblclick : function (_self, rowIndex, e)
53                     {
54                         if (!_this.dialog) return;
55                         _this.dialog.show( this.getDataSource().getAt(rowIndex), function() {
56                             _this.grid.footer.onClick('first');
57                         }); 
58                     },
59                     cellclick : function (_self, rowIndex, columnIndex, e)
60                     {
61                     
62                             var di = this.colModel.getDataIndex(columnIndex);
63                             if (di != 'active') {
64                                 return;
65                             }
66                              
67                             var rec = _this.grid.ds.getAt(rowIndex);
68                             
69                             rec.set('active', rec.data.active ? 0 : 1);
70                             rec.commit();
71                              
72                             
73                     }
74                 },
75                 autoExpandColumn : 'name',
76                 ddGroup : 'groupDD',
77                 enableDrag : true,
78                 loadMask : true,
79                 dataSource : {
80                     xtype: 'Store',
81                     xns: Roo.data,
82                     listeners : {
83                         beforeload : function (_self, o)
84                         {
85                             if(!_this.active_company_button.pressed){
86                                 o.params['!company_id_comptype'] = 'OWNER';
87                             }
88                             
89                             o.params['query[search]'] = _this.searchBox.getValue();
90                             
91                             if (!_this.activeButton) {return; false;}
92                             
93                             if (_this.companyCombo &&   _this.companyCombo.getValue()) {
94                                 o.params.company_id =   _this.companyCombo.getValue();
95                             }
96                             
97                             
98                             o.params.active = _this.activeButton.pressed ? 0 : 1;
99                             
100                             if(_this.active_company_button.pressed){
101                                 o.params.company_id = 0;
102                             }
103                             if (!Pman.Tab.AdminContactsGroup) { 
104                                 return false;
105                             }
106                             
107                             
108                             if (Pman.Tab.AdminContactsGroup && Pman.Tab.AdminContactsGroup.grid) {
109                                 var tms = Pman.Tab.AdminContactsGroup.grid.getSelectionModel().getSelected();
110                                 
111                                 if (!tms) {
112                                     return false;
113                                 }
114                                 o.params['query[in_group]'] = tms.data.id;
115                                 o.params['query[type]'] = 2; // group type..
116                                 
117                             }
118                             //o.params['query[name]'] = _this.searchBox.getValue();
119                           
120                         },
121                         update : function (_self, record, operation)
122                         {
123                             if (operation != 'commit') {
124                                 return;
125                             }
126                             // only used to change active status.
127                             
128                             new Pman.Request({
129                                 url : baseURL + '/Roo/Person.php',
130                                 method :'POST',
131                                 params : {
132                                     id : record.data.id,
133                                     active: record.data.active
134                                     
135                                 },
136                                 success : function() {
137                                     // do nothing
138                                     
139                                     _this.grid.ds.remove(record);
140                                     
141                                 },
142                                 failure : function() 
143                                 {
144                                     Roo.MessageBox.alert("Error", "saving failed", function() {
145                                         _this.grid.footer.onClick('first');
146                                     });
147                                 }
148                             });
149                         }
150                     },
151                     remoteSort : true,
152                     sortInfo : { field : 'name', direction: 'ASC' },
153                     proxy : {
154                         xtype: 'HttpProxy',
155                         xns: Roo.data,
156                         method : 'GET',
157                         url : baseURL + '/Roo/Person.php'
158                     },
159                     reader : {
160                         xtype: 'JsonReader',
161                         xns: Roo.data,
162                         totalProperty : 'total',
163                         root : 'data',
164                         id : 'id',
165                         fields : [
166                             {
167                                 'name': 'id',
168                                 'type': 'int'
169                             },
170                             {
171                                 'name': 'office_id',
172                                 'type': 'int'
173                             },
174                             {
175                                 'name': 'name',
176                                 'type': 'string'
177                             },
178                             {
179                                 'name': 'phone',
180                                 'type': 'string'
181                             },
182                             {
183                                 'name': 'fax',
184                                 'type': 'string'
185                             },
186                             {
187                                 'name': 'email',
188                                 'type': 'string'
189                             },
190                             {
191                                 'name': 'company_id',
192                                 'type': 'int'
193                             },
194                             {
195                                 'name': 'role',
196                                 'type': 'string'
197                             },
198                             {
199                                 'name': 'active',
200                                 'type': 'int'
201                             },
202                             {
203                                 'name': 'remarks',
204                                 'type': 'string'
205                             },
206                             {
207                                 'name': 'passwd',
208                                 'type': 'string'
209                             },
210                             {
211                                 'name': 'owner_id',
212                                 'type': 'int'
213                             },
214                             {
215                                 'name': 'lang',
216                                 'type': 'string'
217                             },
218                             {
219                                 'name': 'no_reset_sent',
220                                 'type': 'int'
221                             },
222                             {
223                                 'name': 'action_type',
224                                 'type': 'string'
225                             },
226                             {
227                                 'name': 'project_id',
228                                 'type': 'int'
229                             },
230                             {
231                                 'name': 'office_id_id',
232                                 'type': 'int'
233                             },
234                             {
235                                 'name': 'office_id_company_id',
236                                 'type': 'int'
237                             },
238                             {
239                                 'name': 'office_id_name',
240                                 'type': 'string'
241                             },
242                             {
243                                 'name': 'office_id_address',
244                                 'type': 'string'
245                             },
246                             {
247                                 'name': 'office_id_phone',
248                                 'type': 'string'
249                             },
250                             {
251                                 'name': 'office_id_fax',
252                                 'type': 'string'
253                             },
254                             {
255                                 'name': 'office_id_email',
256                                 'type': 'string'
257                             },
258                             {
259                                 'name': 'office_id_role',
260                                 'type': 'string'
261                             },
262                             {
263                                 'name': 'company_id_code',
264                                 'type': 'string'
265                             },
266                             {
267                                 'name': 'company_id_name',
268                                 'type': 'string'
269                             },
270                             {
271                                 'name': 'company_id_remarks',
272                                 'type': 'string'
273                             },
274                             {
275                                 'name': 'company_id_owner_id',
276                                 'type': 'int'
277                             },
278                             {
279                                 'name': 'company_id_address',
280                                 'type': 'string'
281                             },
282                             {
283                                 'name': 'company_id_tel',
284                                 'type': 'string'
285                             },
286                             {
287                                 'name': 'company_id_fax',
288                                 'type': 'string'
289                             },
290                             {
291                                 'name': 'company_id_email',
292                                 'type': 'string'
293                             },
294                             {
295                                 'name': 'company_id_id',
296                                 'type': 'int'
297                             },
298                             {
299                                 'name': 'company_id_isOwner',
300                                 'type': 'int'
301                             },
302                             {
303                                 'name': 'company_id_logo_id',
304                                 'type': 'int'
305                             },
306                             {
307                                 'name': 'company_id_background_color',
308                                 'type': 'string'
309                             },
310                             {
311                                 'name': 'company_id_comptype',
312                                 'type': 'string'
313                             },
314                             {
315                                 'name': 'company_id_url',
316                                 'type': 'string'
317                             },
318                             {
319                                 'name': 'company_id_main_office_id',
320                                 'type': 'int'
321                             },
322                             {
323                                 'name': 'company_id_created_by',
324                                 'type': 'int'
325                             },
326                             {
327                                 'name': 'company_id_created_dt',
328                                 'type': 'date'
329                             },
330                             {
331                                 'name': 'company_id_updated_by',
332                                 'type': 'int'
333                             },
334                             {
335                                 'name': 'company_id_updated_dt',
336                                 'type': 'date'
337                             },
338                             {
339                                 'name': 'company_id_passwd',
340                                 'type': 'string'
341                             },
342                             {
343                                 'name': 'project_id_id',
344                                 'type': 'int'
345                             },
346                             {
347                                 'name': 'project_id_name',
348                                 'type': 'string'
349                             },
350                             {
351                                 'name': 'project_id_remarks',
352                                 'type': 'string'
353                             },
354                             {
355                                 'name': 'project_id_owner_id',
356                                 'type': 'int'
357                             },
358                             {
359                                 'name': 'project_id_code',
360                                 'type': 'string'
361                             },
362                             {
363                                 'name': 'project_id_active',
364                                 'type': 'int'
365                             },
366                             {
367                                 'name': 'project_id_type',
368                                 'type': 'string'
369                             },
370                             {
371                                 'name': 'project_id_client_id',
372                                 'type': 'int'
373                             },
374                             {
375                                 'name': 'project_id_team_id',
376                                 'type': 'int'
377                             },
378                             {
379                                 'name': 'project_id_file_location',
380                                 'type': 'string'
381                             },
382                             {
383                                 'name': 'project_id_open_date',
384                                 'type': 'date'
385                             },
386                             {
387                                 'name': 'project_id_open_by',
388                                 'type': 'int'
389                             },
390                             {
391                                 'name': 'project_id_close_date',
392                                 'type': 'date'
393                             },
394                             {
395                                 'name': 'project_id_countries',
396                                 'type': 'string'
397                             },
398                             {
399                                 'name': 'project_id_languages',
400                                 'type': 'string'
401                             },
402                             {
403                                 'name': 'project_id_agency_id',
404                                 'type': 'int'
405                             },
406                             {
407                                 'name': 'owner_id_id',
408                                 'type': 'int'
409                             },
410                             {
411                                 'name': 'owner_id_office_id',
412                                 'type': 'int'
413                             },
414                             {
415                                 'name': 'owner_id_name',
416                                 'type': 'string'
417                             },
418                             {
419                                 'name': 'owner_id_phone',
420                                 'type': 'string'
421                             },
422                             {
423                                 'name': 'owner_id_fax',
424                                 'type': 'string'
425                             },
426                             {
427                                 'name': 'owner_id_email',
428                                 'type': 'string'
429                             },
430                             {
431                                 'name': 'owner_id_company_id',
432                                 'type': 'int'
433                             },
434                             {
435                                 'name': 'owner_id_role',
436                                 'type': 'string'
437                             },
438                             {
439                                 'name': 'owner_id_active',
440                                 'type': 'int'
441                             },
442                             {
443                                 'name': 'owner_id_remarks',
444                                 'type': 'string'
445                             },
446                             {
447                                 'name': 'owner_id_passwd',
448                                 'type': 'string'
449                             },
450                             {
451                                 'name': 'owner_id_owner_id',
452                                 'type': 'int'
453                             },
454                             {
455                                 'name': 'owner_id_lang',
456                                 'type': 'string'
457                             },
458                             {
459                                 'name': 'owner_id_no_reset_sent',
460                                 'type': 'int'
461                             },
462                             {
463                                 'name': 'owner_id_action_type',
464                                 'type': 'string'
465                             },
466                             {
467                                 'name': 'owner_id_project_id',
468                                 'type': 'int'
469                             }
470                         ]
471                     }
472                 },
473                 footer : {
474                     xtype: 'PagingToolbar',
475                     xns: Roo,
476                     pageSize : 25,
477                     displayInfo : true,
478                     displayMsg : "Displaying Person{0} - {1} of {2}",
479                     emptyMsg : "No Person found",
480                     items : [
481                         {
482                             xtype: 'TextItem',
483                             xns: Roo.Toolbar,
484                             text : "Drag person to add or remove from group"
485                         }
486                     ]
487                 },
488                 toolbar : {
489                     xtype: 'Toolbar',
490                     xns: Roo,
491                     items : [
492                         {
493                             xtype: 'TextItem',
494                             xns: Roo.Toolbar,
495                             text : "Search"
496                         },
497                         {
498                             xtype: 'TextField',
499                             xns: Roo.form,
500                             listeners : {
501                                 render : function (_self)
502                                 {
503                                     _this.searchBox = _self;
504                                 },
505                                 show : function (_self,e)
506                                 {
507                                     if (e.getCharCode() != 13) {
508                                         return;
509                                     }
510                                     _this.grid.footer.onClick('first');
511                                 },
512                                 specialkey : function (_self, e)
513                                 {
514                                   if (e.getKey() == 13) {
515                                     _this.grid.footer.onClick('first');
516                                   }
517                                 }
518                             }
519                         },
520                         {
521                             xtype: 'ComboBox',
522                             xns: Roo.form,
523                             listeners : {
524                                 render : function (_self)
525                                 {
526                                   _this.companyCombo = _self;
527                                 },
528                                 select : function (combo, record, index)
529                                 {
530                                    _this.grid.footer.onClick.defer(300,_this.grid.footer,[ 'first'] );
531                                 }
532                             },
533                             displayField : 'name',
534                             editable : true,
535                             emptyText : "Select Company",
536                             forceSelection : true,
537                             hiddenName : 'company_id',
538                             listWidth : 400,
539                             loadingText : "Searching...",
540                             minChars : 2,
541                             name : 'company_name',
542                             pageSize : 20,
543                             qtip : "Select Companies",
544                             queryParam : 'query[name]',
545                             selectOnFocus : true,
546                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>',
547                             triggerAction : 'all',
548                             typeAhead : true,
549                             valueField : 'id',
550                             width : 150,
551                             store : {
552                                 xtype: 'Store',
553                                 xns: Roo.data,
554                                 listeners : {
555                                     beforeload : function (_self, o){
556                                         o.params = o.params || {};
557                                         // set more here
558                                     }
559                                 },
560                                 remoteSort : true,
561                                 sortInfo : { direction : 'ASC', field: 'name' },
562                                 proxy : {
563                                     xtype: 'HttpProxy',
564                                     xns: Roo.data,
565                                     method : 'GET',
566                                     url : baseURL + '/Roo/Companies.php'
567                                 },
568                                 reader : {
569                                     xtype: 'JsonReader',
570                                     xns: Roo.data,
571                                     id : 'id',
572                                     root : 'data',
573                                     totalProperty : 'total',
574                                     fields : [{"name":"id","type":"int"},{"name":"code","type":"string"}]
575                                 }
576                             }
577                         },
578                         {
579                             xtype: 'Button',
580                             xns: Roo.Toolbar,
581                             listeners : {
582                                 click : function (_self, e)
583                                 {
584                                 _this.grid.footer.onClick('first');
585                                 }
586                             },
587                             cls : 'x-btn-icon',
588                             icon : rootURL + '/Pman/templates/images/search.gif'
589                         },
590                         {
591                             xtype: 'Button',
592                             xns: Roo.Toolbar,
593                             listeners : {
594                                 click : function (_self, e)
595                                 {
596                                 _this.searchBox.setValue('');
597                                     _this.grid.footer.onClick('first');
598                                 }
599                             },
600                             cls : 'x-btn-icon',
601                             icon : rootURL + '/Pman/templates/images/edit-clear.gif'
602                         },
603                         {
604                             xtype: 'Button',
605                             xns: Roo.Toolbar,
606                             listeners : {
607                                 toggle : function (_self, pressed)
608                                 {
609                                    _this.grid.footer.onClick('first');
610                                    this.setText(pressed ? "Show Active" : "Show Removed");
611                                    
612                                    
613                                 },
614                                 render : function (_self)
615                                 {
616                                   _this.activeButton = _self;
617                                 }
618                             },
619                             enableToggle : true,
620                             text : "Show Removed"
621                         },
622                         {
623                             xtype: 'Button',
624                             xns: Roo.Toolbar,
625                             listeners : {
626                                 toggle : function (_self, pressed)
627                                 {
628                                    _this.grid.footer.onClick('first');
629                                    this.setText(pressed ? "Show Company" : "Show No Company");
630                                    
631                                    
632                                 },
633                                 render : function (_self)
634                                 {
635                                   _this.active_company_button = _self;
636                                 }
637                             },
638                             enableToggle : true,
639                             text : "Show No Company"
640                         },
641                         {
642                             xtype: 'Button',
643                             xns: Roo.Toolbar,
644                             listeners : {
645                                 click : function (_self, e)
646                                 {
647                                     var s = _this.grid.getSelectionModel().getSelections();
648                                     if(s.length != 1){
649                                         Roo.MessageBox.alert("Error", "Select a Person");
650                                         return;
651                                     }
652                                     
653                                     new Pman.Request({
654                                         url : baseURL + '/Login.php',
655                                         method : 'GET',
656                                         params : {
657                                             'switch' : s[0].data.id
658                                         },
659                                         success : function (){
660                                             document.location = baseURL + '?ts=' + Math.random();
661                                         },
662                                         failure : function (d){
663                                             Roo.log(d);
664                                             Roo.MessageBox.alert("Error", d);
665                                         }
666                                     });
667                                 }
668                             },
669                             text : "Switch to Selected User"
670                         },
671                         {
672                             xtype: 'Fill',
673                             xns: Roo.Toolbar
674                         },
675                         {
676                             xtype: 'Button',
677                             xns: Roo.Toolbar,
678                             listeners : {
679                                 click : function()
680                                 {
681                                     
682                                     _this.dialog.show( { id : 0 } , function() {
683                                         _this.grid.footer.onClick('first');
684                                    }); 
685                                 }
686                             },
687                             cls : 'x-btn-text-icon',
688                             text : "Add",
689                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
690                         },
691                         {
692                             xtype: 'Button',
693                             xns: Roo.Toolbar,
694                             listeners : {
695                                 click : function()
696                                 {
697                                     
698                                     Pman.Dialog.PersonBulkAdd.show( { id : 0 } , function() {
699                                         _this.grid.footer.onClick('first');
700                                    }); 
701                                 }
702                             },
703                             cls : 'x-btn-text-icon',
704                             text : "Bulk Add",
705                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
706                         },
707                         {
708                             xtype: 'Button',
709                             xns: Roo.Toolbar,
710                             listeners : {
711                                 click : function()
712                                 {
713                                     var s = _this.grid.getSelectionModel().getSelections();
714                                     if (!s.length || (s.length > 1))  {
715                                         Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
716                                         return;
717                                     }
718                                   
719                                     _this.dialog.show(s[0].data, function() {
720                                         _this.grid.footer.onClick('first');
721                                     }); 
722                                     
723                                 }
724                             },
725                             cls : 'x-btn-text-icon',
726                             text : "Edit",
727                             icon : Roo.rootURL + 'images/default/tree/leaf.gif'
728                         },
729                         {
730                             xtype: 'Button',
731                             xns: Roo.Toolbar,
732                             listeners : {
733                                 click : function()
734                                 {
735                                      Pman.genericDelete(_this, 'Person'); 
736                                 }
737                             },
738                             cls : 'x-btn-text-icon',
739                             text : "Delete",
740                             icon : rootURL + '/Pman/templates/images/trash.gif'
741                         }
742                     ]
743                 },
744                 colModel : [
745                     {
746                         xtype: 'ColumnModel',
747                         xns: Roo.grid,
748                         dataIndex : 'project_id_code',
749                         header : 'Project',
750                         hidden : true,
751                         sortable : true,
752                         width : 75,
753                         renderer : function(v,x,r) { 
754                               return String.format('<span qtip="{0}">{1}</span>', 
755                                             r.data.project_id_name,
756                                             v);
757                          }
758                     },
759                     {
760                         xtype: 'ColumnModel',
761                         xns: Roo.grid,
762                         dataIndex : 'company_id_comptype',
763                         header : 'Type',
764                         sortable : true,
765                         width : 50,
766                         renderer : function(v,x,r) {
767                             if (r.data.office_id) {
768                                 return String.format('{0} - {1}', v, r.data.office_id_name); 
769                             } 
770                             return String.format('{0}', v); 
771                         }
772                     },
773                     {
774                         xtype: 'ColumnModel',
775                         xns: Roo.grid,
776                         dataIndex : 'company_id_name',
777                         header : 'Company',
778                         sortable : true,
779                         width : 150,
780                         renderer : function(v,x,r) {
781                             if (r.data.office_id) {
782                                 return String.format('{0} - {1}', v, r.data.office_id_name); 
783                             } 
784                             return String.format('{0}', v); 
785                         }
786                     },
787                     {
788                         xtype: 'ColumnModel',
789                         xns: Roo.grid,
790                         dataIndex : 'name',
791                         header : 'Name',
792                         sortable : true,
793                         width : 200,
794                         renderer : function(v) { return String.format('{0}', v); }
795                     },
796                     {
797                         xtype: 'ColumnModel',
798                         xns: Roo.grid,
799                         dataIndex : 'role',
800                         header : 'Role',
801                         width : 100,
802                         renderer : function(v) { return String.format('{0}', v); }
803                     },
804                     {
805                         xtype: 'ColumnModel',
806                         xns: Roo.grid,
807                         dataIndex : 'phone',
808                         header : 'Phone',
809                         width : 100,
810                         renderer : function(v) { return String.format('{0}', v); }
811                     },
812                     {
813                         xtype: 'ColumnModel',
814                         xns: Roo.grid,
815                         dataIndex : 'fax',
816                         header : 'Fax',
817                         width : 100,
818                         renderer : function(v) { return String.format('{0}', v); }
819                     },
820                     {
821                         xtype: 'ColumnModel',
822                         xns: Roo.grid,
823                         dataIndex : 'email',
824                         header : 'Email',
825                         sortable : true,
826                         width : 200,
827                         renderer : function(v) {
828                            return (v.length && v.indexOf('@') > 0 ) ? 
829                                             String.format('<a href="mailto:{0}">{0}</a>',v) : v;
830                          }
831                     },
832                     {
833                         xtype: 'ColumnModel',
834                         xns: Roo.grid,
835                         dataIndex : 'active',
836                         header : 'Active',
837                         width : 75,
838                         renderer : function(v) {  
839                             var state = v> 0 ?  '-checked' : '';
840                         
841                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
842                                         
843                          }
844                     }
845                 ]
846             }
847         };
848     }
849 });