Pman.Dialog.CoreCompanies.bjs
[Pman.Core] / Pman.Dialog.CoreCompanies.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.Dialog.CoreCompanies = {
6
7     dialog : false,
8     callback:  false,
9
10     show : function(data, cb)
11     {
12         if (!this.dialog) {
13             this.create();
14         }
15
16         this.callback = cb;
17         this.data = data;
18         this.dialog.show(this.data._el);
19         if (this.form) {
20            this.form.reset();
21            this.form.setValues(data);
22            this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
23         }
24
25     },
26
27     create : function()
28     {
29         var _this = this;
30         this.dialog = Roo.factory({
31             xtype: 'LayoutDialog',
32             xns: Roo,
33             autoCreate : 'true',
34             closable : false,
35             collapsible : false,
36             draggable : false,
37             height : 400,
38             modal : true,
39             shadow : 'true',
40             title : "Edit Companies",
41             width : 750,
42             items : [
43                 {
44                     xtype: 'ContentPanel',
45                     xns: Roo,
46                     autoCreate : 'true',
47                     fitToFrame : true,
48                     region : 'center',
49                     items : [
50                         {
51                             xtype: 'Form',
52                             xns: Roo.form,
53                             listeners : {
54                                 actionfailed : function(f, act) {
55                                     _this.dialog.el.unmask();
56                                     // error msg???
57                                     Pman.standardActionFailed(f,act);
58                                               
59                                 },
60                                 actioncomplete : function(f, act) {
61                                     _this.dialog.el.unmask();
62                                     //console.log('load completed'); 
63                                     // error messages?????
64                                     if(act.type == 'setdata'){
65                                         if (act.data._fetch) {
66                                             _this.dialog.el.mask("Loading");
67                                             _this.form.doAction('load', {
68                                                 url: baseURL + '/Roo/Companies.html',
69                                                 method: 'GET',
70                                                 params: {
71                                                     _id: this._id ,
72                                                     _ts : Math.random()
73                                                 } 
74                                             });
75                                             return;
76                                         } else {
77                                             _this.form.setValues(data);
78                                         }
79                                         
80                                         if (act.data.isOwner || !Pman.Login.isOwner()) {
81                                             _this.dialog.setTitle("Your Company Details");
82                                             if (_this.form.findField('comptype')) {
83                                                 _this.form.findField('comptype').disable();
84                                             }
85                                         } else {
86                                             _this.dialog.setTitle(data.id ? "Edit Company" : "Add Company");
87                                             if (_this.form.findField('comptype')) {
88                                                 _this.form.findField('comptype').enable();
89                                             }
90                                         }
91                                     }
92                                    
93                                     if (act.type == 'load') {
94                                         _this.data = act.result.data;
95                                         var meth = _this.data.isOwner || !Pman.Login.isOwner() ? 'disable' : 'enable';
96                                      
97                                             
98                                         if (_this.form.findField('comptype')) {
99                                             _this.form.findField('comptype')[meth]();
100                                         }
101                                          
102                                        // _this.loaded();
103                                         return;
104                                     }
105                                     
106                                     
107                                     if (act.type == 'submit') { // only submitted here if we are 
108                                         _this.dialog.hide();
109                                        
110                                         if (_this.callback) {
111                                             _this.callback.call(this, act.result.data);
112                                         }
113                                         return; 
114                                     }
115                                     // unmask?? 
116                                 },
117                                 rendered : function (form)
118                                 {
119                                     _this.form = form;
120                                 }
121                             },
122                             fileUpload : true,
123                             labelWidth : 160,
124                             url : baseURL + '/Roo/Person.php',
125                             items : [
126                                 {
127                                     xtype: 'Column',
128                                     xns: Roo.form,
129                                     width : 500,
130                                     items : [
131                                         {
132                                             xtype: 'TextField',
133                                             xns: Roo.form,
134                                             allowBlank : false,
135                                             fieldLabel : 'Company ID (for filing Ref.)',
136                                             name : 'code',
137                                             qtip : "Enter code",
138                                             width : 100
139                                         },
140                                         {
141                                             xtype: 'ComboBox',
142                                             xns: Roo.form,
143                                             allowBlank : false,
144                                             displayField : 'desc',
145                                             editable : false,
146                                             emptyText : "Select Type",
147                                             fieldLabel : 'Type',
148                                             hiddenName : 'comptype',
149                                             listWidth : 250,
150                                             name : 'comptype_name',
151                                             qtip : "Select Company type",
152                                             selectOnFocus : true,
153                                             triggerAction : 'all',
154                                             typeAhead : false,
155                                             valueField : 'val',
156                                             width : 200,
157                                             store : {
158                                                 xtype: 'SimpleStore',
159                                                 xns: Roo.data,
160                                                 data : '[ \'CONSULTANT\', "Consultant" ],[ \'CLIENT\'    ,  "Client" ],[ \'CONTRACTOR\' , "Contractor" ]',
161                                                 fields : '[\'val\', \'desc\']'
162                                             }
163                                         },
164                                         {
165                                             xtype: 'TextField',
166                                             xns: Roo.form,
167                                             allowBlank : true,
168                                             fieldLabel : 'Company Name',
169                                             name : 'name',
170                                             qtip : "Enter Company Name",
171                                             width : 300
172                                         },
173                                         {
174                                             xtype: 'TextField',
175                                             xns: Roo.form,
176                                             allowBlank : true,
177                                             fieldLabel : 'Phone',
178                                             name : 'tel',
179                                             qtip : "Enter Phone Number",
180                                             width : 300
181                                         },
182                                         {
183                                             xtype: 'TextField',
184                                             xns: Roo.form,
185                                             allowBlank : true,
186                                             fieldLabel : 'Fax',
187                                             name : 'fax',
188                                             qtip : "Enter Fax Number",
189                                             width : 300
190                                         },
191                                         {
192                                             xtype: 'TextField',
193                                             xns: Roo.form,
194                                             allowBlank : true,
195                                             fieldLabel : 'Email',
196                                             name : 'email',
197                                             qtip : "Enter Email Address",
198                                             width : 300
199                                         },
200                                         {
201                                             xtype: 'TextField',
202                                             xns: Roo.form,
203                                             allowBlank : true,
204                                             fieldLabel : 'Address',
205                                             name : 'address',
206                                             qtip : "Enter Address",
207                                             width : 300
208                                         },
209                                         {
210                                             xtype: 'TextArea',
211                                             xns: Roo.form,
212                                             allowBlank : true,
213                                             fieldLabel : 'Remarks',
214                                             height : 40,
215                                             name : 'remarks',
216                                             qtip : "Enter remarks",
217                                             width : 300
218                                         }
219                                     ]
220                                 },
221                                 {
222                                     xtype: 'Column',
223                                     xns: Roo.form,
224                                     labelAlign : 'top',
225                                     width : 200,
226                                     items : [
227                                         {
228                                             xtype: 'TextField',
229                                             xns: Roo.form,
230                                             fieldLabel : 'Background Colour',
231                                             name : 'background_color'
232                                         },
233                                         {
234                                             xtype: 'DisplayField',
235                                             xns: Roo.form,
236                                             fieldLabel : 'Logo Image',
237                                             height : 170,
238                                             icon : 'rootURL + \'images/default/dd/drop-add.gif\'',
239                                             name : 'logo_id',
240                                             style : 'border: 1px solid #ccc;',
241                                             width : 170,
242                                             valueRenderer : function(v) {
243                                                 //var vp = v ? v : 'Companies:' + _this.data.id + ':-LOGO';
244                                                 if (!v) {
245                                                     return "No Image Available" + '<BR/>';
246                                                 }
247                                                 return String.format('<img src="{0}" width="150">', 
248                                                         baseURL + '/Images/Thumb/150x150/' + v + '/logo.jpg'
249                                                 );
250                                             }
251                                         },
252                                         {
253                                             xtype: 'Button',
254                                             xns: Roo,
255                                             listeners : {
256                                                 click : function (_self, e)
257                                                 {
258                                                     var _t = _this.form.findField('logo_id');
259                                                                          
260                                                     Pman.Dialog.Image.show({
261                                                         onid :_this.data.id,
262                                                         ontable : 'Companies',
263                                                         imgtype : 'LOGO'
264                                                     }, function(data) {
265                                                         if  (data) {
266                                                             _t.setValue(data.id);
267                                                         }
268                                                         
269                                                     });
270                                                 }
271                                             },
272                                             text : "Add Image"
273                                         }
274                                     ]
275                                 },
276                                 {
277                                     xtype: 'Hidden',
278                                     xns: Roo.form,
279                                     name : 'isOwner'
280                                 },
281                                 {
282                                     xtype: 'Hidden',
283                                     xns: Roo.form,
284                                     name : 'id'
285                                 }
286                             ]
287                         }
288                     ]
289                 }
290             ],
291             center : {
292                 xtype: 'LayoutRegion',
293                 xns: Roo,
294                 alwaysShowTabs : false,
295                 autoScroll : false,
296                 closeOnTab : true,
297                 hideTabs : true,
298                 titlebar : false
299             },
300             buttons : [
301                 {
302                     xtype: 'Button',
303                     xns: Roo,
304                     text : "Cancel"
305                 },
306                 {
307                     xtype: 'Button',
308                     xns: Roo,
309                     text : "Save"
310                 }
311             ]
312         });
313     }
314 };