Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Pman.Dialog.XtupleShipmentNew.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.XtupleShipmentNew = {
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             listeners : {
34                 show : function (_self)
35                 {
36                     _this.form.findField('shiphead_location_id').focus();
37                 }
38             },
39             closable : false,
40             height : 130,
41             modal : true,
42             resizable : false,
43             title : "Create new Shipment",
44             width : 500,
45             items : [
46                 {
47                     xtype: 'ContentPanel',
48                     xns: Roo,
49                     region : 'center',
50                     items : [
51                         {
52                             xtype: 'Form',
53                             xns: Roo.form,
54                             listeners : {
55                                 rendered : function (form)
56                                 {
57                                   _this.form = form;
58                                 },
59                                 actioncomplete : function (_self, action)
60                                 {
61                                     if (action.type == 'setdata') {
62                                         // see if there are multiple possilbe targets
63                                         new Pman.Request({
64                                             url : baseURL + '/Roo/cohead',
65                                             method : 'GET',
66                                             params : {
67                                                 cohead_id : _this.data.shiphead_order_id,
68                                                 _has_multiple_ship : 1
69                                             },
70                                             success : function(res) {
71                                                 // if there is one row returned, then assign values, and press OK
72                                                 // otherwise.. cary on..
73                                                 if (res.total === 1) {
74                                                     _this.form.setValues( {
75                                                     
76                                                         shiphead_location_id : res.data[0].coitem_location_src,
77                                                         shiphead_location_id_location_name : res.data[0].coitem_location_src_name,                        
78                                                         shiphead_shipto_id : res.data[0].coitem_shipto_id,
79                                                         shiphead_shipto_id_shipto_name : res.data[0].coitem_shipto_id_name
80                                                     });
81                                                     _this.okButton.fireEvent('click');
82                                                 }
83                                                 
84                                             },
85                                             failure : function(res) {
86                                 
87                                                 Roo.MessageBox.alert("Error", res.errorMsg);
88                                                 _this.dialog.hide();
89                                                 
90                                             }
91                                         });
92                                             
93                                     
94                                     }
95                                   
96                                 }
97                             },
98                             items : [
99                                 {
100                                     xtype: 'ComboBox',
101                                     xns: Roo.form,
102                                     allowBlank : false,
103                                     alwaysQuery : true,
104                                     displayField : 'location_name',
105                                     editable : false,
106                                     emptyText : "Select location",
107                                     fieldLabel : 'From Location',
108                                     forceSelection : true,
109                                     hiddenName : 'shiphead_location_id',
110                                     listWidth : 400,
111                                     loadingText : "Searching...",
112                                     minChars : 2,
113                                     name : 'shiphead_location_id_location_name',
114                                     pageSize : 20,
115                                     qtip : "Select location",
116                                     queryParam : '',
117                                     selectOnFocus : true,
118                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{location_name}</b> </div>',
119                                     triggerAction : 'all',
120                                     typeAhead : true,
121                                     valueField : 'location_id',
122                                     width : 300,
123                                     store : {
124                                         xtype: 'Store',
125                                         xns: Roo.data,
126                                         listeners : {
127                                             beforeload : function (_self, o){
128                                                 o.params = o.params || {};
129                                                 o.params['query[for_cohead_id]'] = _this.data.shiphead_order_id;
130                                                 // set more here
131                                             }
132                                         },
133                                         remoteSort : true,
134                                         sortInfo : { direction : 'ASC', field: 'location_name' },
135                                         proxy : {
136                                             xtype: 'HttpProxy',
137                                             xns: Roo.data,
138                                             method : 'GET',
139                                             url : baseURL + '/Roo/location.php'
140                                         },
141                                         reader : {
142                                             xtype: 'JsonReader',
143                                             xns: Roo.data,
144                                             id : 'id',
145                                             root : 'data',
146                                             totalProperty : 'total',
147                                             fields : [{"name":"id","type":"int"},{"name":"location_name","type":"string"}]
148                                         }
149                                     }
150                                 },
151                                 {
152                                     xtype: 'ComboBox',
153                                     xns: Roo.form,
154                                     allowBlank : false,
155                                     alwaysQuery : true,
156                                     displayField : 'shipto_name',
157                                     editable : false,
158                                     emptyText : "Select Ship to name",
159                                     fieldLabel : 'To',
160                                     forceSelection : true,
161                                     hiddenName : 'shiphead_shipto_id',
162                                     listWidth : 400,
163                                     loadingText : "Searching...",
164                                     minChars : 2,
165                                     name : 'shiphead_shipto_id_shipto_name',
166                                     pageSize : 20,
167                                     qtip : "Select Ship to name",
168                                     queryParam : '',
169                                     selectOnFocus : true,
170                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{shipto_name}</b> </div>',
171                                     triggerAction : 'all',
172                                     typeAhead : true,
173                                     valueField : 'shipto_id',
174                                     width : 300,
175                                     store : {
176                                         xtype: 'Store',
177                                         xns: Roo.data,
178                                         listeners : {
179                                             beforeload : function (_self, o){
180                                                 o.params = o.params || {};
181                                                 // set more here
182                                                  o.params['query[for_cohead_id]'] = _this.data.shiphead_order_id;
183                                             }
184                                         },
185                                         remoteSort : true,
186                                         sortInfo : { direction : 'ASC', field: 'shipto_name' },
187                                         proxy : {
188                                             xtype: 'HttpProxy',
189                                             xns: Roo.data,
190                                             method : 'GET',
191                                             url : baseURL + '/Roo/shiptoinfo.php'
192                                         },
193                                         reader : {
194                                             xtype: 'JsonReader',
195                                             xns: Roo.data,
196                                             id : 'id',
197                                             root : 'data',
198                                             totalProperty : 'total',
199                                             fields : [{"name":"id","type":"int"},{"name":"shipto_name","type":"string"}]
200                                         }
201                                     }
202                                 },
203                                 {
204                                     xtype: 'Hidden',
205                                     xns: Roo.form,
206                                     name : 'shiphead_order_id'
207                                 },
208                                 {
209                                     xtype: 'Hidden',
210                                     xns: Roo.form,
211                                     name : 'shiphead_shipdate'
212                                 }
213                             ]
214                         }
215                     ]
216                 }
217             ],
218             center : {
219                 xtype: 'LayoutRegion',
220                 xns: Roo
221             },
222             buttons : [
223                 {
224                     xtype: 'Button',
225                     xns: Roo,
226                     listeners : {
227                         click : function (_self, e)
228                         {
229                            _this.dialog.hide();
230                          
231                          }
232                     },
233                     text : "Cancel"
234                 },
235                 {
236                     xtype: 'Button',
237                     xns: Roo,
238                     listeners : {
239                         click : function (_self, e)
240                         {
241                            //_this.findField('cuinfo_
242                            
243                            // check if customer is filled in.
244                            if (_this.form.findField('shiphead_location_id').getValue() < 1) {
245                                 Roo.MessageBox.alert("Error", "Select a source location");
246                                 return;
247                            }
248                            if (_this.form.findField('shiphead_shipto_id').getValue() < 1) {
249                                 Roo.MessageBox.alert("Error", "Select where to ship to");
250                                 return;
251                            }
252                         
253                              var rv = _this.form.getFieldValues();
254                         
255                             
256                             Pman.Dialog.XtupleShipment.show(rv ,
257                                 function() { 
258                                       _this.dialog.hide();
259                                      _this.callback()
260                                 }
261                             );
262                             
263                          },
264                         render : function (_self)
265                         {
266                             _this.okButton = _self;
267                         }
268                     },
269                     text : "OK"
270                 }
271             ]
272         });
273     }
274 };