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