templates/shipToForm.js.twig line 1

Open in your IDE?
  1. var groupArray = {{ groupArray|raw }};
  2. var myInt = 0;
  3. var product_options = '<option value="" title="Choose a product!">Choose a product here!</option>{{ productOptions|raw }}';
  4. var sizeArray = {{ sizeArray|raw }};
  5. var v_quantity = 0;
  6. var objID;
  7. var v_index = -1;
  8. var RecipientNumber = 0;
  9. var OrderLineNumber = 0;
  10. var size_options = ' ';
  11. var recip_nums = [];
  12. var order_nums = [];
  13. var ShipToSectionNumber = 0;
  14. var myShip2Int = 0;
  15. function format_number(pnumber, decimals) {
  16. if (isNaN(pnumber) || pnumber === '') {
  17. return 0;
  18. }
  19. var snum = String(pnumber);
  20. var sec = snum.split('.');
  21. var whole = parseFloat(sec[0]);
  22. var result = '';
  23. var dot;
  24. var dec;
  25. if (sec.length > 1) {
  26. dec = String(sec[1]);
  27. dec = String(parseFloat(sec[1]) / Math.pow(10, (dec.length - decimals)));
  28. dec = String(whole + Math.round(parseFloat(dec)) / Math.pow(10, decimals));
  29. dot = dec.indexOf('.');
  30. if (dot == -1) {
  31. dec += '.';
  32. dot = dec.indexOf('.');
  33. }
  34. while (dec.length <= dot + decimals) {
  35. dec += '0';
  36. }
  37. result = dec;
  38. } else {
  39. dec = String(whole);
  40. dec += '.';
  41. dot = dec.indexOf('.');
  42. while (dec.length <= dot + decimals) {
  43. dec += '0';
  44. }
  45. result = dec;
  46. }
  47. return result;
  48. }
  49. function calcPrice(lineNo, RecipientNo) {
  50. var v_price = '0.00';
  51. v_quantity = $('#' + RecipientNo.toString() + 'quantity' + lineNo.toString()).val();
  52. v_index = $('#' + RecipientNo.toString() + 'product' + lineNo).val();
  53. objID = '#' + RecipientNo.toString() + 'size' + lineNo.toString();
  54. $(objID).removeAttr("disabled").attr("enabled", "enabled");
  55. if (v_index > '') {
  56. if (v_quantity == '' || isNaN(parseInt(v_quantity)) || v_quantity < 0) {
  57. v_quantity = 0;
  58. }
  59. v_price = $('#' + RecipientNo.toString() + 'size' + lineNo.toString()).val() * v_quantity;
  60. if (v_price == 0) {
  61. v_price = '0';
  62. }
  63. $('#' + RecipientNo.toString() + 'price' + lineNo.toString()).val(format_number(v_price, 2));
  64. var tmp_value = accumulatePrice();
  65. $('#total_price').val(format_number(tmp_value, 2));
  66. $('#submit_order').attr("disabled", (tmp_value === 0));
  67. size_options = sizeArray[groupArray[v_index]['group_id'] - 1]['options'];
  68. }
  69. }
  70. function accumulatePrice() {
  71. var tmp_value = 0;
  72. $.each($('.price'), function (i, val) {
  73. tmp_value += parseFloat(val.value);
  74. });
  75. return tmp_value;
  76. }
  77. function removeOrderLine(lineNo, RecipientNo) {
  78. if (confirm("Are you sure you want to remove the order line?")) {
  79. $('#' + RecipientNo.toString() + 'row' + lineNo.toString()).remove();
  80. $('#total_price').val(format_number(accumulatePrice(), 2));
  81. calcPrice(lineNo, RecipientNo);
  82. var i = 0;
  83. while (order_nums[RecipientNo][i] <= lineNo && order_nums[RecipientNo][i] != 'undefined') {
  84. i++;
  85. }
  86. order_nums[RecipientNo].splice(i, 1);
  87. return false;
  88. }
  89. }
  90. function processProductChange(lineNo, RecipientNo) {
  91. calcPrice(lineNo, RecipientNo);
  92. objID = '#' + RecipientNo.toString() + 'size' + lineNo.toString();
  93. $(objID).html(size_options).change();
  94. }
  95. /**
  96. * @return {string}
  97. */
  98. function GenerateOrderLine(RecipientNumber) {
  99. order_nums[RecipientNumber].push(OrderLineNumber);
  100. var myOrderLine = '<tr class="order_line" id="' + RecipientNumber.toString() + 'row' +
  101. OrderLineNumber.toString() +
  102. '"><td>\n<select onchange="processProductChange(' +
  103. OrderLineNumber.toString() + ', ' + RecipientNumber.toString() + ')" name="' + RecipientNumber.toString() + 'product' +
  104. OrderLineNumber.toString() + '" id="' + RecipientNumber.toString() + 'product' +
  105. OrderLineNumber.toString() + '">\n' + product_options +
  106. '\n</select>\n</td><td style="text-align: left;"><select onchange="calcPrice(' +
  107. OrderLineNumber.toString() + ', ' + RecipientNumber.toString() + ', false)" name="' + RecipientNumber.toString() + 'size' +
  108. OrderLineNumber.toString() + '" id="' + RecipientNumber.toString() + 'size' +
  109. OrderLineNumber.toString() + '" disabled="disabled">' + size_options +
  110. '\n</select>\n</td>\n<td>\n<input size="2" maxlength="3" ' +
  111. 'onkeyup="calcPrice(' +
  112. OrderLineNumber.toString() + ', ' + RecipientNumber.toString() +
  113. ')" style="text-align: right; width: 100%;" name="' + RecipientNumber.toString() + 'quantity' +
  114. OrderLineNumber.toString() + '" id="' + RecipientNumber.toString() + 'quantity' +
  115. OrderLineNumber.toString() + '" class="' + RecipientNumber.toString() + 'quantity' +
  116. OrderLineNumber.toString() +
  117. '" />\n</td>\n<td>\n<input id="' + RecipientNumber.toString() + 'price' +
  118. OrderLineNumber.toString() + '" name="' + RecipientNumber.toString() + 'price' +
  119. OrderLineNumber.toString() +
  120. '" class="price" value="0.00" size="8" style="text-align: right;"' +
  121. ' disabled="disabled" />\n</td>\n<td>\n' +
  122. '<a class="del_row" id="' + RecipientNumber.toString() + 'rem' + OrderLineNumber.toString() +
  123. '" href="javascript:;" onclick="removeOrderLine(' +
  124. OrderLineNumber.toString() + ', ' + RecipientNumber.toString() + '); return false;">X</a>\n</td>\n</tr>';
  125. calcPrice(OrderLineNumber, RecipientNumber);
  126. return myOrderLine;
  127. }
  128. /**
  129. * @return {string}
  130. */
  131. function GenerateShipToSection() {
  132. recip_nums.push(ShipToSectionNumber);
  133. order_nums[ShipToSectionNumber] = [];
  134. return '\n<table class="ship2row" id="ship2row' + ShipToSectionNumber.toString() + '">' +
  135. '\n<tr>' +
  136. '\n<td class="ship2sectionheader" colspan="2">' +
  137. '\n<input type="hidden" name="order_nums' + ShipToSectionNumber.toString() + '" />Ship To Address' +
  138. '\n</td>' +
  139. '\n</tr>' +
  140. '\n<tr>' +
  141. '\n<td class="ship2desc">' +
  142. '\nName: ' +
  143. '\n</td>' +
  144. '\n<td class="ship2item" id="ship2row' + ShipToSectionNumber.toString() + '">' +
  145. '\n<input id="ship_name' + ShipToSectionNumber.toString() + '" name="ship_name' + ShipToSectionNumber.toString() + '" type="text" size="63" />' +
  146. '\n</td>' +
  147. '\n</tr>' +
  148. '\n<tr>' +
  149. '\n<td class="ship2desc">' +
  150. '\nStreet: ' +
  151. '\n</td>' +
  152. '\n<td class="ship2item" id="ship2row' + ShipToSectionNumber.toString() + '">' +
  153. '\n<input name="ship_street' + ShipToSectionNumber.toString() + '" id="ship_street' + ShipToSectionNumber.toString() + '" type="text" size="63" />' +
  154. '\n</td>' +
  155. '\n</tr>' +
  156. '\n<tr>' +
  157. '\n<td>' +
  158. '\n<input name="order_nums' + ShipToSectionNumber.toString() + '" id="order_nums' + ShipToSectionNumber.toString() + '" type="hidden" />&nbsp;' +
  159. '\n</td>' +
  160. '\n<td class="ship2item" id="ship2row' + ShipToSectionNumber.toString() + '">' +
  161. '\n<input name="ship_street_2' + ShipToSectionNumber.toString() + '" id="ship_street_2' + ShipToSectionNumber.toString() + '" type="text" size="63" />' +
  162. '\n</td>' +
  163. '\n</tr>' +
  164. '\n<tr>' +
  165. '\n<td class="ship2desc">' +
  166. '\n<label for="ship2row' + ShipToSectionNumber.toString() + '">City:</label> ' +
  167. '\n</td>' +
  168. '\n<td class="ship2item csz" id="ship2row' + ShipToSectionNumber.toString() + '">' +
  169. '\n<input name="ship_city' + ShipToSectionNumber.toString() + '" id="ship_city' + ShipToSectionNumber.toString() + '" type="text" size="33" />&nbsp;' +
  170. '\n<label>State: <input name="ship_state' + ShipToSectionNumber.toString() + '" id="ship_state' + ShipToSectionNumber.toString() + '" type="text" size="2" /></label>' +
  171. '\n<label>Zip: <input name="ship_zip' + ShipToSectionNumber.toString() + '" id="ship_zip' + ShipToSectionNumber.toString() + '" type="text" size="10" /></label>' +
  172. '\n</td>' +
  173. '\n</tr>' +
  174. '\n<tr>' +
  175. '\n<td class="ship2item" id="ship2row' + ShipToSectionNumber.toString() + '" colspan="2">' +
  176. '\n<input style="margin-left: 20%;" id="bus_add' + ShipToSectionNumber.toString() + '" name="bus_add' + ShipToSectionNumber.toString() + '" type="checkbox" /> This is a Business Address' +
  177. '\n</td>' +
  178. '\n</tr>' +
  179. '\n<tr>' +
  180. '\n<td class="ship2item" id="ship2row' + ShipToSectionNumber.toString() + '" colspan="2">' +
  181. '\n<input style="margin-left: 20%;" id="ship_now' + ShipToSectionNumber.toString() + '" name="ship_now' + ShipToSectionNumber.toString() + '" type="checkbox" /> Ship now' +
  182. '\n</td>' +
  183. '\n</tr>' +
  184. '\n<tr>' +
  185. '\n<td class="csz" id="ship2row' + ShipToSectionNumber.toString() + '" colspan="2">' +
  186. '\n<input style="margin-left: 20%;" id="ship_later' + ShipToSectionNumber.toString() + '" name="ship_later' + ShipToSectionNumber.toString() + '" type="checkbox" checked="checked" /> <label>To Arrive the week of&nbsp;' +
  187. '\n<input id="ship_month' + ShipToSectionNumber.toString() + '" name="ship_month' + ShipToSectionNumber.toString() + '" type="text" size="2" /></label> <label>/ <input id="ship_year' + ShipToSectionNumber.toString() + '" name="ship_year' + ShipToSectionNumber.toString() + '" type="text" size="2" /></label>' +
  188. '\n</td>' +
  189. '\n</tr>' +
  190. '\n<tr>' +
  191. '\n<td class="csz ship2row" id="ship2row' + ShipToSectionNumber.toString() + '" colspan="2">' +
  192. '\n<input style="margin-left: 20%;" id="greeting' + ShipToSectionNumber.toString() + '" name="greeting' + ShipToSectionNumber.toString() + '" type="checkbox" checked="checked" /> <label>Greetings From ' +
  193. '\n<input title="Maximum characters allowed is 100!" maxlength="100" id="greetings_to' + ShipToSectionNumber.toString() + '" name="greetings_to' + ShipToSectionNumber.toString() + '" type="text" size="57" /></label></td></tr>' +
  194. '\n<tr>' +
  195. '\n<td colspan="2">&nbsp;</td>' +
  196. '\n</tr>' +
  197. '\n<tr>' +
  198. '\n<td height="16" colspan="2">' +
  199. '\n<table class="order_table" id="order_table' + ShipToSectionNumber.toString() + '">' +
  200. '\n<thead>' +
  201. '\n<tr>' +
  202. '\n<th>Description</th>' +
  203. '\n<th>Size</th>' +
  204. '\n<th>Qty</th>' +
  205. '\n<th>Total</th>' +
  206. '\n<th>&nbsp;</th>' +
  207. '\n</tr>' +
  208. '\n</thead>' +
  209. '\n<tbody id="order_head' + ShipToSectionNumber.toString() + '" style="height:10pt;">' +
  210. '\n</tbody>' +
  211. '\n<tfoot>' +
  212. '\n<tr>' +
  213. '\n<th colspan="5">' +
  214. '\n<input type="button" value="Add Product" id="add_product' + ShipToSectionNumber.toString() + '" name="add_product' + ShipToSectionNumber.toString() + '" />' +
  215. '\n</th>' +
  216. '\n</tr>' +
  217. '\n</tfoot>' +
  218. '\n</table>' +
  219. '\n</td>' +
  220. '\n</tr>' +
  221. '\n<tr>\n<td class="del_recip" colspan="2">\n<a name="rem' + ShipToSectionNumber.toString() +
  222. '" href="javascript:;" onclick="removeShipToSection(' + (ShipToSectionNumber++).toString() + '); return false;">Remove Recipient</a>\n' +
  223. '</td>\n' +
  224. '</tr>\n' +
  225. '</table>\n';
  226. }
  227. function removeShipToSection(ship2No) {
  228. if (confirm("Are you sure you want to remove the ship to section?")) {
  229. $("#ship2row" + ship2No.toString()).remove();
  230. var i = 0;
  231. while (recip_nums[i] <= ship2No && recip_nums[i] != 'undefined') {
  232. i++;
  233. }
  234. recip_nums.splice(i, 1);
  235. return false;
  236. }
  237. }
  238. function popVals() {
  239. $('#recip_nums').val(recip_nums.join());
  240. var len = recip_nums.length;
  241. for (var i = 0; i < len; i++) {
  242. $('#order_nums' + recip_nums[i]).val(order_nums[recip_nums[i]].join());
  243. }
  244. }
  245. $(document).ready(function () {
  246. $('#add_ship_to' + RecipientNumber.toString())
  247. .click(function () {
  248. ShipToSectionNumber = myShip2Int;
  249. $('#ship_to_head0').append(GenerateShipToSection());
  250. myShip2Int++;
  251. $('#add_product' + RecipientNumber.toString())
  252. .click(function () {
  253. size_options = "<option value='0' selected='selected'>Choose size here!</option>";
  254. var recip = this.id.unformat('add_product{0}')[0];
  255. OrderLineNumber = myInt;
  256. $('#order_head' + recip).append(GenerateOrderLine(recip));
  257. myInt++;
  258. }).click();
  259. RecipientNumber++;
  260. }).click();
  261. $("#bill_name").focus();
  262. });