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