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