mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-09 16:01:30 +08:00
Add main functionality
This commit is contained in:
parent
613843d095
commit
b12916b828
7 changed files with 119 additions and 54 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
|
// Opens create wopi modal on the click of the button
|
||||||
function applyCreateWopiFileCallback() {
|
function applyCreateWopiFileCallback() {
|
||||||
$(".create-wopi-file-btn").off().on('click', function(e){
|
$(".create-wopi-file-btn").off().on('click', function(e){
|
||||||
var $modal = $('#new-office-file-modal');
|
var $modal = $('#new-office-file-modal');
|
||||||
|
$($modal).find('form').clearFormErrors();
|
||||||
|
|
||||||
// Append element info to which the new file will be attached
|
// Append element info to which the new file will be attached
|
||||||
$modal.find('#element_id').val($(this).data('id'));
|
$modal.find('#element_id').val($(this).data('id'));
|
||||||
|
|
@ -11,34 +13,32 @@ function applyCreateWopiFileCallback() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show errors on create wopi modal
|
||||||
(function(global) {
|
function initCreateWopiFileModal() {
|
||||||
function initCreateWopiFileModal() {
|
// Ajax actions
|
||||||
console.log('jeje')
|
$("#new-office-file-modal form")
|
||||||
//Click on cancel button
|
.on('ajax:success', function(ev, data) {
|
||||||
$("#new-office-file-modal form")
|
window.open(data.edit_url, '_blank');
|
||||||
.submit(function(e) {
|
//location.reload();
|
||||||
//var $form = $(this).closest("form");
|
|
||||||
$.ajax({
|
|
||||||
url: $btn.data('href'),
|
|
||||||
method: 'GET',
|
|
||||||
success: function(data) {
|
|
||||||
var $form = $(data.html);
|
|
||||||
animateSpinner(null, false);
|
|
||||||
$('#results').prepend($form);
|
|
||||||
formAjaxResultText($form);
|
|
||||||
Results.initCancelFormButton($form, initNewReslutText);
|
|
||||||
Results.toggleResultEditButtons(false);
|
|
||||||
TinyMCE.refresh();
|
|
||||||
TinyMCE.highlight();
|
|
||||||
$('#result_name').focus();
|
|
||||||
},
|
|
||||||
error: function() {
|
|
||||||
animateSpinner(null, false);
|
|
||||||
initNewReslutText();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
.on('ajax:error', function(ev, response) {
|
||||||
|
$(this).clearFormErrors();
|
||||||
|
var element, msg;
|
||||||
|
|
||||||
|
if (response.status == 400) {
|
||||||
|
element = $(this).find('#new-wopi-file-name');
|
||||||
|
msg = response.responseJSON.message.file.toString();
|
||||||
|
} else if (response.status == 403) {
|
||||||
|
element = $(this).find('#other-wopi-errors'),
|
||||||
|
msg = I18n.t('assets.create_wopi_file.errors.forbidden');
|
||||||
|
} else if (response.status == 404) {
|
||||||
|
element = $(this).find('#other-wopi-errors'),
|
||||||
|
msg = I18n.t('assets.create_wopi_file.errors.not_found');
|
||||||
|
}
|
||||||
|
renderFormError(undefined, element, msg);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
initCreateWopiFileModal();
|
initCreateWopiFileModal();
|
||||||
})(window);
|
});
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
initHandsOnTables($(document));
|
initHandsOnTables($(document));
|
||||||
_expandAllResults();
|
_expandAllResults();
|
||||||
applyCollapseLinkCallBack();
|
applyCollapseLinkCallBack();
|
||||||
|
applyCreateWopiFileCallback();
|
||||||
|
|
||||||
Comments.initialize();
|
Comments.initialize();
|
||||||
|
|
||||||
|
|
@ -185,6 +186,7 @@
|
||||||
initFormSubmitLinks($(this));
|
initFormSubmitLinks($(this));
|
||||||
ResutlAssets.applyEditResultAssetCallback();
|
ResutlAssets.applyEditResultAssetCallback();
|
||||||
applyCollapseLinkCallBack();
|
applyCollapseLinkCallBack();
|
||||||
|
applyCreateWopiFileCallback();
|
||||||
toggleResultEditButtons(true);
|
toggleResultEditButtons(true);
|
||||||
FilePreviewModal.init();
|
FilePreviewModal.init();
|
||||||
Comments.initialize();
|
Comments.initialize();
|
||||||
|
|
|
||||||
|
|
@ -169,24 +169,60 @@ class AssetsController < ApplicationController
|
||||||
formats: :html
|
formats: :html
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# POST: create_wopi_file_path
|
||||||
def create_wopi_file
|
def create_wopi_file
|
||||||
# ASSOC: (stepasset, resultasset),
|
# Presence validation
|
||||||
# ASSOC_ID: bla,
|
create_wopi_params
|
||||||
# TYPE OF DOC: PDF/DOC/XML
|
|
||||||
# name of file
|
# File type validation
|
||||||
# retrieve
|
render_403 && return unless ['docx', 'xlsx', 'pptx'].include?(params[:file_type])
|
||||||
#file = Paperclip.io_adapters.for(StringIO.new())
|
|
||||||
#file.original_filename = 'test.docx'
|
# Asset validation
|
||||||
#file.content_type = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
file = Paperclip.io_adapters.for(StringIO.new())
|
||||||
#asset = Asset.new(file: file, created_by: User.first, file_present: true)
|
file.original_filename = "#{params[:file_name]}.#{params[:file_type]}"
|
||||||
#step_asset = StepAsset.create!(step: Step.last, asset: asset)
|
file.content_type = wopi_content_type(params[:file_type])
|
||||||
|
asset = Asset.new(file: file, created_by: current_user, file_present: true)
|
||||||
|
|
||||||
#redirect_to edit_asset_url(step_asset.asset_id)
|
|
||||||
#
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json do
|
format.json do
|
||||||
render json: { 'bla': 'he' }
|
render json: {
|
||||||
|
error: true,
|
||||||
|
message: asset.errors,
|
||||||
|
}, status: 400
|
||||||
|
end
|
||||||
|
end and return unless asset.valid?
|
||||||
|
|
||||||
|
if params[:element_type] == 'Step'
|
||||||
|
step = Step.find(params[:element_id].to_i)
|
||||||
|
render_403 && return unless can_manage_protocol_in_module?(step.protocol) ||
|
||||||
|
can_manage_protocol_in_repository?(step.protocol)
|
||||||
|
step_asset = StepAsset.create!(step: step, asset: asset)
|
||||||
|
|
||||||
|
edit_url = edit_asset_url(step_asset.asset_id)
|
||||||
|
elsif params[:element_type] == 'Result'
|
||||||
|
my_module = MyModule.find(params[:element_id].to_i)
|
||||||
|
render_403 and return unless can_manage_module?(my_module)
|
||||||
|
|
||||||
|
result = Result.create(name: file.original_filename,
|
||||||
|
my_module: my_module,
|
||||||
|
user: current_user)
|
||||||
|
result_asset = ResultAsset.create!(result: result, asset: asset)
|
||||||
|
|
||||||
|
edit_url = edit_asset_url(result_asset.asset_id)
|
||||||
|
else
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.json do
|
||||||
|
render json: {
|
||||||
|
success: true,
|
||||||
|
edit_url: edit_url
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -244,6 +280,10 @@ class AssetsController < ApplicationController
|
||||||
url + wd_params
|
url + wd_params
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_wopi_params
|
||||||
|
params.require([:element_type, :element_id, :file_type])
|
||||||
|
end
|
||||||
|
|
||||||
def asset_params
|
def asset_params
|
||||||
params.permit(
|
params.permit(
|
||||||
:file
|
:file
|
||||||
|
|
|
||||||
|
|
@ -86,4 +86,16 @@ module FileIconsHelper
|
||||||
t('result_assets.wopi_edit_file', app: app)
|
t('result_assets.wopi_edit_file', app: app)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns correct content type for given extension
|
||||||
|
def wopi_content_type(extension)
|
||||||
|
case extension
|
||||||
|
when 'docx'
|
||||||
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
||||||
|
when 'xlsx'
|
||||||
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||||
|
when 'pptx'
|
||||||
|
'application/vnd.openxmlformats-officedocument.presentationml.presentation'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -16,24 +16,28 @@
|
||||||
<%= hidden_field_tag :element_id, '' %>
|
<%= hidden_field_tag :element_id, '' %>
|
||||||
<%= hidden_field_tag :element_type, '' %>
|
<%= hidden_field_tag :element_type, '' %>
|
||||||
|
|
||||||
<%= f.text_field :name,
|
<%= f.text_field :file_name,
|
||||||
label: t('assets.create_wopi_file.text_field_label'),
|
label: t('assets.create_wopi_file.text_field_label'),
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
placeholder: t('assets.create_wopi_file.text_field_placeholder'),
|
placeholder: t('assets.create_wopi_file.text_field_placeholder'),
|
||||||
id: 'new-wopi-file-name'%>
|
id: 'new-wopi-file-name'%>
|
||||||
|
|
||||||
<div class="btn-group btn-group-justified" role="group" aria-label="...">
|
<div class="btn-group btn-group-toggle btn-group-justified"
|
||||||
<div class="btn-group" role="group">
|
data-toggle="buttons">
|
||||||
<button type="button" class="btn btn-default">Left</button>
|
<label class="btn btn-default active">
|
||||||
</div>
|
<%= image_tag 'office/Excel-xlsx_20x20x32.png' %>
|
||||||
<div class="btn-group" role="group">
|
<input type="radio" name="file_type" value='docx' checked> Active
|
||||||
<button type="button" class="btn btn-default">Middle</button>
|
</label>
|
||||||
</div>
|
<label class="btn btn-default">
|
||||||
<div class="btn-group" role="group">
|
<input type="radio" name="file_type" value='xlsx'> Radio
|
||||||
<button type="button" class="btn btn-default">Right</button>
|
</label>
|
||||||
</div>
|
<label class="btn btn-default">
|
||||||
</div>
|
<input type="radio" name="file_type" value='pptx'> Radio
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class='form-group' id='other-wopi-errors'>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<%= f.submit t('assets.create_wopi_file.create_document_button'),
|
<%= f.submit t('assets.create_wopi_file.create_document_button'),
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
<%= render partial: "shared/sidebar", locals: { current_task: @my_module, page: 'task' } %>
|
<%= render partial: "shared/sidebar", locals: { current_task: @my_module, page: 'task' } %>
|
||||||
<%= render partial: "shared/secondary_navigation" %>
|
<%= render partial: "shared/secondary_navigation" %>
|
||||||
<%= render partial: 'shared/drag_n_drop_overlay' %>
|
<%= render partial: 'shared/drag_n_drop_overlay' %>
|
||||||
|
<%= render partial: 'assets/wopi/create_wopi_file_modal' %>
|
||||||
|
|
||||||
<div class="content-pane">
|
<div class="content-pane">
|
||||||
<div id="results-toolbar">
|
<div id="results-toolbar">
|
||||||
|
|
@ -40,6 +41,8 @@
|
||||||
<span class="fas fa-paperclip"></span>
|
<span class="fas fa-paperclip"></span>
|
||||||
<span class="hidden-xs"><%= t("my_modules.results.new_asset_result") %></span>
|
<span class="hidden-xs"><%= t("my_modules.results.new_asset_result") %></span>
|
||||||
</a>
|
</a>
|
||||||
|
<%= render partial: "assets/wopi/create_wopi_file_button",
|
||||||
|
locals: { element_id: @my_module.id, element_type: 'Result' } %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -69,6 +72,7 @@
|
||||||
<%= stylesheet_link_tag "handsontable.formula" %>
|
<%= stylesheet_link_tag "handsontable.formula" %>
|
||||||
|
|
||||||
<%= javascript_include_tag("canvas-to-blob.min") %>
|
<%= javascript_include_tag("canvas-to-blob.min") %>
|
||||||
|
<%= javascript_include_tag "assets/wopi/create_wopi_file" %>
|
||||||
<%= javascript_include_tag "my_modules/results" %>
|
<%= javascript_include_tag "my_modules/results" %>
|
||||||
<%= javascript_include_tag "results/result_texts" %>
|
<%= javascript_include_tag "results/result_texts" %>
|
||||||
<%= javascript_include_tag "results/result_tables" %>
|
<%= javascript_include_tag "results/result_tables" %>
|
||||||
|
|
|
||||||
|
|
@ -1892,6 +1892,9 @@ en:
|
||||||
text_field_label: 'Document name & type'
|
text_field_label: 'Document name & type'
|
||||||
text_field_placeholder: 'New Document'
|
text_field_placeholder: 'New Document'
|
||||||
create_document_button: 'Create Document'
|
create_document_button: 'Create Document'
|
||||||
|
errors:
|
||||||
|
forbidden: 'You do not have permission to add files.'
|
||||||
|
not_found: 'Element not found.'
|
||||||
atwho:
|
atwho:
|
||||||
no_results: "No results found"
|
no_results: "No results found"
|
||||||
users:
|
users:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue