Pman.Dialog.CoreCompanies.bjs.2MU1LX
[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             center : {
32                 alwaysShowTabs : false,
33                 autoScroll : false,
34                 xtype : 'LayoutRegion',
35                 hideTabs : true,
36                 xns : Roo,
37                 closeOnTab : true,
38                 titlebar : false
39             },
40             modal : true,
41             shadow : true,
42             collapsible : false,
43             title : "Add / Edit Organization",
44             xtype : 'LayoutDialog',
45             autoCreate : true,
46             width : 750,
47             xns : Roo,
48             closable : false,
49             height : 400,
50             draggable : false,
51             buttons : [
52                  {
53                         text : "Cancel",
54                         xtype : 'Button',
55                         xns : Roo,
56                         listeners : {
57                                 click : function (_self, e)
58                                    {
59                                        _this.dialog.hide();
60                                    }
61                         }
62                     },
63 {
64                         text : "Save",
65                         xtype : 'Button',
66                         xns : Roo,
67                         listeners : {
68                                 click : function (_self, e)
69                                    {
70                                        // do some checks?
71                                         
72                                        
73                                        _this.dialog.el.mask("Saving");
74                                        _this.form.doAction("submit");
75                                    
76                                    }
77                         }
78                     }
79             ],
80             items : [
81                 {
82                     region : 'center',
83                     fitToFrame : true,
84                     xtype : 'ContentPanel',
85                     autoCreate : true,
86                     xns : Roo,
87                     items : [
88                         {
89                             url : baseURL + '/Roo/Companies.php',
90                             fileUpload : true,
91                             xtype : 'Form',
92                             labelWidth : 160,
93                             xns : Roo.form,
94                             listeners : {
95                                 actionfailed : function(f, act) {
96                                        _this.dialog.el.unmask();
97                                        // error msg???
98                                        Pman.standardActionFailed(f,act);
99                                                  
100                                    },
101                                 rendered : function (form)
102                                    {
103                                        _this.form = form;
104                                    },
105                                 actioncomplete : function(f, act) {
106                                        _this.dialog.el.unmask();
107                                        //console.log('load completed'); 
108                                        // error messages?????
109                                        if(act.type == 'setdata'){
110                                            this.load({ method: 'GET', params: { '_id' : _this.data.id }});
111                                            return;
112                                        }
113                                       
114                                        if (act.type == 'load') {
115                                            _this.data = act.result.data;
116                                            var meth = _this.data.comptype == 'OWNER' ? 'disable' : 'enable';
117                                         
118                                                
119                                            if (_this.form.findField('comptype')) {
120                                                _this.form.findField('comptype')[meth]();
121                                            }
122                                             
123                                           // _this.loaded();
124                                            return;
125                                        }
126                                        
127                                        
128                                        if (act.type == 'submit') { // only submitted here if we are 
129                                            _this.dialog.hide();
130                                           
131                                            if (_this.callback) {
132                                                _this.callback.call(this, act.result.data);
133                                            }
134                                            return; 
135                                        }
136                                        // unmask?? 
137                                    }
138                             },
139                             items : [
140                                 {
141                                     xtype : 'Column',
142                                     xns : Roo.form,
143                                     width : 500,
144                                     items : [
145                                         {
146                                             fieldLabel : 'Company ID (for filing Ref.)',
147                                             xtype : 'TextField',
148                                             allowBlank : true,
149                                             width : 100,
150                                             xns : Roo.form,
151                                             name : 'code',
152                                             qtip : "Enter code"
153                                         },
154                                         {
155                                             store : {
156                                                 proxy : {
157                                                     url : baseURL + '/Roo/core_enum.php',
158                                                     method : 'GET',
159                                                     xtype : 'HttpProxy',
160                                                     xns : Roo.data
161                                                 },
162                                                 reader : {
163                                                     id : 'id',
164                                                     root : 'data',
165                                                     xtype : 'JsonReader',
166                                                     fields : [{"name":"id","type":"int"},{"name":"name","type":"string"}],
167                                                     xns : Roo.data,
168                                                     totalProperty : 'total'
169                                                 },
170                                                 xtype : 'Store',
171                                                 remoteSort : true,
172                                                 sortInfo : { direction : 'ASC', field: 'id' },
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                                                                o.params.etype = 'COMPTYPE';
180                                                            }
181                                                 },
182                                                 items : [
183
184                                                 ]
185
186                                             },
187                                             alwaysQuery : true,
188                                             listWidth : 250,
189                                             triggerAction : 'all',
190                                             fieldLabel : 'Type',
191                                             forceSelection : true,
192                                             selectOnFocus : true,
193                                             pageSize : 20,
194                                             emptyText : "Select Type",
195                                             displayField : 'display_name',
196                                             hiddenName : 'comptype',
197                                             minChars : 2,
198                                             valueField : 'name',
199                                             xtype : 'ComboBox',
200                                             typeAhead : false,
201                                             width : 200,
202                                             xns : Roo.form,
203                                             name : 'comptype_display_name',
204                                             qtip : "Select type",
205                                             queryParam : 'query[name]',
206                                             tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{name}</b> : {display_name}</div>',
207                                             loadingText : "Searching...",
208                                             listeners : {
209                                                 render : function (_self)
210                                                    {
211                                                        _this.etypeCombo = _self;
212                                                    }
213                                             },
214                                             items : [
215
216                                             ]
217
218                                         },
219                                         {
220                                             fieldLabel : 'Company Name',
221                                             xtype : 'TextField',
222                                             allowBlank : true,
223                                             width : 300,
224                                             xns : Roo.form,
225                                             name : 'name',
226                                             qtip : "Enter Company Name"
227                                         },
228                                         {
229                                             fieldLabel : 'Phone',
230                                             xtype : 'TextField',
231                                             allowBlank : true,
232                                             width : 300,
233                                             xns : Roo.form,
234                                             name : 'tel',
235                                             qtip : "Enter Phone Number"
236                                         },
237                                         {
238                                             fieldLabel : 'Fax',
239                                             xtype : 'TextField',
240                                             allowBlank : true,
241                                             width : 300,
242                                             xns : Roo.form,
243                                             name : 'fax',
244                                             qtip : "Enter Fax Number"
245                                         },
246                                         {
247                                             fieldLabel : 'Email',
248                                             xtype : 'TextField',
249                                             allowBlank : true,
250                                             width : 300,
251                                             xns : Roo.form,
252                                             name : 'email',
253                                             qtip : "Enter Email Address"
254                                         },
255                                         {
256                                             fieldLabel : 'Url',
257                                             xtype : 'TextField',
258                                             allowBlank : true,
259                                             width : 300,
260                                             xns : Roo.form,
261                                             name : 'url',
262                                             qtip : "Enter Url"
263                                         },
264                                         {
265                                             fieldLabel : 'Address',
266                                             xtype : 'TextField',
267                                             allowBlank : true,
268                                             width : 300,
269                                             xns : Roo.form,
270                                             name : 'address',
271                                             qtip : "Enter Address"
272                                         },
273                                         {
274                                             fieldLabel : 'Remarks',
275                                             xtype : 'TextArea',
276                                             allowBlank : true,
277                                             width : 300,
278                                             xns : Roo.form,
279                                             height : 120,
280                                             name : 'remarks',
281                                             qtip : "Enter remarks"
282                                         }
283                                     ]
284
285                                 },
286                                 {
287                                     labelAlign : 'top',
288                                     xtype : 'Column',
289                                     width : 200,
290                                     xns : Roo.form,
291                                     items : [
292                                         {
293                                             fieldLabel : 'Background Colour',
294                                             xtype : 'ColorField',
295                                             xns : Roo.form,
296                                             name : 'background_color'
297                                         },
298                                         {
299                                             fieldLabel : 'Logo Image',
300                                             style : 'border: 1px solid #ccc;',
301                                             xtype : 'DisplayField',
302                                             valueRenderer : function(v) {
303                                                 //var vp = v ? v : 'Companies:' + _this.data.id + ':-LOGO';
304                                                 if (!v) {
305                                                     return "No Image Available" + '<BR/>';
306                                                 }
307                                                 return String.format('<a target="_new" href="{1}"><img src="{0}" width="150"></a>', 
308                                                         baseURL + '/Images/Thumb/150x150/' + v + '/logo.jpg',
309                                                         baseURL + '/Images/Thumb/'+v+'/logo.jpg'           
310                                                 );
311                                             },
312                                             icon : 'rootURL + \'images/default/dd/drop-add.gif\'',
313                                             width : 170,
314                                             xns : Roo.form,
315                                             height : 170,
316                                             name : 'logo_id'
317                                         },
318                                         {
319                                             text : "Add Image",
320                                             xtype : 'Button',
321                                             xns : Roo,
322                                             listeners : {
323                                                 click : function (_self, e)
324                                                    {
325                                                        var _t = _this.form.findField('logo_id');
326                                                                             
327                                                        Pman.Dialog.Image.show({
328                                                            onid :_this.data.id,
329                                                            ontable : 'Companies',
330                                                            imgtype : 'LOGO'
331                                                        }, function(data) {
332                                                            if  (data) {
333                                                                _t.setValue(data.id);
334                                                            }
335                                                            
336                                                        });
337                                                    }
338                                             }
339                                         }
340                                     ]
341
342                                 },
343                                 {
344                                     xtype : 'Hidden',
345                                     xns : Roo.form,
346                                     name : 'id'
347                                 }
348                             ]
349
350                         }
351                     ]
352
353                 }
354             ]
355
356         });
357     }
358 };