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