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