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: 'TextItem',
500                             xns: Roo.Toolbar,
501                             text : "Search"
502                         },
503                         {
504                             xtype: 'TextField',
505                             xns: Roo.form,
506                             listeners : {
507                                 render : function (_self)
508                                 {
509                                     _this.searchBox = _self;
510                                 },
511                                 show : function (_self,e)
512                                 {
513                                     if (e.getCharCode() != 13) {
514                                         return;
515                                     }
516                                     _this.grid.footer.onClick('first');
517                                 },
518                                 specialkey : function (_self, e)
519                                 {
520                                   if (e.getKey() == 13) {
521                                     _this.grid.footer.onClick('first');
522                                   }
523                                 }
524                             }
525                         },
526                         {
527                             xtype: 'Button',
528                             xns: Roo.Toolbar,
529                             listeners : {
530                                 click : function (_self, e)
531                                 {
532                                 _this.grid.footer.onClick('first');
533                                 }
534                             },
535                             cls : 'x-btn-icon',
536                             icon : rootURL + '/Pman/templates/images/search.gif'
537                         },
538                         {
539                             xtype: 'Button',
540                             xns: Roo.Toolbar,
541                             listeners : {
542                                 click : function (_self, e)
543                                 {
544                                 _this.searchBox.setValue('');
545                                     _this.grid.footer.onClick('first');
546                                 }
547                             },
548                             cls : 'x-btn-icon',
549                             icon : rootURL + '/Pman/templates/images/edit-clear.gif'
550                         },
551                         {
552                             xtype: 'Button',
553                             xns: Roo.Toolbar,
554                             listeners : {
555                                 toggle : function (_self, pressed)
556                                 {
557                                    _this.grid.footer.onClick('first');
558                                    this.setText(pressed ? "Show Active" : "Show Removed");
559                                    
560                                    
561                                 },
562                                 render : function (_self)
563                                 {
564                                   _this.activeButton = _self;
565                                 }
566                             },
567                             enableToggle : true,
568                             text : "Show Removed"
569                         },
570                         {
571                             xtype: 'Fill',
572                             xns: Roo.Toolbar
573                         },
574                         {
575                             xtype: 'Button',
576                             xns: Roo.Toolbar,
577                             listeners : {
578                                 click : function()
579                                 {
580                                     
581                                     _this.dialog.show( { id : 0 } , function() {
582                                         _this.grid.footer.onClick('first');
583                                    }); 
584                                 }
585                             },
586                             cls : 'x-btn-text-icon',
587                             text : "Add",
588                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
589                         },
590                         {
591                             xtype: 'Button',
592                             xns: Roo.Toolbar,
593                             listeners : {
594                                 click : function()
595                                 {
596                                     
597                                     Pman.Dialog.PersonBulkAdd.show( { id : 0 } , function() {
598                                         _this.grid.footer.onClick('first');
599                                    }); 
600                                 }
601                             },
602                             cls : 'x-btn-text-icon',
603                             text : "Bulk Add",
604                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
605                         },
606                         {
607                             xtype: 'Button',
608                             xns: Roo.Toolbar,
609                             listeners : {
610                                 click : function()
611                                 {
612                                     var s = _this.grid.getSelectionModel().getSelections();
613                                     if (!s.length || (s.length > 1))  {
614                                         Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
615                                         return;
616                                     }
617                                   
618                                     _this.dialog.show(s[0].data, function() {
619                                         _this.grid.footer.onClick('first');
620                                     }); 
621                                     
622                                 }
623                             },
624                             cls : 'x-btn-text-icon',
625                             text : "Edit",
626                             icon : Roo.rootURL + 'images/default/tree/leaf.gif'
627                         },
628                         {
629                             xtype: 'Button',
630                             xns: Roo.Toolbar,
631                             listeners : {
632                                 click : function()
633                                 {
634                                      Pman.genericDelete(_this, 'Person'); 
635                                 }
636                             },
637                             cls : 'x-btn-text-icon',
638                             text : "Delete",
639                             icon : rootURL + '/Pman/templates/images/trash.gif'
640                         }
641                     ]
642                 },
643                 colModel : [
644                     {
645                         xtype: 'ColumnModel',
646                         xns: Roo.grid,
647                         dataIndex : 'project_id_code',
648                         header : 'Project',
649                         hidden : true,
650                         sortable : true,
651                         width : 75,
652                         renderer : function(v,x,r) { 
653                               return String.format('<span qtip="{0}">{1}</span>', 
654                                             r.data.project_id_name,
655                                             v);
656                          }
657                     },
658                     {
659                         xtype: 'ColumnModel',
660                         xns: Roo.grid,
661                         dataIndex : 'company_id_comptype',
662                         header : 'Type',
663                         sortable : true,
664                         width : 50,
665                         renderer : function(v,x,r) {
666                             if (r.data.office_id) {
667                                 return String.format('{0} - {1}', v, r.data.office_id_name); 
668                             } 
669                             return String.format('{0}', v); 
670                         }
671                     },
672                     {
673                         xtype: 'ColumnModel',
674                         xns: Roo.grid,
675                         dataIndex : 'company_id_name',
676                         header : 'Company',
677                         sortable : true,
678                         width : 150,
679                         renderer : function(v,x,r) {
680                             if (r.data.office_id) {
681                                 return String.format('{0} - {1}', v, r.data.office_id_name); 
682                             } 
683                             return String.format('{0}', v); 
684                         }
685                     },
686                     {
687                         xtype: 'ColumnModel',
688                         xns: Roo.grid,
689                         dataIndex : 'name',
690                         header : 'Name',
691                         sortable : true,
692                         width : 200,
693                         renderer : function(v) { return String.format('{0}', v); }
694                     },
695                     {
696                         xtype: 'ColumnModel',
697                         xns: Roo.grid,
698                         dataIndex : 'role',
699                         header : 'Role',
700                         width : 100,
701                         renderer : function(v) { return String.format('{0}', v); }
702                     },
703                     {
704                         xtype: 'ColumnModel',
705                         xns: Roo.grid,
706                         dataIndex : 'phone',
707                         header : 'Phone',
708                         width : 100,
709                         renderer : function(v) { return String.format('{0}', v); }
710                     },
711                     {
712                         xtype: 'ColumnModel',
713                         xns: Roo.grid,
714                         dataIndex : 'fax',
715                         header : 'Fax',
716                         width : 100,
717                         renderer : function(v) { return String.format('{0}', v); }
718                     },
719                     {
720                         xtype: 'ColumnModel',
721                         xns: Roo.grid,
722                         dataIndex : 'email',
723                         header : 'Email',
724                         sortable : true,
725                         width : 200,
726                         renderer : function(v) {
727                            return (v.length && v.indexOf('@') > 0 ) ? 
728                                             String.format('<a href="mailto:{0}">{0}</a>',v) : v;
729                          }
730                     },
731                     {
732                         xtype: 'ColumnModel',
733                         xns: Roo.grid,
734                         dataIndex : 'active',
735                         header : 'Active',
736                         width : 75,
737                         renderer : function(v) {  
738                             var state = v> 0 ?  '-checked' : '';
739                         
740                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
741                                         
742                          }
743                     }
744                 ]
745             }
746         });
747         this.layout = this.panel.layout;
748
749     }
750 });