Merge branch 'master' of http://git.roojs.com:8081/Pman.Core
[Pman.Core] / Pman.Dialog.Companies.js
1
2
3 Pman.Dialog.Companies =   new Roo.util.Observable({
4     
5     show : function (data, callback)
6     {
7         Pman.Dialog.CoreCompanies.show({id:data.id});
8     }
9
10 });
11
12
13
14 //<script type="text/javascript">
15 /*
16
17
18 Pman.Dialog.Companies =   new Roo.util.Observable({
19     events : {
20         'beforerender' : true, // trigger so we can add modules later..
21         'show' : true, // trigger on showing form.. - to load additiona data..
22         'beforesave' : true
23     },
24      
25     dialog : false,
26     form : false,
27     callback: false,
28     create: function()
29     {
30         if (this.dialog) {
31             return;
32         }
33         
34         this.dialog = new Ext.LayoutDialog(Ext.get(document.body).createChild({tag:'div'}),  { 
35             autoCreated: true,
36             title: "Edit Companies",
37             modal: true,
38             width:  750,
39             height: 400,
40             shadow:true,
41             minWidth:200,
42             minHeight:180,
43             //proxyDrag: true,
44             collapsible : false,
45             closable: false,
46             draggable: false,
47             center: {
48                 autoScroll:false,
49                 titlebar: false,
50                // tabPosition: 'top',
51                 hideTabs: true,
52                 closeOnTab: true,
53                 alwaysShowTabs: false
54             }
55         });
56         this.dialog.addKeyListener(27, this.dialog.hide, this.dialog);
57         this.dialog.addButton("Cancel", this.dialog.hide, this.dialog);
58        
59         this.dialog.addButton("Save", this.save, this);
60         this.layout = this.dialog.getLayout();
61         this.layout.beginUpdate();
62         
63         var _this = this;
64         
65         this.form = new Ext.form.Form({
66             labelWidth: 150 ,
67               
68             fileUpload : true,
69             listeners : {
70                 actionfailed : function(f, act) {
71                     _this.dialog.el.unmask();
72                     // error msg???
73                     Pman.standardActionFailed(f,act);
74                               
75                 },
76                 actioncomplete: function(f, act) {
77                     _this.dialog.el.unmask();
78                     //console.log('load completed'); 
79                     // error messages?????
80                     
81                    
82                     if (act.type == 'load') {
83                         
84                         _this.data = act.result.data;
85                         var meth = _this.data.isOwner || !Pman.Login.isOwner() ? 'disable' : 'enable';
86                      
87                             
88                         if (_this.form.findField('comptype')) {
89                             _this.form.findField('comptype')[meth]();
90                         }
91                          
92                        // _this.loaded();
93                         return;
94                     }
95                     
96                     
97                     if (act.type == 'submit') { // only submitted here if we are 
98                         _this.dialog.hide();
99                        
100                         if (_this.callback) {
101                             _this.callback.call(this, act.result.data);
102                         }
103                         return; 
104                     }
105                     // unmask?? 
106                 }
107             }
108         
109             
110             
111              
112         });
113         //?? will this work...
114         
115         this.form.addxtype.apply(this.form, this.getFormFields());
116          this.fireEvent('beforeRender', this );
117         
118         var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
119         ef.dom.style.margin = 10;
120          
121         this.form.render(ef.dom);
122
123         var vp = this.dialog.getLayout().add('center', new Ext.ContentPanel(ef, {
124             autoCreate : true,
125             //title: 'Org Details',
126             //toolbar: this.tb,
127             width: 250,
128             maxWidth: 250,
129             fitToFrame:true
130         }));
131           
132         
133         
134         
135         this.layout.endUpdate();
136     },
137     show : function (data, callback)
138     {
139         this.callback = callback;
140         this._id = data.id ? data.id : 0;  // modify if you do not use ID !!!!
141         this.create();
142         this.data = data;
143         this.form.reset();
144         if (data._fetch) {
145             this.dialog.show();
146             this.dialog.el.mask("Loading");
147             this.form.doAction('load', {
148                 url: baseURL + '/Roo/Companies.html',
149                 method: 'GET',
150                 params: {
151                     _id: this._id ,
152                     _ts : Math.random()
153                 } 
154             });
155             this.fireEvent('show');
156             return;
157         } else {
158             this.form.setValues(data);
159         }
160         
161         
162         
163         this.dialog.show();
164         
165         if (data.isOwner || !Pman.Login.isOwner()) {
166             this.dialog.setTitle("Your Company Details");
167             if (this.form.findField('comptype')) {
168                 this.form.findField('comptype').disable();
169             }
170             
171             
172             
173             
174         } else {
175             this.dialog.setTitle(data.id ? "Edit Company" : "Add Company");
176             if (this.form.findField('comptype')) {
177                 this.form.findField('comptype').enable();
178             }
179         }
180         this.fireEvent('show');
181
182     },
183     
184     
185     save : function()
186     {
187         this.form.fileUpload = this.form.findField('imageUpload') ? true : false;
188         this.fireEvent('beforesave'); 
189         this.form.doAction('submit', {
190             url: baseURL + '/Roo/Companies.html',
191             method: 'POST',
192             params: {
193                 _id: this._id ,
194                 ts : Math.random()
195             } 
196         });
197     },
198     
199     comptypeList : function()
200     {
201         // should probably be system configurable..
202         return [
203             
204             [ 'CONSULTANT', "Consultant" ],
205             [ 'CLIENT'    ,  "Client" ],
206             [ 'CONTRACTOR' , "Contractor" ]
207           //  [ 'OWNER', "System Owner" ]
208          ];
209     },
210     comptypeListToString: function(v) {
211         if (!v.length) {
212             return '';
213         }
214         if (v== "OWNER") {
215             return "System Owner";
216         }
217         var a = this.comptypeList();
218         var ret = '';
219         Roo.each(a, function( ar) {
220             if (ar[0] == v) {
221                 ret = ar[1];
222                 return false;
223             }
224         });
225         return ret;
226         
227         
228         
229     },
230     
231     getFormFields : function() {
232         return [
233             {   
234                 xtype : 'Column',
235                 width: 500,
236                 items: [
237                     this.c_code(),
238                     this.c_comptype_name(),
239                     this.c_name(),
240                     this.c_tel(),
241                     this.c_fax(),
242                     this.c_email(),
243                     
244                     
245                     this.c_address(),
246                     this.c_remarks()
247                 ]
248             },
249             {   
250                 xtype : 'Column',
251                 width: 200,
252                 labelAlign: 'top',
253                 items : [
254                     this.c_background_color(),
255                     this.c_image_edit()
256                     //this.c_image_view(),
257                     //this.c_image_change(),
258                 ]
259             },
260             this.c_isOwner(),
261             this.c_id()
262         ];
263     },
264     
265     
266     c_code : function() {
267         return {
268                 name : 'code',
269                 fieldLabel : "Company ID (for filing Ref.)",
270                 value : '',
271                 allowBlank : false,
272                 qtip : "Enter code",
273                 xtype : 'TextField',
274                 width : 100
275             }
276     },
277     c_comptype_name : function() {
278         return {
279                         
280                                 fieldLabel : 'Type',
281                                 disabled : Pman.Login.isOwner() ? false : true,
282                 name : 'comptype_name',
283                 xtype : 'ComboBox',
284                 allowBlank : false,
285                                 qtip : 'Select Company type',
286                 
287                 width: 200,
288                 xns : Roo.form,
289                 
290                 listWidth : 250,
291                 
292                
293                 store: {
294                     xtype : 'SimpleStore',
295                     fields: ['val', 'desc'],
296                     data : this.comptypeList()
297                 },
298                 displayField:'desc',
299                 valueField: 'val',
300                 hiddenName : 'comptype',
301                 
302                 typeAhead: false,
303                 editable: false,
304                 //mode: 'local',
305                 triggerAction: 'all',
306                 emptyText: "Select Type",
307                 selectOnFocus: true
308                 
309                 
310            }
311     },
312     c_name : function() {
313         return {
314     
315                 name : 'name',
316                 fieldLabel : "Company Name",
317                 value : '',
318                 allowBlank : true,
319                 qtip : "Enter Company Name",
320                 xtype : 'TextField',
321                 width : 300
322                     }
323     },
324     c_tel : function() {
325         return {
326     
327                 name : 'tel',
328                 fieldLabel : "Phone",
329                 value : '',
330                 allowBlank : true,
331                 qtip : "Enter Phone Number",
332                 xtype : 'TextField',
333                 width : 300
334                     }
335     },
336     c_fax : function() {
337         return {
338     
339                 name : 'fax',
340                 fieldLabel : "fax",
341                 value : '',
342                 allowBlank : true,
343                 qtip : "Enter fax Number",
344                 xtype : 'TextField',
345                 width : 300
346                     }
347     },
348     c_email : function() {
349         return {
350     
351                 name : 'email',
352                 fieldLabel : "Email",
353                 value : '',
354                 allowBlank : true,
355                 qtip : "Enter Email Address",
356                 xtype : 'TextField',
357                 width : 300
358                     }
359     },
360     c_address : function() {
361         return {
362     
363                 name : 'address',
364                 fieldLabel : "Address",
365                 value : '',
366                 allowBlank : true,
367                 qtip : "Enter Address",
368                 xtype : 'TextArea',
369                 height : 70,
370                 width : 300
371         }
372     },
373     c_remarks : function() {
374         return {
375     
376                 name : 'remarks',
377                 fieldLabel : "Remarks",
378                 value : '',
379                 allowBlank : true,
380                 qtip : "Enter remarks",
381                 xtype : 'TextArea',
382                 height : 40,
383                 width : 300
384         }
385     },
386     c_background_color : function() {
387         return {
388                     xtype: 'ColorField',
389                 name : 'background_color',
390                 fieldLabel: "Background Colour"
391         }
392     },
393     c_image_view : function() {
394         var _this = this;
395         return {
396                 xtype :  'FieldSetEx',
397                 name : 'image-view',
398                 collapseGroup : 'companies-image',
399                 value: 0,
400                 labelWidth: 100,
401                 expanded: true,
402                 style: 'width:420px;',
403                 legend : "Logo Image",
404                 items: [
405                     {
406                         xtype :  'DisplayImage', // image preview...
407                         name : 'logo_id',
408                         fieldLabel : 'Logo Image',
409                         width: 300,
410                         height: 50,
411                         renderer : function(v) {
412                             return v ?  String.format('<img src="{0}" height="{1}">', 
413                                 baseURL + '/Images/' + v + '/' + _this.data.logo_id_filename, 
414                                 Math.min(this.height, _this.data.logo_id_height)) : "No Image Attached";
415                             
416                         }
417                     }
418                 ]
419                 
420         }
421     },
422     c_image_edit : function() {
423         var _this = this;
424         return {
425                     name : 'logo_id',
426                     fieldLabel : "Logo Image",
427                     value : '',
428                     allowBlank : true,
429                     style: 'border: 1px solid #ccc;',
430                     xtype : 'DisplayImage',
431                     width : 170,
432                     height: 170,
433                     addTitle : "Change / Add Image",
434                     icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
435                     handler : function() {
436                         var _t = this;
437                          
438                         Pman.Dialog.Image.show({
439                             onid :_this.data.id,
440                             ontable : 'Companies',
441                             imgtype : 'LOGO'
442                         }, function(data) {
443                             if  (data) {
444                                 _t.setValue(data.id);
445                             }
446                             
447                         });
448                     }, 
449                     renderer : function(v) {
450                         //var vp = v ? v : 'Companies:' + _this.data.id + ':-LOGO';
451                         if (!v) {
452                             return "No Image Available" + '<BR/>';
453                         }
454                         return String.format('<img src="{0}" width="150">', 
455                                 baseURL + '/Images/Thumb/150x150/' + v + '/logo.jpg'
456                         );
457                     }
458             
459             }  ;
460         
461     },
462     c_image_change: function() {
463         return { 
464                 xtype :  'FieldSetEx',
465                 collapseGroup : 'companies-image',
466                 name : 'image-change',
467                 value: 0,
468                 labelWidth: 100,
469                 expanded: false,
470                 style: 'width:420px;',
471                 legend : "Add / Change Image",
472                 items : [ 
473                     {   
474                         xtype :  'TextField',
475                         name : 'imageUpload',
476                         fieldLabel : "Upload Image",
477                         inputType : 'file'
478                     }
479                 ]
480         }
481     },
482     c_isOwner : function() {
483         return {                 
484                 name : 'isOwner',
485                 value : '',
486                 xtype : 'Hidden'
487             }
488     },
489     c_id : function() {
490         return { 
491                 name : 'id',
492                 value : '',
493                 xtype : 'Hidden'
494             }
495     }
496          
497 });
498 */