Pman.Dialog.XtupleQuickContact.bjs
[Pman.Xtuple] / Pman.Dialog.XtupleQuickContact.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.XtupleQuickContact = {
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 : 480,
36             modal : true,
37             resizable : false,
38             title : "Quick enter Contact /  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._id) { 
54                                             this.load({ method: 'GET', params: { 
55                                                 _id : _this.data._id , 
56                                                 _with_addr : 1
57                                             }});
58                                         }
59                                        return;
60                                     }
61                                     if (action.type == 'load') {
62                                         return;
63                                     }
64                                     if (action.type =='submit') {
65                                     
66                                         _this.dialog.hide();
67                                     
68                                          if (_this.callback) {
69                                              _this.form.setValues(action.result.data);
70                                             _this.callback.call(_this, _this.form.getValues());
71                                          }
72                                          _this.form.reset();
73                                          return;
74                                     }
75                                 },
76                                 rendered : function (form)
77                                 {
78                                     _this.form= form;
79                                 }
80                             },
81                             method : 'POST',
82                             style : 'margin:10px;',
83                             url : baseURL + '/Roo/cntct.php',
84                             items : [
85                                 {
86                                     xtype: 'TextField',
87                                     xns: Roo.form,
88                                     allowBlank : false,
89                                     fieldLabel : 'First Name',
90                                     name : 'cntct_first_name',
91                                     width : 300
92                                 },
93                                 {
94                                     xtype: 'TextField',
95                                     xns: Roo.form,
96                                     fieldLabel : 'Last Name',
97                                     name : 'cntct_last_name',
98                                     width : 300
99                                 },
100                                 {
101                                     xtype: 'TextField',
102                                     xns: Roo.form,
103                                     fieldLabel : 'Phone',
104                                     name : 'cntct_phone',
105                                     width : 200,
106                                     regex : /^[0-9 +-]+$/
107                                 },
108                                 {
109                                     xtype: 'TextField',
110                                     xns: Roo.form,
111                                     fieldLabel : 'Email',
112                                     name : 'cntct_email',
113                                     vtype : 'email',
114                                     width : 200
115                                 },
116                                 {
117                                     xtype: 'FieldSet',
118                                     xns: Roo.form,
119                                     legend : "Address",
120                                     style : 'width:420px',
121                                     items : [
122                                         {
123                                             xtype: 'TextField',
124                                             xns: Roo.form,
125                                             listeners : {
126                                                 keyup : function (_self, e)
127                                                 {
128                                                     _this.form.findField('addr_number').sync();
129                                                 }
130                                             },
131                                             allowBlank : false,
132                                             fieldLabel : 'Line 1',
133                                             name : 'cntct_addr_id_addr_line1',
134                                             width : 300
135                                         },
136                                         {
137                                             xtype: 'TextField',
138                                             xns: Roo.form,
139                                             fieldLabel : 'Line 2',
140                                             name : 'cntct_addr_id_addr_line2',
141                                             width : 300
142                                         },
143                                         {
144                                             xtype: 'TextField',
145                                             xns: Roo.form,
146                                             fieldLabel : 'Line 3',
147                                             name : 'cntct_addr_id_addr_line3',
148                                             width : 300
149                                         },
150                                         {
151                                             xtype: 'ComboBox',
152                                             xns: Roo.form,
153                                             allowBlank : true,
154                                             displayField : 'addr_state',
155                                             editable : true,
156                                             emptyText : "State",
157                                             fieldLabel : 'State',
158                                             hiddenName : 'cntct_addr_id_addr_state',
159                                             listWidth : 400,
160                                             loadingText : "Searching...",
161                                             minChars : 2,
162                                             name : 'cntct_addr_id_addr_state',
163                                             qtip : "Select State",
164                                             queryParam : 'query[addr_state]',
165                                             selectOnFocus : true,
166                                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{addr_state}</b> </div>',
167                                             triggerAction : 'all',
168                                             typeAhead : true,
169                                             valueField : 'addr_state',
170                                             width : 200,
171                                             store : {
172                                                 xtype: 'Store',
173                                                 xns: Roo.data,
174                                                 listeners : {
175                                                     beforeload : function (_self, o){
176                                                         o.params = o.params || {};
177                                                         
178                                                        // o.params.state_country_id_country_name = _this.form.findField('addr_country').getValue();
179                                                         //if (!o.params.state_country_id_country_name.length) {
180                                                         //    Roo.MessageBox.alert("Select Country First");
181                                                     //        return false;
182                                                       //  }
183                                                       
184                                                        o.params._distinct = 'addr_state';
185                                                        o.params._columns = 'addr_state';
186                                                        o.params.limit = 999;
187                                                         // set more here
188                                                     }
189                                                 },
190                                                 remoteSort : true,
191                                                 sortInfo : { direction : 'ASC', field: 'addr_state' },
192                                                 proxy : {
193                                                     xtype: 'HttpProxy',
194                                                     xns: Roo.data,
195                                                     method : 'GET',
196                                                     url : baseURL + '/Roo/addr.php'
197                                                 },
198                                                 reader : {
199                                                     xtype: 'JsonReader',
200                                                     xns: Roo.data,
201                                                     id : 'addr_state',
202                                                     root : 'data',
203                                                     totalProperty : 'total',
204                                                     fields : [ "addr_state"]
205                                                 }
206                                             }
207                                         },
208                                         {
209                                             xtype: 'TextField',
210                                             xns: Roo.form,
211                                             fieldLabel : 'City',
212                                             name : 'cntct_addr_id_addr_city',
213                                             width : 300
214                                         },
215                                         {
216                                             xtype: 'TextField',
217                                             xns: Roo.form,
218                                             fieldLabel : 'Zip code',
219                                             name : 'cntct_addr_id_addr_postalcode',
220                                             width : 300
221                                         },
222                                         {
223                                             xtype: 'ComboBox',
224                                             xns: Roo.form,
225                                             allowBlank : true,
226                                             displayField : 'country_name',
227                                             editable : true,
228                                             emptyText : "Country",
229                                             fieldLabel : 'Country',
230                                             hiddenName : 'cntct_addr_id_addr_country',
231                                             listWidth : 400,
232                                             loadingText : "Searching...",
233                                             minChars : 2,
234                                             name : 'cntct_addr_id_addr_country',
235                                             qtip : "Select Country",
236                                             queryParam : 'query[country_name]',
237                                             selectOnFocus : true,
238                                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{country_name}</b> </div>',
239                                             triggerAction : 'all',
240                                             typeAhead : true,
241                                             valueField : 'country_name',
242                                             width : 200,
243                                             store : {
244                                                 xtype: 'Store',
245                                                 xns: Roo.data,
246                                                 listeners : {
247                                                     beforeload : function (_self, o){
248                                                         o.params = o.params || {};
249                                                         // set more here
250                                                         o.params.limit = 999;
251                                                     }
252                                                 },
253                                                 remoteSort : true,
254                                                 sortInfo : { direction : 'ASC', field: 'country_name' },
255                                                 proxy : {
256                                                     xtype: 'HttpProxy',
257                                                     xns: Roo.data,
258                                                     method : 'GET',
259                                                     url : baseURL + '/Roo/country.php'
260                                                 },
261                                                 reader : {
262                                                     xtype: 'JsonReader',
263                                                     xns: Roo.data,
264                                                     id : 'country_id',
265                                                     root : 'data',
266                                                     totalProperty : 'total',
267                                                     fields : [{"name":"country_id","type":"int"},"county_name"]
268                                                 }
269                                             }
270                                         }
271                                     ]
272                                 },
273                                 {
274                                     xtype: 'TextField',
275                                     xns: Roo.form,
276                                     allowBlank : true,
277                                     fieldLabel : 'Store (Delivery)',
278                                     name : 'cntct_addr_id_addr_line1',
279                                     readOnly : true,
280                                     width : 300
281                                 },
282                                 {
283                                     xtype: 'Hidden',
284                                     xns: Roo.form,
285                                     name : 'customer_id',
286                                     width : 100
287                                 },
288                                 {
289                                     xtype: 'Hidden',
290                                     xns: Roo.form,
291                                     name : 'cntct_addr_id',
292                                     width : 100
293                                 },
294                                 {
295                                     xtype: 'Hidden',
296                                     xns: Roo.form,
297                                     name : 'cntct_id'
298                                 }
299                             ]
300                         }
301                     ]
302                 }
303             ],
304             center : {
305                 xtype: 'LayoutRegion',
306                 xns: Roo
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                          
330                             _this.form.doAction("submit");
331                         
332                         }
333                     },
334                     text : "Save"
335                 }
336             ]
337         });
338     }
339 };