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                                 render : function (_self)
645                                 {
646                                   _this.active_company_button = _self;
647                                 }
648                             },
649                             enableToggle : true,
650                             text : "Switch to Selected User"
651                         },
652                         {
653                             xtype: 'Fill',
654                             xns: Roo.Toolbar
655                         },
656                         {
657                             xtype: 'Button',
658                             xns: Roo.Toolbar,
659                             listeners : {
660                                 click : function()
661                                 {
662                                     
663                                     _this.dialog.show( { id : 0 } , function() {
664                                         _this.grid.footer.onClick('first');
665                                    }); 
666                                 }
667                             },
668                             cls : 'x-btn-text-icon',
669                             text : "Add",
670                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
671                         },
672                         {
673                             xtype: 'Button',
674                             xns: Roo.Toolbar,
675                             listeners : {
676                                 click : function()
677                                 {
678                                     
679                                     Pman.Dialog.PersonBulkAdd.show( { id : 0 } , function() {
680                                         _this.grid.footer.onClick('first');
681                                    }); 
682                                 }
683                             },
684                             cls : 'x-btn-text-icon',
685                             text : "Bulk Add",
686                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
687                         },
688                         {
689                             xtype: 'Button',
690                             xns: Roo.Toolbar,
691                             listeners : {
692                                 click : function()
693                                 {
694                                     var s = _this.grid.getSelectionModel().getSelections();
695                                     if (!s.length || (s.length > 1))  {
696                                         Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
697                                         return;
698                                     }
699                                   
700                                     _this.dialog.show(s[0].data, function() {
701                                         _this.grid.footer.onClick('first');
702                                     }); 
703                                     
704                                 }
705                             },
706                             cls : 'x-btn-text-icon',
707                             text : "Edit",
708                             icon : Roo.rootURL + 'images/default/tree/leaf.gif'
709                         },
710                         {
711                             xtype: 'Button',
712                             xns: Roo.Toolbar,
713                             listeners : {
714                                 click : function()
715                                 {
716                                      Pman.genericDelete(_this, 'Person'); 
717                                 }
718                             },
719                             cls : 'x-btn-text-icon',
720                             text : "Delete",
721                             icon : rootURL + '/Pman/templates/images/trash.gif'
722                         }
723                     ]
724                 },
725                 colModel : [
726                     {
727                         xtype: 'ColumnModel',
728                         xns: Roo.grid,
729                         dataIndex : 'project_id_code',
730                         header : 'Project',
731                         hidden : true,
732                         sortable : true,
733                         width : 75,
734                         renderer : function(v,x,r) { 
735                               return String.format('<span qtip="{0}">{1}</span>', 
736                                             r.data.project_id_name,
737                                             v);
738                          }
739                     },
740                     {
741                         xtype: 'ColumnModel',
742                         xns: Roo.grid,
743                         dataIndex : 'company_id_comptype',
744                         header : 'Type',
745                         sortable : true,
746                         width : 50,
747                         renderer : function(v,x,r) {
748                             if (r.data.office_id) {
749                                 return String.format('{0} - {1}', v, r.data.office_id_name); 
750                             } 
751                             return String.format('{0}', v); 
752                         }
753                     },
754                     {
755                         xtype: 'ColumnModel',
756                         xns: Roo.grid,
757                         dataIndex : 'company_id_name',
758                         header : 'Company',
759                         sortable : true,
760                         width : 150,
761                         renderer : function(v,x,r) {
762                             if (r.data.office_id) {
763                                 return String.format('{0} - {1}', v, r.data.office_id_name); 
764                             } 
765                             return String.format('{0}', v); 
766                         }
767                     },
768                     {
769                         xtype: 'ColumnModel',
770                         xns: Roo.grid,
771                         dataIndex : 'name',
772                         header : 'Name',
773                         sortable : true,
774                         width : 200,
775                         renderer : function(v) { return String.format('{0}', v); }
776                     },
777                     {
778                         xtype: 'ColumnModel',
779                         xns: Roo.grid,
780                         dataIndex : 'role',
781                         header : 'Role',
782                         width : 100,
783                         renderer : function(v) { return String.format('{0}', v); }
784                     },
785                     {
786                         xtype: 'ColumnModel',
787                         xns: Roo.grid,
788                         dataIndex : 'phone',
789                         header : 'Phone',
790                         width : 100,
791                         renderer : function(v) { return String.format('{0}', v); }
792                     },
793                     {
794                         xtype: 'ColumnModel',
795                         xns: Roo.grid,
796                         dataIndex : 'fax',
797                         header : 'Fax',
798                         width : 100,
799                         renderer : function(v) { return String.format('{0}', v); }
800                     },
801                     {
802                         xtype: 'ColumnModel',
803                         xns: Roo.grid,
804                         dataIndex : 'email',
805                         header : 'Email',
806                         sortable : true,
807                         width : 200,
808                         renderer : function(v) {
809                            return (v.length && v.indexOf('@') > 0 ) ? 
810                                             String.format('<a href="mailto:{0}">{0}</a>',v) : v;
811                          }
812                     },
813                     {
814                         xtype: 'ColumnModel',
815                         xns: Roo.grid,
816                         dataIndex : 'active',
817                         header : 'Active',
818                         width : 75,
819                         renderer : function(v) {  
820                             var state = v> 0 ?  '-checked' : '';
821                         
822                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
823                                         
824                          }
825                     }
826                 ]
827             }
828         };
829     }
830 });