Pman.Dialog.XtupleBankAccnt.bjs
[Pman.Xtuple] / Pman.Dialog.XtupleAddress.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.XtupleAddress = {
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             closable : false,
34             collapsible : false,
35             height : 400,
36             modal : true,
37             resizable : false,
38             title : "Edit Address",
39             width : 500,
40             items : [
41                 {
42                     xtype: 'ContentPanel',
43                     xns: Roo,
44                     region : 'center',
45                     items : [
46                         {
47                             xtype: 'Form',
48                             xns: Roo.form,
49                             listeners : {
50                                 actioncomplete : function(_self,action)
51                                 {
52                                     if (action.type == 'setdata') {
53                                         if (_this.data.addr_id) { 
54                                             this.load({ method: 'GET', params: { '_id' : _this.data.addr_id }});
55                                         }
56                                        return;
57                                     }
58                                     if (action.type == 'load') {
59                                         return;
60                                     }
61                                     if (action.type =='submit') {
62                                     
63                                         _this.dialog.hide();
64                                     
65                                          if (_this.callback) {
66                                              _this.form.setValues(action.result.data);
67                                             _this.callback.call(_this, _this.form.getValues());
68                                          }
69                                          _this.form.reset();
70                                          return;
71                                     }
72                                 },
73                                 rendered : function (form)
74                                 {
75                                     _this.form= form;
76                                 }
77                             },
78                             method : 'POST',
79                             style : 'margin:10px;',
80                             url : baseURL + '/Roo/addr.php',
81                             items : [
82                                 {
83                                     xtype: 'TextField',
84                                     xns: Roo.form,
85                                     listeners : {
86                                         keyup : function (_self, e)
87                                         {
88                                             _this.form.findField('addr_number').sync();
89                                         }
90                                     },
91                                     allowBlank : false,
92                                     fieldLabel : 'Line 1',
93                                     name : 'addr_line1',
94                                     width : 300
95                                 },
96                                 {
97                                     xtype: 'TextField',
98                                     xns: Roo.form,
99                                     fieldLabel : 'Line 2',
100                                     name : 'addr_line2',
101                                     width : 300
102                                 },
103                                 {
104                                     xtype: 'TextField',
105                                     xns: Roo.form,
106                                     fieldLabel : 'Line 3',
107                                     name : 'addr_line3',
108                                     width : 300
109                                 },
110                                 {
111                                     xtype: 'TextField',
112                                     xns: Roo.form,
113                                     fieldLabel : 'City',
114                                     name : 'addr_city',
115                                     width : 300
116                                 },
117                                 {
118                                     xtype: 'ComboBox',
119                                     xns: Roo.form,
120                                     allowBlank : true,
121                                     displayField : 'addr_state',
122                                     editable : true,
123                                     emptyText : "State",
124                                     fieldLabel : 'State',
125                                     listWidth : 400,
126                                     loadingText : "Searching...",
127                                     minChars : 2,
128                                     name : 'addr_state',
129                                     qtip : "Select State",
130                                     queryParam : 'query[addr_state]',
131                                     selectOnFocus : true,
132                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{addr_state}</b></div>',
133                                     triggerAction : 'all',
134                                     typeAhead : false,
135                                     valueField : 'addr_state',
136                                     width : 200,
137                                     store : {
138                                         xtype: 'Store',
139                                         xns: Roo.data,
140                                         listeners : {
141                                             beforeload : function (_self, o){
142                                                 o.params = o.params || {};
143                                                 
144                                                // o.params.state_country_id_country_name = _this.form.findField('addr_country').getValue();
145                                                 //if (!o.params.state_country_id_country_name.length) {
146                                                 //    Roo.MessageBox.alert("Select Country First");
147                                             //        return false;
148                                               //  }
149                                               
150                                                o.params._distinct = 'addr_state';
151                                                o.params._columns = 'addr_state';
152                                                o.params.limit = 999;
153                                                 // set more here
154                                             }
155                                         },
156                                         remoteSort : true,
157                                         sortInfo : { direction : 'ASC', field: 'addr_state' },
158                                         proxy : {
159                                             xtype: 'HttpProxy',
160                                             xns: Roo.data,
161                                             method : 'GET',
162                                             url : baseURL + '/Roo/addr.php'
163                                         },
164                                         reader : {
165                                             xtype: 'JsonReader',
166                                             xns: Roo.data,
167                                             id : 'addr_state',
168                                             root : 'data',
169                                             totalProperty : 'total',
170                                             fields : [ 'addr_state' ]
171                                         }
172                                     }
173                                 },
174                                 {
175                                     xtype: 'ComboBox',
176                                     xns: Roo.form,
177                                     allowBlank : true,
178                                     displayField : 'country_name',
179                                     editable : true,
180                                     emptyText : "Country",
181                                     fieldLabel : 'Country',
182                                     listWidth : 400,
183                                     loadingText : "Searching...",
184                                     minChars : 2,
185                                     name : 'addr_country',
186                                     qtip : "Select Country",
187                                     queryParam : 'query[country_name]',
188                                     selectOnFocus : true,
189                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{country_name}</b> </div>',
190                                     triggerAction : 'all',
191                                     typeAhead : false,
192                                     valueField : 'country_name',
193                                     width : 200,
194                                     store : {
195                                         xtype: 'Store',
196                                         xns: Roo.data,
197                                         listeners : {
198                                             beforeload : function (_self, o){
199                                                 o.params = o.params || {};
200                                                 // set more here
201                                                 o.params.limit = 999;
202                                             }
203                                         },
204                                         remoteSort : true,
205                                         sortInfo : { direction : 'ASC', field: 'country_name' },
206                                         proxy : {
207                                             xtype: 'HttpProxy',
208                                             xns: Roo.data,
209                                             method : 'GET',
210                                             url : baseURL + '/Roo/country.php'
211                                         },
212                                         reader : {
213                                             xtype: 'JsonReader',
214                                             xns: Roo.data,
215                                             id : 'country_id',
216                                             root : 'data',
217                                             totalProperty : 'total',
218                                             fields : [{'name':'country_id','type':'int'},'county_name']
219                                         }
220                                     }
221                                 },
222                                 {
223                                     xtype: 'TextField',
224                                     xns: Roo.form,
225                                     fieldLabel : 'postalcode',
226                                     name : 'addr_postalcode',
227                                     width : 150
228                                 },
229                                 {
230                                     xtype: 'TextField',
231                                     xns: Roo.form,
232                                     fieldLabel : 'Unique#',
233                                     name : 'addr_number',
234                                     width : 150,
235                                     sync : function() {
236                                         if (_this.form.findField('addr_id') * 1 > 0 ) {
237                                             return;
238                                         }
239                                         this.setValue('C' + _this.form.findField('customer_id').getValue() + '-' + 
240                                             _this.form.findField('addr_line1').getValue()
241                                         );
242                                             
243                                     }
244                                 },
245                                 {
246                                     xtype: 'TextArea',
247                                     xns: Roo.form,
248                                     fieldLabel : 'notes',
249                                     name : 'addr_notes',
250                                     width : 300
251                                 },
252                                 {
253                                     xtype: 'Hidden',
254                                     xns: Roo.form,
255                                     name : 'customer_id',
256                                     width : 100
257                                 },
258                                 {
259                                     xtype: 'Hidden',
260                                     xns: Roo.form,
261                                     name : 'addr_id',
262                                     width : 100
263                                 }
264                             ]
265                         }
266                     ],
267                     toolbar : {
268                         xtype: 'Toolbar',
269                         xns: Roo,
270                         items : [
271                             {
272                                 xtype: 'Fill',
273                                 xns: Roo.Toolbar
274                             },
275                             {
276                                 xtype: 'Button',
277                                 xns: Roo.Toolbar,
278                                 listeners : {
279                                     click : function()
280                                     {
281                                         var id = _this.form.findField('addr_id').getValue() *1;
282                                         if (!id) {
283                                             Roo.MessageBox.alert("Error", "You can not delete this, you have not created it yet");
284                                             return;
285                                         }
286                                         
287                                         
288                                         Roo.MessageBox.confirm("Confirm", "You will only be able to delete this if it is not referenced anywhere<BR>"+
289                                                 ", are you sure you want to try that?",
290                                                 function (res) {
291                                                     if(res!='yes') {
292                                                         return;
293                                                     
294                                                     }
295                                                     new Pman.Request({
296                                                         method: 'POST',
297                                                         url: baseURL+ '/Roo/addr',
298                                                         params : {
299                                                             _delete : id
300                                                         },
301                                                         success : function() {
302                                                             _this.callback({ addr_id : 0, addr_line1 : '' });
303                                                             _this.dialog.hide();
304                                                         }
305                                                     });
306                                             });
307                                             
308                                         
309                                         
310                                     }
311                                 },
312                                 cls : 'x-btn-text-icon',
313                                 text : "Delete",
314                                 icon : rootURL + '/Pman/templates/images/trash.gif'
315                             }
316                         ]
317                     }
318                 }
319             ],
320             center : {
321                 xtype: 'LayoutRegion',
322                 xns: Roo
323             },
324             buttons : [
325                 {
326                     xtype: 'Button',
327                     xns: Roo,
328                     listeners : {
329                         click : function (_self, e)
330                         {
331                             _this.dialog.hide();
332                         }
333                     },
334                     text : "Cancel"
335                 },
336                 {
337                     xtype: 'Button',
338                     xns: Roo,
339                     listeners : {
340                         click : function (_self, e)
341                         {
342                             // do some checks?
343                              
344                             
345                          
346                             _this.form.doAction('submit');
347                         
348                         }
349                     },
350                     text : "Save"
351                 }
352             ]
353         });
354     }
355 };