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                                         
115                                         
116                                         _this.data = act.result.data;
117                                         var meth = _this.data.isOwner || !Pman.Login.isOwner() ? 'disable' : 'enable';
118                                      
119                                             
120                                         if (_this.form.findField('comptype')) {
121                                             _this.form.findField('comptype')[meth]();
122                                         }
123                                          
124                                        // _this.loaded();
125                                         return;
126                                     }
127                                     
128                                     
129                                     if (act.type == 'submit') { // only submitted here if we are 
130                                         _this.dialog.hide();
131                                        
132                                         if (_this.callback) {
133                                             _this.callback.call(this, act.result.data);
134                                         }
135                                         return; 
136                                     }
137                                     // unmask?? 
138                                 },
139                                 rendered : function (form)
140                                 {
141                                     _this.form = form;
142                                 }
143                             },
144                             fileUpload : true,
145                             labelWidth : 160,
146                             items : [
147                                 {
148                                     xtype: 'Column',
149                                     xns: Roo.form,
150                                     width : 500,
151                                     items : [
152                                         {
153                                             xtype: 'TextField',
154                                             xns: Roo.form,
155                                             allowBlank : false,
156                                             fieldLabel : 'Company ID (for filing Ref.)',
157                                             name : 'code',
158                                             qtip : "Enter code",
159                                             width : 100
160                                         },
161                                         {
162                                             xtype: 'ComboBox',
163                                             xns: Roo.form,
164                                             allowBlank : false,
165                                             displayField : 'desc',
166                                             editable : false,
167                                             emptyText : "Select Type",
168                                             fieldLabel : 'Type',
169                                             hiddenName : 'comptype',
170                                             listWidth : 250,
171                                             name : 'comptype_name',
172                                             qtip : "Select Company type",
173                                             selectOnFocus : true,
174                                             triggerAction : 'all',
175                                             typeAhead : false,
176                                             valueField : 'val',
177                                             width : 200,
178                                             store : {
179                                                 xtype: 'SimpleStore',
180                                                 xns: Roo.data,
181                                                 data : '[ \'CONSULTANT\', "Consultant" ],[ \'CLIENT\'    ,  "Client" ],[ \'CONTRACTOR\' , "Contractor" ]',
182                                                 fields : '[\'val\', \'desc\']'
183                                             }
184                                         },
185                                         {
186                                             xtype: 'TextField',
187                                             xns: Roo.form,
188                                             allowBlank : true,
189                                             fieldLabel : 'Company Name',
190                                             name : 'name',
191                                             qtip : "Enter Company Name",
192                                             width : 300
193                                         },
194                                         {
195                                             xtype: 'TextField',
196                                             xns: Roo.form,
197                                             allowBlank : true,
198                                             fieldLabel : 'Phone',
199                                             name : 'tel',
200                                             qtip : "Enter Phone Number",
201                                             width : 300
202                                         },
203                                         {
204                                             xtype: 'TextField',
205                                             xns: Roo.form,
206                                             allowBlank : true,
207                                             fieldLabel : 'Fax',
208                                             name : 'fax',
209                                             qtip : "Enter Fax Number",
210                                             width : 300
211                                         },
212                                         {
213                                             xtype: 'TextField',
214                                             xns: Roo.form,
215                                             allowBlank : true,
216                                             fieldLabel : 'Email',
217                                             name : 'email',
218                                             qtip : "Enter Email Address",
219                                             width : 300
220                                         },
221                                         {
222                                             xtype: 'TextField',
223                                             xns: Roo.form,
224                                             allowBlank : true,
225                                             fieldLabel : 'Address',
226                                             name : 'address',
227                                             qtip : "Enter Address",
228                                             width : 300
229                                         },
230                                         {
231                                             xtype: 'TextArea',
232                                             xns: Roo.form,
233                                             allowBlank : true,
234                                             fieldLabel : 'Remarks',
235                                             height : 40,
236                                             name : 'remarks',
237                                             qtip : "Enter remarks",
238                                             width : 300
239                                         }
240                                     ]
241                                 },
242                                 {
243                                     xtype: 'Column',
244                                     xns: Roo.form,
245                                     labelAlign : 'top',
246                                     width : 200,
247                                     items : [
248                                         {
249                                             xtype: 'TextField',
250                                             xns: Roo.form,
251                                             fieldLabel : 'Background Colour',
252                                             name : 'background_color'
253                                         },
254                                         {
255                                             xtype: 'DisplayField',
256                                             xns: Roo.form,
257                                             fieldLabel : 'Logo Image',
258                                             height : 170,
259                                             icon : 'rootURL + \'images/default/dd/drop-add.gif\'',
260                                             name : 'logo_id',
261                                             style : 'border: 1px solid #ccc;',
262                                             width : 170,
263                                             valueRenderer : function(v) {
264                                                 //var vp = v ? v : 'Companies:' + _this.data.id + ':-LOGO';
265                                                 if (!v) {
266                                                     return "No Image Available" + '<BR/>';
267                                                 }
268                                                 return String.format('<img src="{0}" width="150">', 
269                                                         baseURL + '/Images/Thumb/150x150/' + v + '/logo.jpg'
270                                                 );
271                                             }
272                                         },
273                                         {
274                                             xtype: 'Button',
275                                             xns: Roo,
276                                             listeners : {
277                                                 click : function (_self, e)
278                                                 {
279                                                     var _t = _this.form.findField('logo_id');
280                                                                          
281                                                     Pman.Dialog.Image.show({
282                                                         onid :_this.data.id,
283                                                         ontable : 'Companies',
284                                                         imgtype : 'LOGO'
285                                                     }, function(data) {
286                                                         if  (data) {
287                                                             _t.setValue(data.id);
288                                                         }
289                                                         
290                                                     });
291                                                 }
292                                             },
293                                             text : "Add Image"
294                                         }
295                                     ]
296                                 },
297                                 {
298                                     xtype: 'Hidden',
299                                     xns: Roo.form,
300                                     name : 'isOwner'
301                                 },
302                                 {
303                                     xtype: 'Hidden',
304                                     xns: Roo.form,
305                                     name : 'id'
306                                 }
307                             ]
308                         }
309                     ]
310                 }
311             ],
312             center : {
313                 xtype: 'LayoutRegion',
314                 xns: Roo,
315                 alwaysShowTabs : false,
316                 autoScroll : false,
317                 closeOnTab : true,
318                 hideTabs : true,
319                 titlebar : false
320             },
321             buttons : [
322                 {
323                     xtype: 'Button',
324                     xns: Roo,
325                     text : "Cancel"
326                 },
327                 {
328                     xtype: 'Button',
329                     xns: Roo,
330                     text : "Save"
331                 }
332             ]
333         });
334     }
335 };