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