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