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                                 select : function (combo, record, index)
539                                 {
540                                    _this.grid.footer.onClick.defer(300,_this.grid.footer,[ 'first'] );
541                                 }
542                             },
543                             displayField : 'name',
544                             editable : true,
545                             emptyText : "Select Company",
546                             forceSelection : true,
547                             hiddenName : 'company_id',
548                             listWidth : 400,
549                             loadingText : "Searching...",
550                             minChars : 2,
551                             name : 'company_name',
552                             pageSize : 20,
553                             qtip : "Select Companies",
554                             queryParam : 'query[name]',
555                             selectOnFocus : true,
556                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>',
557                             triggerAction : 'all',
558                             typeAhead : true,
559                             valueField : 'id',
560                             width : 150,
561                             store : {
562                                 xtype: 'Store',
563                                 xns: Roo.data,
564                                 listeners : {
565                                     beforeload : function (_self, o){
566                                         o.params = o.params || {};
567                                         // set more here
568                                     }
569                                 },
570                                 remoteSort : true,
571                                 sortInfo : { direction : 'ASC', field: 'name' },
572                                 proxy : {
573                                     xtype: 'HttpProxy',
574                                     xns: Roo.data,
575                                     method : 'GET',
576                                     url : baseURL + '/Roo/Companies.php'
577                                 },
578                                 reader : {
579                                     xtype: 'JsonReader',
580                                     xns: Roo.data,
581                                     id : 'id',
582                                     root : 'data',
583                                     totalProperty : 'total',
584                                     fields : [{"name":"id","type":"int"},{"name":"code","type":"string"}]
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: 'Button',
615                             xns: Roo.Toolbar,
616                             listeners : {
617                                 toggle : function (_self, pressed)
618                                 {
619                                    _this.grid.footer.onClick('first');
620                                    this.setText(pressed ? "Show Active" : "Show Removed");
621                                    
622                                    
623                                 },
624                                 render : function (_self)
625                                 {
626                                   _this.activeButton = _self;
627                                 }
628                             },
629                             enableToggle : true,
630                             text : "Show Removed"
631                         },
632                         {
633                             xtype: 'Fill',
634                             xns: Roo.Toolbar
635                         },
636                         {
637                             xtype: 'Button',
638                             xns: Roo.Toolbar,
639                             listeners : {
640                                 click : function()
641                                 {
642                                     
643                                     _this.dialog.show( { id : 0 } , function() {
644                                         _this.grid.footer.onClick('first');
645                                    }); 
646                                 }
647                             },
648                             cls : 'x-btn-text-icon',
649                             text : "Add",
650                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
651                         },
652                         {
653                             xtype: 'Button',
654                             xns: Roo.Toolbar,
655                             listeners : {
656                                 click : function()
657                                 {
658                                     
659                                     Pman.Dialog.PersonBulkAdd.show( { id : 0 } , function() {
660                                         _this.grid.footer.onClick('first');
661                                    }); 
662                                 }
663                             },
664                             cls : 'x-btn-text-icon',
665                             text : "Bulk Add",
666                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
667                         },
668                         {
669                             xtype: 'Button',
670                             xns: Roo.Toolbar,
671                             listeners : {
672                                 click : function()
673                                 {
674                                     var s = _this.grid.getSelectionModel().getSelections();
675                                     if (!s.length || (s.length > 1))  {
676                                         Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
677                                         return;
678                                     }
679                                   
680                                     _this.dialog.show(s[0].data, function() {
681                                         _this.grid.footer.onClick('first');
682                                     }); 
683                                     
684                                 }
685                             },
686                             cls : 'x-btn-text-icon',
687                             text : "Edit",
688                             icon : Roo.rootURL + 'images/default/tree/leaf.gif'
689                         },
690                         {
691                             xtype: 'Button',
692                             xns: Roo.Toolbar,
693                             listeners : {
694                                 click : function()
695                                 {
696                                      Pman.genericDelete(_this, 'Person'); 
697                                 }
698                             },
699                             cls : 'x-btn-text-icon',
700                             text : "Delete",
701                             icon : rootURL + '/Pman/templates/images/trash.gif'
702                         }
703                     ]
704                 },
705                 colModel : [
706                     {
707                         xtype: 'ColumnModel',
708                         xns: Roo.grid,
709                         dataIndex : 'project_id_code',
710                         header : 'Project',
711                         hidden : true,
712                         sortable : true,
713                         width : 75,
714                         renderer : function(v,x,r) { 
715                               return String.format('<span qtip="{0}">{1}</span>', 
716                                             r.data.project_id_name,
717                                             v);
718                          }
719                     },
720                     {
721                         xtype: 'ColumnModel',
722                         xns: Roo.grid,
723                         dataIndex : 'company_id_comptype',
724                         header : 'Type',
725                         sortable : true,
726                         width : 50,
727                         renderer : function(v,x,r) {
728                             if (r.data.office_id) {
729                                 return String.format('{0} - {1}', v, r.data.office_id_name); 
730                             } 
731                             return String.format('{0}', v); 
732                         }
733                     },
734                     {
735                         xtype: 'ColumnModel',
736                         xns: Roo.grid,
737                         dataIndex : 'company_id_name',
738                         header : 'Company',
739                         sortable : true,
740                         width : 150,
741                         renderer : function(v,x,r) {
742                             if (r.data.office_id) {
743                                 return String.format('{0} - {1}', v, r.data.office_id_name); 
744                             } 
745                             return String.format('{0}', v); 
746                         }
747                     },
748                     {
749                         xtype: 'ColumnModel',
750                         xns: Roo.grid,
751                         dataIndex : 'name',
752                         header : 'Name',
753                         sortable : true,
754                         width : 200,
755                         renderer : function(v) { return String.format('{0}', v); }
756                     },
757                     {
758                         xtype: 'ColumnModel',
759                         xns: Roo.grid,
760                         dataIndex : 'role',
761                         header : 'Role',
762                         width : 100,
763                         renderer : function(v) { return String.format('{0}', v); }
764                     },
765                     {
766                         xtype: 'ColumnModel',
767                         xns: Roo.grid,
768                         dataIndex : 'phone',
769                         header : 'Phone',
770                         width : 100,
771                         renderer : function(v) { return String.format('{0}', v); }
772                     },
773                     {
774                         xtype: 'ColumnModel',
775                         xns: Roo.grid,
776                         dataIndex : 'fax',
777                         header : 'Fax',
778                         width : 100,
779                         renderer : function(v) { return String.format('{0}', v); }
780                     },
781                     {
782                         xtype: 'ColumnModel',
783                         xns: Roo.grid,
784                         dataIndex : 'email',
785                         header : 'Email',
786                         sortable : true,
787                         width : 200,
788                         renderer : function(v) {
789                            return (v.length && v.indexOf('@') > 0 ) ? 
790                                             String.format('<a href="mailto:{0}">{0}</a>',v) : v;
791                          }
792                     },
793                     {
794                         xtype: 'ColumnModel',
795                         xns: Roo.grid,
796                         dataIndex : 'active',
797                         header : 'Active',
798                         width : 75,
799                         renderer : function(v) {  
800                             var state = v> 0 ?  '-checked' : '';
801                         
802                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
803                                         
804                          }
805                     }
806                 ]
807             }
808         });
809         this.layout = this.panel.layout;
810
811     }
812 });