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