mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-22 14:54:38 +08:00
Merge pull request #2393 from okriuchykhin/ok_SCI_4321
Fix file result only name update [SCI-4321]
This commit is contained in:
commit
08140f23e5
6 changed files with 17 additions and 10 deletions
|
@ -101,6 +101,11 @@
|
|||
|
||||
// create custom ajax request in order to fix issuses with remote: true from
|
||||
function handleResultFileSubmit(form, ev) {
|
||||
if (!(form.find('#result_asset_attributes_file')[0].files.length > 0)) {
|
||||
// Assuming that only result name is getting updated
|
||||
return;
|
||||
}
|
||||
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
|
||||
|
@ -157,15 +162,15 @@
|
|||
var $form = $(ev.target.form);
|
||||
$form.clearFormErrors();
|
||||
|
||||
textValidator(ev, $form.find('#result_name'), 0, GLOBAL_CONSTANTS.NAME_MAX_LENGTH);
|
||||
|
||||
switch (resultTypeEnum) {
|
||||
case ResultTypeEnum.FILE:
|
||||
handleResultFileSubmit($form, ev);
|
||||
break;
|
||||
case ResultTypeEnum.TABLE:
|
||||
textValidator(ev, $form.find('#result_name'), 0, GLOBAL_CONSTANTS.NAME_MAX_LENGTH);
|
||||
break;
|
||||
case ResultTypeEnum.TEXT:
|
||||
textValidator(ev, $form.find('#result_name'), 0, GLOBAL_CONSTANTS.NAME_MAX_LENGTH);
|
||||
textValidator(
|
||||
ev, $form.find('#result_text_attributes_textarea'), 1,
|
||||
$form.data('rich-text-max-length'), false, TinyMCE.getContent()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
globals HelperModule animateSpinner SmartAnnotation AssetColumnHelper
|
||||
globals HelperModule animateSpinner SmartAnnotation AssetColumnHelper GLOBAL_CONSTANTS
|
||||
*/
|
||||
/* eslint-disable no-unused-vars */
|
||||
|
||||
|
@ -7,7 +7,7 @@ var RepositoryDatatableRowEditor = (function() {
|
|||
const NAME_COLUMN_ID = 'row-name';
|
||||
const TABLE_ROW = '<tr></tr>';
|
||||
const TABLE_CELL = '<td></td>';
|
||||
const EDIT_FORM_CLASS_NAME = 'repository-row-edit-form';
|
||||
const EDIT_FORM_CLASS_NAME = GLOBAL_CONSTANTS.REPOSITORY_ROW_EDITOR_FORM_CLASS_NAME;
|
||||
|
||||
var TABLE;
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ const GLOBAL_CONSTANTS = {
|
|||
FILENAME_TRUNCATION_LENGTH: <%= Constants::FILENAME_TRUNCATION_LENGTH %>,
|
||||
FILE_MAX_SIZE_MB: <%= Rails.configuration.x.file_max_size_mb %>,
|
||||
IS_SAFARI: /^((?!chrome|android).)*safari/i.test(navigator.userAgent),
|
||||
REPOSITORY_ROW_EDITOR_FORM_CLASS_NAME: 'repository-row-edit-form',
|
||||
REPOSITORY_LIST_ITEMS_PER_COLUMN: <%= Constants::REPOSITORY_LIST_ITEMS_PER_COLUMN %>,
|
||||
REPOSITORY_CHECKLIST_ITEMS_PER_COLUMN: <%= Constants::REPOSITORY_CHECKLIST_ITEMS_PER_COLUMN %>
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* global RepositoryDatatableRowEditor I18n */
|
||||
/* global GLOBAL_CONSTANTS I18n */
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
@ -6,7 +6,7 @@
|
|||
function initUnsavedWorkDialog() {
|
||||
$(document).on('turbolinks:before-visit', () => {
|
||||
let exit = true;
|
||||
let editing = $(`.${RepositoryDatatableRowEditor.EDIT_FORM_CLASS_NAME}`).length > 0;
|
||||
let editing = $(`.${GLOBAL_CONSTANTS.REPOSITORY_ROW_EDITOR_FORM_CLASS_NAME}`).length > 0;
|
||||
|
||||
if (editing) {
|
||||
exit = confirm(I18n.t('repositories.js.leaving_warning'));
|
||||
|
|
|
@ -65,7 +65,7 @@ class ResultAssetsController < ApplicationController
|
|||
saved = false
|
||||
|
||||
@result.transaction do
|
||||
update_params = result_params
|
||||
update_params = result_params.reject { |_, v| v.blank? }
|
||||
previous_size = @result.space_taken
|
||||
|
||||
if update_params.dig(:asset_attributes, :signed_blob_id)
|
||||
|
@ -96,17 +96,18 @@ class ResultAssetsController < ApplicationController
|
|||
raise ActiveRecord:: Rollback
|
||||
end
|
||||
# Asset (file) and/or name has been changed
|
||||
asset_changed = @result.asset.changed?
|
||||
saved = @result.save
|
||||
|
||||
if saved
|
||||
# Release team's space taken due to
|
||||
# previous asset being removed
|
||||
team = @result.my_module.experiment.project.team
|
||||
team.release_space(previous_size)
|
||||
team.release_space(previous_size) if asset_changed
|
||||
team.save
|
||||
|
||||
# Post process new file if neccesary
|
||||
@result.asset.post_process_file(team) if @result.asset.present?
|
||||
@result.asset.post_process_file(team) if asset_changed && @result.asset.present?
|
||||
|
||||
log_activity(:edit_result)
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<div class="well">
|
||||
<%= bootstrap_form_for(@result, url: result_asset_path(format: :json), multipart: true, data: { type: :json }) do |f| %>
|
||||
<%= bootstrap_form_for(@result, url: result_asset_path(format: :json), remote: true) do |f| %>
|
||||
<%= f.text_field :name, style: "margin-top: 10px;" %><br />
|
||||
<%= f.fields_for :asset do |ff| %>
|
||||
<span><strong><%=t "result_assets.edit.uploaded_asset" %></strong></span>
|
||||
|
|
Loading…
Reference in a new issue