set_liquid.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. var i = 1;
  2. function Add(evt){
  3. evt.style.display="none";
  4. i ++;
  5. var div = document.createElement('div');
  6. var from_hr = 'from_hr' + i;
  7. var from_min = 'from_min' + i;
  8. var to_hr = 'to_hr' + i;
  9. var to_min = 'to_min' + i;
  10. var id = evt.getAttribute('id');
  11. var len = id.length;
  12. var name = id.split('_')[0];
  13. var add = id.split('_')[0] + '_add' + i;
  14. var del = id.split('_')[0] + '_del' + i;
  15. var html = '';
  16. div.className = "col-12 row";
  17. div.style.marginTop = "10px";
  18. html += '<div class="col-xl-5 col-lg-5 col-md-4" style="margin-top:10px;">';
  19. html += '<span>Duration</span>';
  20. if(id.split('_')[0] == 'tank1'){
  21. html += ' <select name="tank1_duration' + i + '" class="duration">';
  22. }else if(id.split('_')[0] == 'tank2'){
  23. html += ' <select name="tank2_duration' + i + '" class="duration">';
  24. }else{
  25. html += '<select name="tank2_duration' + i + '" class="duration">';
  26. };
  27. html += '<option selected value="30min">30 min</option>';
  28. html += '<option value="60min">60 min</option>';
  29. html += '<option value="90min">90 min</option>';
  30. html += '<option value="120min">120 min</option>';
  31. html += '<option value="150min">150 min</option>';
  32. html += '</select>';
  33. html += '</div>';
  34. html += '<div class="from-to col-xl-7 col-lg-7 col-md-8" style="margin-top:10px;">';
  35. html += '<div>';
  36. html += '<div class="from row">';
  37. html += '<div class="col-xs-3">';
  38. html += '<span> From</span>';
  39. html += '</div>';
  40. html += '<div class="col-xs-6">';
  41. html += '<select name="' + name + '_from_hr' + i + '">';
  42. for(var hr = 0; hr < 24; hr++){
  43. if(hr < 10){
  44. html += '<option value="0' + hr + '">0' + hr + '</option>';
  45. }else{
  46. html += '<option value="' + hr + '">' + hr + '</option>';
  47. };
  48. };
  49. html += '</select>';
  50. html += ' :<select name="' + name + '_from_min' + i + '">';
  51. for(var min = 0; min < 60; min++){
  52. if(min < 10){
  53. html += '<option value="0' + min + '">0' + min + '</option>';
  54. }else{
  55. html += '<option value="' + min + '">' + min + '</option>';
  56. };
  57. };
  58. html += '</select>';
  59. html += '</div>';
  60. html += '<div class="col-xs-3">';
  61. html += '<input id=' + del + ' class="delete" type="button" value="Delete" onclick="Delete(' + del + ');">';
  62. html += '</div>';
  63. html += '</div>';
  64. html += '<div class="to row">';
  65. html += '<div class="col-xs-3">';
  66. html += '<span style="margin-left: 23px;">To</span>';
  67. html += '</div>';
  68. html += '<div class="col-xs-6">';
  69. html += '<select name="' + name + '_to_hr' + i + '">';
  70. for(var hr = 0; hr < 24; hr++){
  71. if(hr < 10){
  72. html += '<option value="0' + hr + '">0' + hr + '</option>';
  73. }else{
  74. html += '<option value="' + hr + '">' + hr + '</option>';
  75. };
  76. };
  77. html += '</select>';
  78. html += ' :<select name="' + name + '_to_min' + i + '">';
  79. for(var min = 0; min < 60; min++){
  80. if(min < 10){
  81. html += '<option value="0' + min + '">0' + min + '</option>';
  82. }else{
  83. html += '<option value="' + min + '">' + min + '</option>';
  84. };
  85. };
  86. html += '</select><br>';
  87. html += '<input id=' + add + ' class="add" type="button" value="Add" onclick="Add(' + add + ');">';
  88. html += '</div>';
  89. html += '<div class="col-xs-3"></div>';
  90. html += '</div>';
  91. html += '</div>';
  92. html += '</div>';
  93. div.innerHTML = html;
  94. div.style.marginTop = '15px';
  95. div.style.zIndex = '100';
  96. evt.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.appendChild(div);
  97. };
  98. function Delete(evt){
  99. var id = evt.getAttribute('id');
  100. var add = id.split('_')[0] + '_' + 'add';
  101. var clo_xs_3 = evt.parentNode;
  102. var from = clo_xs_3.parentNode;
  103. var div = from.parentNode.parentNode.parentNode;
  104. var next_div = div.nextElementSibling;
  105. var pre_div = div.previousElementSibling;
  106. if(next_div && pre_div == null){
  107. div.parentNode.removeChild(div);
  108. next_div.style.marginTop = '0px';
  109. }else if(next_div && pre_div){
  110. div.parentNode.removeChild(div);
  111. }else if(next_div == null && pre_div == null){
  112. div.parentNode.parentNode.children[1].style.display = 'inline-block';
  113. div.parentNode.style.visibility = 'hidden';
  114. console.log("test");
  115. var name = id.split('_')[0];
  116. var from_hr = name + '_from_hr' + 1;
  117. var from_min = name + '_from_min' + 1;
  118. var to_hr = name + '_to_hr' + 1;
  119. var to_min = name + '_to_min' + 1;
  120. console.log(from_hr);
  121. $('select[name=' + from_hr + ']').val('00');
  122. $('select[name=' + from_min + ']').val('00');
  123. $('select[name=' + to_hr + ']').val('00');
  124. $('select[name=' + to_min + ']').val('00');
  125. }else{
  126. div.parentNode.removeChild(div);
  127. i --;
  128. add = add + i;
  129. add = document.getElementById(add);
  130. if(add == null){
  131. add = pre_div.children[1].children[0].children[1].children[1].children[3];
  132. };
  133. add.style.display = 'block';
  134. };
  135. };
  136. $(function(){
  137. var tank1 = $(".set-schedule")[0];
  138. var tank1_div = $("#tank1_div");
  139. var tank2 = $(".set-schedule")[1];
  140. var tank2_div = $("#tank2_div");
  141. tank1.onclick = function(){
  142. tank1.style.display = 'none';
  143. tank1_div.css('visibility','visible');
  144. };
  145. tank2.onclick = function(){
  146. tank2.style.display = 'none';
  147. tank2_div.css('visibility','visible');
  148. };
  149. $(".form-control")[0].onclick = function(){
  150. window.location.href = '/setting_root';
  151. };
  152. });