| Conditions | 1 |
| Paths | 1 |
| Total Lines | 828 |
| Code Lines | 331 |
| Lines | 828 |
| Ratio | 100 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | View Code Duplication | /******/ (function(modules) { // webpackBootstrap |
|
| 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); |
||
| 934 | /******/ ]); |