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