Pman.Dialog.CoreCompanies.bjs
[Pman.Core] / Pman.Dialog.CoreCompanies.js
index 38ad060..b8bacc9 100644 (file)
@@ -30,6 +30,26 @@ Pman.Dialog.CoreCompanies = {
         this.dialog = Roo.factory({
             xtype: 'LayoutDialog',
             xns: Roo,
+            listeners : {
+                beforeshow : function (_self)
+                {
+                    if (data.isOwner || !Pman.Login.isOwner()) {
+                        this.dialog.setTitle("Your Company Details");
+                        if (_this.form.findField('comptype')) {
+                            _this.form.findField('comptype').disable();
+                        }
+                        
+                        
+                        
+                        
+                    } else {
+                        this.dialog.setTitle(data.id ? "Edit Company" : "Add Company");
+                        if (_this.form.findField('comptype')) {
+                            _this.form.findField('comptype').enable();
+                        }
+                    }
+                }
+            },
             autoCreate : 'true',
             closable : false,
             collapsible : false,
@@ -61,10 +81,36 @@ Pman.Dialog.CoreCompanies = {
                                     _this.dialog.el.unmask();
                                     //console.log('load completed'); 
                                     // error messages?????
-                                    
+                                    if(act.type == 'setdata'){
+                                        if (act.data._fetch) {
+                                            _this.dialog.el.mask("Loading");
+                                            _this.form.doAction('load', {
+                                                url: baseURL + '/Roo/Companies.html',
+                                                method: 'GET',
+                                                params: {
+                                                    _id: this._id ,
+                                                    _ts : Math.random()
+                                                } 
+                                            });
+                                            return;
+                                        } else {
+                                            _this.form.setValues(data);
+                                        }
+                                        
+                                        if (act.data.isOwner || !Pman.Login.isOwner()) {
+                                            _this.dialog.setTitle("Your Company Details");
+                                            if (_this.form.findField('comptype')) {
+                                                _this.form.findField('comptype').disable();
+                                            }
+                                        } else {
+                                            _this.dialog.setTitle(data.id ? "Edit Company" : "Add Company");
+                                            if (_this.form.findField('comptype')) {
+                                                _this.form.findField('comptype').enable();
+                                            }
+                                        }
+                                    }
                                    
                                     if (act.type == 'load') {
-                                        
                                         _this.data = act.result.data;
                                         var meth = _this.data.isOwner || !Pman.Login.isOwner() ? 'disable' : 'enable';
                                      
@@ -95,6 +141,7 @@ Pman.Dialog.CoreCompanies = {
                             },
                             fileUpload : true,
                             labelWidth : 160,
+                            url : baseURL + '/Roo/Person.php',
                             items : [
                                 {
                                     xtype: 'Column',
@@ -204,10 +251,57 @@ Pman.Dialog.CoreCompanies = {
                                             name : 'background_color'
                                         },
                                         {
-                                            xtype: 'FieldSet',
-                                            xns: Roo.form
+                                            xtype: 'DisplayField',
+                                            xns: Roo.form,
+                                            fieldLabel : 'Logo Image',
+                                            height : 170,
+                                            icon : 'rootURL + \'images/default/dd/drop-add.gif\'',
+                                            name : 'logo_id',
+                                            style : 'border: 1px solid #ccc;',
+                                            width : 170,
+                                            valueRenderer : function(v) {
+                                                //var vp = v ? v : 'Companies:' + _this.data.id + ':-LOGO';
+                                                if (!v) {
+                                                    return "No Image Available" + '<BR/>';
+                                                }
+                                                return String.format('<img src="{0}" width="150">', 
+                                                        baseURL + '/Images/Thumb/150x150/' + v + '/logo.jpg'
+                                                );
+                                            }
+                                        },
+                                        {
+                                            xtype: 'Button',
+                                            xns: Roo,
+                                            listeners : {
+                                                click : function (_self, e)
+                                                {
+                                                    var _t = _this.form.findField('logo_id');
+                                                                         
+                                                    Pman.Dialog.Image.show({
+                                                        onid :_this.data.id,
+                                                        ontable : 'Companies',
+                                                        imgtype : 'LOGO'
+                                                    }, function(data) {
+                                                        if  (data) {
+                                                            _t.setValue(data.id);
+                                                        }
+                                                        
+                                                    });
+                                                }
+                                            },
+                                            text : "Add Image"
                                         }
                                     ]
+                                },
+                                {
+                                    xtype: 'Hidden',
+                                    xns: Roo.form,
+                                    name : 'isOwner'
+                                },
+                                {
+                                    xtype: 'Hidden',
+                                    xns: Roo.form,
+                                    name : 'id'
                                 }
                             ]
                         }