Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.39 KB | None | 0 0
  1. // var script = document.createElement('script');
  2. // script.src = '//code.jquery.com/jquery-3.4.1.min.js';
  3. // document.getElementsByTagName('head')[0].appendChild(script);
  4.  
  5.  
  6. var siteNameValidator;
  7. var siteTypeValidator;
  8. var siteDescriptionValidator;
  9. var existingSiteValidator;
  10. var urlNameValidator;
  11. var suffixValidator;
  12. var bossSurnameValidator;
  13. var secondBossSurnameValidator;
  14. var superiorUnitValidator;
  15. var bossEmailValidator;
  16. var secondBossEmailValidator;
  17.  
  18.  
  19. function createValidators(sbs) {
  20.  
  21. AUI().use('aui-form-validator', function (A) {
  22. var defaultFormValidator = A.config.FormValidator;
  23. A.mix(
  24. defaultFormValidator.RULES,
  25. {
  26. siteName: function (val, fieldNode, ruleValue) {
  27. var regexp = /^[a-zA-Z\-\z\ż\ź\ć\ń\ó\ł\ę\ą\ś\Ż\Ź\Ć\Ą\Ś\Ę\Ł\Ó\Ń\!\+\(\)\/\'\"\;\,\:\?\s]+$/;
  28. siteNameValidator = checkField(val, regexp);
  29. enableButton("#btSubmit", areViewValidatorsTrue, sbs);
  30. return siteNameValidator;
  31.  
  32. },
  33. siteDescription: function (val) {
  34. var regexp = /^[a-zA-Z\-\z\ż\ź\ć\ń\ó\ł\ę\ą\ś\Ż\Ź\Ć\Ą\Ś\Ę\Ł\Ó\Ń\!\+\(\)\/\'\"\;\,\.\:\?\s]+$/;
  35. siteDescriptionValidator = checkField(val, regexp);
  36. enableButton("#btSubmit", areViewValidatorsTrue, sbs);
  37. return siteDescriptionValidator;
  38. },
  39. existingSite: function (val) {
  40. var regexp = /^[a-zA-Z\-\/\.]+$/;
  41. existingSiteValidator = checkField(val, regexp);
  42. enableButton("#btSubmit", areViewValidatorsTrue, sbs);
  43. return existingSiteValidator;
  44. },
  45. urlName: function (val) {
  46. var regexp = /^[a-z0-9\-\.]+$/;
  47. urlNameValidator = checkField(val, regexp);
  48. enableButton("#btSubmit2", areSecondValidatorsTrue, sbs);
  49. return urlNameValidator;
  50. },
  51. suffix: function (val) {
  52. var regexp = /^[a-z0-9\-\.]+$/;
  53. suffixValidator = checkField(val, regexp);
  54. enableButton("#btSubmit2", areSecondValidatorsTrue, sbs);
  55. return suffixValidator;
  56. },
  57. bossSurname: function (val) {
  58. var regexp = /^[a-zA-Z\-\z\ż\ź\ć\ń\ó\ł\ę\ą\ś\Ż\Ź\Ć\Ą\Ś\Ę\Ł\Ó\Ń]+$/;
  59. bossSurnameValidator = checkField(val, regexp);
  60. enableButton("#btSubmit2", areSecondValidatorsTrue, sbs);
  61. return bossSurnameValidator;
  62. },
  63. secondBossSurname: function (val) {
  64. var regexp = /^[a-zA-Z\-\z\ż\ź\ć\ń\ó\ł\ę\ą\ś\Ż\Ź\Ć\Ą\Ś\Ę\Ł\Ó\Ń]+$/;
  65. secondBossSurnameValidator = checkField(val, regexp);
  66. enableButton("#btSubmit2", areSecondValidatorsTrue, sbs);
  67. return secondBossSurnameValidator;
  68. },
  69. superiorUnit: function (val) {
  70. var regexp = /^[a-zA-Z0-9\-\.\,\z\ż\ź\ć\ń\ó\ł\ę\ą\ś\Ż\Ź\Ć\Ą\Ś\Ę\Ł\Ó\Ń\s]+$/;
  71. superiorUnitValidator = checkField(val, regexp);
  72. enableButton("#btSubmit2", areSecondValidatorsTrue, sbs);
  73. return superiorUnitValidator;
  74. }
  75. },
  76. true
  77. );
  78. A.mix(
  79. defaultFormValidator.STRINGS,
  80. {
  81. siteName: Liferay.Language.get('please-enter-a-valid-site-name'),
  82. siteDescription: Liferay.Language.get('please-select-a-valid-site-description'),
  83. existingSite: Liferay.Language.get('please-select-a-valid-existing-site'),
  84. urlName: Liferay.Language.get('please-enter-a-valid-url-name'),
  85. suffix: Liferay.Language.get('please-enter-a-valid-suffix'),
  86. bossSurname: Liferay.Language.get('please-enter-a-valid-boss-surname'),
  87. secondBossSurname: Liferay.Language.get('please-enter-a-valid-second-boss-surname'),
  88. superiorUnit: Liferay.Language.get('please-choose-a-valid-superior-unit')
  89. },
  90. true
  91. );
  92.  
  93. console.log(A.config);
  94. console.log(A.FormValidator);
  95.  
  96.  
  97. });
  98. }
  99.  
  100. function checkField(value, regex) {
  101. return regex.test(value);
  102. }
  103.  
  104.  
  105. function enableButton(idButton, areAllValidatorsTrue, sBS) {
  106. var A = AUI();
  107. var button = A.one(idButton);
  108. if(areAllValidatorsTrue(sBS)) {
  109. button.attr("disabled", false);
  110. button.attr("class", "btn btn-primary");
  111. } else {
  112. button.attr("disabled", "true");
  113. }
  114. }
  115.  
  116.  
  117. function areViewValidatorsTrue(isExistingSiteField) {
  118. console.log("\n");
  119. console.log("Walidatory:");
  120. console.log(siteNameValidator);
  121. console.log(siteDescriptionValidator);
  122. console.log(siteTypeValidator);
  123. console.log(existingSiteValidator);
  124. if(isExistingSiteField.value == "true") {
  125. console.log("4 if");
  126. return siteNameValidator && siteTypeValidator && siteDescriptionValidator && existingSiteValidator;
  127. } else {
  128. console.log("3 if");
  129. return siteNameValidator && siteTypeValidator && siteDescriptionValidator;
  130. }
  131. }
  132.  
  133. function areSecondValidatorsTrue(sBS) {
  134. if (sBS.type == "hidden" || sBS.disabled == true) {
  135. // if there is no secondBossSurname
  136. // if (rOA.disabled == false)
  137. // if there is manual suffix
  138. return urlNameValidator && suffixValidator && bossSurnameValidator
  139. && superiorUnitValidator;
  140. // else
  141. // return urlNameValidator && bossSurnameValidator && superiorUnitValidator;
  142.  
  143. } else {
  144. // if (rOA.disabled == false)
  145. return urlNameValidator && suffixValidator && bossSurnameValidator
  146. && secondBossSurnameValidator && superiorUnitValidator;
  147. // else
  148. // return urlNameValidator && bossSurnameValidator && secondBossSurnameValidator
  149. // && superiorUnitValidator;
  150. }
  151. }
  152.  
  153. function areEmailValidatorsTrue() {
  154. if(isSecondBoss) {
  155. console.log("2 if");
  156. console.log(window.bossEmailValidator);
  157. console.log(window.secondBossEmailValidator);
  158. return window.bossEmailValidator && window.secondBossEmailValidator;
  159. } else {
  160. console.log('1 if');
  161. return window.bossEmailValidator;
  162. }
  163. }
  164.  
  165. function validateOnKeyUp(formValidator, inputObject) {
  166.  
  167. console.log(inputObject.toString());
  168.  
  169. if(inputObject.toString().startsWith("SELECT")) {
  170. inputObject.on('click', function (event) {
  171. if(inputObject.toString().includes("siteType")) {
  172. window.formSelectValidator.validateField(inputObject);
  173. formValidator.validateField(inputObject);
  174. }
  175. else if(inputObject.toString().includes("bossEmail")) {
  176. window.formBossValidator.validateField(inputObject);
  177. formValidator.validateField(inputObject);
  178. }
  179. else if(inputObject.toString().includes("secondBossEmail")) {
  180. window.formSecondBossValidator.validateField(inputObject);
  181. formValidator.validateField(inputObject);
  182. }
  183. });
  184.  
  185. } else {
  186. inputObject.on('keyup', function (event) {
  187. formValidator.validateField(inputObject);
  188. });
  189. }
  190.  
  191. }
  192.  
  193. var buttonPDF = document.getElementById("pdf");
  194. if(buttonPDF) {
  195. buttonPDF.addEventListener("click", function () {
  196.  
  197. var doc = new jsPDF();
  198. doc.addFont("Abha.ttf", "Abha", "normal", "Identity-H");
  199. doc.setFont("Abha"); // set font
  200. doc.setFontSize(14);
  201. //doc.setTextColor(153,051,102);
  202. // doc.setCharSpace(1);
  203.  
  204. var today = new Date();
  205. var dd = String(today.getDate()).padStart(2, '0');
  206. var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
  207. var yyyy = today.getFullYear();
  208. today = dd + '.' + mm + '.' + yyyy + 'r.';
  209. doc.drawText("Kraków, " + today, 151, 18);
  210.  
  211.  
  212. doc.setFontSize(14);
  213. doc.drawText("Sekcja ds. Portalu Uniwersyteckiego", 70, 30);
  214. doc.setFontStyle("bold");
  215. doc.drawText("WNIOSEK",90, 45);
  216. doc.setFontStyle("normal");
  217. doc.setFont("Abha");
  218. doc.drawText("Zwracamy się z uprzejmą prośbą" +
  219. " o zgodę na utworzenie witryny naszej",25, 60);
  220. doc.drawText("jednostki w Portalu UJ.", 25, 65);
  221. doc.drawText("Poniżej załączamy wymagane dane: ", 25, 70);
  222.  
  223. doc.setFontSize(12);
  224. doc.drawText("Nazwa witryny ",25, 85);
  225. doc.setFontSize(14);
  226. doc.drawText(name,25, 92);
  227. doc.setFontSize(5);
  228. doc.drawText("...................................................................." +
  229. ".................................................................................." +
  230. ".................................................................................." +
  231. ".................................................................................." +
  232. ".................................................................................." +
  233. "............................................................................", 25, 93);
  234. doc.setFontSize(12);
  235. doc.drawText("Rodzaj witryny ",25, 105);
  236. doc.setFontSize(14);
  237. doc.drawText( type,25, 112);
  238. doc.setFontSize(5);
  239. doc.drawText("...................................................................." +
  240. ".................................................................................." +
  241. ".................................................................................." +
  242. ".................................................................................." +
  243. ".................................................................................." +
  244. "............................................................................", 25, 113);
  245.  
  246. doc.setFontSize(12);
  247. doc.drawText("Opis witryny ",25, 125);
  248. doc.setFontSize(14);
  249. doc.drawText(description,25, 132);
  250. doc.setFontSize(5);
  251. doc.drawText("...................................................................." +
  252. ".................................................................................." +
  253. ".................................................................................." +
  254. ".................................................................................." +
  255. ".................................................................................." +
  256. "............................................................................", 25, 133);
  257.  
  258. doc.setFontSize(12);
  259. doc.drawText("Adres witryny ",25, 145);
  260. doc.setFontSize(14);
  261. doc.drawText(address + "." + roa,25, 152);
  262. doc.setFontSize(5);
  263. doc.drawText("...................................................................." +
  264. ".................................................................................." +
  265. ".................................................................................." +
  266. ".................................................................................." +
  267. ".................................................................................." +
  268. "............................................................................", 25, 153);
  269.  
  270. doc.setFontSize(12);
  271. doc.drawText("Jednostka nadrzędna ",25, 165);
  272. doc.setFontSize(14);
  273. doc.drawText(superiorUnit,25, 172);
  274. doc.setFontSize(5);
  275. doc.drawText("...................................................................." +
  276. ".................................................................................." +
  277. ".................................................................................." +
  278. ".................................................................................." +
  279. ".................................................................................." +
  280. "............................................................................", 25, 173);
  281.  
  282. doc.setFontSize(12);
  283. doc.drawText("Email przełożonego ",25, 185);
  284. doc.setFontSize(14);
  285. doc.drawText(bossEmail,25, 192);
  286. doc.setFontSize(5);
  287. doc.drawText("...................................................................." +
  288. ".................................................................................." +
  289. ".................................................................................." +
  290. ".................................................................................." +
  291. ".................................................................................." +
  292. "............................................................................", 25, 193);
  293.  
  294. if(secondBossEmail != "brak") {
  295. doc.setFontSize(12);
  296. doc.drawText("Email drugiego przełożonego ", 25, 205);
  297. doc.setFontSize(14);
  298. doc.drawText(secondBossEmail, 25, 212);
  299. doc.setFontSize(5);
  300. doc.drawText("...................................................................." +
  301. ".................................................................................." +
  302. ".................................................................................." +
  303. ".................................................................................." +
  304. ".................................................................................." +
  305. "............................................................................", 25, 213);
  306. }
  307.  
  308.  
  309. doc.setFontSize(14);
  310. doc.drawText("Podpis i pieczęć", 120, 240);
  311. doc.drawText("Dziekana/Kierownika/Dyrektora/ ...", 99, 245);
  312.  
  313. doc.save("wniosek.pdf");
  314. });
  315. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement