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