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