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