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