Merge pull request #4140 from aignatov-bio/ai-sci-6868-remove-new-protocal-modal

Remove protocol creation modal [SCI-6868]
This commit is contained in:
aignatov-bio 2022-06-05 22:41:57 +02:00 committed by GitHub
commit a8fe943658
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 105 deletions

View file

@ -298,56 +298,6 @@ function initLinkedChildrenModal() {
}
}
function initCreateNewModal() {
var link = $("[data-action='create-new']");
var modal = $("#create-new-modal");
var submitBtn = modal.find(".modal-footer [data-action='submit']");
var newProtocol = parseInt(sessionStorage.getItem('scinote-dashboard-new-protocol'), 10);
link.on("click", function() {
$.ajax({
url: link.attr("data-url"),
type: "GET",
dataType: "json",
success: function (data) {
var modalBody = modal.find(".modal-body");
modalBody.html(data.html);
modalBody.find("form")
.on("ajax:success", function(ev2, data2, status2) {
// Redirect to edit page
$(location).attr("href", data2.url);
})
.on("ajax:error", function(ev2, data2, status2) {
// Display errors if needed
$(this).renderFormErrors("protocol", data2.responseJSON);
});
modal.modal("show");
modalBody.find("input[type='text']").focus();
},
error: function (error) {
// TODO
}
});
});
if (Math.floor(Date.now() / 1000) - newProtocol < 15) {
link.click();
sessionStorage.removeItem('scinote-dashboard-new-protocol');
}
submitBtn.on("click", function() {
// Submit the form inside modal
$(this).closest(".modal").find(".modal-body form").submit();
});
modal.on("hidden.bs.modal", function(e) {
modal.find(".modal-body form").off("ajax:success ajax:error");
modal.find(".modal-body").html("");
});
}
function initModals() {
function refresh(modal) {
modal.find(".modal-body").html("");

View file

@ -12,7 +12,6 @@ class ProtocolsController < ApplicationController
include CommentHelper
before_action :check_create_permissions, only: %i(
create_new_modal
create
)
before_action :check_clone_permissions, only: [:clone]
@ -234,9 +233,9 @@ class ProtocolsController < ApplicationController
@protocol = Protocol.new(
team: @current_team,
protocol_type: Protocol.protocol_types[@type == :public ? :in_repository_public : :in_repository_private],
added_by: current_user
added_by: current_user,
name: t('protocols.index.default_name')
)
@protocol.assign_attributes(create_params)
ts = Time.now
@protocol.record_timestamps = false
@ -244,27 +243,16 @@ class ProtocolsController < ApplicationController
@protocol.updated_at = ts
@protocol.published_on = ts if @type == :public
respond_to do |format|
if @protocol.save
rename_record(@protocol, :name)
if @protocol.save
log_activity(:create_protocol_in_repository, nil, protocol: @protocol.id)
log_activity(:create_protocol_in_repository, nil, protocol: @protocol.id)
TinyMceAsset.update_images(@protocol, params[:tiny_mce_images], current_user)
format.json do
render json: {
url: edit_protocol_path(
@protocol,
team: @current_team,
type: @type
)
}
end
else
format.json do
render json: @protocol.errors,
status: :unprocessable_entity
end
end
TinyMceAsset.update_images(@protocol, params[:tiny_mce_images], current_user)
redirect_to protocol_path(@protocol)
else
flash[:error] = @protocol.errors.full_messages.join(', ')
redirect_to protocols_path
end
end
@ -942,19 +930,6 @@ class ProtocolsController < ApplicationController
end
end
def create_new_modal
@new_protocol = Protocol.new
respond_to do |format|
format.json do
render json: {
html: render_to_string({
partial: "protocols/index/create_new_modal_body.html.erb"
})
}
end
end
end
def edit_name_modal
respond_to do |format|
format.json do
@ -1201,10 +1176,6 @@ class ProtocolsController < ApplicationController
params.require(:protocol).permit(:name, :protocol_type)
end
def create_params
params.require(:protocol).permit(:name)
end
def check_protocolsio_import_permissions
render_403 unless can_create_protocols_in_repository?(current_team)
end

View file

@ -29,10 +29,10 @@
<%= t(@type == :public ? "protocols.index.public_description" : "protocols.index.private_description") %>
</div>
<div class="sci-btn-group" role="group">
<button class="btn btn-primary" <%= can_create_protocols_in_repository?(@current_team) ? "data-action=create-new" : "disabled" %> data-url="<%= create_new_modal_protocols_path(team: @current_team, type: @type) %>">
<%= button_to protocols_path(type: @type), disabled: !can_create_protocols_in_repository?(@current_team), class: 'btn btn-primary' do %>
<span class="fas fa-plus"></span>
<span class="hidden-xs">&nbsp;<%= t("protocols.index.create_new") %></span>
</button>
<% end %>
<button class="btn btn-light disabled hidden" data-action="edit">
<span class="fas fa-pencil-alt"></span>
<span class="hidden-xs">&nbsp;<%= t("protocols.index.edit") %></span>
@ -118,7 +118,6 @@
<div id="protocolsio-preview-modal-target"></div>
<%= render partial: "protocols/import_export/import_json_protocol_modal.html.erb" %>
<%= render partial: "protocols/index/create_new_modal.html.erb" %>
<%= render partial: "protocols/index/make_private_results_modal.html.erb" %>
<%= render partial: "protocols/index/publish_results_modal.html.erb" %>
<%= render partial: "protocols/index/confirm_archive_modal.html.erb" %>

View file

@ -1,12 +0,0 @@
<%= bootstrap_form_for @new_protocol, remote: :true do |f| %>
<input type="hidden" name="team" id="team" value="<%= @current_team.id %>">
<input type="hidden" name="type" id="type" value="<%= @type %>">
<%= f.text_field :name, label: t("protocols.index.create.name_label"), placeholder: t("protocols.index.create.name_placeholder") %>
<% if @type == :public %>
<em><%= t("protocols.index.create.message_public") %></em>
<% elsif @type == :private %>
<em><%= t("protocols.index.create.message_private") %></em>
<% end %>
<% end %>

View file

@ -2376,6 +2376,7 @@ en:
label: "Description"
index:
head_title: "Protocol management"
default_name: 'New protocol'
navigation:
public: "Team protocols"
private: "My protocols"

View file

@ -549,7 +549,6 @@ Rails.application.routes.draw do
get 'edit_description_modal', to: 'protocols#edit_description_modal'
end
collection do
get 'create_new_modal', to: 'protocols#create_new_modal'
post 'datatable', to: 'protocols#datatable'
post 'make_private', to: 'protocols#make_private'
post 'publish', to: 'protocols#publish'