Guest User

Untitled

a guest
Jan 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. // Finds what datetime selections have and have not been filled out
  2. // Also finds all the datetime selections that was passed in the array
  3. function find_max_filled_out( check_arrays )
  4. {
  5. var filled_out = [];
  6. var not_filled_out = [];
  7. var all_selections = [];
  8.  
  9. for ( check in check_arrays )
  10. {
  11. base = check_arrays[check][0];
  12. all_selections.push( base );
  13.  
  14. i = 1;
  15. while (i <= check_arrays[check][1])
  16. {
  17. select_string = '#' + base + '_' + i.toString() + 'i';
  18. select = $('#' + base + '_' + i.toString() + 'i');
  19. select_value = select.val();
  20.  
  21. if( select_value != '' & jQuery.inArray( base , filled_out )== -1 )
  22. {
  23. filled_out.push( base );
  24. }
  25. else if( select_value == '' & jQuery.inArray( base , not_filled_out )== -1
  26. {
  27. not_filled_out.push( base );
  28. }
  29. else
  30. {
  31. break;
  32. }
  33. i++;
  34. }
  35. }
  36.  
  37. return {
  38. 'filled_out' : filled_out,
  39. 'not_filled_out' : not_filled_out,
  40. 'all_selections' : all_selections
  41. };
  42. };
  43.  
  44.  
  45. // Adds warnings to all previous datetime selections that haven't been filled out
  46. $('#order_submit').live('click', function() {
  47.  
  48. var number_of_fields_order_order_date = '3'
  49. var number_of_fields_all_others = '5'
  50. var check_arrays = [
  51. ['order_order_date', number_of_fields_order_order_date],
  52. ['order_csr_received_at', number_of_fields_all_others],
  53. ['order_so_received_at', number_of_fields_all_others],
  54. ['order_warehouse_received_at', number_of_fields_all_others],
  55. ['order_staged_at', number_of_fields_all_others],
  56. ['order_order_qced_at', number_of_fields_all_others],
  57. ['order_shipped_at', number_of_fields_all_others],
  58. ['order_shipped_confirmed_at', number_of_fields_all_others],
  59. ];
  60.  
  61. // Call function to get all selections that have been filled out, have not
  62. // been filled out, and all the selections we are checking
  63. var return_values = find_max_filled_out( check_arrays );
  64. var filled_out = return_values.filled_out;
  65. var not_filled_out = return_values.not_filled_out;
  66. var all_selections = return_values.all_selections;
  67.  
  68. // Put all the indexs of the selections into in an array
  69. var index_holder = [];
  70.  
  71. // Get all the indexs for the selections that have been filled out
  72. for ( fill in filled_out )
  73. {
  74. //alert( 'x down here: ' + filled_out[ append_to ]);
  75. var find_index = jQuery.inArray( filled_out[fill], all_selections )
  76. // if index is not already in the array then add it
  77. if( find_index != -1 )
  78. {
  79. index_holder.push( find_index );
  80. ///alert('for value: ' + filled_out[ append_to ] + ' the index is: ' + find_
  81. }
  82. else
  83. {
  84. //alert('not found')
  85. break;
  86. }
  87. }
  88.  
  89. // Find the max index for selection that has been filled out, so we can
  90. // cascade down the selections
  91. Array.max = function( array ){
  92. return Math.max.apply( Math, array )
  93. }
  94.  
  95. // the highest index for the selections that have been filled out
  96. max_index = Array.max(index_holder);
  97.  
  98. // Get the selections that have not been filled out and have an index less
  99. // than the highest index for the selection that has been filled out
  100. for ( not_filled in not_filled_out )
  101. {
  102. check_index = jQuery.inArray( not_filled_out[not_filled], all_selections );
  103. if ( check_index != -1 & check_index < max_index )
  104. {
  105. alert( 'Add warning to ' + '#' + not_filled_out[not_filled] + '_input' );
  106. $('#' + not_filled_out[not_filled] + '_input').append('<p class="inline-errors">W
  107. }
  108. else
  109. {
  110. break;
  111. }
  112. };
  113. alert('Warning, there are some fields that should probably be filled out');
  114. });
Add Comment
Please, Sign In to add comment