Pman.Tab.AdminContacts.bjs
[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         part :  ["Admin","Contacts"],
12         modKey : '001-Pman.Tab.AdminContacts',
13         module : Pman.Tab.AdminContacts,
14         region : 'center',
15         parent : Pman.Tab.AdminContactsManager,
16         name : "Pman.Tab.AdminContacts",
17         disabled : false, 
18         permname: 'Core.Person' 
19     });
20 });
21
22 Pman.Tab.AdminContacts = new Roo.util.Observable({
23
24     panel : false,
25     disabled : false,
26     parentLayout:  false,
27
28     add : function(parentLayout, region)
29     {
30
31         var _this = this;
32         this.parentLayout = parentLayout;
33
34         this.panel = parentLayout.addxtype({
35             xtype: 'GridPanel',
36             xns: Roo,
37             listeners : {
38                 activate : function() {
39                     _this.panel = this;
40                     if (_this.grid) {
41                         _this.grid.footer.onClick('first');
42                     }
43                 }
44             },
45             autoScroll : true,
46             background : true,
47             fitContainer : true,
48             fitToframe : true,
49             region : 'center',
50             tableName : 'Person',
51             title : "Person",
52             grid : {
53                 xtype: 'Grid',
54                 xns: Roo.grid,
55                 listeners : {
56                     render : function() 
57                     {
58                         _this.grid = this; 
59                         if (!_this.dialog) {
60                             _this.dialog = Pman.Dialog.PersonEdit;
61                             
62                         }
63                         //_this.dialog = Pman.Dialog.FILL_IN
64                         if (_this.panel.active) {
65                            this.footer.onClick('first');
66                         }
67                     },
68                     rowdblclick : function (_self, rowIndex, e)
69                     {
70                         if (!_this.dialog) return;
71                         _this.dialog.show( this.getDataSource().getAt(rowIndex), function() {
72                             _this.grid.footer.onClick('first');
73                         }); 
74                     },
75                     cellclick : function (_self, rowIndex, columnIndex, e)
76                     {
77                     
78                             var di = this.colModel.getDataIndex(columnIndex);
79                             if (di != 'active') {
80                                 return;
81                             }
82                              
83                             var rec = _this.grid.ds.getAt(rowIndex);
84                             
85                             rec.set('active', rec.data.active ? 0 : 1);
86                             rec.commit();
87                              
88                             
89                     }
90                 },
91                 autoExpandColumn : 'name',
92                 ddGroup : 'groupDD',
93                 enableDrag : true,
94                 loadMask : true,
95                 dataSource : {
96                     xtype: 'Store',
97                     xns: Roo.data,
98                     listeners : {
99                         beforeload : function (_self, o)
100                         {
101                           
102                             o.params['!company_id_comptype'] = 'OWNER';
103                             o.params['query[search]'] = _this.searchBox.getValue();
104                             
105                             if (!_this.activeButton) {return; false;}
106                             
107                              if (_this.companyCombo &&   _this.companyCombo.getValue()) {
108                                 o.params.company_id =   _this.companyCombo.getValue();
109                             }
110                             
111                             
112                             o.params.active = _this.activeButton.pressed ? 0 : 1;
113                             if (!Pman.Tab.AdminContactsGroup) { 
114                                 return false;
115                             }
116                             
117                             
118                             if (Pman.Tab.AdminContactsGroup && Pman.Tab.AdminContactsGroup.grid) {
119                                 var tms = Pman.Tab.AdminContactsGroup.grid.getSelectionModel().getSelected();
120                                 
121                                 if (!tms) {
122                                     return false;
123                                 }
124                                 o.params['query[in_group]'] = tms.data.id;
125                                 o.params['query[type]'] = 2; // group type..
126                                 
127                             }
128                             //o.params['query[name]'] = _this.searchBox.getValue();
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: 'TextItem',
504                             xns: Roo.Toolbar,
505                             text : "Search"
506                         },
507                         {
508                             xtype: 'TextField',
509                             xns: Roo.form,
510                             listeners : {
511                                 render : function (_self)
512                                 {
513                                     _this.searchBox = _self;
514                                 },
515                                 show : function (_self,e)
516                                 {
517                                     if (e.getCharCode() != 13) {
518                                         return;
519                                     }
520                                     _this.grid.footer.onClick('first');
521                                 },
522                                 specialkey : function (_self, e)
523                                 {
524                                   if (e.getKey() == 13) {
525                                     _this.grid.footer.onClick('first');
526                                   }
527                                 }
528                             }
529                         },
530                         {
531                             xtype: 'ComboBox',
532                             xns: Roo.form,
533                             listeners : {
534                                 render : function (_self)
535                                 {
536                                   _this.companyCombo = _self;
537                                 }
538                             },
539                             displayField : 'name',
540                             editable : true,
541                             emptyText : "Select Company",
542                             forceSelection : true,
543                             hiddenName : 'company_id',
544                             listWidth : 400,
545                             loadingText : "Searching...",
546                             minChars : 2,
547                             name : 'company_name',
548                             pageSize : 20,
549                             qtip : "Select Companies",
550                             queryParam : 'query[name]',
551                             selectOnFocus : true,
552                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>',
553                             triggerAction : 'all',
554                             typeAhead : true,
555                             valueField : 'id',
556                             width : 150,
557                             store : {
558                                 xtype: 'Store',
559                                 xns: Roo.data,
560                                 listeners : {
561                                     beforeload : function (_self, o){
562                                         o.params = o.params || {};
563                                         // set more here
564                                     }
565                                 },
566                                 remoteSort : true,
567                                 sortInfo : { direction : 'ASC', field: 'name' },
568                                 proxy : {
569                                     xtype: 'HttpProxy',
570                                     xns: Roo.data,
571                                     method : 'GET',
572                                     url : baseURL + '/Roo/Companies.php'
573                                 },
574                                 reader : {
575                                     xtype: 'JsonReader',
576                                     xns: Roo.data,
577                                     id : 'id',
578                                     root : 'data',
579                                     totalProperty : 'total',
580                                     fields : [{"name":"id","type":"int"},{"name":"code","type":"string"}]
581                                 }
582                             }
583                         },
584                         {
585                             xtype: 'Button',
586                             xns: Roo.Toolbar,
587                             listeners : {
588                                 click : function (_self, e)
589                                 {
590                                 _this.grid.footer.onClick('first');
591                                 }
592                             },
593                             cls : 'x-btn-icon',
594                             icon : rootURL + '/Pman/templates/images/search.gif'
595                         },
596                         {
597                             xtype: 'Button',
598                             xns: Roo.Toolbar,
599                             listeners : {
600                                 click : function (_self, e)
601                                 {
602                                 _this.searchBox.setValue('');
603                                     _this.grid.footer.onClick('first');
604                                 }
605                             },
606                             cls : 'x-btn-icon',
607                             icon : rootURL + '/Pman/templates/images/edit-clear.gif'
608                         },
609                         {
610                             xtype: 'Button',
611                             xns: Roo.Toolbar,
612                             listeners : {
613                                 toggle : function (_self, pressed)
614                                 {
615                                    _this.grid.footer.onClick('first');
616                                    this.setText(pressed ? "Show Active" : "Show Removed");
617                                    
618                                    
619                                 },
620                                 render : function (_self)
621                                 {
622                                   _this.activeButton = _self;
623                                 }
624                             },
625                             enableToggle : true,
626                             text : "Show Removed"
627                         },
628                         {
629                             xtype: 'Fill',
630                             xns: Roo.Toolbar
631                         },
632                         {
633                             xtype: 'Button',
634                             xns: Roo.Toolbar,
635                             listeners : {
636                                 click : function()
637                                 {
638                                     
639                                     _this.dialog.show( { id : 0 } , function() {
640                                         _this.grid.footer.onClick('first');
641                                    }); 
642                                 }
643                             },
644                             cls : 'x-btn-text-icon',
645                             text : "Add",
646                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
647                         },
648                         {
649                             xtype: 'Button',
650                             xns: Roo.Toolbar,
651                             listeners : {
652                                 click : function()
653                                 {
654                                     
655                                     Pman.Dialog.PersonBulkAdd.show( { id : 0 } , function() {
656                                         _this.grid.footer.onClick('first');
657                                    }); 
658                                 }
659                             },
660                             cls : 'x-btn-text-icon',
661                             text : "Bulk Add",
662                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
663                         },
664                         {
665                             xtype: 'Button',
666                             xns: Roo.Toolbar,
667                             listeners : {
668                                 click : function()
669                                 {
670                                     var s = _this.grid.getSelectionModel().getSelections();
671                                     if (!s.length || (s.length > 1))  {
672                                         Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
673                                         return;
674                                     }
675                                   
676                                     _this.dialog.show(s[0].data, function() {
677                                         _this.grid.footer.onClick('first');
678                                     }); 
679                                     
680                                 }
681                             },
682                             cls : 'x-btn-text-icon',
683                             text : "Edit",
684                             icon : Roo.rootURL + 'images/default/tree/leaf.gif'
685                         },
686                         {
687                             xtype: 'Button',
688                             xns: Roo.Toolbar,
689                             listeners : {
690                                 click : function()
691                                 {
692                                      Pman.genericDelete(_this, 'Person'); 
693                                 }
694                             },
695                             cls : 'x-btn-text-icon',
696                             text : "Delete",
697                             icon : rootURL + '/Pman/templates/images/trash.gif'
698                         }
699                     ]
700                 },
701                 colModel : [
702                     {
703                         xtype: 'ColumnModel',
704                         xns: Roo.grid,
705                         dataIndex : 'project_id_code',
706                         header : 'Project',
707                         hidden : true,
708                         sortable : true,
709                         width : 75,
710                         renderer : function(v,x,r) { 
711                               return String.format('<span qtip="{0}">{1}</span>', 
712                                             r.data.project_id_name,
713                                             v);
714                          }
715                     },
716                     {
717                         xtype: 'ColumnModel',
718                         xns: Roo.grid,
719                         dataIndex : 'company_id_comptype',
720                         header : 'Type',
721                         sortable : true,
722                         width : 50,
723                         renderer : function(v,x,r) {
724                             if (r.data.office_id) {
725                                 return String.format('{0} - {1}', v, r.data.office_id_name); 
726                             } 
727                             return String.format('{0}', v); 
728                         }
729                     },
730                     {
731                         xtype: 'ColumnModel',
732                         xns: Roo.grid,
733                         dataIndex : 'company_id_name',
734                         header : 'Company',
735                         sortable : true,
736                         width : 150,
737                         renderer : function(v,x,r) {
738                             if (r.data.office_id) {
739                                 return String.format('{0} - {1}', v, r.data.office_id_name); 
740                             } 
741                             return String.format('{0}', v); 
742                         }
743                     },
744                     {
745                         xtype: 'ColumnModel',
746                         xns: Roo.grid,
747                         dataIndex : 'name',
748                         header : 'Name',
749                         sortable : true,
750                         width : 200,
751                         renderer : function(v) { return String.format('{0}', v); }
752                     },
753                     {
754                         xtype: 'ColumnModel',
755                         xns: Roo.grid,
756                         dataIndex : 'role',
757                         header : 'Role',
758                         width : 100,
759                         renderer : function(v) { return String.format('{0}', v); }
760                     },
761                     {
762                         xtype: 'ColumnModel',
763                         xns: Roo.grid,
764                         dataIndex : 'phone',
765                         header : 'Phone',
766                         width : 100,
767                         renderer : function(v) { return String.format('{0}', v); }
768                     },
769                     {
770                         xtype: 'ColumnModel',
771                         xns: Roo.grid,
772                         dataIndex : 'fax',
773                         header : 'Fax',
774                         width : 100,
775                         renderer : function(v) { return String.format('{0}', v); }
776                     },
777                     {
778                         xtype: 'ColumnModel',
779                         xns: Roo.grid,
780                         dataIndex : 'email',
781                         header : 'Email',
782                         sortable : true,
783                         width : 200,
784                         renderer : function(v) {
785                            return (v.length && v.indexOf('@') > 0 ) ? 
786                                             String.format('<a href="mailto:{0}">{0}</a>',v) : v;
787                          }
788                     },
789                     {
790                         xtype: 'ColumnModel',
791                         xns: Roo.grid,
792                         dataIndex : 'active',
793                         header : 'Active',
794                         width : 75,
795                         renderer : function(v) {  
796                             var state = v> 0 ?  '-checked' : '';
797                         
798                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
799                                         
800                          }
801                     }
802                 ]
803             }
804         });
805         this.layout = this.panel.layout;
806
807     }
808 });