mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-03 10:24:30 +08:00
optimised code so i dont need javascript locals anymore and working to fix infamous html tags bug where second modal doesnt show
This commit is contained in:
parent
f861b1fc52
commit
7aba782639
7 changed files with 129 additions and 44 deletions
|
@ -468,6 +468,7 @@ class ProtocolsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_from_repository
|
def load_from_repository
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @protocol.can_destroy?
|
if @protocol.can_destroy?
|
||||||
transaction_error = false
|
transaction_error = false
|
||||||
|
@ -518,6 +519,7 @@ class ProtocolsController < ApplicationController
|
||||||
|
|
||||||
def load_from_file
|
def load_from_file
|
||||||
# This is actually very similar to import
|
# This is actually very similar to import
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @protocol.can_destroy?
|
if @protocol.can_destroy?
|
||||||
transaction_error = false
|
transaction_error = false
|
||||||
|
@ -566,7 +568,8 @@ class ProtocolsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def import
|
def import #tega uporabi .eln import
|
||||||
|
|
||||||
protocol = nil
|
protocol = nil
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
transaction_error = false
|
transaction_error = false
|
||||||
|
@ -605,7 +608,10 @@ def protocolsio_import_create
|
||||||
|
|
||||||
|
|
||||||
json_file_contents=File.read(params[:json_file].path)
|
json_file_contents=File.read(params[:json_file].path)
|
||||||
@json_object=JSON.parse(json_file_contents)
|
json_file_contents.gsub! '\"', "'"
|
||||||
|
#byebug
|
||||||
|
|
||||||
|
@json_object=JSON.parse((json_file_contents))
|
||||||
@protocol=Protocol.new
|
@protocol=Protocol.new
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
@ -615,12 +621,44 @@ def protocolsio_import_create
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def protocolsio_import_save
|
def protocolsio_import_save
|
||||||
#@temp_json=JsonTemp.new
|
#@temp_json=JsonTemp.new
|
||||||
|
byebug
|
||||||
|
protocol = nil
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {render protocols}
|
transaction_error = false
|
||||||
format.js {render nothing}
|
@steps_object=JSON.parse(params["steps"]["steps_object"])
|
||||||
|
byebug
|
||||||
|
Protocol.transaction do
|
||||||
|
begin
|
||||||
|
|
||||||
|
|
||||||
|
protocol = import_new_protocol(@protocol_json, @team, @type, current_user)
|
||||||
|
rescue Exception
|
||||||
|
transaction_error = true
|
||||||
|
raise ActiveRecord:: Rollback
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
p_name =
|
||||||
|
if @protocol_json['name'].present? && !@protocol_json['name'].empty?
|
||||||
|
escape_input(@protocol_json['name'])
|
||||||
|
else
|
||||||
|
t('protocols.index.no_protocol_name')
|
||||||
|
end
|
||||||
|
if transaction_error
|
||||||
|
format.json {
|
||||||
|
render json: { name: p_name, status: :bad_request }, status: :bad_request
|
||||||
|
}
|
||||||
|
else
|
||||||
|
format.json {
|
||||||
|
render json: {
|
||||||
|
name: p_name, new_name: protocol.name, status: :ok
|
||||||
|
},
|
||||||
|
status: :ok
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
module ProtocolsImporter
|
module ProtocolsImporter
|
||||||
include RenamingUtil
|
include RenamingUtil
|
||||||
|
|
||||||
def import_new_protocol(protocol_json, team, type, user)
|
def import_new_protocol(protocol_json, team, type, user) # .eln import
|
||||||
remove_empty_inputs(protocol_json)
|
remove_empty_inputs(protocol_json)
|
||||||
protocol = Protocol.new(
|
protocol = Protocol.new(
|
||||||
name: protocol_json["name"],
|
name: protocol_json["name"],
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<div class="modal fade" id="modal-import-json-protocol" tabindex="-1" role="dialog" aria-labelledby="modal-import-json-protocol-label">
|
<div class="modal fade" id="modal-import-json-protocol" tabindex="-1" role="dialog" >
|
||||||
<div class="modal-dialog" role="document">
|
<div class="modal-dialog" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
|
@ -6,7 +6,7 @@
|
||||||
<h4 class="modal-title"><%= t('protocols.index.modal_import_json_title') %></h4>
|
<h4 class="modal-title"><%= t('protocols.index.modal_import_json_title') %></h4>
|
||||||
<%= t("protocols.index.modal_import_json_notice") %>
|
<%= t("protocols.index.modal_import_json_notice") %>
|
||||||
</div>
|
</div>
|
||||||
<%= form_tag({ action: "protocolsio_import_create"}, format: "json", multipart: true,remote: true,:method => "post", html: {'data-type' => 'json'}) do %>
|
<%= form_tag({ action: "protocolsio_import_create"}, id:"protocols_io_form", format: :json, multipart: true,remote: true,:method => "post") do %>
|
||||||
|
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
|
|
||||||
|
@ -22,3 +22,29 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<% if false %>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
$('#protocols_io_form').submit(function() {
|
||||||
|
$("#ajax").after(status);
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: $(this).attr('action'),
|
||||||
|
data: $(this).serialize(),
|
||||||
|
dataType: 'json',
|
||||||
|
success: function(json) {
|
||||||
|
if(json.type == 'success') {
|
||||||
|
$('#msg').css("color","green").html(json.message);
|
||||||
|
} else if(json.type == 'warning'){
|
||||||
|
$('#msg').css("color","yellow").html(json.message);
|
||||||
|
} else if(json.type == 'error'){
|
||||||
|
$('#msg').css("color","red").html(json.message);
|
||||||
|
}
|
||||||
|
$('.loading').remove();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<% end %>
|
||||||
|
|
|
@ -1,5 +1,18 @@
|
||||||
<%= form_for(protocol, :url => "protocols/protocolsio_import_save",method: :post) do |f| %>
|
<%= form_for(@protocol, :url => url_for(:controller => 'protocols', :action => 'protocolsio_import_save'),method: :post,format: :json,remote: true) do |f| %>
|
||||||
<div id="modal-import-json-protocol-preview" class="modal fade" role="dialog">
|
<%#= fields_for :steps do |g| %>
|
||||||
|
<% #json_string= JSON.parse(json_string)%>
|
||||||
|
<% #json_string = JSON.generate(json_string['steps'])
|
||||||
|
#json_object['steps'][0]['components'][0]['data']
|
||||||
|
#Sanitize, sanitize_input, CGI.escape ,
|
||||||
|
#byebug
|
||||||
|
#kaj dela: .remove("\"") na stringih, sanitize_input ampak pokvari stran
|
||||||
|
%>
|
||||||
|
|
||||||
|
<%= hidden_field_tag :banana, (@json_object['steps'][0]['components'][0]) %>
|
||||||
|
|
||||||
|
|
||||||
|
<%# end %>
|
||||||
|
<div id="modal-import-json-protocol-preview" class="modal fade" role="dialog" tabindex="-1">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
|
@ -18,34 +31,34 @@
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|
||||||
<label><%= t("protocols.import_export.import_modal.name_label") %></label>
|
<label><%= t("protocols.import_export.import_modal.name_label") %></label>
|
||||||
<!-- <input type="text" class="form-control" id="import_protocol_name" value="<%= json_object['protocol_name'] %>"> -->
|
|
||||||
<%= f.text_field :name, :value => json_object['protocol_name'], class: "form-control" %>
|
<%= f.text_field :name, :value => @json_object['protocol_name'], class: "form-control" %>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>
|
<label>
|
||||||
<span class="glyphicon glyphicon-user"></span> <%= t("protocols.import_export.import_modal.authors_label") %>
|
<span class="glyphicon glyphicon-user"></span> <%= t("protocols.import_export.import_modal.authors_label") %>
|
||||||
</label>
|
</label>
|
||||||
<%= f.text_field :authors, :value => json_object['full_name'], class: "form-control" %>
|
<%= f.text_field :authors, :value => @json_object['full_name'], class: "form-control" %>
|
||||||
<!-- <input type="text" class="form-control" id="protocol_authors"> -->
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label><%= t("protocols.import_export.import_modal.description_label") %></label>
|
<label><%= t("protocols.import_export.import_modal.description_label") %></label>
|
||||||
<!-- <textarea class="form-control" id="import_protocol_description" rows="2"></textarea> -->
|
|
||||||
<%= f.text_area :description, :value => json_object['description'], class: "form-control" %>
|
<%= f.text_area :description, :value => @json_object['description'], class: "form-control" %>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-4">
|
<div class="col-xs-4">
|
||||||
<label><%= t("protocols.import_export.import_modal.created_at_label") %></label>
|
<label><%= t("protocols.import_export.import_modal.created_at_label") %></label>
|
||||||
<!-- <input type="text" class="form-control" id="protocol_created_at" disabled> -->
|
|
||||||
<% display_created_at=Time.at(json_object['created_on'].to_i) %>
|
<% display_created_at=Time.at(@json_object['created_on'].to_i) %>
|
||||||
<%= f.text_field :doesnt_exist, :value => display_created_at.to_s+" (Protocols.io value)", class: "form-control" %>
|
<%= f.text_field :doesnt_exist, :value => display_created_at.to_s+" (Protocols.io value)", class: "form-control" %>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xs-4">
|
<div class="col-xs-4">
|
||||||
<label><%= t("protocols.import_export.import_modal.updated_at_label") %></label>
|
<label><%= t("protocols.import_export.import_modal.updated_at_label") %></label>
|
||||||
<!-- <input type="text" class="form-control" id="protocol_updated_at" disabled> -->
|
|
||||||
<% display_last_modified=Time.at(json_object['last_modified'].to_i) %>
|
<% display_last_modified=Time.at(@json_object['last_modified'].to_i) %>
|
||||||
<%= f.text_field :doesnt_exist, :value => display_last_modified.to_s+" (Protocols.io value)", class: "form-control" %>
|
<%= f.text_field :doesnt_exist, :value => display_last_modified.to_s+" (Protocols.io value)", class: "form-control" %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -63,23 +76,23 @@
|
||||||
<div class="import-protocols-modal-preview-container-json" data-role="preview-container">
|
<div class="import-protocols-modal-preview-container-json" data-role="preview-container">
|
||||||
<table>
|
<table>
|
||||||
|
|
||||||
<% if json_object["before_start"]&&json_object["before_start"]!="" %>
|
<% if @json_object["before_start"]&&@json_object["before_start"]!="" %>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<h2>Before starting protocol information</h2>
|
<h2>Before starting protocol information</h2>
|
||||||
<%= strip_tags(json_object["before_start"].remove("\"")) %>
|
<%= strip_tags(@json_object["before_start"].remove("\"")) %>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if json_object["warning"]&&json_object["warning"]!="" %>
|
<% if @json_object["warning"]&&@json_object["warning"]!="" %>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<h2>Protocol warning</h2>
|
<h2>Protocol warning</h2>
|
||||||
<%= strip_tags(json_object["warning"].remove("\"")) %>
|
<%= strip_tags(@json_object["warning"].remove("\"")) %>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -88,12 +101,12 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|
||||||
<% if json_object["guidelines"]&&json_object["guidelines"]!="" %>
|
<% if @json_object["guidelines"]&&@json_object["guidelines"]!="" %>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<h2>Guidelines</h2>
|
<h2>Guidelines</h2>
|
||||||
<%= strip_tags(json_object["guidelines"].remove("\"")) %>
|
<%= strip_tags(@json_object["guidelines"].remove("\"")) %>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -106,7 +119,7 @@
|
||||||
whitelist_simple=["1","6","17"]
|
whitelist_simple=["1","6","17"]
|
||||||
whitelist_complex=["8","9","15","18","19","20"]%>
|
whitelist_complex=["8","9","15","18","19","20"]%>
|
||||||
|
|
||||||
<% json_object["steps"].each do |step| %>
|
<% @json_object["steps"].each do |step| %>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td> <h3>Step <%= (counter+=1).to_s %> </h3><br>
|
<td> <h3>Step <%= (counter+=1).to_s %> </h3><br>
|
||||||
|
@ -275,69 +288,69 @@
|
||||||
<tr><td><br><br><div style="border-bottom-style:solid">
|
<tr><td><br><br><div style="border-bottom-style:solid">
|
||||||
</div></td></tr>
|
</div></td></tr>
|
||||||
|
|
||||||
<% if json_object["manuscript_citation"]&&json_object["manuscript_citation"]!="" %>
|
<% if @json_object["manuscript_citation"]&&@json_object["manuscript_citation"]!="" %>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<h4>Manuscript citation</h4>
|
<h4>Manuscript citation</h4>
|
||||||
<%= strip_tags(json_object["manuscript_citation"].remove("\"")) %>
|
<%= strip_tags(@json_object["manuscript_citation"].remove("\"")) %>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if json_object["publish_date"]&&json_object["publish_date"]!="" %>
|
<% if @json_object["publish_date"]&&@json_object["publish_date"]!="" %>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<h4>Publish date</h4>
|
<h4>Publish date</h4>
|
||||||
<%= strip_tags(json_object["publish_date"].remove("\"")) %>
|
<%= strip_tags(@json_object["publish_date"].remove("\"")) %>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if json_object["vendor_name"]&&json_object["vendor_name"]!="" %>
|
<% if @json_object["vendor_name"]&&@json_object["vendor_name"]!="" %>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<h4>Vendor name</h4>
|
<h4>Vendor name</h4>
|
||||||
<%= strip_tags(json_object["vendor_name"].remove("\"")) %>
|
<%= strip_tags(@json_object["vendor_name"].remove("\"")) %>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if json_object["vendor_link"]&&json_object["vendor_link"]!="" %>
|
<% if @json_object["vendor_link"]&&@json_object["vendor_link"]!="" %>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<h4>Vendor link</h4>
|
<h4>Vendor link</h4>
|
||||||
<%= strip_tags(json_object["vendor_link"].remove("\"")) %>
|
<%= strip_tags(@json_object["vendor_link"].remove("\"")) %>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if json_object["keywords"]&&json_object["keywords"]!="" %>
|
<% if @json_object["keywords"]&&@json_object["keywords"]!="" %>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<h4>Keywords</h4>
|
<h4>Keywords</h4>
|
||||||
<%= strip_tags(json_object["keywords"].remove("\"")) %>
|
<%= strip_tags(@json_object["keywords"].remove("\"")) %>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if json_object["tags"]&&json_object["tags"]!="" %>
|
<% if @json_object["tags"]&&@json_object["tags"]!="" %>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<h4>Tags</h4>
|
<h4>Tags</h4>
|
||||||
<% json_object["tags"].each do |tag| %>
|
<% @json_object["tags"].each do |tag| %>
|
||||||
<%= strip_tags(tag["tag_name"].remove("\""))+" , " %>
|
<%= strip_tags(tag["tag_name"].remove("\""))+" , " %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
|
@ -354,7 +367,11 @@
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-default" data-dismiss="modal"><%= t("general.cancel") %></button>
|
<button type="button" class="btn btn-default" data-dismiss="modal"><%= t("general.cancel") %></button>
|
||||||
|
|
||||||
<!-- <button type="submit" class="btn btn-primary" data-action="import-current"><%= t("protocols.import_export.import_modal.import") %></button> -->
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<%= f.submit t("protocols.import_export.import_modal.import"),class: "btn btn-primary" %>
|
<%= f.submit t("protocols.import_export.import_modal.import"),class: "btn btn-primary" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|
|
@ -141,9 +141,9 @@
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<div id="protocolsio_preview_modal_target"></div>
|
<div id="protocolsio-preview-modal-target"></div>
|
||||||
<%= render partial: "protocols/import_export/import_json_protocol_modal" %>
|
<%= render partial: "protocols/import_export/import_json_protocol_modal.html.erb" %>
|
||||||
<%#= render partial: "protocols/import_export/import_json_protocol_preview_modal" %>
|
|
||||||
<%= render partial: "protocols/index/create_new_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/make_private_results_modal.html.erb" %>
|
||||||
<%= render partial: "protocols/index/publish_results_modal.html.erb" %>
|
<%= render partial: "protocols/index/publish_results_modal.html.erb" %>
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
|
||||||
$('#modal-import-json-protocol').modal('hide');
|
$('#modal-import-json-protocol').modal('hide');
|
||||||
$('#protocolsio_preview_modal_target').append("<%= j render(:partial => "protocols/import_export/import_json_protocol_preview_modal", :locals => {:json_object => @json_object,:protocol => @protocol}) %>")
|
|
||||||
|
$('#protocolsio-preview-modal-target').html("<%= j(render(:partial => 'protocols/import_export/import_json_protocol_preview_modal')) %>")
|
||||||
|
|
||||||
$('#modal-import-json-protocol-preview').modal('show');
|
$('#modal-import-json-protocol-preview').modal('show');
|
||||||
|
|
|
@ -421,6 +421,7 @@ Rails.application.routes.draw do
|
||||||
##-tule gre tvoje json_import match
|
##-tule gre tvoje json_import match
|
||||||
post 'protocolsio_import_create', to: 'protocols#protocolsio_import_create'
|
post 'protocolsio_import_create', to: 'protocols#protocolsio_import_create'
|
||||||
post 'protocolsio_import_save', to: 'protocols#protocolsio_import_save'
|
post 'protocolsio_import_save', to: 'protocols#protocolsio_import_save'
|
||||||
|
#get 'testcontroller', to: 'protocols#testcontroller'
|
||||||
##
|
##
|
||||||
get 'export', to: 'protocols#export'
|
get 'export', to: 'protocols#export'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue