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