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