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