mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-12 01:11:24 +08:00
Add delete feature
This commit is contained in:
parent
46f0e0c0c2
commit
cf4ff41ec6
10 changed files with 82 additions and 26 deletions
|
|
@ -4,6 +4,7 @@ var MarvinJsEditor = (function() {
|
||||||
var marvinJsContainer = $('#marvinjs-editor');
|
var marvinJsContainer = $('#marvinjs-editor');
|
||||||
var marvinJsObject = $('#marvinjs-sketch');
|
var marvinJsObject = $('#marvinjs-sketch');
|
||||||
var emptySketch = "<cml><MDocument></MDocument></cml>"
|
var emptySketch = "<cml><MDocument></MDocument></cml>"
|
||||||
|
var sketchName = marvinJsModal.find('.file-name input')
|
||||||
|
|
||||||
var loadEditor = () => {
|
var loadEditor = () => {
|
||||||
return MarvinJSUtil.getEditor('#marvinjs-sketch')
|
return MarvinJSUtil.getEditor('#marvinjs-sketch')
|
||||||
|
|
@ -14,7 +15,6 @@ var MarvinJsEditor = (function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function preloadActions(config) {
|
function preloadActions(config) {
|
||||||
var sketchName = marvinJsModal.find('.file-name input')
|
|
||||||
if (config.mode === 'new'){
|
if (config.mode === 'new'){
|
||||||
loadEditor().then(function(sketcherInstance) {
|
loadEditor().then(function(sketcherInstance) {
|
||||||
sketcherInstance.importStructure("mrv",emptySketch)
|
sketcherInstance.importStructure("mrv",emptySketch)
|
||||||
|
|
@ -75,7 +75,8 @@ var MarvinJsEditor = (function() {
|
||||||
$.post(config.marvinUrl,{
|
$.post(config.marvinUrl,{
|
||||||
description: source,
|
description: source,
|
||||||
object_id: config.objectId,
|
object_id: config.objectId,
|
||||||
object_type: config.objectType
|
object_type: config.objectType,
|
||||||
|
name: sketchName.val()
|
||||||
}, function(result){
|
}, function(result){
|
||||||
console.log(result)
|
console.log(result)
|
||||||
$(marvinJsModal).modal('hide');
|
$(marvinJsModal).modal('hide');
|
||||||
|
|
@ -94,6 +95,17 @@ var MarvinJsEditor = (function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
delete_sketch: function(url,object){
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
dataType: 'json',
|
||||||
|
type: 'DELETE',
|
||||||
|
success: function(json) {
|
||||||
|
$(object).remove()
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -81,3 +81,10 @@
|
||||||
margin-right: 20px;
|
margin-right: 20px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#new-step-sketch{
|
||||||
|
.sketch-container {
|
||||||
|
width: 100%;
|
||||||
|
float:left;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -167,6 +167,7 @@
|
||||||
|
|
||||||
.remove-icon {
|
.remove-icon {
|
||||||
bottom: 15px;
|
bottom: 15px;
|
||||||
|
cursor: pointer;
|
||||||
position: relative;
|
position: relative;
|
||||||
right: 10px;
|
right: 10px;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,16 @@ class MarvinJsAssetsController < ApplicationController
|
||||||
render json: new_asset
|
render json: new_asset
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
sketch=MarvinJsAsset.find(params[:id])
|
||||||
|
sketch.destroy
|
||||||
|
render json: sketch
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def marvin_params
|
def marvin_params
|
||||||
params.permit(:description, :object_id, :object_type)
|
params.permit(:description, :object_id, :object_type, :name)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,5 @@
|
||||||
data-marvin-url="<%= marvin_js_assets_path %>"
|
data-marvin-url="<%= marvin_js_assets_path %>"
|
||||||
>
|
>
|
||||||
<span class="fas fa-file-invoice new-marvinjs-upload-icon"></span>
|
<span class="fas fa-file-invoice new-marvinjs-upload-icon"></span>
|
||||||
New chemical drawing
|
<%= t('marvinjs.new_button') %>
|
||||||
</span>
|
</span>
|
||||||
|
|
@ -11,24 +11,7 @@
|
||||||
'asset-type': 'marvin-sketch',
|
'asset-type': 'marvin-sketch',
|
||||||
'asset-id': sketch.id
|
'asset-id': sketch.id
|
||||||
} do %>
|
} do %>
|
||||||
|
<%= render partial: 'assets/marvinjs/marvin_sketch_card_placeholder.html.erb',
|
||||||
<div class="attachment-placeholder pull-left">
|
locals: { edit_page: false, sketch: sketch } %>
|
||||||
<div class="attachment-thumbnail">
|
|
||||||
<img src>
|
|
||||||
<%= hidden_field_tag :description, sketch.description %>
|
|
||||||
</div>
|
|
||||||
<div class="attachment-label"><%= truncate(sketch.name,
|
|
||||||
length: Constants::FILENAME_TRUNCATION_LENGTH) %></div>
|
|
||||||
<div class="spencer-bonnet-modif">
|
|
||||||
<%= t('protocols.steps.attachments.modified_label') %> <%= l(sketch.updated_at, format: :full_date) if sketch.updated_at %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<script>
|
|
||||||
(function(){
|
|
||||||
src=$('#marvin_js_sketch_<%= sketch.id %>').find('#description')
|
|
||||||
target=$('#marvin_js_sketch_<%= sketch.id %>').find('img')
|
|
||||||
MarvinJsEditor().create_preview(src,target)
|
|
||||||
})()
|
|
||||||
</script>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
<div class="attachment-placeholder pull-left" data-marvinjs-sketch="<%= sketch.id %>">
|
||||||
|
<div class="attachment-thumbnail">
|
||||||
|
<img src>
|
||||||
|
<%= hidden_field_tag :description, sketch.description %>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
(function(){
|
||||||
|
src=$('.attachment-placeholder[data-marvinjs-sketch="<%= sketch.id %>"]').find('#description')
|
||||||
|
target=$('.attachment-placeholder[data-marvinjs-sketch="<%= sketch.id %>"]').find('img')
|
||||||
|
MarvinJsEditor().create_preview(src,target)
|
||||||
|
})()
|
||||||
|
</script>
|
||||||
|
<div class="attachment-label"><%= truncate(sketch.name,
|
||||||
|
length: Constants::FILENAME_TRUNCATION_LENGTH) %></div>
|
||||||
|
<div class="spencer-bonnet-modif">
|
||||||
|
<%= t('protocols.steps.attachments.modified_label') %> <%= l(sketch.updated_at, format: :full_date) if sketch.updated_at %>
|
||||||
|
</div>
|
||||||
|
<% if edit_page %>
|
||||||
|
<div class="remove-icon pull-right">
|
||||||
|
<span class="fas fa-trash"></span>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
$('.attachment-placeholder[data-marvinjs-sketch="<%= sketch.id %>"]').find('.remove-icon')
|
||||||
|
.click(function() {
|
||||||
|
MarvinJsEditor().delete_sketch(
|
||||||
|
'<%= marvin_js_asset_path(sketch.id) %>',
|
||||||
|
'.attachment-placeholder[data-marvinjs-sketch="<%= sketch.id %>"]'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
@ -24,6 +24,12 @@
|
||||||
<%= t("protocols.steps.new.tab_tables") %>
|
<%= t("protocols.steps.new.tab_tables") %>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li role="presentation" id="new-step-sketch-tab">
|
||||||
|
<a href="#new-step-sketch" data-toggle="tab" data-no-turbolink="true">
|
||||||
|
<span class="fas fa-file-invoice"></span>
|
||||||
|
<%= t('marvinjs.checmical_drawing') %>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<div class="tab-pane active" role="tabpanel" id="new-step-main">
|
<div class="tab-pane active" role="tabpanel" id="new-step-main">
|
||||||
|
|
@ -84,4 +90,12 @@
|
||||||
<%= t("protocols.steps.new.add_table") %>
|
<%= t("protocols.steps.new.add_table") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="tab-pane" role="tabpanel" id="new-step-sketch">
|
||||||
|
<div class="sketch-container">
|
||||||
|
<% @step.marvin_js_assets.each do |sketch| %>
|
||||||
|
<%= render partial: 'assets/marvinjs/marvin_sketch_card_placeholder.html.erb',
|
||||||
|
locals: { sketch: sketch, edit_page: true} %>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -2142,3 +2142,7 @@ en:
|
||||||
new: "https://support.scinote.net/hc/en-us/articles/360004627792"
|
new: "https://support.scinote.net/hc/en-us/articles/360004627792"
|
||||||
visibility: "https://support.scinote.net/hc/en-us/articles/360004627472"
|
visibility: "https://support.scinote.net/hc/en-us/articles/360004627472"
|
||||||
manage_columns: "https://support.scinote.net/hc/en-us/articles/360004695831"
|
manage_columns: "https://support.scinote.net/hc/en-us/articles/360004695831"
|
||||||
|
marvinjs:
|
||||||
|
new_sketch: "New sketch"
|
||||||
|
new_button: "New chemical drawing"
|
||||||
|
checmical_drawing: "Chemical drawings"
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
en:
|
|
||||||
marvinjs:
|
|
||||||
new_sketch: 'New sketch'
|
|
||||||
Loading…
Add table
Reference in a new issue