1import { Controller } from "@hotwired/stimulus" 2 3export default class extends Controller { 4 5 static targets = [ "keyDate" ] 6 7 connect() { 8 this.#setupInlineEdit(); 9 this.#bindInlineEdit(); 10 } 11 12 #reloadRelatedFields($field, data) { 13 var $container, $otherContainer, $otherContainerInput, $placeholder, area, deliverable_id, new_value, other_area, updateClass; 14 new_value = $field.val(); 15 $container = $field.closest(".key_date_container"); 16 deliverable_id = $container.data("item_id"); 17 area = $container.data("area"); 18 other_area = area === "arm_content" ? "timeline" : "arm_content"; 19 $otherContainer = $(`#key_date_for_deliverable_${deliverable_id}_${other_area}`); 20 $otherContainerInput = $otherContainer.find("input"); 21 $placeholder = $otherContainer.find("[data-role='editField']"); 22 $otherContainerInput.val(new_value); 23 $placeholder.html(new_value); 24 updateClass = data.is_overdue ? 'addClass' : 'removeClass'; 25 $container.find("input")[updateClass]("overdue"); 26 return $otherContainerInput[updateClass]("overdue"); 27 } 28 29 #updateDeliverableDueDate(date, callback) { 30 $.ajax({ 31 url: $(this.element).find(".key_date_container").data("update_url"), 32 type: "patch", 33 dataType: "json", 34 data: { 35 deliverable: { 36 "end_date": date 37 } 38 } 39 }).done(function(data) { 40 return typeof callback === "function" ? callback(data) : void 0; 41 }).fail(function(jqXHR, textStatus, errorThrown) { 42 switch (jqXHR.status) { 43 case 422: 44 return pam.modules.inlineEditing.processErrors(jqXHR.responseText); 45 case 500: 46 return window.unexpectedError(); 47 } 48 }); 49 }; 50 51 #bindInlineEdit() { 52 $(this.element).off("inlineEdit:save:clicked"); 53 $(this.element).on("inlineEdit:save:clicked", (e, fieldInfo) => { 54 this.#updateDeliverableDueDate(fieldInfo.$field.val(), (data) => { 55 $(this.element).trigger("inlineEdit:save:success", [fieldInfo]); 56 this.#reloadRelatedFields(fieldInfo.$field, data); 57 }); 58 }); 59 } 60 61 62 #closeOtherTimelineOpenFields($container) { 63 const $timeline = $container.closest(".timeline_in_page_container"); 64 if ($timeline.length) { 65 $timeline.find(".editableFieldOpen").not($container).find("[data-role='cancelEdit']").trigger("click"); 66 } 67 $(".arm_step_title_container").removeClass("edit_step_date_open"); 68 return $container.closest(".arm_step_title_container").addClass("edit_step_date_open"); 69 } 70 71 #setupInlineEdit() { 72 if (!this.keyDateTargets[0]?.dataset.initialised) { 73 return $('body').on("datepickers:init", () => this.#initInlineEdit()); 74 } 75 76 this.#initInlineEdit(); 77 } 78 79 #initInlineEdit() { 80 new pam.modules.inlineEditing({ 81 context: `#${this.element.id}`, 82 editFieldWidth: "auto", 83 styling: "light isms_online_brand" 84 }); 85 $(this.element).off('inlineEdit:show') 86 $(this.element).on('inlineEdit:show', (event, data) => { 87 this.#closeOtherTimelineOpenFields(data.$container); 88 }); 89 } 90}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.