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