Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.81 KB | None | 0 0
  1. function getRandomInt(min, max) {
  2. return Math.floor(Math.random() * (max - min + 1)) + min;
  3. }
  4.  
  5. function getCheckDigit(value) {
  6.  
  7. const nif = value.toString();
  8.  
  9. const total = nif[0] * 9 + nif[1] * 8 + nif[2] * 7 + nif[3] * 6 + nif[4] * 5 + nif[5] * 4 + nif[6] * 3 + nif[7] * 2;
  10.  
  11. const modulo11 = (Number(total) % 11);
  12.  
  13. const checkDigit = modulo11 < 2 ? 0 : 11 - modulo11;
  14.  
  15. return checkDigit;
  16. }
  17.  
  18. function getNif(minAndMax) {
  19.  
  20. var minAndMaxSplitted = minAndMax.split("|");
  21.  
  22. var min= parseInt(minAndMaxSplitted[0]);
  23. var max= parseInt(minAndMaxSplitted[1]);
  24.  
  25. var random = getRandomInt(min, max);
  26.  
  27. var checkDigit = getCheckDigit(random);
  28.  
  29. var nif = random.toString() + checkDigit.toString();
  30.  
  31. return nif;
  32. }
  33.  
  34. function makeDate(start, end) {
  35. var date = new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
  36. date = $.datepicker.formatDate("dd-mm-yy", date);
  37. return date;
  38. }
  39.  
  40. function makeValue(type, length, minDate, maxDate) {
  41.  
  42. var characters = "";
  43.  
  44. if(type == 'only-letters')
  45. {
  46. characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  47. } else if(type == 'only-numbers') {
  48. characters = "1234567890";
  49. }else if(type == 'money') {
  50. characters = "1234567890";
  51. }else if(type == 'no-numbers') {
  52. characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZÇ#$%&/()?.-*€";
  53. } else {
  54. characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZÇ#$%&/()?.-*€123456789";
  55. }
  56.  
  57. var result = '';
  58. var charactersLength = characters.length;
  59. for ( var i = 0; i < length; i++ ) {
  60. result += characters.charAt(Math.floor(Math.random() * charactersLength));
  61. }
  62. if(type=='money')
  63. {
  64. result = (Number(result) / 100).toString();
  65. }
  66.  
  67. return result;
  68. }
  69.  
  70. function getRandomInt(min, max) {
  71. min = Math.ceil(min);
  72. max = Math.floor(max);
  73. return Math.floor(Math.random() * (max - min + 1)) + min;
  74. }
  75.  
  76. $('input[class*="form-field-input"]:not(.form-field-input-button)').each(function(){
  77.  
  78. var $this = $(this);
  79.  
  80. if(!$this.is(":visible") || $this.is('[readonly]'))
  81. return;
  82.  
  83. var value = "";
  84. if($this.hasClass("js-form-address-line"))
  85. return;
  86.  
  87. if($this.hasClass("input-mask-postCode")){
  88. value = "1495-139";
  89.  
  90. $this.val(value);
  91. $this.blur();
  92. return;
  93.  
  94. } else if($this.hasClass("input-mask-iban")){
  95. value = "003600709910009773572";
  96. $this.val(value);
  97. $this.blur();
  98. return;
  99. } else if($this.hasClass("input-mask-money")){
  100. value = makeValue('money', 5);
  101. } else if($this.hasClass("input-mask-phone")){
  102.  
  103. if($this.data("valRegexPattern").startsWith("^2"))
  104. {
  105. value = "21";
  106. }else if($this.hasClass("input-mask-phone")){
  107. value = "91";
  108. }
  109. value += makeValue('only-numbers', 7);
  110. } else
  111. if($this.hasClass("form-field-input-email"))
  112. {
  113. value = makeValue('only-letters', 7)+"@"+makeValue('only-letters', 4)+".pt";
  114. } else
  115. if($this.hasClass("input-mask-only-letters"))
  116. {
  117. value = makeValue('only-letters', 30);
  118. } else if($this.hasClass("input-mask-only-numbers"))
  119. {
  120. if($this.data("valIsvalidnif"))
  121. {
  122. value = getNif("10000000|29999999")
  123. } else {
  124. value = makeValue('only-numbers', 2);
  125. }
  126.  
  127. } else if($this.hasClass('input-mask-no-numbers'))
  128. {
  129. value = makeValue('no-numbers', 30);
  130. } else if($this.hasClass('form-field-input-date'))
  131. {
  132. console.log($this.data("scFieldName"),$this.datepicker('getStartDate'), $this.datepicker('getEndDate'))
  133. value = makeDate($this.datepicker('getStartDate'), $this.datepicker('getEndDate'));
  134. } else {
  135. value = makeValue('', 10);
  136. }
  137. $this.val(value);
  138. $this.trigger("change");
  139. });
  140.  
  141. $('.form-field-custom-dropdownlist:visible select[class*="form-field-select"]').each(function(){
  142. var $this = $(this);
  143. var options = $this.siblings(".select-items").children();
  144.  
  145. var optionToChoose = getRandomInt(1, options.length-1);
  146. var option = $(options[optionToChoose]);
  147. option.data("select-item").interact.call(option[0]);
  148. })
  149.  
  150. $('.form-field-label-radiobuttonlist:visible').each(function(){
  151. var $this = $(this);
  152.  
  153. var options = $this.parent().find('input.form-field-input-radiobutton');
  154.  
  155. var selectedOption = options.filter(function(){
  156. return $(this).is(":checked");
  157.  
  158. });
  159. if(selectedOption.length == 0)
  160. $($this.parent().find('.form-field-inner-label-radiobuttonlist')[0]).click();
  161.  
  162.  
  163. })
  164.  
  165.  
  166. $('.form-field-label-checkbox.form-field-required:visible').each(function(){
  167. var $this = $(this);
  168.  
  169. $this.find('.form-field-span-checkbox').click();
  170.  
  171. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement