mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-06 15:05:26 +08:00
Merge pull request #145 from mz3944/mz_checklists_items_move_and_step/result_comment_fix
Fixed step's checklist items editing (items not multiplying and new i…
This commit is contained in:
commit
ea898ed3ce
2 changed files with 61 additions and 45 deletions
|
@ -97,6 +97,7 @@ function initResultCommentsLink($el) {
|
||||||
moreBtn.remove();
|
moreBtn.remove();
|
||||||
} else {
|
} else {
|
||||||
moreBtn.attr("href", data.more_url);
|
moreBtn.attr("href", data.more_url);
|
||||||
|
moreBtn.trigger("blur");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reposition dropdown comment options
|
// Reposition dropdown comment options
|
||||||
|
@ -113,9 +114,6 @@ function initResultCommentTabAjax() {
|
||||||
var targetId = $this.attr("aria-controls");
|
var targetId = $this.attr("aria-controls");
|
||||||
|
|
||||||
if (parentNode.hasClass("active")) {
|
if (parentNode.hasClass("active")) {
|
||||||
// TODO move to fn
|
|
||||||
parentNode.removeClass("active");
|
|
||||||
$("#" + targetId).removeClass("active");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -137,9 +135,6 @@ function initResultCommentTabAjax() {
|
||||||
})
|
})
|
||||||
.on("ajax:error", function(e, xhr, status, error) {
|
.on("ajax:error", function(e, xhr, status, error) {
|
||||||
// TODO
|
// TODO
|
||||||
})
|
|
||||||
.on("ajax:complete", function () {
|
|
||||||
$(this).tab("show");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -422,6 +422,7 @@ function initStepCommentsLink($el) {
|
||||||
moreBtn.remove();
|
moreBtn.remove();
|
||||||
} else {
|
} else {
|
||||||
moreBtn.attr("href", data.more_url);
|
moreBtn.attr("href", data.more_url);
|
||||||
|
moreBtn.trigger("blur");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reposition dropdown comment options
|
// Reposition dropdown comment options
|
||||||
|
@ -439,9 +440,6 @@ function initStepCommentTabAjax() {
|
||||||
var targetId = $this.attr("aria-controls");
|
var targetId = $this.attr("aria-controls");
|
||||||
|
|
||||||
if (parentNode.hasClass("active")) {
|
if (parentNode.hasClass("active")) {
|
||||||
// TODO move to fn
|
|
||||||
parentNode.removeClass("active");
|
|
||||||
$("#" + targetId).removeClass("active");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -463,9 +461,6 @@ function initStepCommentTabAjax() {
|
||||||
})
|
})
|
||||||
.on("ajax:error", function(e, xhr, status, error) {
|
.on("ajax:error", function(e, xhr, status, error) {
|
||||||
// TODO
|
// TODO
|
||||||
})
|
|
||||||
.on("ajax:complete", function () {
|
|
||||||
$(this).tab("show");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -495,49 +490,75 @@ function initCallBacks() {
|
||||||
initDeleteStep();
|
initDeleteStep();
|
||||||
}
|
}
|
||||||
|
|
||||||
function reorderCheckboxData(el) {
|
/*
|
||||||
var itemIds = [];
|
* Correction for sorting with "Sortable.min" JS library to work correctly with
|
||||||
var checkboxes = $(el).find(".nested_fields:not(:hidden) .form-group");
|
* "nested_form_fields" gem.
|
||||||
|
*/
|
||||||
|
function reorderCheckboxData(checkboxUl) {
|
||||||
|
// Make sure checkbox item insertion script is always at the bottom of "ul"
|
||||||
|
// tag, otherwise item will not be inserted at bottom
|
||||||
|
if(!$(checkboxUl).children().last().is('script')) {
|
||||||
|
$(checkboxUl).find("script").appendTo(checkboxUl);
|
||||||
|
}
|
||||||
|
|
||||||
checkboxes.each(function () {
|
var $checkboxes = $(checkboxUl).find(".nested_fields");
|
||||||
var itemId = $(this).find("label").attr("for").match(/(\d+)_text/)[1];
|
$checkboxes.each(function (itemPos) {
|
||||||
itemIds.push(itemId);
|
|
||||||
});
|
|
||||||
|
|
||||||
itemIds.sort();
|
|
||||||
|
|
||||||
checkboxes.each(function (i) {
|
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
var label = $this.find(".control-label");
|
|
||||||
var input = $this.find(".form-control");
|
|
||||||
var posInput = $this.parent().find(".checklist-item-pos");
|
|
||||||
var itemId = itemIds[i];
|
|
||||||
var forAttr = label.attr("for");
|
|
||||||
var idAttr = input.attr("id");
|
|
||||||
var nameAttr = input.attr("name");
|
|
||||||
var posIdAttr = posInput.attr("id");
|
|
||||||
var posNameAttr = posInput.attr("name");
|
|
||||||
|
|
||||||
forAttr = forAttr.replace(/\d+_text/, itemId + "_text");
|
var $formGroup = $this.find(".form-group");
|
||||||
nameAttr = nameAttr.replace(/\[\d+\]\[text\]/, "[" + itemId + "][text]");
|
var $label = $formGroup.find(".control-label");
|
||||||
posIdAttr = posIdAttr.replace(/\d+_position/, itemId + "_text");
|
var $textInput = $formGroup.find(".checklist-item-text");
|
||||||
posNameAttr = posNameAttr.replace(/\[\d+\]\[position\]/, "[" + itemId + "][position]");
|
var $posInput = $formGroup.parent().find(".checklist-item-pos");
|
||||||
|
var $destroyLink = $this.find(".remove_nested_fields_link");
|
||||||
|
|
||||||
label.attr("for", forAttr);
|
var labelFor = $label.attr("for");
|
||||||
input.attr("name", nameAttr);
|
var textName = $textInput.attr("name");
|
||||||
input.attr("id", forAttr);
|
var textId = $textInput.attr("id");
|
||||||
posInput.attr("name", posNameAttr);
|
var posName = $posInput.attr("name");
|
||||||
posInput.attr("id", posIdAttr);
|
var posId = $posInput.attr("id");
|
||||||
posInput.val(itemId);
|
var destroyLink = $destroyLink.attr("data-delete-association-field-name");
|
||||||
|
|
||||||
|
labelFor = labelFor.replace(/\d+_text/, itemPos + "_text");
|
||||||
|
textName = textName.replace(/\[\d+\]\[text\]/, "[" + itemPos + "][text]");
|
||||||
|
textId = textId.replace(/\d+_text/, itemPos + "_text");
|
||||||
|
posName = posName.replace(/\[\d+\]\[position\]/, "[" + itemPos + "][position]");
|
||||||
|
posId = posId.replace(/\d+_position/, itemPos + "_position");
|
||||||
|
destroyLink = destroyLink.replace(/\[\d+\]\[_destroy\]/, "[" + itemPos + "][_destroy]");
|
||||||
|
|
||||||
|
$label.attr("for", labelFor);
|
||||||
|
$textInput.attr("name", textName); // Actually needed for sorting to work
|
||||||
|
$textInput.attr("id", textId);
|
||||||
|
$posInput.attr("name", posName);
|
||||||
|
$posInput.attr("id", posId);
|
||||||
|
$posInput.val(itemPos);
|
||||||
|
$destroyLink.attr("data-delete-association-field-name", destroyLink);
|
||||||
|
|
||||||
|
var $idInput = $this.find("> input");
|
||||||
|
if ($idInput.length) {
|
||||||
|
var idName = $idInput.attr("name");
|
||||||
|
var idId = $idInput.attr("id");
|
||||||
|
|
||||||
|
idName = idName.replace(/\[\d+\]\[id\]/, "[" + itemPos + "][id]");
|
||||||
|
idId = idId.replace(/\d+_id/, itemPos + "_id");
|
||||||
|
|
||||||
|
$idInput.attr("name", idName);
|
||||||
|
$idInput.attr("id", idId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this.css('display') == 'none') {
|
||||||
|
// Actually needed for deleting to work
|
||||||
|
var $destroyInput = $this.prev();
|
||||||
|
var destroyName = $destroyInput.attr("name");
|
||||||
|
destroyName = destroyName.replace(/\[\d+\]\[_destroy\]/, "[" + itemPos + "][_destroy]");
|
||||||
|
$destroyInput.attr("name", destroyName);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function enableCheckboxSorting(el) {
|
function enableCheckboxSorting(el) {
|
||||||
Sortable.create(el, {
|
Sortable.create(el, {
|
||||||
draggable: 'fieldset',
|
draggable: 'fieldset',
|
||||||
filter: 'script',
|
|
||||||
handle: '.glyphicon-chevron-right',
|
handle: '.glyphicon-chevron-right',
|
||||||
|
|
||||||
onUpdate: function () {
|
onUpdate: function () {
|
||||||
reorderCheckboxData(el);
|
reorderCheckboxData(el);
|
||||||
}
|
}
|
||||||
|
@ -548,7 +569,7 @@ function initializeCheckboxSorting() {
|
||||||
var el = $("#new-step-checklists a[data-association-path=step_checklists]");
|
var el = $("#new-step-checklists a[data-association-path=step_checklists]");
|
||||||
|
|
||||||
el.click(function () {
|
el.click(function () {
|
||||||
// calling code below must be defered because at this step HTML in not
|
// calling code below must be defered because at this step HTML is not
|
||||||
// inserted into DOM.
|
// inserted into DOM.
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
var list = el.parent().find("fieldset.nested_step_checklists:last ul");
|
var list = el.parent().find("fieldset.nested_step_checklists:last ul");
|
||||||
|
|
Loading…
Reference in a new issue