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