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