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