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