diff --git a/app/assets/javascripts/protocols/index.js b/app/assets/javascripts/protocols/index.js index 0f0f659fd..cc46b477c 100644 --- a/app/assets/javascripts/protocols/index.js +++ b/app/assets/javascripts/protocols/index.js @@ -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(""); diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 63c821203..ad73aad30 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -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 diff --git a/app/views/protocols/index.html.erb b/app/views/protocols/index.html.erb index a1c09644d..e021f162c 100644 --- a/app/views/protocols/index.html.erb +++ b/app/views/protocols/index.html.erb @@ -29,10 +29,10 @@ <%= t(@type == :public ? "protocols.index.public_description" : "protocols.index.private_description") %>
- + <% end %>