/[drupal]/contributions/modules/ubercart/uc_order/uc_order.js
ViewVC logotype

Contents of /contributions/modules/ubercart/uc_order/uc_order.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.9 - (show annotations) (download) (as text)
Thu Jul 10 12:41:02 2008 UTC (16 months, 2 weeks ago) by islandusurper
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--2
Changes since 1.8: +109 -21 lines
File MIME type: text/javascript
Begin the Ubercart 6.x-2.x branch.
1 // $Id$
2
3 var customer_select = '';
4 var add_product_browser = '';
5 var order_save_holds = 0;
6
7 // Add the double click to the order table at admin/store/orders.
8 $(document).ready(
9 function() {
10 if (order_save_holds == 0) {
11 release_held_buttons();
12 }
13
14 $('.uc-orders-table tr.odd, .uc-orders-table tr.even').each(
15 function() {
16 $(this).dblclick(
17 function() {
18 var url = Drupal.settings.basePath + 'admin/store/orders/' + this.id.substring(6);
19 window.location = url;
20 }
21 );
22 }
23 );
24
25 $('#uc-order-edit-form').submit(
26 function() {
27 $('#products-selector').empty().removeClass();
28 $('#delivery_address_select').empty().removeClass();
29 $('#billing_address_select').empty().removeClass();
30 $('#customer-select').empty().removeClass();
31 }
32 );
33 }
34 );
35
36 /**
37 * Copy the shipping data on the order edit screen to the corresponding billing
38 * fields if they exist.
39 */
40 function uc_order_copy_shipping_to_billing() {
41 if ($('#edit-delivery-zone').html() != $('#edit-billing-zone').html()) {
42 $('#edit-billing-zone').empty().append($('#edit-delivery-zone').children().clone());
43 }
44
45 $('#uc-order-edit-form input, select, textarea').each(
46 function() {
47 if (this.id.substring(0, 13) == 'edit-delivery') {
48 $('#edit-billing' + this.id.substring(13)).val($(this).val());
49 }
50 }
51 );
52 }
53
54 /**
55 * Load the address book div on the order edit screen.
56 */
57 function load_address_select(uid, div, address_type) {
58 var options = {
59 'uid' : uid,
60 'type' : address_type,
61 'func' : "apply_address('" + address_type + "', this.value);"
62 };
63
64 $.post(Drupal.settings.basePath + 'admin/store/orders/address_book', options,
65 function (contents) {
66 $(div).empty().addClass('address-select-box').append(contents);
67 }
68 );
69 }
70
71 /**
72 * Apply the selected address to the appropriate fields in the order edit form.
73 */
74 function apply_address(type, address_str) {
75 eval('var address = ' + address_str + ';');
76 $('#edit-' + type + '-first-name').val(address['first_name']);
77 $('#edit-' + type + '-last-name').val(address['last_name']);
78 $('#edit-' + type + '-phone').val(address['phone']);
79 $('#edit-' + type + '-company').val(address['company']);
80 $('#edit-' + type + '-street1').val(address['street1']);
81 $('#edit-' + type + '-street2').val(address['street2']);
82 $('#edit-' + type + '-city').val(address['city']);
83 $('#edit-' + type + '-postal-code').val(address['postal_code']);
84
85 if ($('#edit-' + type + '-country').val() != address['country']) {
86 $('#edit-' + type + '-country').val(address['country']);
87 try {
88 uc_update_zone_select('#edit-' + type + '-country', address['zone']);
89 }
90 catch (err) {}
91 }
92
93 $('#edit-' + type + '-zone').val(address['zone']);
94 }
95
96 /**
97 * Close the address book div.
98 */
99 function close_address_select(div) {
100 $(div).empty().removeClass('address-select-box');
101 return false;
102 }
103
104 /**
105 * Load the customer select div on the order edit screen.
106 */
107 function load_customer_search() {
108 if (customer_select == 'search' && $('#customer-select #edit-back').val() == null) {
109 return close_customer_select();
110 }
111
112 $.post(Drupal.settings.basePath + 'admin/store/orders/customer', {},
113 function (contents) {
114 $('#customer-select').empty().addClass('customer-select-box').append(contents);
115 $('#customer-select #edit-first-name').val($('#edit-billing-first-name').val());
116 $('#customer-select #edit-last-name').val($('#edit-billing-last-name').val());
117 customer_select = 'search';
118 }
119 );
120
121 return false;
122 }
123
124 function load_customer_search_results() {
125 var first_name = $('#customer-select #edit-first-name').val();
126 var last_name = $('#customer-select #edit-last-name').val();
127 var email = $('#customer-select #edit-email').val();
128
129 if (first_name == '') {
130 first_name = '0';
131 }
132 if (last_name == '') {
133 last_name = '0';
134 }
135 if (email == '') {
136 email = '0';
137 }
138
139 $.post(Drupal.settings.basePath + 'admin/store/orders/customer/search/' + first_name + '/' + last_name + '/' + email,
140 { },
141 function (contents) {
142 $('#customer-select').empty().append(contents);
143 }
144 );
145 return false;
146 }
147
148 function select_customer_search() {
149 var data = $('#edit-cust-select').val();
150 $('#edit-uid').val(data.substr(0, data.indexOf(':')));
151 $('#edit-uid-text').val(data.substr(0, data.indexOf(':')));
152 $('#edit-primary-email').val(data.substr(data.indexOf(':') + 1));
153 $('#edit-primary-email-text').val(data.substr(data.indexOf(':') + 1));
154 $('#edit-submit-changes').click();
155 return close_customer_select();
156 }
157
158 function load_new_customer_form() {
159 if (customer_select == 'new') {
160 return close_customer_select();
161 }
162
163 $.post(Drupal.settings.basePath + 'admin/store/orders/customer/new', {},
164 function (contents) {
165 $('#customer-select').empty().addClass('customer-select-box').append(contents);
166 customer_select = 'new';
167 }
168 );
169 return false;
170 }
171
172 function check_new_customer_address() {
173 var options = {
174 'email' : $('#customer-select #edit-email').val(),
175 'sendmail' : $('#customer-select #edit-sendmail').attr('checked')
176 };
177 $.post(Drupal.settings.basePath + 'admin/store/orders/customer/new/check/' + options['email'], options,
178 function (contents) {
179 $('#customer-select').empty().append(contents);
180 }
181 );
182 return false;
183 }
184
185 function select_existing_customer(uid, email) {
186 $('#edit-uid').val(uid);
187 $('#edit-uid-text').val(uid);
188 $('#edit-primary-email').val(email);
189 $('#edit-primary-email-text').val(email);
190 $('#edit-submit-changes').click();
191 return close_customer_select();
192 }
193
194 function close_customer_select() {
195 $('#customer-select').empty().removeClass('customer-select-box');
196 customer_select = '';
197 return false;
198 }
199
200 /**
201 * Load the products div on the order edit screen.
202 */
203 function uc_order_load_product_edit_div(order_id) {
204 $(document).ready(
205 function() {
206 add_order_save_hold();
207
208 show_product_throbber();
209
210 $.post(Drupal.settings.basePath + 'admin/store/orders/' + order_id + '/products',
211 { action: 'view' },
212 function(contents) {
213 if (contents != '') {
214 $('#products-container').empty().append(contents);
215 }
216 remove_order_save_hold();
217 hide_product_throbber();
218 });
219 }
220 );
221 }
222
223 function load_product_select(order_id, search) {
224 if (search == true) {
225 options = {'search' : $('#edit-product-search').val()};
226 }
227 else {
228 options = { };
229 }
230
231 show_product_throbber();
232
233 $.post(Drupal.settings.basePath + 'admin/store/orders/' + order_id + '/product_select', options,
234 function (contents) {
235 $('#products-selector').empty().addClass('product-select-box2').append(contents);
236 hide_product_throbber();
237 }
238 );
239
240 return false;
241 }
242
243 function select_product() {
244 add_product_form();
245 return false;
246 }
247
248 function close_product_select() {
249 $('#products-selector').empty().removeClass('product-select-box2');
250 return false;
251 }
252
253 function add_product_form() {
254 add_product_browser = $('#products-selector').html();
255
256 show_product_throbber();
257
258 if (parseInt($('#edit-unid').val()) > 0) {
259 $.post(Drupal.settings.basePath + 'admin/store/orders/' + $('#edit-order-id').val() + '/add_product/' + $('#edit-unid').val(), { },
260 function(contents) {
261 $('#products-selector').empty().append(contents);
262 hide_product_throbber();
263 }
264 );
265 }
266 }
267
268 function add_product_to_order(order_id, node_id) {
269 var post_vars = fetch_product_data();
270 post_vars['action'] = 'add';
271 post_vars['nid'] = node_id;
272 post_vars['qty'] = $('#edit-add-qty').val();
273
274 $('#uc-order-add-product-form :input').each(
275 function() {
276 if ($(this).attr('name').substr(0, 10) == 'attributes') {
277 post_vars[$(this).attr('name')] = $(this).val();
278 }
279 }
280 );
281
282 show_product_throbber();
283
284 $.post(Drupal.settings.basePath + 'admin/store/orders/' + order_id + '/products', post_vars,
285 function(contents) {
286 if (contents != '') {
287 $('#products-container').empty().append(contents);
288 }
289 hide_product_throbber();
290 }
291 );
292
293 $('#add-product-button').click();
294
295 return false;
296 }
297
298 function fetch_product_data() {
299 var pdata = { };
300
301 $('.order-pane-table :input').each(
302 function() {
303 pdata[$(this).attr('name')] = $(this).val();
304 }
305 );
306
307 return pdata;
308 }
309
310 function add_blank_line_button(order_id) {
311 var post_vars = fetch_product_data();
312 post_vars['action'] = 'add_blank';
313
314 show_product_throbber();
315
316 $.post(Drupal.settings.basePath + 'admin/store/orders/' + order_id + '/products',
317 post_vars,
318 function(contents) {
319 if (contents != '') {
320 $('#products-container').empty().append(contents);
321 }
322 hide_product_throbber();
323 }
324 );
325 }
326
327 function remove_product_button(message, opid) {
328 if (confirm(message)) {
329 var post_vars = fetch_product_data();
330 post_vars['action'] = 'remove';
331 post_vars['opid'] = opid;
332
333 show_product_throbber();
334
335 $.post(Drupal.settings.basePath + 'admin/store/orders/' + $('#edit-order-id').val() + '/products',
336 post_vars,
337 function(contents) {
338 if (contents != '') {
339 $('#products-container').empty().append(contents);
340 }
341 hide_product_throbber();
342 }
343 );
344 }
345 }
346
347 function confirm_line_item_delete(message, img_id) {
348 if (confirm(message)) {
349 var li_id = img_id.substring(3);
350 $('#edit-li-delete-id').val(li_id);
351 $('#uc-order-edit-form #edit-submit-changes').click();
352 }
353 }
354
355 // Disable order submit button while parts of the page are still loading.
356 function add_order_save_hold() {
357 order_save_holds++;
358 $('#uc-order-edit-form input.save-button').attr('disabled', 'disabled');
359 }
360
361 // Remove a hold and enable the save buttons when all holds are gone!
362 function remove_order_save_hold() {
363 order_save_holds--;
364
365 if (order_save_holds == 0) {
366 release_held_buttons();
367 }
368 }
369
370 // Removes the disable attribute on any input item with the save-button class.
371 function release_held_buttons() {
372 $('#uc-order-edit-form input.save-button').removeAttr('disabled');
373 }
374
375 function show_product_throbber() {
376 $('#product-div-throbber').attr('style', 'background-image: url(' + Drupal.settings.basePath + 'misc/throbber.gif); background-repeat: no-repeat; background-position: 100% -20px;').html('    ');
377 }
378
379 function hide_product_throbber() {
380 $('#product-div-throbber').removeAttr('style').empty();
381 }
382

  ViewVC Help
Powered by ViewVC 1.1.2