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/Companies.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: 'ComboBox',
142                                             xns: Roo.form,
143                                             listeners : {
144                                                 render : function (_self)
145                                                 {
146                                                     _this.etypeCombo = _self;
147                                                 },
148                                                 select : function (combo, record, index)
149                                                 {
150                                                     _this.grid.footer.onClick('first');
151                                                 }
152                                             },
153                                             alwaysQuery : true,
154                                             displayField : 'name',
155                                             editable : 'false',
156                                             emptyText : "Select Type",
157                                             fieldLabel : 'Type',
158                                             forceSelection : true,
159                                             hiddenName : 'comptype',
160                                             listWidth : 250,
161                                             loadingText : "Searching...",
162                                             minChars : 2,
163                                             name : 'comptype_name',
164                                             pageSize : 20,
165                                             qtip : "Select type",
166                                             queryParam : 'query[name]',
167                                             selectOnFocus : true,
168                                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>',
169                                             triggerAction : 'all',
170                                             typeAhead : false,
171                                             valueField : 'val',
172                                             width : 200,
173                                             store : {
174                                                 xtype: 'Store',
175                                                 xns: Roo.data,
176                                                 listeners : {
177                                                     beforeload : function (_self, o){
178                                                         o.params = o.params || {};
179                                                         // set more here
180                                                         o.params['query[empty_etype]'] = 1;
181                                                     }
182                                                 },
183                                                 remoteSort : true,
184                                                 sortInfo : { direction : 'ASC', field: 'id' },
185                                                 proxy : {
186                                                     xtype: 'HttpProxy',
187                                                     xns: Roo.data,
188                                                     method : 'GET',
189                                                     url : baseURL + '/Roo/core_enum.php'
190                                                 },
191                                                 reader : {
192                                                     xtype: 'JsonReader',
193                                                     xns: Roo.data,
194                                                     id : 'id',
195                                                     root : 'data',
196                                                     totalProperty : 'total',
197                                                     fields : [{"name":"id","type":"int"},{"name":"etype","type":"string"}]
198                                                 }
199                                             }
200                                         },
201                                         {
202                                             xtype: 'TextField',
203                                             xns: Roo.form,
204                                             allowBlank : true,
205                                             fieldLabel : 'Company Name',
206                                             name : 'name',
207                                             qtip : "Enter Company Name",
208                                             width : 300
209                                         },
210                                         {
211                                             xtype: 'TextField',
212                                             xns: Roo.form,
213                                             allowBlank : true,
214                                             fieldLabel : 'Phone',
215                                             name : 'tel',
216                                             qtip : "Enter Phone Number",
217                                             width : 300
218                                         },
219                                         {
220                                             xtype: 'TextField',
221                                             xns: Roo.form,
222                                             allowBlank : true,
223                                             fieldLabel : 'Fax',
224                                             name : 'fax',
225                                             qtip : "Enter Fax Number",
226                                             width : 300
227                                         },
228                                         {
229                                             xtype: 'TextField',
230                                             xns: Roo.form,
231                                             allowBlank : true,
232                                             fieldLabel : 'Email',
233                                             name : 'email',
234                                             qtip : "Enter Email Address",
235                                             width : 300
236                                         },
237                                         {
238                                             xtype: 'TextField',
239                                             xns: Roo.form,
240                                             allowBlank : true,
241                                             fieldLabel : 'Address',
242                                             name : 'address',
243                                             qtip : "Enter Address",
244                                             width : 300
245                                         },
246                                         {
247                                             xtype: 'TextArea',
248                                             xns: Roo.form,
249                                             allowBlank : true,
250                                             fieldLabel : 'Remarks',
251                                             height : 40,
252                                             name : 'remarks',
253                                             qtip : "Enter remarks",
254                                             width : 300
255                                         }
256                                     ]
257                                 },
258                                 {
259                                     xtype: 'Column',
260                                     xns: Roo.form,
261                                     labelAlign : 'top',
262                                     width : 200,
263                                     items : [
264                                         {
265                                             xtype: 'TextField',
266                                             xns: Roo.form,
267                                             fieldLabel : 'Background Colour',
268                                             name : 'background_color'
269                                         },
270                                         {
271                                             xtype: 'DisplayField',
272                                             xns: Roo.form,
273                                             fieldLabel : 'Logo Image',
274                                             height : 170,
275                                             icon : 'rootURL + \'images/default/dd/drop-add.gif\'',
276                                             name : 'logo_id',
277                                             style : 'border: 1px solid #ccc;',
278                                             width : 170,
279                                             valueRenderer : function(v) {
280                                                 //var vp = v ? v : 'Companies:' + _this.data.id + ':-LOGO';
281                                                 if (!v) {
282                                                     return "No Image Available" + '<BR/>';
283                                                 }
284                                                 return String.format('<img src="{0}" width="150">', 
285                                                         baseURL + '/Images/Thumb/150x150/' + v + '/logo.jpg'
286                                                 );
287                                             }
288                                         },
289                                         {
290                                             xtype: 'Button',
291                                             xns: Roo,
292                                             listeners : {
293                                                 click : function (_self, e)
294                                                 {
295                                                     var _t = _this.form.findField('logo_id');
296                                                                          
297                                                     Pman.Dialog.Image.show({
298                                                         onid :_this.data.id,
299                                                         ontable : 'Companies',
300                                                         imgtype : 'LOGO'
301                                                     }, function(data) {
302                                                         if  (data) {
303                                                             _t.setValue(data.id);
304                                                         }
305                                                         
306                                                     });
307                                                 }
308                                             },
309                                             text : "Add Image"
310                                         }
311                                     ]
312                                 },
313                                 {
314                                     xtype: 'Hidden',
315                                     xns: Roo.form,
316                                     name : 'isOwner'
317                                 },
318                                 {
319                                     xtype: 'Hidden',
320                                     xns: Roo.form,
321                                     name : 'id'
322                                 }
323                             ]
324                         }
325                     ]
326                 }
327             ],
328             center : {
329                 xtype: 'LayoutRegion',
330                 xns: Roo,
331                 alwaysShowTabs : false,
332                 autoScroll : false,
333                 closeOnTab : true,
334                 hideTabs : true,
335                 titlebar : false
336             },
337             buttons : [
338                 {
339                     xtype: 'Button',
340                     xns: Roo,
341                     listeners : {
342                         click : function (_self, e)
343                         {
344                             _this.dialog.hide();
345                         }
346                     },
347                     text : "Cancel"
348                 },
349                 {
350                     xtype: 'Button',
351                     xns: Roo,
352                     listeners : {
353                         click : function (_self, e)
354                         {
355                             // do some checks?
356                              
357                             
358                             _this.dialog.el.mask("Saving");
359                             _this.form.doAction("submit");
360                         
361                         }
362                     },
363                     text : "Save"
364                 }
365             ]
366         });
367     }
368 };