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