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