Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // var script = document.createElement('script');
- // script.src = '//code.jquery.com/jquery-3.4.1.min.js';
- // document.getElementsByTagName('head')[0].appendChild(script);
- var siteNameValidator;
- var siteTypeValidator;
- var siteDescriptionValidator;
- var existingSiteValidator;
- var urlNameValidator;
- var suffixValidator;
- var bossSurnameValidator;
- var secondBossSurnameValidator;
- var superiorUnitValidator;
- var bossEmailValidator;
- var secondBossEmailValidator;
- function createValidators(sbs) {
- AUI().use('aui-form-validator', function (A) {
- var defaultFormValidator = A.config.FormValidator;
- A.mix(
- defaultFormValidator.RULES,
- {
- siteName: function (val, fieldNode, ruleValue) {
- var regexp = /^[a-zA-Z\-\z\ż\ź\ć\ń\ó\ł\ę\ą\ś\Ż\Ź\Ć\Ą\Ś\Ę\Ł\Ó\Ń\!\+\(\)\/\'\"\;\,\:\?\s]+$/;
- siteNameValidator = checkField(val, regexp);
- enableButton("#btSubmit", areViewValidatorsTrue, sbs);
- return siteNameValidator;
- },
- siteDescription: function (val) {
- var regexp = /^[a-zA-Z\-\z\ż\ź\ć\ń\ó\ł\ę\ą\ś\Ż\Ź\Ć\Ą\Ś\Ę\Ł\Ó\Ń\!\+\(\)\/\'\"\;\,\.\:\?\s]+$/;
- siteDescriptionValidator = checkField(val, regexp);
- enableButton("#btSubmit", areViewValidatorsTrue, sbs);
- return siteDescriptionValidator;
- },
- existingSite: function (val) {
- var regexp = /^[a-zA-Z\-\/\.]+$/;
- existingSiteValidator = checkField(val, regexp);
- enableButton("#btSubmit", areViewValidatorsTrue, sbs);
- return existingSiteValidator;
- },
- urlName: function (val) {
- var regexp = /^[a-z0-9\-\.]+$/;
- urlNameValidator = checkField(val, regexp);
- enableButton("#btSubmit2", areSecondValidatorsTrue, sbs);
- return urlNameValidator;
- },
- suffix: function (val) {
- var regexp = /^[a-z0-9\-\.]+$/;
- suffixValidator = checkField(val, regexp);
- enableButton("#btSubmit2", areSecondValidatorsTrue, sbs);
- return suffixValidator;
- },
- bossSurname: function (val) {
- var regexp = /^[a-zA-Z\-\z\ż\ź\ć\ń\ó\ł\ę\ą\ś\Ż\Ź\Ć\Ą\Ś\Ę\Ł\Ó\Ń]+$/;
- bossSurnameValidator = checkField(val, regexp);
- enableButton("#btSubmit2", areSecondValidatorsTrue, sbs);
- return bossSurnameValidator;
- },
- secondBossSurname: function (val) {
- var regexp = /^[a-zA-Z\-\z\ż\ź\ć\ń\ó\ł\ę\ą\ś\Ż\Ź\Ć\Ą\Ś\Ę\Ł\Ó\Ń]+$/;
- secondBossSurnameValidator = checkField(val, regexp);
- enableButton("#btSubmit2", areSecondValidatorsTrue, sbs);
- return secondBossSurnameValidator;
- },
- superiorUnit: function (val) {
- var regexp = /^[a-zA-Z0-9\-\.\,\z\ż\ź\ć\ń\ó\ł\ę\ą\ś\Ż\Ź\Ć\Ą\Ś\Ę\Ł\Ó\Ń\s]+$/;
- superiorUnitValidator = checkField(val, regexp);
- enableButton("#btSubmit2", areSecondValidatorsTrue, sbs);
- return superiorUnitValidator;
- }
- },
- true
- );
- A.mix(
- defaultFormValidator.STRINGS,
- {
- siteName: Liferay.Language.get('please-enter-a-valid-site-name'),
- siteDescription: Liferay.Language.get('please-select-a-valid-site-description'),
- existingSite: Liferay.Language.get('please-select-a-valid-existing-site'),
- urlName: Liferay.Language.get('please-enter-a-valid-url-name'),
- suffix: Liferay.Language.get('please-enter-a-valid-suffix'),
- bossSurname: Liferay.Language.get('please-enter-a-valid-boss-surname'),
- secondBossSurname: Liferay.Language.get('please-enter-a-valid-second-boss-surname'),
- superiorUnit: Liferay.Language.get('please-choose-a-valid-superior-unit')
- },
- true
- );
- console.log(A.config);
- console.log(A.FormValidator);
- });
- }
- function checkField(value, regex) {
- return regex.test(value);
- }
- function enableButton(idButton, areAllValidatorsTrue, sBS) {
- var A = AUI();
- var button = A.one(idButton);
- if(areAllValidatorsTrue(sBS)) {
- button.attr("disabled", false);
- button.attr("class", "btn btn-primary");
- } else {
- button.attr("disabled", "true");
- }
- }
- function areViewValidatorsTrue(isExistingSiteField) {
- console.log("\n");
- console.log("Walidatory:");
- console.log(siteNameValidator);
- console.log(siteDescriptionValidator);
- console.log(siteTypeValidator);
- console.log(existingSiteValidator);
- if(isExistingSiteField.value == "true") {
- console.log("4 if");
- return siteNameValidator && siteTypeValidator && siteDescriptionValidator && existingSiteValidator;
- } else {
- console.log("3 if");
- return siteNameValidator && siteTypeValidator && siteDescriptionValidator;
- }
- }
- function areSecondValidatorsTrue(sBS) {
- if (sBS.type == "hidden" || sBS.disabled == true) {
- // if there is no secondBossSurname
- // if (rOA.disabled == false)
- // if there is manual suffix
- return urlNameValidator && suffixValidator && bossSurnameValidator
- && superiorUnitValidator;
- // else
- // return urlNameValidator && bossSurnameValidator && superiorUnitValidator;
- } else {
- // if (rOA.disabled == false)
- return urlNameValidator && suffixValidator && bossSurnameValidator
- && secondBossSurnameValidator && superiorUnitValidator;
- // else
- // return urlNameValidator && bossSurnameValidator && secondBossSurnameValidator
- // && superiorUnitValidator;
- }
- }
- function areEmailValidatorsTrue() {
- if(isSecondBoss) {
- console.log("2 if");
- console.log(window.bossEmailValidator);
- console.log(window.secondBossEmailValidator);
- return window.bossEmailValidator && window.secondBossEmailValidator;
- } else {
- console.log('1 if');
- return window.bossEmailValidator;
- }
- }
- function validateOnKeyUp(formValidator, inputObject) {
- console.log(inputObject.toString());
- if(inputObject.toString().startsWith("SELECT")) {
- inputObject.on('click', function (event) {
- if(inputObject.toString().includes("siteType")) {
- window.formSelectValidator.validateField(inputObject);
- formValidator.validateField(inputObject);
- }
- else if(inputObject.toString().includes("bossEmail")) {
- window.formBossValidator.validateField(inputObject);
- formValidator.validateField(inputObject);
- }
- else if(inputObject.toString().includes("secondBossEmail")) {
- window.formSecondBossValidator.validateField(inputObject);
- formValidator.validateField(inputObject);
- }
- });
- } else {
- inputObject.on('keyup', function (event) {
- formValidator.validateField(inputObject);
- });
- }
- }
- var buttonPDF = document.getElementById("pdf");
- if(buttonPDF) {
- buttonPDF.addEventListener("click", function () {
- var doc = new jsPDF();
- doc.addFont("Abha.ttf", "Abha", "normal", "Identity-H");
- doc.setFont("Abha"); // set font
- doc.setFontSize(14);
- //doc.setTextColor(153,051,102);
- // doc.setCharSpace(1);
- var today = new Date();
- var dd = String(today.getDate()).padStart(2, '0');
- var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
- var yyyy = today.getFullYear();
- today = dd + '.' + mm + '.' + yyyy + 'r.';
- doc.drawText("Kraków, " + today, 151, 18);
- doc.setFontSize(14);
- doc.drawText("Sekcja ds. Portalu Uniwersyteckiego", 70, 30);
- doc.setFontStyle("bold");
- doc.drawText("WNIOSEK",90, 45);
- doc.setFontStyle("normal");
- doc.setFont("Abha");
- doc.drawText("Zwracamy się z uprzejmą prośbą" +
- " o zgodę na utworzenie witryny naszej",25, 60);
- doc.drawText("jednostki w Portalu UJ.", 25, 65);
- doc.drawText("Poniżej załączamy wymagane dane: ", 25, 70);
- doc.setFontSize(12);
- doc.drawText("Nazwa witryny ",25, 85);
- doc.setFontSize(14);
- doc.drawText(name,25, 92);
- doc.setFontSize(5);
- doc.drawText("...................................................................." +
- ".................................................................................." +
- ".................................................................................." +
- ".................................................................................." +
- ".................................................................................." +
- "............................................................................", 25, 93);
- doc.setFontSize(12);
- doc.drawText("Rodzaj witryny ",25, 105);
- doc.setFontSize(14);
- doc.drawText( type,25, 112);
- doc.setFontSize(5);
- doc.drawText("...................................................................." +
- ".................................................................................." +
- ".................................................................................." +
- ".................................................................................." +
- ".................................................................................." +
- "............................................................................", 25, 113);
- doc.setFontSize(12);
- doc.drawText("Opis witryny ",25, 125);
- doc.setFontSize(14);
- doc.drawText(description,25, 132);
- doc.setFontSize(5);
- doc.drawText("...................................................................." +
- ".................................................................................." +
- ".................................................................................." +
- ".................................................................................." +
- ".................................................................................." +
- "............................................................................", 25, 133);
- doc.setFontSize(12);
- doc.drawText("Adres witryny ",25, 145);
- doc.setFontSize(14);
- doc.drawText(address + "." + roa,25, 152);
- doc.setFontSize(5);
- doc.drawText("...................................................................." +
- ".................................................................................." +
- ".................................................................................." +
- ".................................................................................." +
- ".................................................................................." +
- "............................................................................", 25, 153);
- doc.setFontSize(12);
- doc.drawText("Jednostka nadrzędna ",25, 165);
- doc.setFontSize(14);
- doc.drawText(superiorUnit,25, 172);
- doc.setFontSize(5);
- doc.drawText("...................................................................." +
- ".................................................................................." +
- ".................................................................................." +
- ".................................................................................." +
- ".................................................................................." +
- "............................................................................", 25, 173);
- doc.setFontSize(12);
- doc.drawText("Email przełożonego ",25, 185);
- doc.setFontSize(14);
- doc.drawText(bossEmail,25, 192);
- doc.setFontSize(5);
- doc.drawText("...................................................................." +
- ".................................................................................." +
- ".................................................................................." +
- ".................................................................................." +
- ".................................................................................." +
- "............................................................................", 25, 193);
- if(secondBossEmail != "brak") {
- doc.setFontSize(12);
- doc.drawText("Email drugiego przełożonego ", 25, 205);
- doc.setFontSize(14);
- doc.drawText(secondBossEmail, 25, 212);
- doc.setFontSize(5);
- doc.drawText("...................................................................." +
- ".................................................................................." +
- ".................................................................................." +
- ".................................................................................." +
- ".................................................................................." +
- "............................................................................", 25, 213);
- }
- doc.setFontSize(14);
- doc.drawText("Podpis i pieczęć", 120, 240);
- doc.drawText("Dziekana/Kierownika/Dyrektora/ ...", 99, 245);
- doc.save("wniosek.pdf");
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement