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 Roo.namespace('Pman.Dialog');
6
7 Pman.Dialog.CoreCompanies = {
8
9  _strings : {
10   'ce8ae9da5b7cd6c3df2929543a9af92d' :"Email",
11   '231bc72756b5e6de492aaaa1577f61b1' :"Remarks",
12   'b33457e7e1cd5dbf1db34a0c60fcb75f' :"Company ID (for filing Ref.)",
13   '023a5dfa857c4aa0156e6685231a1dbd' :"Select Type",
14   '8535bcc0f05358a583bb432bbadf7e0d' :"Select type",
15   '733640ec0c9367df1b4d85eb286ed9ae' :"Enter code",
16   '8c04eb09879a05470fae436ba76e3bb9' :"Enter Url",
17   '4ef6052d74436756f08e95fd63949653' :"Enter Company Name",
18   'c54b90756cfbeff9217293b567cb2eb0' :"Enter remarks",
19   '1243daf593fa297e07ab03bf06d925af' :"Searching...",
20   'bcc254b55c4a1babdf1dcb82c207506b' :"Phone",
21   'cf3a5d25d39613ad5bbc2f5eb0f9b675' :"Enter Fax Number",
22   '9f86c00615b1a210935ac28ff8ebbb22' :"Enter Email Address",
23   'e7b47c58815acf1d3afa59a84b5db7fb' :"Company Name",
24   'ea4788705e6873b424c65e91c2846b19' :"Cancel",
25   '32c4e9483403d60115b21519178e5384' :"Enter Address",
26   'b9c49611cfda3259a2b837b39489e650' :"Add Image",
27   '72b9d3d2e231f1de7a2bd70737f644aa' :"Add / Edit Organization",
28   'a1fa27779242b4902f7ae3bdd5c6d508' :"Type",
29   '02a3a357710cc2a5dfdfb74ed012fb59' :"Url",
30   'dd7bf230fde8d4836917806aff6a6b27' :"Address",
31   'c9cc8cce247e49bae79f15173ce97354' :"Save",
32   'bc3a4c40d007b8d610a16312970e5cb3' :"Enter Phone Number",
33   '9810aa2b9f44401be4bf73188ef2b67d' :"Fax",
34   '35cb9e66ff801a819684ee0fbeabaeeb' :"Background Colour",
35   'bc87ef2144ae15ef4f78211e73948051' :"Logo Image"
36  },
37
38  dialog : false,
39  callback:  false,
40
41  show : function(data, cb)
42  {
43   if (!this.dialog) {
44    this.create();
45   }
46
47   this.callback = cb;
48   this.data = data;
49   this.dialog.show(this.data._el);
50   if (this.form) {
51    this.form.reset();
52    this.form.setValues(data);
53    this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
54   }
55
56  },
57
58  create : function()
59  {
60    var _this = this;
61    this.dialog = Roo.factory({
62     xtype : 'LayoutDialog',
63     autoCreate : true,
64     closable : false,
65     collapsible : false,
66     draggable : false,
67     height : 400,
68     modal : true,
69     shadow : true,
70     title : _this._strings['72b9d3d2e231f1de7a2bd70737f644aa'] /* Add / Edit Organization */,
71     width : 750,
72     xns : Roo,
73     '|xns' : 'Roo',
74     center : {
75      xtype : 'LayoutRegion',
76      alwaysShowTabs : false,
77      autoScroll : false,
78      closeOnTab : true,
79      hideTabs : true,
80      titlebar : false,
81      xns : Roo,
82      '|xns' : 'Roo'
83     },
84     buttons : [
85      {
86       xtype : 'Button',
87       text : _this._strings['ea4788705e6873b424c65e91c2846b19'] /* Cancel */,
88       listeners : {
89        click : function (_self, e)
90         {
91             _this.dialog.hide();
92         }
93       },
94       xns : Roo,
95       '|xns' : 'Roo'
96      },
97      {
98       xtype : 'Button',
99       text : _this._strings['c9cc8cce247e49bae79f15173ce97354'] /* Save */,
100       listeners : {
101        click : function (_self, e)
102         {
103             if(!_this.form.isValid()){
104                 Roo.MessageBox.alert('Error', 'Please Correct all the errors in red');
105                 return;
106             }
107             
108             new Pman.Request({
109                 url : baseURL + '/Roo/Core_company.php',
110                 method : 'POST',
111                 params : {
112                   id : _this.form.findField('id').getValue() * 1,
113                   name : _this.form.findField('name').getValue(),
114                   _check_name : 1
115                 }, 
116                 success : function(res) {
117                     _this.dialog.el.mask("Saving");
118                     _this.form.doAction("submit");
119                 },
120                 failure : function(res) {
121                     Roo.log(res);
122                 }
123             });
124             
125             return;
126             
127         }
128       },
129       xns : Roo,
130       '|xns' : 'Roo'
131      }
132     ],
133     items  : [
134      {
135       xtype : 'ContentPanel',
136       autoCreate : true,
137       fitToFrame : true,
138       region : 'center',
139       xns : Roo,
140       '|xns' : 'Roo',
141       items  : [
142        {
143         xtype : 'Form',
144         fileUpload : true,
145         labelWidth : 160,
146         url : baseURL + '/Roo/Companies.php',
147         listeners : {
148          actioncomplete : function(f, act) {
149               _this.dialog.el.unmask();
150               //console.log('load completed'); 
151               // error messages?????
152               if(act.type == 'setdata'){
153                   this.load({ method: 'GET', params: { '_id' : _this.data.id }});
154                   return;
155               }
156              
157               if (act.type == 'load') {
158                   _this.data = act.result.data;
159                   var meth = _this.data.comptype == 'OWNER' ? 'disable' : 'enable';
160                
161                       
162                   if (_this.form.findField('comptype')) {
163                       _this.form.findField('comptype')[meth]();
164                   }
165                    
166                  // _this.loaded();
167                   return;
168               }
169               
170               
171               if (act.type == 'submit') { // only submitted here if we are 
172                   _this.dialog.hide();
173                  
174                   if (_this.callback) {
175                       _this.callback.call(this, act.result.data);
176                   }
177                   return; 
178               }
179               // unmask?? 
180           },
181          actionfailed : function(f, act) {
182               _this.dialog.el.unmask();
183               // error msg???
184               Pman.standardActionFailed(f,act);
185                         
186           },
187          rendered : function (form)
188           {
189               _this.form = form;
190           }
191         },
192         xns : Roo.form,
193         '|xns' : 'Roo.form',
194         items  : [
195          {
196           xtype : 'Column',
197           width : 500,
198           xns : Roo.form,
199           '|xns' : 'Roo.form',
200           items  : [
201            {
202             xtype : 'TextField',
203             allowBlank : true,
204             fieldLabel : _this._strings['b33457e7e1cd5dbf1db34a0c60fcb75f'] /* Company ID (for filing Ref.) */,
205             name : 'code',
206             qtip : _this._strings['733640ec0c9367df1b4d85eb286ed9ae'] /* Enter code */,
207             width : 100,
208             xns : Roo.form,
209             '|xns' : 'Roo.form'
210            },
211            {
212             xtype : 'ComboBox',
213             allowBlank : false,
214             alwaysQuery : true,
215             displayField : 'display_name',
216             emptyText : _this._strings['023a5dfa857c4aa0156e6685231a1dbd'] /* Select Type */,
217             fieldLabel : _this._strings['a1fa27779242b4902f7ae3bdd5c6d508'] /* Type */,
218             forceSelection : true,
219             hiddenName : 'comptype',
220             listWidth : 250,
221             loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
222             minChars : 2,
223             name : 'comptype_display_name',
224             pageSize : 20,
225             qtip : _this._strings['8535bcc0f05358a583bb432bbadf7e0d'] /* Select type */,
226             queryParam : 'query[name]',
227             selectOnFocus : true,
228             tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{name}</b> : {display_name}</div>',
229             triggerAction : 'all',
230             typeAhead : false,
231             valueField : 'name',
232             width : 200,
233             listeners : {
234              render : function (_self)
235               {
236                   _this.etypeCombo = _self;
237               }
238             },
239             xns : Roo.form,
240             '|xns' : 'Roo.form',
241             store : {
242              xtype : 'Store',
243              remoteSort : true,
244              sortInfo : { direction : 'ASC', field: 'id' },
245              listeners : {
246               beforeload : function (_self, o){
247                    o.params = o.params || {};
248                    // set more here
249                    //o.params['query[empty_etype]'] = 1;
250                    o.params.etype = 'COMPTYPE';
251                }
252              },
253              xns : Roo.data,
254              '|xns' : 'Roo.data',
255              proxy : {
256               xtype : 'HttpProxy',
257               method : 'GET',
258               url : baseURL + '/Roo/core_enum.php',
259               xns : Roo.data,
260               '|xns' : 'Roo.data'
261              },
262              reader : {
263               xtype : 'JsonReader',
264               fields : [{"name":"id","type":"int"},{"name":"name","type":"string"}],
265               id : 'id',
266               root : 'data',
267               totalProperty : 'total',
268               xns : Roo.data,
269               '|xns' : 'Roo.data'
270              }
271             }
272            },
273            {
274             xtype : 'TextField',
275             allowBlank : false,
276             fieldLabel : _this._strings['e7b47c58815acf1d3afa59a84b5db7fb'] /* Company Name */,
277             name : 'name',
278             qtip : _this._strings['4ef6052d74436756f08e95fd63949653'] /* Enter Company Name */,
279             width : 300,
280             xns : Roo.form,
281             '|xns' : 'Roo.form'
282            },
283            {
284             xtype : 'TextField',
285             allowBlank : true,
286             fieldLabel : _this._strings['bcc254b55c4a1babdf1dcb82c207506b'] /* Phone */,
287             name : 'tel',
288             qtip : _this._strings['bc3a4c40d007b8d610a16312970e5cb3'] /* Enter Phone Number */,
289             width : 300,
290             xns : Roo.form,
291             '|xns' : 'Roo.form'
292            },
293            {
294             xtype : 'TextField',
295             allowBlank : true,
296             fieldLabel : _this._strings['9810aa2b9f44401be4bf73188ef2b67d'] /* Fax */,
297             name : 'fax',
298             qtip : _this._strings['cf3a5d25d39613ad5bbc2f5eb0f9b675'] /* Enter Fax Number */,
299             width : 300,
300             xns : Roo.form,
301             '|xns' : 'Roo.form'
302            },
303            {
304             xtype : 'TextField',
305             allowBlank : true,
306             fieldLabel : _this._strings['ce8ae9da5b7cd6c3df2929543a9af92d'] /* Email */,
307             name : 'email',
308             qtip : _this._strings['9f86c00615b1a210935ac28ff8ebbb22'] /* Enter Email Address */,
309             width : 300,
310             xns : Roo.form,
311             '|xns' : 'Roo.form'
312            },
313            {
314             xtype : 'TextField',
315             allowBlank : true,
316             fieldLabel : _this._strings['02a3a357710cc2a5dfdfb74ed012fb59'] /* Url */,
317             name : 'url',
318             qtip : _this._strings['8c04eb09879a05470fae436ba76e3bb9'] /* Enter Url */,
319             width : 300,
320             xns : Roo.form,
321             '|xns' : 'Roo.form'
322            },
323            {
324             xtype : 'TextField',
325             allowBlank : true,
326             fieldLabel : _this._strings['dd7bf230fde8d4836917806aff6a6b27'] /* Address */,
327             name : 'address',
328             qtip : _this._strings['32c4e9483403d60115b21519178e5384'] /* Enter Address */,
329             width : 300,
330             xns : Roo.form,
331             '|xns' : 'Roo.form'
332            },
333            {
334             xtype : 'TextArea',
335             allowBlank : true,
336             fieldLabel : _this._strings['231bc72756b5e6de492aaaa1577f61b1'] /* Remarks */,
337             height : 120,
338             name : 'remarks',
339             qtip : _this._strings['c54b90756cfbeff9217293b567cb2eb0'] /* Enter remarks */,
340             width : 300,
341             xns : Roo.form,
342             '|xns' : 'Roo.form'
343            }
344           ]
345          },
346          {
347           xtype : 'Column',
348           labelAlign : 'top',
349           width : 200,
350           xns : Roo.form,
351           '|xns' : 'Roo.form',
352           items  : [
353            {
354             xtype : 'ColorField',
355             fieldLabel : _this._strings['35cb9e66ff801a819684ee0fbeabaeeb'] /* Background Colour */,
356             name : 'background_color',
357             xns : Roo.form,
358             '|xns' : 'Roo.form'
359            },
360            {
361             xtype : 'DisplayField',
362             fieldLabel : _this._strings['bc87ef2144ae15ef4f78211e73948051'] /* Logo Image */,
363             height : 170,
364             icon : 'rootURL + \'images/default/dd/drop-add.gif\'',
365             name : 'logo_id',
366             style : 'border: 1px solid #ccc;',
367             valueRenderer : function(v) {
368                 //var vp = v ? v : 'Companies:' + _this.data.id + ':-LOGO';
369                 if (!v) {
370                     return "No Image Available" + '<BR/>';
371                 }
372                 return String.format('<a target="_new" href="{1}"><img src="{0}" width="150"></a>', 
373                         baseURL + '/Images/Thumb/150x150/' + v + '/logo.jpg',
374                         baseURL + '/Images/'+v+'/logo.jpg'           // fixme - put escaped company name..
375                 );
376             },
377             width : 170,
378             xns : Roo.form,
379             '|xns' : 'Roo.form'
380            },
381            {
382             xtype : 'Button',
383             text : _this._strings['b9c49611cfda3259a2b837b39489e650'] /* Add Image */,
384             listeners : {
385              click : function (_self, e)
386               {
387                   var _t = _this.form.findField('logo_id');
388                                        
389                   Pman.Dialog.Image.show({
390                       onid :_this.data.id,
391                       ontable : 'Companies',
392                       imgtype : 'LOGO'
393                   }, function(data) {
394                       if  (data) {
395                           _t.setValue(data.id);
396                       }
397                       
398                   });
399               }
400             },
401             xns : Roo,
402             '|xns' : 'Roo'
403            }
404           ]
405          },
406          {
407           xtype : 'Hidden',
408           name : 'id',
409           xns : Roo.form,
410           '|xns' : 'Roo.form'
411          }
412         ]
413        }
414       ]
415      }
416     ]
417    });
418  }
419 };