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