Pman.Tab.AdminContacts.js
[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
6
7 // register the module first
8 Pman.on('beforeload', function()
9 {
10     Pman.register({
11         modKey : '001-Pman.Tab.AdminContacts',
12         module : Pman.Tab.AdminContacts,
13         region : 'center',
14         parent : Pman.Tab.AdminContactsManager,
15         name : "Pman.Tab.AdminContacts",
16         disabled : false, 
17         permname: 'Core.Person' 
18     });
19 });
20
21 Pman.Tab.AdminContacts = new Roo.util.Observable({
22
23     panel : false,
24     disabled : false,
25     parentLayout:  false,
26
27     add : function(parentLayout, region)
28     {
29
30         var _this = this;
31         this.parentLayout = parentLayout;
32
33         this.panel = parentLayout.addxtype({
34             xtype: 'GridPanel',
35             xns: Roo,
36             listeners : {
37                 activate : function() {
38                     _this.panel = this;
39                     if (_this.grid) {
40                         _this.grid.footer.onClick('first');
41                     }
42                 }
43             },
44             autoScroll : true,
45             background : true,
46             fitContainer : true,
47             fitToframe : true,
48             region : 'center',
49             tableName : 'Person',
50             title : "Person",
51             grid : {
52                 xtype: 'Grid',
53                 xns: Roo.grid,
54                 listeners : {
55                     render : function() 
56                     {
57                         _this.grid = this; 
58                         if (!_this.dialog) {
59                             _this.dialog = Pman.Dialog.PersonEdit;
60                             
61                         }
62                         //_this.dialog = Pman.Dialog.FILL_IN
63                         if (_this.panel.active) {
64                            this.footer.onClick('first');
65                         }
66                     },
67                     rowdblclick : function (_self, rowIndex, e)
68                     {
69                         if (!_this.dialog) return;
70                         _this.dialog.show( this.getDataSource().getAt(rowIndex), function() {
71                             _this.grid.footer.onClick('first');
72                         }); 
73                     },
74                     cellclick : function (_self, rowIndex, columnIndex, e)
75                     {
76                     
77                             var di = this.colModel.getDataIndex(columnIndex);
78                             if (di != 'active') {
79                                 return;
80                             }
81                              
82                             var rec = _this.grid.ds.getAt(rowIndex);
83                             
84                             rec.set('active', rec.data.active ? 0 : 1);
85                             rec.commit();
86                              
87                             
88                     }
89                 },
90                 autoExpandColumn : 'name',
91                 ddGroup : 'groupDD',
92                 enableDrag : true,
93                 loadMask : true,
94                 dataSource : {
95                     xtype: 'Store',
96                     xns: Roo.data,
97                     listeners : {
98                         beforeload : function (_self, o)
99                         {
100                           
101                             o.params['!company_id_comptype'] = 'OWNER';
102                             o.params['query[search]'] = _this.searchBox.getValue();
103                             
104                             if (!_this.activeButton) {return; false;}
105                             
106                             
107                             o.params.active = _this.activeButton.pressed ? 0 : 1;
108                             
109                             if (Pman.Tab.AdminContactsGroup && Pman.Tab.AdminContactsGroup.grid) {
110                                 var tms = Pman.Tab.ContactsGroup.grid.getLeftSelections();
111                             
112                                 if (tms.length) {
113                                     o.params['query[in_group]'] = tms[0].data.id;
114                                     o.params['query[type]'] = 2; // group type..
115                                 }
116                             }
117                             //o.params['query[name]'] = _this.searchBox.getValue();
118                           
119                             
120                         },
121                         update : function (_self, record, operation)
122                         {
123                             if (operation != 'commit') {
124                                 return;
125                             }
126                             // only used to change active status.
127                             
128                             new Pman.Request({
129                                 url : baseURL + '/Roo/Person.php',
130                                 method :'POST',
131                                 params : {
132                                     id : record.data.id,
133                                     active: record.data.active
134                                     
135                                 },
136                                 success : function() {
137                                     // do nothing
138                                     
139                                     _this.grid.ds.remove(record);
140                                     
141                                 },
142                                 failure : function() 
143                                 {
144                                     Roo.MessageBox.alert("Error", "saving failed", function() {
145                                         _this.grid.footer.onClick('first');
146                                     });
147                                 }
148                             });
149                         }
150                     },
151                     remoteSort : true,
152                     sortInfo : { field : 'name', direction: 'ASC' },
153                     proxy : {
154                         xtype: 'HttpProxy',
155                         xns: Roo.data,
156                         method : 'GET',
157                         url : baseURL + '/Roo/Person.php'
158                     },
159                     reader : {
160                         xtype: 'JsonReader',
161                         xns: Roo.data,
162                         totalProperty : 'total',
163                         root : 'data',
164                         id : 'id',
165                         fields : [
166                             {
167                                 'name': 'id',
168                                 'type': 'int'
169                             },
170                             {
171                                 'name': 'office_id',
172                                 'type': 'int'
173                             },
174                             {
175                                 'name': 'name',
176                                 'type': 'string'
177                             },
178                             {
179                                 'name': 'phone',
180                                 'type': 'string'
181                             },
182                             {
183                                 'name': 'fax',
184                                 'type': 'string'
185                             },
186                             {
187                                 'name': 'email',
188                                 'type': 'string'
189                             },
190                             {
191                                 'name': 'company_id',
192                                 'type': 'int'
193                             },
194                             {
195                                 'name': 'role',
196                                 'type': 'string'
197                             },
198                             {
199                                 'name': 'active',
200                                 'type': 'int'
201                             },
202                             {
203                                 'name': 'remarks',
204                                 'type': 'string'
205                             },
206                             {
207                                 'name': 'passwd',
208                                 'type': 'string'
209                             },
210                             {
211                                 'name': 'owner_id',
212                                 'type': 'int'
213                             },
214                             {
215                                 'name': 'lang',
216                                 'type': 'string'
217                             },
218                             {
219                                 'name': 'no_reset_sent',
220                                 'type': 'int'
221                             },
222                             {
223                                 'name': 'action_type',
224                                 'type': 'string'
225                             },
226                             {
227                                 'name': 'project_id',
228                                 'type': 'int'
229                             },
230                             {
231                                 'name': 'office_id_id',
232                                 'type': 'int'
233                             },
234                             {
235                                 'name': 'office_id_company_id',
236                                 'type': 'int'
237                             },
238                             {
239                                 'name': 'office_id_name',
240                                 'type': 'string'
241                             },
242                             {
243                                 'name': 'office_id_address',
244                                 'type': 'string'
245                             },
246                             {
247                                 'name': 'office_id_phone',
248                                 'type': 'string'
249                             },
250                             {
251                                 'name': 'office_id_fax',
252                                 'type': 'string'
253                             },
254                             {
255                                 'name': 'office_id_email',
256                                 'type': 'string'
257                             },
258                             {
259                                 'name': 'office_id_role',
260                                 'type': 'string'
261                             },
262                             {
263                                 'name': 'company_id_code',
264                                 'type': 'string'
265                             },
266                             {
267                                 'name': 'company_id_name',
268                                 'type': 'string'
269                             },
270                             {
271                                 'name': 'company_id_remarks',
272                                 'type': 'string'
273                             },
274                             {
275                                 'name': 'company_id_owner_id',
276                                 'type': 'int'
277                             },
278                             {
279                                 'name': 'company_id_address',
280                                 'type': 'string'
281                             },
282                             {
283                                 'name': 'company_id_tel',
284                                 'type': 'string'
285                             },
286                             {
287                                 'name': 'company_id_fax',
288                                 'type': 'string'
289                             },
290                             {
291                                 'name': 'company_id_email',
292                                 'type': 'string'
293                             },
294                             {
295                                 'name': 'company_id_id',
296                                 'type': 'int'
297                             },
298                             {
299                                 'name': 'company_id_isOwner',
300                                 'type': 'int'
301                             },
302                             {
303                                 'name': 'company_id_logo_id',
304                                 'type': 'int'
305                             },
306                             {
307                                 'name': 'company_id_background_color',
308                                 'type': 'string'
309                             },
310                             {
311                                 'name': 'company_id_comptype',
312                                 'type': 'string'
313                             },
314                             {
315                                 'name': 'company_id_url',
316                                 'type': 'string'
317                             },
318                             {
319                                 'name': 'company_id_main_office_id',
320                                 'type': 'int'
321                             },
322                             {
323                                 'name': 'company_id_created_by',
324                                 'type': 'int'
325                             },
326                             {
327                                 'name': 'company_id_created_dt',
328                                 'type': 'date'
329                             },
330                             {
331                                 'name': 'company_id_updated_by',
332                                 'type': 'int'
333                             },
334                             {
335                                 'name': 'company_id_updated_dt',
336                                 'type': 'date'
337                             },
338                             {
339                                 'name': 'company_id_passwd',
340                                 'type': 'string'
341                             },
342                             {
343                                 'name': 'project_id_id',
344                                 'type': 'int'
345                             },
346                             {
347                                 'name': 'project_id_name',
348                                 'type': 'string'
349                             },
350                             {
351                                 'name': 'project_id_remarks',
352                                 'type': 'string'
353                             },
354                             {
355                                 'name': 'project_id_owner_id',
356                                 'type': 'int'
357                             },
358                             {
359                                 'name': 'project_id_code',
360                                 'type': 'string'
361                             },
362                             {
363                                 'name': 'project_id_active',
364                                 'type': 'int'
365                             },
366                             {
367                                 'name': 'project_id_type',
368                                 'type': 'string'
369                             },
370                             {
371                                 'name': 'project_id_client_id',
372                                 'type': 'int'
373                             },
374                             {
375                                 'name': 'project_id_team_id',
376                                 'type': 'int'
377                             },
378                             {
379                                 'name': 'project_id_file_location',
380                                 'type': 'string'
381                             },
382                             {
383                                 'name': 'project_id_open_date',
384                                 'type': 'date'
385                             },
386                             {
387                                 'name': 'project_id_open_by',
388                                 'type': 'int'
389                             },
390                             {
391                                 'name': 'project_id_close_date',
392                                 'type': 'date'
393                             },
394                             {
395                                 'name': 'project_id_countries',
396                                 'type': 'string'
397                             },
398                             {
399                                 'name': 'project_id_languages',
400                                 'type': 'string'
401                             },
402                             {
403                                 'name': 'project_id_agency_id',
404                                 'type': 'int'
405                             },
406                             {
407                                 'name': 'owner_id_id',
408                                 'type': 'int'
409                             },
410                             {
411                                 'name': 'owner_id_office_id',
412                                 'type': 'int'
413                             },
414                             {
415                                 'name': 'owner_id_name',
416                                 'type': 'string'
417                             },
418                             {
419                                 'name': 'owner_id_phone',
420                                 'type': 'string'
421                             },
422                             {
423                                 'name': 'owner_id_fax',
424                                 'type': 'string'
425                             },
426                             {
427                                 'name': 'owner_id_email',
428                                 'type': 'string'
429                             },
430                             {
431                                 'name': 'owner_id_company_id',
432                                 'type': 'int'
433                             },
434                             {
435                                 'name': 'owner_id_role',
436                                 'type': 'string'
437                             },
438                             {
439                                 'name': 'owner_id_active',
440                                 'type': 'int'
441                             },
442                             {
443                                 'name': 'owner_id_remarks',
444                                 'type': 'string'
445                             },
446                             {
447                                 'name': 'owner_id_passwd',
448                                 'type': 'string'
449                             },
450                             {
451                                 'name': 'owner_id_owner_id',
452                                 'type': 'int'
453                             },
454                             {
455                                 'name': 'owner_id_lang',
456                                 'type': 'string'
457                             },
458                             {
459                                 'name': 'owner_id_no_reset_sent',
460                                 'type': 'int'
461                             },
462                             {
463                                 'name': 'owner_id_action_type',
464                                 'type': 'string'
465                             },
466                             {
467                                 'name': 'owner_id_project_id',
468                                 'type': 'int'
469                             }
470                         ]
471                     }
472                 },
473                 footer : {
474                     xtype: 'PagingToolbar',
475                     xns: Roo,
476                     pageSize : 25,
477                     displayInfo : true,
478                     displayMsg : 'Displaying Person{0} - {1} of {2}',
479                     emptyMsg : 'No Person found',
480                     items : [
481                         {
482                             xtype: 'TextItem',
483                             xns: Roo.Toolbar,
484                             text : "Drag person to add or remove from group"
485                         }
486                     ]
487                 },
488                 toolbar : {
489                     xtype: 'Toolbar',
490                     xns: Roo,
491                     items : [
492                         {
493                             xtype: 'Button',
494                             xns: Roo.Toolbar,
495                             listeners : {
496                                 click : function()
497                                 {
498                                     
499                                     _this.dialog.show( { id : 0 } , function() {
500                                         _this.grid.footer.onClick('first');
501                                    }); 
502                                 }
503                             },
504                             cls : 'x-btn-text-icon',
505                             text : "Add",
506                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
507                         },
508                         {
509                             xtype: 'Button',
510                             xns: Roo.Toolbar,
511                             listeners : {
512                                 click : function()
513                                 {
514                                     
515                                     Pman.Dialog.PersonBulkAdd.dialog.show( { id : 0 } , function() {
516                                         _this.grid.footer.onClick('first');
517                                    }); 
518                                 }
519                             },
520                             cls : 'x-btn-text-icon',
521                             text : "Bulk Add",
522                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
523                         },
524                         {
525                             xtype: 'Button',
526                             xns: Roo.Toolbar,
527                             listeners : {
528                                 click : function()
529                                 {
530                                     var s = _this.grid.getSelectionModel().getSelections();
531                                     if (!s.length || (s.length > 1))  {
532                                         Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
533                                         return;
534                                     }
535                                   
536                                     Pman.Dialog.PersonEdit.dialog.show(s[0].data, function() {
537                                         _this.grid.footer.onClick('first');
538                                     }); 
539                                     
540                                 }
541                             },
542                             cls : 'x-btn-text-icon',
543                             text : "Edit",
544                             icon : Roo.rootURL + 'images/default/tree/leaf.gif'
545                         },
546                         {
547                             xtype: 'Separator',
548                             xns: Roo.Toolbar
549                         },
550                         {
551                             xtype: 'TextItem',
552                             xns: Roo.Toolbar,
553                             text : "Search"
554                         },
555                         {
556                             xtype: 'TextField',
557                             xns: Roo.form,
558                             listeners : {
559                                 render : function (_self)
560                                 {
561                                     _this.searchBox = _self;
562                                 },
563                                 show : function (_self,e)
564                                 {
565                                     if (e.getCharCode() != 13) {
566                                         return;
567                                     }
568                                     _this.grid.footer.onClick('first');
569                                 }
570                             }
571                         },
572                         {
573                             xtype: 'Button',
574                             xns: Roo.Toolbar,
575                             listeners : {
576                                 click : function (_self, e)
577                                 {
578                                 _this.grid.footer.onClick('first');
579                                 }
580                             },
581                             cls : 'x-btn-icon',
582                             icon : rootURL + '/Pman/templates/images/search.gif'
583                         },
584                         {
585                             xtype: 'Button',
586                             xns: Roo.Toolbar,
587                             listeners : {
588                                 click : function (_self, e)
589                                 {
590                                 _this.searchBox.setValue('');
591                                     _this.grid.footer.onClick('first');
592                                 }
593                             },
594                             cls : 'x-btn-icon',
595                             icon : rootURL + '/Pman/templates/images/edit-clear.gif'
596                         },
597                         {
598                             xtype: 'Fill',
599                             xns: Roo.Toolbar
600                         },
601                         {
602                             xtype: 'Button',
603                             xns: Roo.Toolbar,
604                             listeners : {
605                                 toggle : function (_self, pressed)
606                                 {
607                                    _this.grid.footer.onClick('first');
608                                    this.setText(pressed ? "Show Active" : "Show Removed");
609                                    
610                                    
611                                 },
612                                 render : function (_self)
613                                 {
614                                   _this.activeButton = _self;
615                                 }
616                             },
617                             enableToggle : true,
618                             text : "Show Removed"
619                         }
620                     ]
621                 },
622                 colModel : [
623                     {
624                         xtype: 'ColumnModel',
625                         xns: Roo.grid,
626                         dataIndex : 'project_id_code',
627                         header : 'Project',
628                         hidden : true,
629                         sortable : true,
630                         width : 75,
631                         renderer : function(v,x,r) { 
632                               return String.format('<span qtip="{0}">{1}</span>', 
633                                             r.data.project_id_name,
634                                             v);
635                          }
636                     },
637                     {
638                         xtype: 'ColumnModel',
639                         xns: Roo.grid,
640                         dataIndex : 'company_id_comptype',
641                         header : 'Type',
642                         sortable : true,
643                         width : 50,
644                         renderer : function(v,x,r) {
645                             if (r.data.office_id) {
646                                 return String.format('{0} - {1}', v, r.data.office_id_name); 
647                             } 
648                             return String.format('{0}', v); 
649                         }
650                     },
651                     {
652                         xtype: 'ColumnModel',
653                         xns: Roo.grid,
654                         dataIndex : 'company_id_name',
655                         header : 'Company',
656                         sortable : true,
657                         width : 150,
658                         renderer : function(v,x,r) {
659                             if (r.data.office_id) {
660                                 return String.format('{0} - {1}', v, r.data.office_id_name); 
661                             } 
662                             return String.format('{0}', v); 
663                         }
664                     },
665                     {
666                         xtype: 'ColumnModel',
667                         xns: Roo.grid,
668                         dataIndex : 'name',
669                         header : 'Name',
670                         sortable : true,
671                         width : 200,
672                         renderer : function(v) { return String.format('{0}', v); }
673                     },
674                     {
675                         xtype: 'ColumnModel',
676                         xns: Roo.grid,
677                         dataIndex : 'role',
678                         header : 'Role',
679                         width : 100,
680                         renderer : function(v) { return String.format('{0}', v); }
681                     },
682                     {
683                         xtype: 'ColumnModel',
684                         xns: Roo.grid,
685                         dataIndex : 'phone',
686                         header : 'Phone',
687                         width : 100,
688                         renderer : function(v) { return String.format('{0}', v); }
689                     },
690                     {
691                         xtype: 'ColumnModel',
692                         xns: Roo.grid,
693                         dataIndex : 'fax',
694                         header : 'Fax',
695                         width : 100,
696                         renderer : function(v) { return String.format('{0}', v); }
697                     },
698                     {
699                         xtype: 'ColumnModel',
700                         xns: Roo.grid,
701                         dataIndex : 'email',
702                         header : 'Email',
703                         sortable : true,
704                         width : 200,
705                         renderer : function(v) {
706                            return (v.length && v.indexOf('@') > 0 ) ? 
707                                             String.format('<a href="mailto:{0}">{0}</a>',v) : v;
708                          }
709                     },
710                     {
711                         xtype: 'ColumnModel',
712                         xns: Roo.grid,
713                         dataIndex : 'active',
714                         header : 'Active',
715                         width : 75,
716                         renderer : function(v) {  
717                             var state = v> 0 ?  '-checked' : '';
718                         
719                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
720                                         
721                          }
722                     }
723                 ]
724             }
725         });
726         this.layout = this.panel.layout;
727
728     }
729 });