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