| @@ 7-901 (lines=895) @@ | ||
| 4 | ||
| 5 | // ============================================================================= |
|
| 6 | ||
| 7 | (function($) { |
|
| 8 | ||
| 9 | // Add isValid() |
|
| 10 | ||
| 11 | $.fn.isValid = function(){ |
|
| 12 | return this[0].checkValidity() |
|
| 13 | } |
|
| 14 | ||
| 15 | $(document).ready(function() { |
|
| 16 | ||
| 17 | // Accordion Handlers ================================================== |
|
| 18 | ||
| 19 | function accordionTrigger(trigger) { |
|
| 20 | if ($(trigger).parent(".accordion").hasClass("active")) { |
|
| 21 | $(trigger).attr("aria-expanded", "false"); |
|
| 22 | $(trigger).parent(".accordion").removeClass("active"); |
|
| 23 | $(trigger).parent(".accordion").find(".accordion-content").attr("aria-hidden", "true"); |
|
| 24 | } |
|
| 25 | else { |
|
| 26 | $(trigger).attr("aria-expanded", "true"); |
|
| 27 | $(trigger).parent(".accordion").addClass("active"); |
|
| 28 | $(trigger).parent(".accordion").find(".accordion-content").attr("aria-hidden", "false"); |
|
| 29 | } |
|
| 30 | } |
|
| 31 | ||
| 32 | $(document).on("click", ".accordion-trigger", function(e){ |
|
| 33 | ||
| 34 | accordionTrigger(this); |
|
| 35 | ||
| 36 | }); |
|
| 37 | ||
| 38 | $(document).on("keyup", ".accordion-trigger", function(e){ |
|
| 39 | ||
| 40 | if(e.which == 13) { |
|
| 41 | accordionTrigger(this); |
|
| 42 | } |
|
| 43 | ||
| 44 | }); |
|
| 45 | ||
| 46 | // Modal Handlers ====================================================== |
|
| 47 | ||
| 48 | function openModal(trigger) { |
|
| 49 | ||
| 50 | var modalID = $(trigger).attr("data-modal-id"); |
|
| 51 | var modal = $(".modal[data-modal-id="+modalID+"]"); |
|
| 52 | var modalObject = $(trigger).parents(".modal-target-object"); |
|
| 53 | $(".modal-overlay").addClass("active"); |
|
| 54 | modal.addClass("active"); |
|
| 55 | $("body").css("overflow", "hidden"); |
|
| 56 | ||
| 57 | // Tab Items |
|
| 58 | ||
| 59 | var focusableItems = modal.find(":focusable"); |
|
| 60 | ||
| 61 | var firstInput = focusableItems.first(); |
|
| 62 | var lastInput = focusableItems.last(); |
|
| 63 | ||
| 64 | if (modal.find("form").length == 0) { |
|
| 65 | lastInput.focus(); |
|
| 66 | } |
|
| 67 | else { |
|
| 68 | firstInput.focus(); |
|
| 69 | } |
|
| 70 | ||
| 71 | modalTabHandler(firstInput, lastInput); |
|
| 72 | modalDeleteTrigger(trigger, modal, modalObject); |
|
| 73 | escapeModalHandler(); |
|
| 74 | ||
| 75 | } |
|
| 76 | ||
| 77 | $(document).on("click", ".modal-trigger", function(e){ |
|
| 78 | ||
| 79 | openModal(this); |
|
| 80 | ||
| 81 | }); |
|
| 82 | ||
| 83 | $(document).on("keyup", ".modal-trigger", function(e){ |
|
| 84 | ||
| 85 | if(e.which == 13) { |
|
| 86 | openModal(this); |
|
| 87 | } |
|
| 88 | ||
| 89 | }); |
|
| 90 | ||
| 91 | ||
| 92 | function closeModal(trigger) { |
|
| 93 | ||
| 94 | $(".modal-overlay").removeClass("active"); |
|
| 95 | $(".modal").removeClass("active"); |
|
| 96 | $("body").css("overflow", "visible"); |
|
| 97 | ||
| 98 | } |
|
| 99 | ||
| 100 | $(document).on("click", ".modal-cancel-trigger", function(e){ |
|
| 101 | ||
| 102 | closeModal(this); |
|
| 103 | ||
| 104 | }); |
|
| 105 | ||
| 106 | $(document).on("keyup", ".modal-cancel-trigger", function(e){ |
|
| 107 | ||
| 108 | if(e.which == 13) { |
|
| 109 | closeModal(this); |
|
| 110 | } |
|
| 111 | ||
| 112 | }); |
|
| 113 | ||
| 114 | // Delete Trigger ================================================== |
|
| 115 | ||
| 116 | function modalDeleteTrigger(trigger, modal, object) { |
|
| 117 | ||
| 118 | $(document).on("click", ".modal-delete-trigger", function(e){ |
|
| 119 | ||
| 120 | closeModal(trigger); |
|
| 121 | ||
| 122 | $(object).remove(); |
|
| 123 | ||
| 124 | }); |
|
| 125 | ||
| 126 | } |
|
| 127 | ||
| 128 | // Tab Handler ===================================================== |
|
| 129 | ||
| 130 | function modalTabHandler(first, last) { |
|
| 131 | ||
| 132 | $(document).on("keydown", function(e){ |
|
| 133 | ||
| 134 | var keyCode = e.keyCode || e.which; |
|
| 135 | ||
| 136 | if (keyCode == 9 && !e.shiftKey) { |
|
| 137 | ||
| 138 | if ($(last).is(":focus")) { |
|
| 139 | e.preventDefault(); |
|
| 140 | $(first).focus(); |
|
| 141 | } |
|
| 142 | ||
| 143 | } |
|
| 144 | else if (keyCode == 9 && e.shiftKey) { |
|
| 145 | ||
| 146 | if($(first).is(":focus")) { |
|
| 147 | e.preventDefault(); |
|
| 148 | $(last).focus(); |
|
| 149 | } |
|
| 150 | ||
| 151 | } |
|
| 152 | ||
| 153 | }); |
|
| 154 | ||
| 155 | } |
|
| 156 | ||
| 157 | // Escape Handler ================================================== |
|
| 158 | ||
| 159 | function escapeModalHandler() { |
|
| 160 | ||
| 161 | $(document).on("keyup", function(e){ |
|
| 162 | ||
| 163 | if((e.key==='Escape'||e.key==='Esc'||e.keyCode===27)){ |
|
| 164 | ||
| 165 | $(".modal-overlay").removeClass("active"); |
|
| 166 | $(".modal").removeClass("active"); |
|
| 167 | $("body").css("overflow", "visible"); |
|
| 168 | ||
| 169 | // FF and compatible |
|
| 170 | if (e.stopPropagation) { |
|
| 171 | e.stopPropagation(); |
|
| 172 | e.preventDefault(); |
|
| 173 | } |
|
| 174 | ||
| 175 | } |
|
| 176 | ||
| 177 | }); |
|
| 178 | ||
| 179 | } |
|
| 180 | ||
| 181 | // Form Handlers ======================================================= |
|
| 182 | ||
| 183 | // Required Fields |
|
| 184 | ||
| 185 | function requiredFields() { |
|
| 186 | $("input:required, textarea:required").each(function(e) { |
|
| 187 | $(this).parent().addClass("required"); |
|
| 188 | $(this).parent().find("label").append("<span class='form__required'><i class='fa fa-asterisk' aria-label='Asterisk'></i></span>"); |
|
| 189 | }); |
|
| 190 | } |
|
| 191 | ||
| 192 | requiredFields(); |
|
| 193 | ||
| 194 | // Label Handers =================================================== |
|
| 195 | ||
| 196 | function labelHandlers() { |
|
| 197 | ||
| 198 | $("[class*='form__input-wrapper'] input, [class*='form__input-wrapper'] textarea").focusin(function(e) { |
|
| 199 | $(this).parent().addClass("active"); |
|
| 200 | }); |
|
| 201 | ||
| 202 | $("[class*='form__input-wrapper'] input, [class*='form__input-wrapper'] textarea").focusout(function(e) { |
|
| 203 | ||
| 204 | // Check for existing value. |
|
| 205 | ||
| 206 | if ($(this).val() == "") { |
|
| 207 | $(this).parent().removeClass("active"); |
|
| 208 | } |
|
| 209 | ||
| 210 | // Check Validity |
|
| 211 | ||
| 212 | if ($(this).isValid() == true) { |
|
| 213 | ||
| 214 | if ($(this).val() == "" || $(this).attr("type") == "password") { |
|
| 215 | $(this).parent().removeClass("valid"); |
|
| 216 | $(this).parent().removeClass("invalid"); |
|
| 217 | } |
|
| 218 | else { |
|
| 219 | $(this).parent().addClass("valid"); |
|
| 220 | $(this).parent().removeClass("invalid"); |
|
| 221 | } |
|
| 222 | ||
| 223 | } |
|
| 224 | else { |
|
| 225 | ||
| 226 | if ($(this).attr("type") == "password") { |
|
| 227 | return false; |
|
| 228 | } |
|
| 229 | else { |
|
| 230 | $(this).parent().addClass("invalid"); |
|
| 231 | $(this).parent().removeClass("valid"); |
|
| 232 | } |
|
| 233 | ||
| 234 | } |
|
| 235 | ||
| 236 | }); |
|
| 237 | ||
| 238 | } |
|
| 239 | ||
| 240 | labelHandlers(); |
|
| 241 | ||
| 242 | // Individualizing repeater name and id attributes====================== |
|
| 243 | ||
| 244 | //Individualize template attributes |
|
| 245 | function appendToAttributes(parent, attribute, suffix, conditions = null) { |
|
| 246 | var selector = "*[" + attribute + "]"; |
|
| 247 | ||
| 248 | //If conditions is set, only modify attributes that also |
|
| 249 | //satisfy that selector |
|
| 250 | if (conditions) { |
|
| 251 | selector = conditions + selector; |
|
| 252 | } |
|
| 253 | ||
| 254 | parent.find(selector).each(function() { |
|
| 255 | $(this).attr(attribute, $(this).attr(attribute) + suffix); |
|
| 256 | }); |
|
| 257 | } |
|
| 258 | ||
| 259 | //Individualize template attributes |
|
| 260 | function replaceInAttributes(parent, attribute, oldString, newString, conditions = null) { |
|
| 261 | var selector = "*[" + attribute + "]"; |
|
| 262 | ||
| 263 | //If conditions is set, only modify attributes that also |
|
| 264 | //satisfy that selector |
|
| 265 | if (conditions) { |
|
| 266 | selector = conditions + selector; |
|
| 267 | } |
|
| 268 | ||
| 269 | parent.find(selector).each(function() { |
|
| 270 | //replaces only the first instance of a match in a string |
|
| 271 | $(this).attr(attribute, $(this).attr(attribute).replace(oldString, newString)); |
|
| 272 | }); |
|
| 273 | } |
|
| 274 | ||
| 275 | //Return the next unused idAttr value |
|
| 276 | function getNextItemId(parent, idAttr = "data-item-id") { |
|
| 277 | var maxId = 0; |
|
| 278 | parent.find("*[" + idAttr + "]").each(function() { |
|
| 279 | var id = parseInt( $(this).attr(idAttr) ); |
|
| 280 | if (id > maxId) { |
|
| 281 | maxId = id; |
|
| 282 | } |
|
| 283 | }); |
|
| 284 | return maxId + 1; |
|
| 285 | } |
|
| 286 | ||
| 287 | //The all in one function to set proper ids and form names |
|
| 288 | function individualizeFormIdsAndNames(template, wrapper) { |
|
| 289 | // Get New ID |
|
| 290 | var newId = getNextItemId(wrapper); |
|
| 291 | ||
| 292 | //Set date-item-id, used to track which newId's are taken |
|
| 293 | template.attr('data-item-id', newId); |
|
| 294 | ||
| 295 | //Differentiate real forms from templates |
|
| 296 | ||
| 297 | // filter, if we only want to affect certain results |
|
| 298 | var filter = ''; |
|
| 299 | ||
| 300 | replaceInAttributes(template, 'id', ':template', 'new', filter); |
|
| 301 | replaceInAttributes(template, 'for', ':template', 'new', filter); |
|
| 302 | replaceInAttributes(template, 'name', ':template', 'new', filter); |
|
| 303 | replaceInAttributes(template, 'submit', ':template', 'new', filter); |
|
| 304 | replaceInAttributes(template, 'value', ':template', 'new', filter+'[name=submit]'); |
|
| 305 | ||
| 306 | replaceInAttributes(template, 'id', ':id', newId, filter); |
|
| 307 | replaceInAttributes(template, 'for', ':id', newId, filter); |
|
| 308 | replaceInAttributes(template, 'name', ':id', newId, filter); |
|
| 309 | replaceInAttributes(template, 'submit', ':id', newId, filter); |
|
| 310 | replaceInAttributes(template, 'value', ':id', newId, filter+'[name=submit]'); |
|
| 311 | } |
|
| 312 | ||
| 313 | // Profile List Handlers =============================================== |
|
| 314 | ||
| 315 | // Add Profile Element |
|
| 316 | function addProfileElement(trigger) { |
|
| 317 | ||
| 318 | // Get Parent |
|
| 319 | var parent = $(trigger).parents(".profile-list"); |
|
| 320 | ||
| 321 | // Get List Wrapper |
|
| 322 | var wrapper = parent.find(".profile-element-list"); |
|
| 323 | ||
| 324 | // Set Null to Hidden |
|
| 325 | parent.find(".profile-null").removeClass("active"); |
|
| 326 | ||
| 327 | // Get Template |
|
| 328 | var template = parent.find(".profile-element.template").clone(); |
|
| 329 | ||
| 330 | // Remove Template Class |
|
| 331 | template.removeClass("template"); |
|
| 332 | ||
| 333 | //Set ids and form names to be unique |
|
| 334 | individualizeFormIdsAndNames(template, wrapper); |
|
| 335 | ||
| 336 | // Prepend Clone to the Wrapper |
|
| 337 | wrapper.prepend(template); |
|
| 338 | ||
| 339 | // Reactivate Required Fields |
|
| 340 | requiredFields(); |
|
| 341 | ||
| 342 | // Reactivate Labels |
|
| 343 | labelHandlers(); |
|
| 344 | ||
| 345 | // Reactivate Nested Relatives |
|
| 346 | loadProfileRelatives(); |
|
| 347 | ||
| 348 | } |
|
| 349 | ||
| 350 | // Click Trigger |
|
| 351 | $(".profile-list__add-element-trigger").on("click", function(e) { |
|
| 352 | ||
| 353 | // Prevent Default Functions |
|
| 354 | e.preventDefault(); |
|
| 355 | ||
| 356 | // Add Profile Elements |
|
| 357 | addProfileElement(this); |
|
| 358 | ||
| 359 | }); |
|
| 360 | ||
| 361 | // Enter Key Trigger |
|
| 362 | $(".profile-list__add-element-trigger").on("keyup", function(e) { |
|
| 363 | ||
| 364 | if(e.which == 13) { |
|
| 365 | ||
| 366 | // Prevent Default Functions |
|
| 367 | e.preventDefault(); |
|
| 368 | ||
| 369 | // Add Profile Elements |
|
| 370 | addProfileElement(this); |
|
| 371 | ||
| 372 | } |
|
| 373 | ||
| 374 | }); |
|
| 375 | ||
| 376 | // Remove Profile Element |
|
| 377 | ||
| 378 | // Add Profile Relative |
|
| 379 | function addProfileRelative(trigger) { |
|
| 380 | ||
| 381 | // Get Parent |
|
| 382 | var parent = $(trigger).parents(".profile-relative-list"); |
|
| 383 | ||
| 384 | // Get List Wrapper |
|
| 385 | var wrapper = parent.find(".profile-relative-list__wrapper"); |
|
| 386 | ||
| 387 | // Set Null to Hidden |
|
| 388 | // parent.find(".profile-null").removeClass("active"); |
|
| 389 | ||
| 390 | // Get Template |
|
| 391 | var template = parent.find(".profile-relative.template").clone(); |
|
| 392 | ||
| 393 | // Remove Template Class |
|
| 394 | template.removeClass("template"); |
|
| 395 | ||
| 396 | //Set ids and form names to be unique |
|
| 397 | individualizeFormIdsAndNames(template, wrapper); |
|
| 398 | ||
| 399 | // Append Clone to the Wrapper |
|
| 400 | wrapper.append(template); |
|
| 401 | ||
| 402 | // Reactivate Required Fields |
|
| 403 | requiredFields(); |
|
| 404 | ||
| 405 | // Reactivate Labels |
|
| 406 | labelHandlers(); |
|
| 407 | ||
| 408 | // Reactivate Nested Relatives |
|
| 409 | loadProfileRelativeDeletion(); |
|
| 410 | ||
| 411 | } |
|
| 412 | ||
| 413 | // Load Function |
|
| 414 | function loadProfileRelatives() { |
|
| 415 | ||
| 416 | // Click Trigger |
|
| 417 | $(".profile-relative__add-trigger").off("click"); |
|
| 418 | ||
| 419 | $(".profile-relative__add-trigger").on("click", function(e) { |
|
| 420 | ||
| 421 | // Prevent Default Functions |
|
| 422 | e.preventDefault(); |
|
| 423 | ||
| 424 | // Add Profile Relative |
|
| 425 | addProfileRelative(this); |
|
| 426 | ||
| 427 | }); |
|
| 428 | ||
| 429 | // Enter Key Trigger |
|
| 430 | $(".profile-relative__add-trigger").off("keyup"); |
|
| 431 | ||
| 432 | $(".profile-relative__add-trigger").on("keyup", function(e) { |
|
| 433 | ||
| 434 | if(e.which == 13) { |
|
| 435 | ||
| 436 | // Prevent Default Functions |
|
| 437 | e.preventDefault(); |
|
| 438 | ||
| 439 | // Add Profile Relative |
|
| 440 | addProfileRelative(this); |
|
| 441 | ||
| 442 | } |
|
| 443 | ||
| 444 | }); |
|
| 445 | ||
| 446 | } |
|
| 447 | ||
| 448 | loadProfileRelatives(); |
|
| 449 | ||
| 450 | // Remove Profile Relative |
|
| 451 | function deleteProfileRelative(trigger) { |
|
| 452 | ||
| 453 | $(trigger).parents(".profile-relative").remove(); |
|
| 454 | ||
| 455 | } |
|
| 456 | ||
| 457 | // Load Function |
|
| 458 | function loadProfileRelativeDeletion() { |
|
| 459 | ||
| 460 | // Click Trigger |
|
| 461 | $(".profile-relative__remove-trigger").on("click", function(e) { |
|
| 462 | ||
| 463 | // Prevent Default Functions |
|
| 464 | e.preventDefault(); |
|
| 465 | ||
| 466 | // Delete Profile Relative |
|
| 467 | deleteProfileRelative(this); |
|
| 468 | ||
| 469 | }); |
|
| 470 | ||
| 471 | // Enter Key Trigger |
|
| 472 | $(".profile-relative__remove-trigger").on("keyup", function(e) { |
|
| 473 | ||
| 474 | if(e.which == 13) { |
|
| 475 | ||
| 476 | // Prevent Default Functions |
|
| 477 | e.preventDefault(); |
|
| 478 | ||
| 479 | // Delete Profile Relative |
|
| 480 | deleteProfileRelative(this); |
|
| 481 | ||
| 482 | } |
|
| 483 | ||
| 484 | }); |
|
| 485 | ||
| 486 | } |
|
| 487 | ||
| 488 | loadProfileRelativeDeletion(); |
|
| 489 | ||
| 490 | // Experience Handlers ================================================= |
|
| 491 | ||
| 492 | // Degrees |
|
| 493 | ||
| 494 | function addDegree(trigger) { |
|
| 495 | ||
| 496 | // Get Wrapper |
|
| 497 | var wrapper = $(".application-post__experience-wrapper"); |
|
| 498 | ||
| 499 | // Get Template |
|
| 500 | var template = $(".application-post__accordion--degree.template").clone(); |
|
| 501 | ||
| 502 | // Remove Template Class |
|
| 503 | template.removeClass("template"); |
|
| 504 | ||
| 505 | //Set ids and form names to be unique |
|
| 506 | individualizeFormIdsAndNames(template, wrapper); |
|
| 507 | ||
| 508 | // Append Clone to the Wrapper |
|
| 509 | wrapper.append(template); |
|
| 510 | ||
| 511 | requiredFields(); |
|
| 512 | labelHandlers(); |
|
| 513 | ||
| 514 | } |
|
| 515 | ||
| 516 | $("#addDegreeButton").on("click", function(e) { |
|
| 517 | ||
| 518 | e.preventDefault(); |
|
| 519 | ||
| 520 | addDegree(this); |
|
| 521 | ||
| 522 | }); |
|
| 523 | ||
| 524 | $("#addDegreeButton").on("keyup", function(e) { |
|
| 525 | ||
| 526 | if(e.which == 13) { |
|
| 527 | e.preventDefault(); |
|
| 528 | addDegree(this); |
|
| 529 | } |
|
| 530 | ||
| 531 | }); |
|
| 532 | ||
| 533 | // Courses |
|
| 534 | ||
| 535 | function addCourse(trigger) { |
|
| 536 | ||
| 537 | // Get Wrapper |
|
| 538 | var wrapper = $(".application-post__experience-wrapper"); |
|
| 539 | ||
| 540 | // Get Template |
|
| 541 | var template = $(".application-post__accordion--course.template").clone(); |
|
| 542 | ||
| 543 | // Remove Template Class |
|
| 544 | template.removeClass("template"); |
|
| 545 | ||
| 546 | //Set ids and form names to be unique |
|
| 547 | individualizeFormIdsAndNames(template, wrapper); |
|
| 548 | ||
| 549 | // Append Clone to the Wrapper |
|
| 550 | wrapper.append(template); |
|
| 551 | ||
| 552 | requiredFields(); |
|
| 553 | labelHandlers(); |
|
| 554 | ||
| 555 | } |
|
| 556 | ||
| 557 | $("#addCourseButton").on("click", function(e) { |
|
| 558 | ||
| 559 | e.preventDefault(); |
|
| 560 | ||
| 561 | addCourse(this); |
|
| 562 | ||
| 563 | }); |
|
| 564 | ||
| 565 | $("#addCourseButton").on("keyup", function(e) { |
|
| 566 | ||
| 567 | if(e.which == 13) { |
|
| 568 | e.preventDefault(); |
|
| 569 | addCourse(this); |
|
| 570 | } |
|
| 571 | ||
| 572 | }); |
|
| 573 | ||
| 574 | // Work |
|
| 575 | ||
| 576 | function addWork(trigger) { |
|
| 577 | ||
| 578 | // Get Wrapper |
|
| 579 | var wrapper = $(".application-post__experience-wrapper"); |
|
| 580 | ||
| 581 | // Get Template |
|
| 582 | var template = $(".application-post__accordion--work.template").clone(); |
|
| 583 | ||
| 584 | // Remove Template Class |
|
| 585 | template.removeClass("template"); |
|
| 586 | ||
| 587 | //Set ids and form names to be unique |
|
| 588 | individualizeFormIdsAndNames(template, wrapper); |
|
| 589 | ||
| 590 | // Append Clone to the Wrapper |
|
| 591 | wrapper.append(template); |
|
| 592 | ||
| 593 | requiredFields(); |
|
| 594 | labelHandlers(); |
|
| 595 | ||
| 596 | } |
|
| 597 | ||
| 598 | $("#addWorkButton").on("click", function(e) { |
|
| 599 | ||
| 600 | e.preventDefault(); |
|
| 601 | ||
| 602 | addWork(this); |
|
| 603 | ||
| 604 | }); |
|
| 605 | ||
| 606 | $("#addWorkButton").on("keyup", function(e) { |
|
| 607 | ||
| 608 | if(e.which == 13) { |
|
| 609 | e.preventDefault(); |
|
| 610 | addWork(this); |
|
| 611 | } |
|
| 612 | ||
| 613 | }); |
|
| 614 | ||
| 615 | // Create Job Handlers ================================================= |
|
| 616 | ||
| 617 | // Tasks |
|
| 618 | ||
| 619 | function addTask(trigger) { |
|
| 620 | ||
| 621 | // Get Wrapper |
|
| 622 | var wrapper = $(".manager-jobs__create-task-wrapper"); |
|
| 623 | ||
| 624 | // Get Template |
|
| 625 | var template = $(".manager-jobs__create-task.template").clone(); |
|
| 626 | ||
| 627 | console.log(wrapper.find(".manager-jobs__create-task")); |
|
| 628 | ||
| 629 | // Get New ID |
|
| 630 | if (wrapper.find(".manager-jobs__create-task").length == 0) { |
|
| 631 | var newID = parseInt(template.attr("data-task-id")) + 1; |
|
| 632 | } |
|
| 633 | else { |
|
| 634 | var newID = parseInt(wrapper.find("[class*='manager-jobs__create-task']").last().attr("data-task-id")) + 1; |
|
| 635 | } |
|
| 636 | ||
| 637 | // Remove Template Class |
|
| 638 | template.removeClass("template"); |
|
| 639 | ||
| 640 | //TODO: replace with call to individualizeFormIdsAndNames(template, wrapper); |
|
| 641 | //TODO: This requires changes to JobController@create, because the id would change places |
|
| 642 | ||
| 643 | // Assign the New ID |
|
| 644 | template.attr("data-task-id", newID); |
|
| 645 | ||
| 646 | // Add newID as suffix to all "id" and "for" attributes |
|
| 647 | template.find("*[id]").each(function() { $(this).attr("id", this.id + newID)}); |
|
| 648 | template.find("*[for]").each(function() { $(this).attr("for", $(this).attr("for") + newID)}); |
|
| 649 | ||
| 650 | // Replace :id with newID in all form names |
|
| 651 | template.find("*[name]").each(function() { $(this).attr('name', $(this).attr("name").replace(":id", newID))}); |
|
| 652 | ||
| 653 | // Task (English) |
|
| 654 | //template.find("[data-form-id*='task-english']").find("label").attr("for", "taskEN" + newID); |
|
| 655 | //template.find("[data-form-id*='task-english']").find("input").attr("id", "taskEN" + newID); |
|
| 656 | ||
| 657 | // Task (French) |
|
| 658 | //template.find("[data-form-id*='task-french']").find("label").attr("for", "taskFR" + newID); |
|
| 659 | //template.find("[data-form-id*='task-french']").find("input").attr("id", "taskFR" + newID); |
|
| 660 | ||
| 661 | // Append Clone to the Wrapper |
|
| 662 | wrapper.append(template); |
|
| 663 | ||
| 664 | requiredFields(); |
|
| 665 | labelHandlers(); |
|
| 666 | deleteTaskTrigger(); |
|
| 667 | ||
| 668 | } |
|
| 669 | ||
| 670 | $("#addTaskButton").on("click", function(e) { |
|
| 671 | ||
| 672 | e.preventDefault(); |
|
| 673 | ||
| 674 | addTask(this); |
|
| 675 | ||
| 676 | }); |
|
| 677 | ||
| 678 | $("#addTaskButton").on("keyup", function(e) { |
|
| 679 | ||
| 680 | if(e.which == 13) { |
|
| 681 | e.preventDefault(); |
|
| 682 | addTask(this); |
|
| 683 | } |
|
| 684 | ||
| 685 | }); |
|
| 686 | ||
| 687 | // Task Deletion |
|
| 688 | ||
| 689 | function deleteTask(trigger) { |
|
| 690 | ||
| 691 | $(trigger).parents(".manager-jobs__create-task").remove(); |
|
| 692 | ||
| 693 | } |
|
| 694 | ||
| 695 | function deleteTaskTrigger() { |
|
| 696 | ||
| 697 | $(".manager-jobs__delete-task-button").on("click", function(e) { |
|
| 698 | ||
| 699 | e.preventDefault(); |
|
| 700 | ||
| 701 | deleteTask(this); |
|
| 702 | ||
| 703 | }); |
|
| 704 | ||
| 705 | $(".manager-jobs__delete-task-button").on("keyup", function(e) { |
|
| 706 | ||
| 707 | if(e.which == 13) { |
|
| 708 | e.preventDefault(); |
|
| 709 | deleteTask(this); |
|
| 710 | } |
|
| 711 | ||
| 712 | }); |
|
| 713 | ||
| 714 | } |
|
| 715 | ||
| 716 | deleteTaskTrigger(); |
|
| 717 | ||
| 718 | // Skills |
|
| 719 | ||
| 720 | function addSkill(trigger) { |
|
| 721 | ||
| 722 | // Get Parent |
|
| 723 | var parent = $(trigger).parents(".manager-jobs__skill-wrapper"); |
|
| 724 | ||
| 725 | // Get Wrapper |
|
| 726 | var wrapper = parent.find(".manager-jobs__create-skill-wrapper"); |
|
| 727 | ||
| 728 | // Get Template |
|
| 729 | var template = parent.find(".manager-jobs__create-skill.template").clone(); |
|
| 730 | ||
| 731 | console.log(wrapper.find(".manager-jobs__create-skill")); |
|
| 732 | ||
| 733 | // Remove Template Class |
|
| 734 | template.removeClass("template"); |
|
| 735 | ||
| 736 | //Set ids and form names to be unique |
|
| 737 | individualizeFormIdsAndNames(template, wrapper); |
|
| 738 | ||
| 739 | // Append Clone to the Wrapper |
|
| 740 | wrapper.append(template); |
|
| 741 | ||
| 742 | requiredFields(); |
|
| 743 | labelHandlers(); |
|
| 744 | deleteSkillTrigger(); |
|
| 745 | ||
| 746 | } |
|
| 747 | ||
| 748 | $(".manager-jobs__add-skill-button").on("click", function(e) { |
|
| 749 | ||
| 750 | e.preventDefault(); |
|
| 751 | ||
| 752 | addSkill(this); |
|
| 753 | ||
| 754 | }); |
|
| 755 | ||
| 756 | $(".manager-jobs__add-skill-button").on("keyup", function(e) { |
|
| 757 | ||
| 758 | if(e.which == 13) { |
|
| 759 | e.preventDefault(); |
|
| 760 | addSkill(this); |
|
| 761 | } |
|
| 762 | ||
| 763 | }); |
|
| 764 | ||
| 765 | // Skill Deletion |
|
| 766 | ||
| 767 | function deleteSkill(trigger) { |
|
| 768 | ||
| 769 | $(trigger).parents(".manager-jobs__create-skill").remove(); |
|
| 770 | ||
| 771 | } |
|
| 772 | ||
| 773 | function deleteSkillTrigger() { |
|
| 774 | ||
| 775 | $(".manager-jobs__delete-skill-button").on("click", function(e) { |
|
| 776 | ||
| 777 | e.preventDefault(); |
|
| 778 | ||
| 779 | deleteSkill(this); |
|
| 780 | ||
| 781 | }); |
|
| 782 | ||
| 783 | $(".manager-jobs__delete-skill-button").on("keyup", function(e) { |
|
| 784 | ||
| 785 | if(e.which == 13) { |
|
| 786 | e.preventDefault(); |
|
| 787 | deleteSkill(this); |
|
| 788 | } |
|
| 789 | ||
| 790 | }); |
|
| 791 | ||
| 792 | } |
|
| 793 | ||
| 794 | deleteSkillTrigger(); |
|
| 795 | ||
| 796 | // Questions |
|
| 797 | ||
| 798 | function addQuestion(trigger) { |
|
| 799 | ||
| 800 | // Get Wrapper |
|
| 801 | var wrapper = $(".manager-jobs__create-question-wrapper"); |
|
| 802 | ||
| 803 | // Get Template |
|
| 804 | var template = $(".manager-jobs__create-question.template").clone(); |
|
| 805 | ||
| 806 | console.log(wrapper.find(".manager-jobs__create-question")); |
|
| 807 | ||
| 808 | // Get New ID |
|
| 809 | if (wrapper.find(".manager-jobs__create-question").length == 0) { |
|
| 810 | var newID = parseInt(template.attr("data-question-id")) + 1; |
|
| 811 | } |
|
| 812 | else { |
|
| 813 | var newID = parseInt(wrapper.find("[class*='manager-jobs__create-question']").last().attr("data-question-id")) + 1; |
|
| 814 | } |
|
| 815 | ||
| 816 | // Remove Template Class |
|
| 817 | template.removeClass("template"); |
|
| 818 | ||
| 819 | //TODO: replace with call to individualizeFormIdsAndNames(template, wrapper); |
|
| 820 | //TODO: This requires changes to JobController@create, because the id would change places |
|
| 821 | ||
| 822 | // Assign the New ID |
|
| 823 | template.attr("data-question-id", newID); |
|
| 824 | ||
| 825 | // Add newID as suffix to all "id" and "for" attributes |
|
| 826 | template.find("*[id]").each(function() { $(this).attr("id", this.id + newID)}); |
|
| 827 | template.find("*[for]").each(function() { $(this).attr("for", $(this).attr("for") + newID)}); |
|
| 828 | ||
| 829 | // Replace :id with newID in all form names |
|
| 830 | template.find("*[name]").each(function() { $(this).attr('name', $(this).attr("name").replace(":id", newID))}); |
|
| 831 | ||
| 832 | // Edit Form IDs |
|
| 833 | // |
|
| 834 | // // Queestion (English) |
|
| 835 | // template.find("[data-form-id*='question-english']").find("label").attr("for", "questionEN" + newID); |
|
| 836 | // template.find("[data-form-id*='question-english']").find("input").attr("id", "questionEN" + newID); |
|
| 837 | // |
|
| 838 | // // Queestion (French) |
|
| 839 | // template.find("[data-form-id*='question-french']").find("label").attr("for", "questionFR" + newID); |
|
| 840 | // template.find("[data-form-id*='question-french']").find("input").attr("id", "questionFR" + newID); |
|
| 841 | ||
| 842 | // Append Clone to the Wrapper |
|
| 843 | wrapper.append(template); |
|
| 844 | ||
| 845 | requiredFields(); |
|
| 846 | labelHandlers(); |
|
| 847 | deleteQuestionTrigger(); |
|
| 848 | ||
| 849 | } |
|
| 850 | ||
| 851 | $("#addQuestionButton").on("click", function(e) { |
|
| 852 | ||
| 853 | e.preventDefault(); |
|
| 854 | ||
| 855 | addQuestion(this); |
|
| 856 | ||
| 857 | }); |
|
| 858 | ||
| 859 | $("#addQuestionButton").on("keyup", function(e) { |
|
| 860 | ||
| 861 | if(e.which == 13) { |
|
| 862 | e.preventDefault(); |
|
| 863 | addQuestion(this); |
|
| 864 | } |
|
| 865 | ||
| 866 | }); |
|
| 867 | ||
| 868 | // Question Deletion |
|
| 869 | ||
| 870 | function deleteQuestion(trigger) { |
|
| 871 | ||
| 872 | $(trigger).parents(".manager-jobs__create-question").remove(); |
|
| 873 | ||
| 874 | } |
|
| 875 | ||
| 876 | function deleteQuestionTrigger() { |
|
| 877 | ||
| 878 | $(".manager-jobs__delete-question-button").on("click", function(e) { |
|
| 879 | ||
| 880 | e.preventDefault(); |
|
| 881 | ||
| 882 | deleteQuestion(this); |
|
| 883 | ||
| 884 | }); |
|
| 885 | ||
| 886 | $(".manager-jobs__delete-question-button").on("keyup", function(e) { |
|
| 887 | ||
| 888 | if(e.which == 13) { |
|
| 889 | e.preventDefault(); |
|
| 890 | deleteQuestion(this); |
|
| 891 | } |
|
| 892 | ||
| 893 | }); |
|
| 894 | ||
| 895 | } |
|
| 896 | ||
| 897 | deleteQuestionTrigger(); |
|
| 898 | ||
| 899 | }); |
|
| 900 | ||
| 901 | })(jQuery); |
|
| 902 | ||
| @@ 71-917 (lines=847) @@ | ||
| 68 | /************************************************************************/ |
|
| 69 | /******/ ([ |
|
| 70 | /* 0 */ |
|
| 71 | /***/ (function(module, exports) { |
|
| 72 | ||
| 73 | // ============================================================================= |
|
| 74 | ||
| 75 | // Utilities JavaScript (jQuery) |
|
| 76 | ||
| 77 | // ============================================================================= |
|
| 78 | ||
| 79 | (function ($) { |
|
| 80 | ||
| 81 | // Add isValid() |
|
| 82 | ||
| 83 | $.fn.isValid = function () { |
|
| 84 | return this[0].checkValidity(); |
|
| 85 | }; |
|
| 86 | ||
| 87 | $(document).ready(function () { |
|
| 88 | ||
| 89 | // Accordion Handlers ================================================== |
|
| 90 | ||
| 91 | function accordionTrigger(trigger) { |
|
| 92 | if ($(trigger).parent(".accordion").hasClass("active")) { |
|
| 93 | $(trigger).attr("aria-expanded", "false"); |
|
| 94 | $(trigger).parent(".accordion").removeClass("active"); |
|
| 95 | $(trigger).parent(".accordion").find(".accordion-content").attr("aria-hidden", "true"); |
|
| 96 | } else { |
|
| 97 | $(trigger).attr("aria-expanded", "true"); |
|
| 98 | $(trigger).parent(".accordion").addClass("active"); |
|
| 99 | $(trigger).parent(".accordion").find(".accordion-content").attr("aria-hidden", "false"); |
|
| 100 | } |
|
| 101 | } |
|
| 102 | ||
| 103 | $(document).on("click", ".accordion-trigger", function (e) { |
|
| 104 | ||
| 105 | accordionTrigger(this); |
|
| 106 | }); |
|
| 107 | ||
| 108 | $(document).on("keyup", ".accordion-trigger", function (e) { |
|
| 109 | ||
| 110 | if (e.which == 13) { |
|
| 111 | accordionTrigger(this); |
|
| 112 | } |
|
| 113 | }); |
|
| 114 | ||
| 115 | // Modal Handlers ====================================================== |
|
| 116 | ||
| 117 | function openModal(trigger) { |
|
| 118 | ||
| 119 | var modalID = $(trigger).attr("data-modal-id"); |
|
| 120 | var modal = $(".modal[data-modal-id=" + modalID + "]"); |
|
| 121 | var modalObject = $(trigger).parents(".modal-target-object"); |
|
| 122 | $(".modal-overlay").addClass("active"); |
|
| 123 | modal.addClass("active"); |
|
| 124 | $("body").css("overflow", "hidden"); |
|
| 125 | ||
| 126 | // Tab Items |
|
| 127 | ||
| 128 | var focusableItems = modal.find(":focusable"); |
|
| 129 | ||
| 130 | var firstInput = focusableItems.first(); |
|
| 131 | var lastInput = focusableItems.last(); |
|
| 132 | ||
| 133 | if (modal.find("form").length == 0) { |
|
| 134 | lastInput.focus(); |
|
| 135 | } else { |
|
| 136 | firstInput.focus(); |
|
| 137 | } |
|
| 138 | ||
| 139 | modalTabHandler(firstInput, lastInput); |
|
| 140 | modalDeleteTrigger(trigger, modal, modalObject); |
|
| 141 | escapeModalHandler(); |
|
| 142 | } |
|
| 143 | ||
| 144 | $(document).on("click", ".modal-trigger", function (e) { |
|
| 145 | ||
| 146 | openModal(this); |
|
| 147 | }); |
|
| 148 | ||
| 149 | $(document).on("keyup", ".modal-trigger", function (e) { |
|
| 150 | ||
| 151 | if (e.which == 13) { |
|
| 152 | openModal(this); |
|
| 153 | } |
|
| 154 | }); |
|
| 155 | ||
| 156 | function closeModal(trigger) { |
|
| 157 | ||
| 158 | $(".modal-overlay").removeClass("active"); |
|
| 159 | $(".modal").removeClass("active"); |
|
| 160 | $("body").css("overflow", "visible"); |
|
| 161 | } |
|
| 162 | ||
| 163 | $(document).on("click", ".modal-cancel-trigger", function (e) { |
|
| 164 | ||
| 165 | closeModal(this); |
|
| 166 | }); |
|
| 167 | ||
| 168 | $(document).on("keyup", ".modal-cancel-trigger", function (e) { |
|
| 169 | ||
| 170 | if (e.which == 13) { |
|
| 171 | closeModal(this); |
|
| 172 | } |
|
| 173 | }); |
|
| 174 | ||
| 175 | // Delete Trigger ================================================== |
|
| 176 | ||
| 177 | function modalDeleteTrigger(trigger, modal, object) { |
|
| 178 | ||
| 179 | $(document).on("click", ".modal-delete-trigger", function (e) { |
|
| 180 | ||
| 181 | closeModal(trigger); |
|
| 182 | ||
| 183 | $(object).remove(); |
|
| 184 | }); |
|
| 185 | } |
|
| 186 | ||
| 187 | // Tab Handler ===================================================== |
|
| 188 | ||
| 189 | function modalTabHandler(first, last) { |
|
| 190 | ||
| 191 | $(document).on("keydown", function (e) { |
|
| 192 | ||
| 193 | var keyCode = e.keyCode || e.which; |
|
| 194 | ||
| 195 | if (keyCode == 9 && !e.shiftKey) { |
|
| 196 | ||
| 197 | if ($(last).is(":focus")) { |
|
| 198 | e.preventDefault(); |
|
| 199 | $(first).focus(); |
|
| 200 | } |
|
| 201 | } else if (keyCode == 9 && e.shiftKey) { |
|
| 202 | ||
| 203 | if ($(first).is(":focus")) { |
|
| 204 | e.preventDefault(); |
|
| 205 | $(last).focus(); |
|
| 206 | } |
|
| 207 | } |
|
| 208 | }); |
|
| 209 | } |
|
| 210 | ||
| 211 | // Escape Handler ================================================== |
|
| 212 | ||
| 213 | function escapeModalHandler() { |
|
| 214 | ||
| 215 | $(document).on("keyup", function (e) { |
|
| 216 | ||
| 217 | if (e.key === 'Escape' || e.key === 'Esc' || e.keyCode === 27) { |
|
| 218 | ||
| 219 | $(".modal-overlay").removeClass("active"); |
|
| 220 | $(".modal").removeClass("active"); |
|
| 221 | $("body").css("overflow", "visible"); |
|
| 222 | ||
| 223 | // FF and compatible |
|
| 224 | if (e.stopPropagation) { |
|
| 225 | e.stopPropagation(); |
|
| 226 | e.preventDefault(); |
|
| 227 | } |
|
| 228 | } |
|
| 229 | }); |
|
| 230 | } |
|
| 231 | ||
| 232 | // Form Handlers ======================================================= |
|
| 233 | ||
| 234 | // Required Fields |
|
| 235 | ||
| 236 | function requiredFields() { |
|
| 237 | $("input:required, textarea:required").each(function (e) { |
|
| 238 | $(this).parent().addClass("required"); |
|
| 239 | $(this).parent().find("label").append("<span class='form__required'><i class='fa fa-asterisk' aria-label='Asterisk'></i></span>"); |
|
| 240 | }); |
|
| 241 | } |
|
| 242 | ||
| 243 | requiredFields(); |
|
| 244 | ||
| 245 | // Label Handers =================================================== |
|
| 246 | ||
| 247 | function labelHandlers() { |
|
| 248 | ||
| 249 | $("[class*='form__input-wrapper'] input, [class*='form__input-wrapper'] textarea").focusin(function (e) { |
|
| 250 | $(this).parent().addClass("active"); |
|
| 251 | }); |
|
| 252 | ||
| 253 | $("[class*='form__input-wrapper'] input, [class*='form__input-wrapper'] textarea").focusout(function (e) { |
|
| 254 | ||
| 255 | // Check for existing value. |
|
| 256 | ||
| 257 | if ($(this).val() == "") { |
|
| 258 | $(this).parent().removeClass("active"); |
|
| 259 | } |
|
| 260 | ||
| 261 | // Check Validity |
|
| 262 | ||
| 263 | if ($(this).isValid() == true) { |
|
| 264 | ||
| 265 | if ($(this).val() == "" || $(this).attr("type") == "password") { |
|
| 266 | $(this).parent().removeClass("valid"); |
|
| 267 | $(this).parent().removeClass("invalid"); |
|
| 268 | } else { |
|
| 269 | $(this).parent().addClass("valid"); |
|
| 270 | $(this).parent().removeClass("invalid"); |
|
| 271 | } |
|
| 272 | } else { |
|
| 273 | ||
| 274 | if ($(this).attr("type") == "password") { |
|
| 275 | return false; |
|
| 276 | } else { |
|
| 277 | $(this).parent().addClass("invalid"); |
|
| 278 | $(this).parent().removeClass("valid"); |
|
| 279 | } |
|
| 280 | } |
|
| 281 | }); |
|
| 282 | } |
|
| 283 | ||
| 284 | labelHandlers(); |
|
| 285 | ||
| 286 | // Individualizing repeater name and id attributes====================== |
|
| 287 | ||
| 288 | //Individualize template attributes |
|
| 289 | function appendToAttributes(parent, attribute, suffix) { |
|
| 290 | var conditions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; |
|
| 291 | ||
| 292 | var selector = "*[" + attribute + "]"; |
|
| 293 | ||
| 294 | //If conditions is set, only modify attributes that also |
|
| 295 | //satisfy that selector |
|
| 296 | if (conditions) { |
|
| 297 | selector = conditions + selector; |
|
| 298 | } |
|
| 299 | ||
| 300 | parent.find(selector).each(function () { |
|
| 301 | $(this).attr(attribute, $(this).attr(attribute) + suffix); |
|
| 302 | }); |
|
| 303 | } |
|
| 304 | ||
| 305 | //Individualize template attributes |
|
| 306 | function replaceInAttributes(parent, attribute, oldString, newString) { |
|
| 307 | var conditions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null; |
|
| 308 | ||
| 309 | var selector = "*[" + attribute + "]"; |
|
| 310 | ||
| 311 | //If conditions is set, only modify attributes that also |
|
| 312 | //satisfy that selector |
|
| 313 | if (conditions) { |
|
| 314 | selector = conditions + selector; |
|
| 315 | } |
|
| 316 | ||
| 317 | parent.find(selector).each(function () { |
|
| 318 | //replaces only the first instance of a match in a string |
|
| 319 | $(this).attr(attribute, $(this).attr(attribute).replace(oldString, newString)); |
|
| 320 | }); |
|
| 321 | } |
|
| 322 | ||
| 323 | //Return the next unused idAttr value |
|
| 324 | function getNextItemId(parent) { |
|
| 325 | var idAttr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "data-item-id"; |
|
| 326 | ||
| 327 | var maxId = 0; |
|
| 328 | parent.find("*[" + idAttr + "]").each(function () { |
|
| 329 | var id = parseInt($(this).attr(idAttr)); |
|
| 330 | if (id > maxId) { |
|
| 331 | maxId = id; |
|
| 332 | } |
|
| 333 | }); |
|
| 334 | return maxId + 1; |
|
| 335 | } |
|
| 336 | ||
| 337 | //The all in one function to set proper ids and form names |
|
| 338 | function individualizeFormIdsAndNames(template, wrapper) { |
|
| 339 | // Get New ID |
|
| 340 | var newId = getNextItemId(wrapper); |
|
| 341 | ||
| 342 | //Set date-item-id, used to track which newId's are taken |
|
| 343 | template.attr('data-item-id', newId); |
|
| 344 | ||
| 345 | //Differentiate real forms from templates |
|
| 346 | ||
| 347 | // filter, if we only want to affect certain results |
|
| 348 | var filter = ''; |
|
| 349 | ||
| 350 | replaceInAttributes(template, 'id', ':template', 'new', filter); |
|
| 351 | replaceInAttributes(template, 'for', ':template', 'new', filter); |
|
| 352 | replaceInAttributes(template, 'name', ':template', 'new', filter); |
|
| 353 | replaceInAttributes(template, 'submit', ':template', 'new', filter); |
|
| 354 | replaceInAttributes(template, 'value', ':template', 'new', filter + '[name=submit]'); |
|
| 355 | ||
| 356 | replaceInAttributes(template, 'id', ':id', newId, filter); |
|
| 357 | replaceInAttributes(template, 'for', ':id', newId, filter); |
|
| 358 | replaceInAttributes(template, 'name', ':id', newId, filter); |
|
| 359 | replaceInAttributes(template, 'submit', ':id', newId, filter); |
|
| 360 | replaceInAttributes(template, 'value', ':id', newId, filter + '[name=submit]'); |
|
| 361 | } |
|
| 362 | ||
| 363 | // Profile List Handlers =============================================== |
|
| 364 | ||
| 365 | // Add Profile Element |
|
| 366 | function addProfileElement(trigger) { |
|
| 367 | ||
| 368 | // Get Parent |
|
| 369 | var parent = $(trigger).parents(".profile-list"); |
|
| 370 | ||
| 371 | // Get List Wrapper |
|
| 372 | var wrapper = parent.find(".profile-element-list"); |
|
| 373 | ||
| 374 | // Set Null to Hidden |
|
| 375 | parent.find(".profile-null").removeClass("active"); |
|
| 376 | ||
| 377 | // Get Template |
|
| 378 | var template = parent.find(".profile-element.template").clone(); |
|
| 379 | ||
| 380 | // Remove Template Class |
|
| 381 | template.removeClass("template"); |
|
| 382 | ||
| 383 | //Set ids and form names to be unique |
|
| 384 | individualizeFormIdsAndNames(template, wrapper); |
|
| 385 | ||
| 386 | // Prepend Clone to the Wrapper |
|
| 387 | wrapper.prepend(template); |
|
| 388 | ||
| 389 | // Reactivate Required Fields |
|
| 390 | requiredFields(); |
|
| 391 | ||
| 392 | // Reactivate Labels |
|
| 393 | labelHandlers(); |
|
| 394 | ||
| 395 | // Reactivate Nested Relatives |
|
| 396 | loadProfileRelatives(); |
|
| 397 | } |
|
| 398 | ||
| 399 | // Click Trigger |
|
| 400 | $(".profile-list__add-element-trigger").on("click", function (e) { |
|
| 401 | ||
| 402 | // Prevent Default Functions |
|
| 403 | e.preventDefault(); |
|
| 404 | ||
| 405 | // Add Profile Elements |
|
| 406 | addProfileElement(this); |
|
| 407 | }); |
|
| 408 | ||
| 409 | // Enter Key Trigger |
|
| 410 | $(".profile-list__add-element-trigger").on("keyup", function (e) { |
|
| 411 | ||
| 412 | if (e.which == 13) { |
|
| 413 | ||
| 414 | // Prevent Default Functions |
|
| 415 | e.preventDefault(); |
|
| 416 | ||
| 417 | // Add Profile Elements |
|
| 418 | addProfileElement(this); |
|
| 419 | } |
|
| 420 | }); |
|
| 421 | ||
| 422 | // Remove Profile Element |
|
| 423 | ||
| 424 | // Add Profile Relative |
|
| 425 | function addProfileRelative(trigger) { |
|
| 426 | ||
| 427 | // Get Parent |
|
| 428 | var parent = $(trigger).parents(".profile-relative-list"); |
|
| 429 | ||
| 430 | // Get List Wrapper |
|
| 431 | var wrapper = parent.find(".profile-relative-list__wrapper"); |
|
| 432 | ||
| 433 | // Set Null to Hidden |
|
| 434 | // parent.find(".profile-null").removeClass("active"); |
|
| 435 | ||
| 436 | // Get Template |
|
| 437 | var template = parent.find(".profile-relative.template").clone(); |
|
| 438 | ||
| 439 | // Remove Template Class |
|
| 440 | template.removeClass("template"); |
|
| 441 | ||
| 442 | //Set ids and form names to be unique |
|
| 443 | individualizeFormIdsAndNames(template, wrapper); |
|
| 444 | ||
| 445 | // Append Clone to the Wrapper |
|
| 446 | wrapper.append(template); |
|
| 447 | ||
| 448 | // Reactivate Required Fields |
|
| 449 | requiredFields(); |
|
| 450 | ||
| 451 | // Reactivate Labels |
|
| 452 | labelHandlers(); |
|
| 453 | ||
| 454 | // Reactivate Nested Relatives |
|
| 455 | loadProfileRelativeDeletion(); |
|
| 456 | } |
|
| 457 | ||
| 458 | // Load Function |
|
| 459 | function loadProfileRelatives() { |
|
| 460 | ||
| 461 | // Click Trigger |
|
| 462 | $(".profile-relative__add-trigger").off("click"); |
|
| 463 | ||
| 464 | $(".profile-relative__add-trigger").on("click", function (e) { |
|
| 465 | ||
| 466 | // Prevent Default Functions |
|
| 467 | e.preventDefault(); |
|
| 468 | ||
| 469 | // Add Profile Relative |
|
| 470 | addProfileRelative(this); |
|
| 471 | }); |
|
| 472 | ||
| 473 | // Enter Key Trigger |
|
| 474 | $(".profile-relative__add-trigger").off("keyup"); |
|
| 475 | ||
| 476 | $(".profile-relative__add-trigger").on("keyup", function (e) { |
|
| 477 | ||
| 478 | if (e.which == 13) { |
|
| 479 | ||
| 480 | // Prevent Default Functions |
|
| 481 | e.preventDefault(); |
|
| 482 | ||
| 483 | // Add Profile Relative |
|
| 484 | addProfileRelative(this); |
|
| 485 | } |
|
| 486 | }); |
|
| 487 | } |
|
| 488 | ||
| 489 | loadProfileRelatives(); |
|
| 490 | ||
| 491 | // Remove Profile Relative |
|
| 492 | function deleteProfileRelative(trigger) { |
|
| 493 | ||
| 494 | $(trigger).parents(".profile-relative").remove(); |
|
| 495 | } |
|
| 496 | ||
| 497 | // Load Function |
|
| 498 | function loadProfileRelativeDeletion() { |
|
| 499 | ||
| 500 | // Click Trigger |
|
| 501 | $(".profile-relative__remove-trigger").on("click", function (e) { |
|
| 502 | ||
| 503 | // Prevent Default Functions |
|
| 504 | e.preventDefault(); |
|
| 505 | ||
| 506 | // Delete Profile Relative |
|
| 507 | deleteProfileRelative(this); |
|
| 508 | }); |
|
| 509 | ||
| 510 | // Enter Key Trigger |
|
| 511 | $(".profile-relative__remove-trigger").on("keyup", function (e) { |
|
| 512 | ||
| 513 | if (e.which == 13) { |
|
| 514 | ||
| 515 | // Prevent Default Functions |
|
| 516 | e.preventDefault(); |
|
| 517 | ||
| 518 | // Delete Profile Relative |
|
| 519 | deleteProfileRelative(this); |
|
| 520 | } |
|
| 521 | }); |
|
| 522 | } |
|
| 523 | ||
| 524 | loadProfileRelativeDeletion(); |
|
| 525 | ||
| 526 | // Experience Handlers ================================================= |
|
| 527 | ||
| 528 | // Degrees |
|
| 529 | ||
| 530 | function addDegree(trigger) { |
|
| 531 | ||
| 532 | // Get Wrapper |
|
| 533 | var wrapper = $(".application-post__experience-wrapper"); |
|
| 534 | ||
| 535 | // Get Template |
|
| 536 | var template = $(".application-post__accordion--degree.template").clone(); |
|
| 537 | ||
| 538 | // Remove Template Class |
|
| 539 | template.removeClass("template"); |
|
| 540 | ||
| 541 | //Set ids and form names to be unique |
|
| 542 | individualizeFormIdsAndNames(template, wrapper); |
|
| 543 | ||
| 544 | // Append Clone to the Wrapper |
|
| 545 | wrapper.append(template); |
|
| 546 | ||
| 547 | requiredFields(); |
|
| 548 | labelHandlers(); |
|
| 549 | } |
|
| 550 | ||
| 551 | $("#addDegreeButton").on("click", function (e) { |
|
| 552 | ||
| 553 | e.preventDefault(); |
|
| 554 | ||
| 555 | addDegree(this); |
|
| 556 | }); |
|
| 557 | ||
| 558 | $("#addDegreeButton").on("keyup", function (e) { |
|
| 559 | ||
| 560 | if (e.which == 13) { |
|
| 561 | e.preventDefault(); |
|
| 562 | addDegree(this); |
|
| 563 | } |
|
| 564 | }); |
|
| 565 | ||
| 566 | // Courses |
|
| 567 | ||
| 568 | function addCourse(trigger) { |
|
| 569 | ||
| 570 | // Get Wrapper |
|
| 571 | var wrapper = $(".application-post__experience-wrapper"); |
|
| 572 | ||
| 573 | // Get Template |
|
| 574 | var template = $(".application-post__accordion--course.template").clone(); |
|
| 575 | ||
| 576 | // Remove Template Class |
|
| 577 | template.removeClass("template"); |
|
| 578 | ||
| 579 | //Set ids and form names to be unique |
|
| 580 | individualizeFormIdsAndNames(template, wrapper); |
|
| 581 | ||
| 582 | // Append Clone to the Wrapper |
|
| 583 | wrapper.append(template); |
|
| 584 | ||
| 585 | requiredFields(); |
|
| 586 | labelHandlers(); |
|
| 587 | } |
|
| 588 | ||
| 589 | $("#addCourseButton").on("click", function (e) { |
|
| 590 | ||
| 591 | e.preventDefault(); |
|
| 592 | ||
| 593 | addCourse(this); |
|
| 594 | }); |
|
| 595 | ||
| 596 | $("#addCourseButton").on("keyup", function (e) { |
|
| 597 | ||
| 598 | if (e.which == 13) { |
|
| 599 | e.preventDefault(); |
|
| 600 | addCourse(this); |
|
| 601 | } |
|
| 602 | }); |
|
| 603 | ||
| 604 | // Work |
|
| 605 | ||
| 606 | function addWork(trigger) { |
|
| 607 | ||
| 608 | // Get Wrapper |
|
| 609 | var wrapper = $(".application-post__experience-wrapper"); |
|
| 610 | ||
| 611 | // Get Template |
|
| 612 | var template = $(".application-post__accordion--work.template").clone(); |
|
| 613 | ||
| 614 | // Remove Template Class |
|
| 615 | template.removeClass("template"); |
|
| 616 | ||
| 617 | //Set ids and form names to be unique |
|
| 618 | individualizeFormIdsAndNames(template, wrapper); |
|
| 619 | ||
| 620 | // Append Clone to the Wrapper |
|
| 621 | wrapper.append(template); |
|
| 622 | ||
| 623 | requiredFields(); |
|
| 624 | labelHandlers(); |
|
| 625 | } |
|
| 626 | ||
| 627 | $("#addWorkButton").on("click", function (e) { |
|
| 628 | ||
| 629 | e.preventDefault(); |
|
| 630 | ||
| 631 | addWork(this); |
|
| 632 | }); |
|
| 633 | ||
| 634 | $("#addWorkButton").on("keyup", function (e) { |
|
| 635 | ||
| 636 | if (e.which == 13) { |
|
| 637 | e.preventDefault(); |
|
| 638 | addWork(this); |
|
| 639 | } |
|
| 640 | }); |
|
| 641 | ||
| 642 | // Create Job Handlers ================================================= |
|
| 643 | ||
| 644 | // Tasks |
|
| 645 | ||
| 646 | function addTask(trigger) { |
|
| 647 | ||
| 648 | // Get Wrapper |
|
| 649 | var wrapper = $(".manager-jobs__create-task-wrapper"); |
|
| 650 | ||
| 651 | // Get Template |
|
| 652 | var template = $(".manager-jobs__create-task.template").clone(); |
|
| 653 | ||
| 654 | console.log(wrapper.find(".manager-jobs__create-task")); |
|
| 655 | ||
| 656 | // Get New ID |
|
| 657 | if (wrapper.find(".manager-jobs__create-task").length == 0) { |
|
| 658 | var newID = parseInt(template.attr("data-task-id")) + 1; |
|
| 659 | } else { |
|
| 660 | var newID = parseInt(wrapper.find("[class*='manager-jobs__create-task']").last().attr("data-task-id")) + 1; |
|
| 661 | } |
|
| 662 | ||
| 663 | // Remove Template Class |
|
| 664 | template.removeClass("template"); |
|
| 665 | ||
| 666 | //TODO: replace with call to individualizeFormIdsAndNames(template, wrapper); |
|
| 667 | //TODO: This requires changes to JobController@create, because the id would change places |
|
| 668 | ||
| 669 | // Assign the New ID |
|
| 670 | template.attr("data-task-id", newID); |
|
| 671 | ||
| 672 | // Add newID as suffix to all "id" and "for" attributes |
|
| 673 | template.find("*[id]").each(function () { |
|
| 674 | $(this).attr("id", this.id + newID); |
|
| 675 | }); |
|
| 676 | template.find("*[for]").each(function () { |
|
| 677 | $(this).attr("for", $(this).attr("for") + newID); |
|
| 678 | }); |
|
| 679 | ||
| 680 | // Replace :id with newID in all form names |
|
| 681 | template.find("*[name]").each(function () { |
|
| 682 | $(this).attr('name', $(this).attr("name").replace(":id", newID)); |
|
| 683 | }); |
|
| 684 | ||
| 685 | // Task (English) |
|
| 686 | //template.find("[data-form-id*='task-english']").find("label").attr("for", "taskEN" + newID); |
|
| 687 | //template.find("[data-form-id*='task-english']").find("input").attr("id", "taskEN" + newID); |
|
| 688 | ||
| 689 | // Task (French) |
|
| 690 | //template.find("[data-form-id*='task-french']").find("label").attr("for", "taskFR" + newID); |
|
| 691 | //template.find("[data-form-id*='task-french']").find("input").attr("id", "taskFR" + newID); |
|
| 692 | ||
| 693 | // Append Clone to the Wrapper |
|
| 694 | wrapper.append(template); |
|
| 695 | ||
| 696 | requiredFields(); |
|
| 697 | labelHandlers(); |
|
| 698 | deleteTaskTrigger(); |
|
| 699 | } |
|
| 700 | ||
| 701 | $("#addTaskButton").on("click", function (e) { |
|
| 702 | ||
| 703 | e.preventDefault(); |
|
| 704 | ||
| 705 | addTask(this); |
|
| 706 | }); |
|
| 707 | ||
| 708 | $("#addTaskButton").on("keyup", function (e) { |
|
| 709 | ||
| 710 | if (e.which == 13) { |
|
| 711 | e.preventDefault(); |
|
| 712 | addTask(this); |
|
| 713 | } |
|
| 714 | }); |
|
| 715 | ||
| 716 | // Task Deletion |
|
| 717 | ||
| 718 | function deleteTask(trigger) { |
|
| 719 | ||
| 720 | $(trigger).parents(".manager-jobs__create-task").remove(); |
|
| 721 | } |
|
| 722 | ||
| 723 | function deleteTaskTrigger() { |
|
| 724 | ||
| 725 | $(".manager-jobs__delete-task-button").on("click", function (e) { |
|
| 726 | ||
| 727 | e.preventDefault(); |
|
| 728 | ||
| 729 | deleteTask(this); |
|
| 730 | }); |
|
| 731 | ||
| 732 | $(".manager-jobs__delete-task-button").on("keyup", function (e) { |
|
| 733 | ||
| 734 | if (e.which == 13) { |
|
| 735 | e.preventDefault(); |
|
| 736 | deleteTask(this); |
|
| 737 | } |
|
| 738 | }); |
|
| 739 | } |
|
| 740 | ||
| 741 | deleteTaskTrigger(); |
|
| 742 | ||
| 743 | // Skills |
|
| 744 | ||
| 745 | function addSkill(trigger) { |
|
| 746 | ||
| 747 | // Get Parent |
|
| 748 | var parent = $(trigger).parents(".manager-jobs__skill-wrapper"); |
|
| 749 | ||
| 750 | // Get Wrapper |
|
| 751 | var wrapper = parent.find(".manager-jobs__create-skill-wrapper"); |
|
| 752 | ||
| 753 | // Get Template |
|
| 754 | var template = parent.find(".manager-jobs__create-skill.template").clone(); |
|
| 755 | ||
| 756 | console.log(wrapper.find(".manager-jobs__create-skill")); |
|
| 757 | ||
| 758 | // Remove Template Class |
|
| 759 | template.removeClass("template"); |
|
| 760 | ||
| 761 | //Set ids and form names to be unique |
|
| 762 | individualizeFormIdsAndNames(template, wrapper); |
|
| 763 | ||
| 764 | // Append Clone to the Wrapper |
|
| 765 | wrapper.append(template); |
|
| 766 | ||
| 767 | requiredFields(); |
|
| 768 | labelHandlers(); |
|
| 769 | deleteSkillTrigger(); |
|
| 770 | } |
|
| 771 | ||
| 772 | $(".manager-jobs__add-skill-button").on("click", function (e) { |
|
| 773 | ||
| 774 | e.preventDefault(); |
|
| 775 | ||
| 776 | addSkill(this); |
|
| 777 | }); |
|
| 778 | ||
| 779 | $(".manager-jobs__add-skill-button").on("keyup", function (e) { |
|
| 780 | ||
| 781 | if (e.which == 13) { |
|
| 782 | e.preventDefault(); |
|
| 783 | addSkill(this); |
|
| 784 | } |
|
| 785 | }); |
|
| 786 | ||
| 787 | // Skill Deletion |
|
| 788 | ||
| 789 | function deleteSkill(trigger) { |
|
| 790 | ||
| 791 | $(trigger).parents(".manager-jobs__create-skill").remove(); |
|
| 792 | } |
|
| 793 | ||
| 794 | function deleteSkillTrigger() { |
|
| 795 | ||
| 796 | $(".manager-jobs__delete-skill-button").on("click", function (e) { |
|
| 797 | ||
| 798 | e.preventDefault(); |
|
| 799 | ||
| 800 | deleteSkill(this); |
|
| 801 | }); |
|
| 802 | ||
| 803 | $(".manager-jobs__delete-skill-button").on("keyup", function (e) { |
|
| 804 | ||
| 805 | if (e.which == 13) { |
|
| 806 | e.preventDefault(); |
|
| 807 | deleteSkill(this); |
|
| 808 | } |
|
| 809 | }); |
|
| 810 | } |
|
| 811 | ||
| 812 | deleteSkillTrigger(); |
|
| 813 | ||
| 814 | // Questions |
|
| 815 | ||
| 816 | function addQuestion(trigger) { |
|
| 817 | ||
| 818 | // Get Wrapper |
|
| 819 | var wrapper = $(".manager-jobs__create-question-wrapper"); |
|
| 820 | ||
| 821 | // Get Template |
|
| 822 | var template = $(".manager-jobs__create-question.template").clone(); |
|
| 823 | ||
| 824 | console.log(wrapper.find(".manager-jobs__create-question")); |
|
| 825 | ||
| 826 | // Get New ID |
|
| 827 | if (wrapper.find(".manager-jobs__create-question").length == 0) { |
|
| 828 | var newID = parseInt(template.attr("data-question-id")) + 1; |
|
| 829 | } else { |
|
| 830 | var newID = parseInt(wrapper.find("[class*='manager-jobs__create-question']").last().attr("data-question-id")) + 1; |
|
| 831 | } |
|
| 832 | ||
| 833 | // Remove Template Class |
|
| 834 | template.removeClass("template"); |
|
| 835 | ||
| 836 | //TODO: replace with call to individualizeFormIdsAndNames(template, wrapper); |
|
| 837 | //TODO: This requires changes to JobController@create, because the id would change places |
|
| 838 | ||
| 839 | // Assign the New ID |
|
| 840 | template.attr("data-question-id", newID); |
|
| 841 | ||
| 842 | // Add newID as suffix to all "id" and "for" attributes |
|
| 843 | template.find("*[id]").each(function () { |
|
| 844 | $(this).attr("id", this.id + newID); |
|
| 845 | }); |
|
| 846 | template.find("*[for]").each(function () { |
|
| 847 | $(this).attr("for", $(this).attr("for") + newID); |
|
| 848 | }); |
|
| 849 | ||
| 850 | // Replace :id with newID in all form names |
|
| 851 | template.find("*[name]").each(function () { |
|
| 852 | $(this).attr('name', $(this).attr("name").replace(":id", newID)); |
|
| 853 | }); |
|
| 854 | ||
| 855 | // Edit Form IDs |
|
| 856 | // |
|
| 857 | // // Queestion (English) |
|
| 858 | // template.find("[data-form-id*='question-english']").find("label").attr("for", "questionEN" + newID); |
|
| 859 | // template.find("[data-form-id*='question-english']").find("input").attr("id", "questionEN" + newID); |
|
| 860 | // |
|
| 861 | // // Queestion (French) |
|
| 862 | // template.find("[data-form-id*='question-french']").find("label").attr("for", "questionFR" + newID); |
|
| 863 | // template.find("[data-form-id*='question-french']").find("input").attr("id", "questionFR" + newID); |
|
| 864 | ||
| 865 | // Append Clone to the Wrapper |
|
| 866 | wrapper.append(template); |
|
| 867 | ||
| 868 | requiredFields(); |
|
| 869 | labelHandlers(); |
|
| 870 | deleteQuestionTrigger(); |
|
| 871 | } |
|
| 872 | ||
| 873 | $("#addQuestionButton").on("click", function (e) { |
|
| 874 | ||
| 875 | e.preventDefault(); |
|
| 876 | ||
| 877 | addQuestion(this); |
|
| 878 | }); |
|
| 879 | ||
| 880 | $("#addQuestionButton").on("keyup", function (e) { |
|
| 881 | ||
| 882 | if (e.which == 13) { |
|
| 883 | e.preventDefault(); |
|
| 884 | addQuestion(this); |
|
| 885 | } |
|
| 886 | }); |
|
| 887 | ||
| 888 | // Question Deletion |
|
| 889 | ||
| 890 | function deleteQuestion(trigger) { |
|
| 891 | ||
| 892 | $(trigger).parents(".manager-jobs__create-question").remove(); |
|
| 893 | } |
|
| 894 | ||
| 895 | function deleteQuestionTrigger() { |
|
| 896 | ||
| 897 | $(".manager-jobs__delete-question-button").on("click", function (e) { |
|
| 898 | ||
| 899 | e.preventDefault(); |
|
| 900 | ||
| 901 | deleteQuestion(this); |
|
| 902 | }); |
|
| 903 | ||
| 904 | $(".manager-jobs__delete-question-button").on("keyup", function (e) { |
|
| 905 | ||
| 906 | if (e.which == 13) { |
|
| 907 | e.preventDefault(); |
|
| 908 | deleteQuestion(this); |
|
| 909 | } |
|
| 910 | }); |
|
| 911 | } |
|
| 912 | ||
| 913 | deleteQuestionTrigger(); |
|
| 914 | }); |
|
| 915 | })(jQuery); |
|
| 916 | ||
| 917 | /***/ }), |
|
| 918 | /* 1 */, |
|
| 919 | /* 2 */, |
|
| 920 | /* 3 */ |
|