mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-13 00:24:42 +08:00
prevent to duplicate new step [fixes SCI-1280]
This commit is contained in:
parent
18e11fde59
commit
b21923cf98
2 changed files with 624 additions and 585 deletions
|
@ -4,6 +4,9 @@
|
||||||
//= require assets
|
//= require assets
|
||||||
//= require comments
|
//= require comments
|
||||||
|
|
||||||
|
(function(global) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
// Sets callbacks for toggling checkboxes
|
// Sets callbacks for toggling checkboxes
|
||||||
function applyCheckboxCallBack() {
|
function applyCheckboxCallBack() {
|
||||||
$("[data-action='check-item']").on('click', function(e){
|
$("[data-action='check-item']").on('click', function(e){
|
||||||
|
@ -418,9 +421,15 @@ function initEditableHandsOnTable(root) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyCancelOnNew() {
|
function applyCancelOnNew() {
|
||||||
$("[data-action='cancel-new']").click(function() {
|
$("[data-action='cancel-new']").click(function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
event.stopImmediatePropagation();
|
||||||
|
|
||||||
var $form = $(this).closest("form");
|
var $form = $(this).closest("form");
|
||||||
$form.parent().remove();
|
$form.parent().remove().promise().done(function() {
|
||||||
|
newStepHandler();
|
||||||
|
});
|
||||||
toggleButtons(true);
|
toggleButtons(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -532,30 +541,54 @@ function initializeCheckboxSorting() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New step AJAX
|
// New step AJAX
|
||||||
$("[data-action='new-step']").on("ajax:success", function(e, data) {
|
function newStepHandler() {
|
||||||
var $form = $(data.html);
|
$("[data-action='new-step']").off().on('click', function(event) {
|
||||||
$("#steps").append($form);
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
event.stopImmediatePropagation();
|
||||||
|
var $btn = $(this);
|
||||||
|
$btn.off();
|
||||||
|
animateSpinner(null, true);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: $btn.data('href'),
|
||||||
|
method: 'GET',
|
||||||
|
success: function(data) {
|
||||||
|
var $form = $(data.html);
|
||||||
|
$('#steps').append($form).promise().done(function() {
|
||||||
|
animateSpinner(null, false);
|
||||||
// Scroll to bottom
|
// Scroll to bottom
|
||||||
$("html, body").animate({ scrollTop: $(document).height()-$(window).height() });
|
$('html, body').animate({
|
||||||
|
scrollTop: $(document).height() - $(window).height()
|
||||||
|
});
|
||||||
formCallback($form);
|
formCallback($form);
|
||||||
formNewAjax($form);
|
formNewAjax($form);
|
||||||
applyCancelOnNew();
|
applyCancelOnNew();
|
||||||
toggleButtons(false);
|
toggleButtons(false);
|
||||||
initializeCheckboxSorting();
|
initializeCheckboxSorting();
|
||||||
|
|
||||||
$("#step_name").focus();
|
$('#step_name').focus();
|
||||||
$("#new-step-main-tab a").on("shown.bs.tab", function() {
|
$('#new-step-main-tab a').on('shown.bs.tab', function() {
|
||||||
$("#step_name").focus();
|
$('#step_name').focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
TinyMCE.refresh();
|
TinyMCE.refresh();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
newStepHandler();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Needed because server-side validation failure clears locations of
|
// Needed because server-side validation failure clears locations of
|
||||||
// files to be uploaded and checklist's items etc. Also user
|
// files to be uploaded and checklist's items etc. Also user
|
||||||
// experience is improved
|
// experience is improved
|
||||||
function processStep(ev, editMode) {
|
global.processStep = function processStep(ev, editMode) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
|
||||||
var $form = $(ev.target.form);
|
var $form = $(ev.target.form);
|
||||||
$form.clearFormErrors();
|
$form.clearFormErrors();
|
||||||
$form.removeBlankFileForms();
|
$form.removeBlankFileForms();
|
||||||
|
@ -574,6 +607,7 @@ function processStep(ev, editMode) {
|
||||||
if (filesValid && checklistsValid && nameValid && descriptionValid) {
|
if (filesValid && checklistsValid && nameValid && descriptionValid) {
|
||||||
// Local file uploading
|
// Local file uploading
|
||||||
animateSpinner();
|
animateSpinner();
|
||||||
|
newStepHandler();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -624,7 +658,7 @@ $(document).ready(function() {
|
||||||
initPreviewModal();
|
initPreviewModal();
|
||||||
TinyMCE.highlight();
|
TinyMCE.highlight();
|
||||||
SmartAnnotation.preventPropagation('.atwho-user-popover');
|
SmartAnnotation.preventPropagation('.atwho-user-popover');
|
||||||
|
newStepHandler();
|
||||||
$(function () {
|
$(function () {
|
||||||
|
|
||||||
$("[data-action='collapse-steps']").click(function () {
|
$("[data-action='collapse-steps']").click(function () {
|
||||||
|
@ -638,3 +672,5 @@ $(document).ready(function() {
|
||||||
$("[data-action='expand-steps']").click(expandAllSteps);
|
$("[data-action='expand-steps']").click(expandAllSteps);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
|
})(window);
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="pull-right" style="margin: 20px 15px 0 0;">
|
<div class="pull-right" style="margin: 20px 15px 0 0;">
|
||||||
<% if can_create_step_in_protocol(@protocol) %>
|
<% if can_create_step_in_protocol(@protocol) %>
|
||||||
<a class="btn btn-primary" data-action="new-step" href="<%= new_protocol_step_path(protocol_id: @protocol.id, format: :json) %>" data-remote="true">
|
<a href="#"
|
||||||
|
class="btn btn-primary"
|
||||||
|
data-action="new-step"
|
||||||
|
data-href="<%= new_protocol_step_path(protocol_id: @protocol.id, format: :json) %>">
|
||||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
|
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
|
||||||
<span class="hidden-xs"><%=t "protocols.steps.new_step" %></span>
|
<span class="hidden-xs"><%=t "protocols.steps.new_step" %></span>
|
||||||
</a>
|
</a>
|
||||||
|
|
Loading…
Add table
Reference in a new issue