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