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