From 7f713b429350dbb8705ba3d50c691fbb552bdf38 Mon Sep 17 00:00:00 2001
From: Oleksii Kriuchykhin
<%= t "samples.modal_info.custom_field", cf: sample_custom_field.custom_field.name %>
- <%= sample_custom_field.value %>
+ <%= custom_auto_link(sample_custom_field.value, simple_format: false, team: @team) %>
<% end %>
Your export request is being processed.
When completed we will send an email to %{email} inbox with a link to your exported samples. Note that the link will expire in 7 days.
" # This section contains general words that can be used in any parts of # application. tiny_mce: From 6e1f93dd116538a4394985f3d71c4a2ce77c8a35 Mon Sep 17 00:00:00 2001 From: zmagod<%= I18n.t 'general.file.size_exceeded', file_size: Constants::FILE_MAX_SIZE_MB %>
"; + } + totalSize += parseInt(file.size/1048576); + return ''; + } + + function _validateTotalSize() { + if(totalSize > <%= Constants::FILE_MAX_SIZE_MB %>) { + filesValid = false; + $.each($('.panel-step-attachment-new'), function() { + $(this) + .find('.panel-body') + .append("<%= I18n.t('general.file.total_size', size: Constants::FILE_MAX_SIZE_MB) %>
"); + }); + } else { + $('.dnd-error').remove(); + filesValid = true; + } + } + + function _uploadedAseetPreview(asset, i) { + var html = ' '; + return html; + } + + function _removeItemHandler(id) { + $('[data-item-id="' + id +'"]').off('click').on('click', function(e) { + e.preventDefault(); + e.stopImmediatePropagation(); + e.stopPropagation(); + var $el = $(this); + var index = $el.data('item-id'); + totalSize -= parseInt(droppedFiles[index]/1048576); + droppedFiles.splice(parseInt(index), 1); + $el.closest('.panel-step-attachment-new').remove(); + _validateTotalSize(); + }); + } + + return Object.freeze({ + init: init, + appendFilesToForm: appendFilesToForm, + listItems: listItems, + filesStatus: filesStatus + }) + })(); + + global.dragNdropAssetsInit = function() { + var in_window = true; + + $('body').on('drag dragstart dragend dragover dragenter dragleave drop', + function(e) { + e.preventDefault(); + e.stopPropagation(); + }).on('dragover', function() { + in_window = true; + $('.is-dragover').show(); + }).on('dragleave', function() { + in_window = false; + setTimeout(function() { + if(!in_window) { + $('.is-dragover').hide(); + } + }, 5000); + + }).on('drop', function(e) { + $('.is-dragover').hide(); + DroppedFiles.init(e.originalEvent.dataTransfer.files); + DroppedFiles.listItems(); + }); + + } + + global.dragNdropAssetsOff = function() { + $('body').off('drag dragstart dragend dragover dragenter dragleave drop'); + $('.is-dragover').hide(); + } + // New step AJAX function newStepHandler() { $("[data-action='new-step']").off().on('click', function(event) { @@ -562,7 +663,6 @@ scrollTop: $(document).height() - $(window).height() }); formCallback($form); - formNewAjax($form); applyCancelOnNew(); toggleButtons(false); initializeCheckboxSorting(); @@ -588,13 +688,16 @@ // experience is improved global.processStep = function processStep(ev, editMode) { ev.stopPropagation(); + ev.preventDefault(); + ev.stopImmediatePropagation(); var $form = $(ev.target.form); $form.clearFormErrors(); $form.removeBlankFileForms(); - var $fileInputs = $form.find("input[type=file]"); - var filesValid = filesValidator(ev, $fileInputs, FileTypeEnum.FILE); + // var $fileInputs = $form.find("input[type=file]"); + // var filesValid = filesValidator(ev, $fileInputs, FileTypeEnum.FILE, true); + // debugger; var $checklists = $form.find(".nested_step_checklists"); var checklistsValid = checklistsValidator(ev, $checklists, editMode); var $nameInput = $form.find("#step_name"); @@ -604,9 +707,76 @@ var descriptionValid = textValidator(ev, $descrTextarea, 0, <%= Constants::TEXT_MAX_LENGTH %>); - if (filesValid && checklistsValid && nameValid && descriptionValid) { - // Local file uploading + if (DroppedFiles.filesStatus() && + checklistsValid && + nameValid && + descriptionValid) { + + $form.find("[data-role='editable-table']").each(function() { + var hot = $(this).find(".hot").handsontable('getInstance'); + var contents = $(this).find('.hot-contents'); + var data = JSON.stringify({data: hot.getData()}); + contents.attr("value", data); + }); + + setTimeout(function() { + initStepsComments(); + animateSpinner(null, false); + SmartAnnotation.preventPropagation('.atwho-user-popover'); + }, 1000); + + animateSpinner(null, true); + var data = DroppedFiles.appendFilesToForm(ev); + data.append('step[description]', TinyMCE.getContent()); + $.ajax({ + url: $form.attr('action'), + method: 'POST', + data: data, + contentType: false, + processData: false, + beforeSend: function() { + $(".nested_step_checklists ul").each(function () { + reorderCheckboxData(this); + }); + }, + success: function(data) { + $($form.closest('.well')).after(data.html); + var $new_step = $($form.closest('.well')).next(); + $($form.closest('.well')).remove(); + + initCallBacks(); + initHandsOnTable($new_step); + expandStep($new_step); + toggleButtons(true); + SmartAnnotation.preventPropagation('.atwho-user-popover'); + + //Rerender tables + $new_step.find("div.step-result-hot-table").each(function() { + $(this).handsontable("render"); + }); + animateSpinner(null, false); + setupAssetsLoading(); + }, + error: function(e) { + $form.after(xhr.responseJSON.html); + var $new_form = $form.next(); + $form.remove(); + + $errInput = $new_form.find(".form-group.has-error") + .first() + .find("input"); + renderFormError(e, $errInput); + + formCallback($form); + applyCancelOnNew(); + animateSpinner(null, false); + + TinyMCE.destroyAll(); + SmartAnnotation.preventPropagation('.atwho-user-popover'); + } + }); newStepHandler(); + } } diff --git a/app/assets/stylesheets/themes/scinote.scss b/app/assets/stylesheets/themes/scinote.scss index 7429fa6ff..bf72c7cdb 100644 --- a/app/assets/stylesheets/themes/scinote.scss +++ b/app/assets/stylesheets/themes/scinote.scss @@ -1265,6 +1265,45 @@ ul.content-module-activities { } } +.new-asset-box { + border: 1px solid $color-silver; + border-radius: 2px; + margin-bottom: 20px; + margin-top: 20px; + padding-bottom: 30px; + padding-top: 30px; + font-size: 2rem; +} + +.dnd-error { + color: $color-milano-red; +} + +.is-dragover { + background: rgba(0,0,0,0.4); + bottom: 0; + display: none; + height: 100%; + left: 0; + min-height: 100%; + pointer-events: none; + position: fixed; + right: 0; + top: 0; + width: 100%; + z-index: 999999; + + span { + color: $color-white; + display: block; + font-size: 4em; + font-weight: bold; + padding-top: 25%; + pointer-events: none; + text-align: center; + } +} + .step, .result { .panel { diff --git a/app/controllers/steps_controller.rb b/app/controllers/steps_controller.rb index a9cbf6409..20ee1b81b 100644 --- a/app/controllers/steps_controller.rb +++ b/app/controllers/steps_controller.rb @@ -44,7 +44,6 @@ class StepsController < ApplicationController table.created_by = current_user table.team = current_team end - # Update default checked state @step.checklists.each do |checklist| checklist.checklist_items.each do |checklist_item| diff --git a/app/views/my_modules/protocols.html.erb b/app/views/my_modules/protocols.html.erb index d90814371..d4ebcd9de 100644 --- a/app/views/my_modules/protocols.html.erb +++ b/app/views/my_modules/protocols.html.erb @@ -1,4 +1,8 @@ <% provide(:head_title, t("my_modules.protocols.head_title", project: h(@project.name), module: h(@my_module.name)).html_safe) %> + +<%= I18n.t 'general.file.size_exceeded', file_size: Constants::FILE_MAX_SIZE_MB %>
"; - } - totalSize += parseInt(file.size/1048576); - return ''; - } - - function _validateTotalSize() { - if(totalSize > <%= Constants::FILE_MAX_SIZE_MB %>) { - filesValid = false; - $.each($('.panel-step-attachment-new'), function() { - $(this) - .find('.panel-body') - .append("<%= I18n.t('general.file.total_size', size: Constants::FILE_MAX_SIZE_MB) %>
"); - }); - } else { - $('.dnd-error').remove(); - filesValid = true; - } - } - - function _uploadedAseetPreview(asset, i) { - var html = ' '; - return html; - } - - function _removeItemHandler(id) { - $('[data-item-id="' + id +'"]').off('click').on('click', function(e) { - e.preventDefault(); - e.stopImmediatePropagation(); - e.stopPropagation(); - var $el = $(this); - var index = $el.data('item-id'); - totalSize -= parseInt(droppedFiles[index]/1048576); - droppedFiles.splice(parseInt(index), 1); - $el.closest('.panel-step-attachment-new').remove(); - _validateTotalSize(); - }); - } - - return Object.freeze({ - init: init, - appendFilesToForm: appendFilesToForm, - listItems: listItems, - filesStatus: filesStatus - }) - })(); - - global.dragNdropAssetsInit = function() { - var in_window = true; - - $('body').on('drag dragstart dragend dragover dragenter dragleave drop', - function(e) { - e.preventDefault(); - e.stopPropagation(); - }).on('dragover', function() { - in_window = true; - $('.is-dragover').show(); - }).on('dragleave', function() { - in_window = false; - setTimeout(function() { - if(!in_window) { - $('.is-dragover').hide(); - } - }, 5000); - - }).on('drop', function(e) { - $('.is-dragover').hide(); - DroppedFiles.init(e.originalEvent.dataTransfer.files); - DroppedFiles.listItems(); - }); - - } - - global.dragNdropAssetsOff = function() { - $('body').off('drag dragstart dragend dragover dragenter dragleave drop'); - $('.is-dragover').hide(); - } - // New step AJAX function newStepHandler() { $("[data-action='new-step']").off().on('click', function(event) { @@ -695,9 +551,6 @@ $form.clearFormErrors(); $form.removeBlankFileForms(); - // var $fileInputs = $form.find("input[type=file]"); - // var filesValid = filesValidator(ev, $fileInputs, FileTypeEnum.FILE, true); - // debugger; var $checklists = $form.find(".nested_step_checklists"); var checklistsValid = checklistsValidator(ev, $checklists, editMode); var $nameInput = $form.find("#step_name"); @@ -707,7 +560,7 @@ var descriptionValid = textValidator(ev, $descrTextarea, 0, <%= Constants::TEXT_MAX_LENGTH %>); - if (DroppedFiles.filesStatus() && + if (DragNDrop.filesStatus() && checklistsValid && nameValid && descriptionValid) { @@ -721,12 +574,11 @@ setTimeout(function() { initStepsComments(); - animateSpinner(null, false); SmartAnnotation.preventPropagation('.atwho-user-popover'); }, 1000); animateSpinner(null, true); - var data = DroppedFiles.appendFilesToForm(ev); + var data = DragNDrop.appendFilesToForm(ev); data.append('step[description]', TinyMCE.getContent()); $.ajax({ url: $form.attr('action'), diff --git a/app/assets/javascripts/sitewide/drag_n_drop.js.erb b/app/assets/javascripts/sitewide/drag_n_drop.js.erb new file mode 100644 index 000000000..d11098ad0 --- /dev/null +++ b/app/assets/javascripts/sitewide/drag_n_drop.js.erb @@ -0,0 +1,151 @@ +(function(global) { + 'use strict'; + + global.DragNDrop = (function() { + var droppedFiles = []; + var filesValid = true; + var totalSize = 0; + + function init(files, action) { + for(var i = 0; i < files.length; i++) { + droppedFiles.push(files[i]); + } + if(action === 'select') { + listItems(); + } + } + + // return the status of files if they are ready to submit + function filesStatus() { + return filesValid; + } + + // loops through a list of files and display each file in a separate panel + function listItems() { + $('.panel-step-attachment-new').remove(); + _dragNdropAssetsOff(); + for(var i = 0; i < droppedFiles.length; i++) { + $('#new-step-assets') + .append(_uploadedAseetPreview(droppedFiles[i], i)) + .promise() + .done(function() { + _removeItemHandler(i); + }); + } + _validateTotalSize(); + dragNdropAssetsInit(); + } + + // appent the files to the form before submit + function appendFilesToForm(ev) { + var regex = /step\[assets_attributes\]\[[0-9]*\]\[id\]/; + var prevEls = $('input').filter(function() { + return this.name.match(regex); + }); + + var fd = new FormData($(ev.target).closest('form').get(0)); + for(var i = 0; i < droppedFiles.length; i++) { + var index = i + prevEls.length; + var name = 'step[assets_attributes][' + index + '][file]'; + fd.append(name, droppedFiles[i]); + } + droppedFiles = []; + filesValid = true; + totalSize = 0; + _dragNdropAssetsOff(); + return fd; + } + + function _validateFilesSize(file) { + if((file.size/1048576) > <%= Constants::FILE_MAX_SIZE_MB %> && filesValid) { + return "<%= I18n.t 'general.file.size_exceeded', file_size: Constants::FILE_MAX_SIZE_MB %>
"; + } + totalSize += parseInt(file.size/1048576); + return ''; + } + + function _validateTotalSize() { + if(totalSize > <%= Constants::FILE_MAX_SIZE_MB %>) { + filesValid = false; + $.each($('.panel-step-attachment-new'), function() { + $(this) + .find('.panel-body') + .append("<%= I18n.t('general.file.total_size', size: Constants::FILE_MAX_SIZE_MB) %>
"); + }); + } else { + $('.dnd-error').remove(); + filesValid = true; + } + } + + function _uploadedAseetPreview(asset, i) { + var html = ' '; + return html; + } + + function _removeItemHandler(id) { + $('[data-item-id="' + id +'"]').off('click').on('click', function(e) { + e.preventDefault(); + e.stopImmediatePropagation(); + e.stopPropagation(); + var $el = $(this); + var index = $el.data('item-id'); + totalSize -= parseInt(droppedFiles[index]/1048576); + droppedFiles.splice(parseInt(index), 1); + $el.closest('.panel-step-attachment-new').remove(); + _validateTotalSize(); + }); + } + + function _dragNdropAssetsOff() { + $('body').off('drag dragstart dragend dragover dragenter dragleave drop'); + $('.is-dragover').hide(); + } + + return Object.freeze({ + init: init, + appendFilesToForm: appendFilesToForm, + listItems: listItems, + filesStatus: filesStatus + }) + })(); + + global.dragNdropAssetsInit = function() { + var in_window = true; + + $('body').on('drag dragstart dragend dragover dragenter dragleave drop', + function(e) { + e.preventDefault(); + e.stopPropagation(); + }).on('dragover', function() { + in_window = true; + $('.is-dragover').show(); + }).on('dragleave', function() { + in_window = false; + setTimeout(function() { + if(!in_window) { + $('.is-dragover').hide(); + } + }, 5000); + + }).on('drop', function(e) { + $('.is-dragover').hide(); + DragNDrop.init(e.originalEvent.dataTransfer.files); + DragNDrop.listItems(); + }); + } + +})(window); diff --git a/app/helpers/tiny_mce_helper.rb b/app/helpers/tiny_mce_helper.rb index 0b9da187e..62431604d 100644 --- a/app/helpers/tiny_mce_helper.rb +++ b/app/helpers/tiny_mce_helper.rb @@ -18,6 +18,7 @@ module TinyMceHelper end def generate_image_tag_from_token(text) + return unless text regex = /\[~tiny_mce_id:([0-9a-zA-Z]+)\]/ text.gsub(regex) do |el| match = el.match(regex) diff --git a/app/views/my_modules/protocols.html.erb b/app/views/my_modules/protocols.html.erb index d4ebcd9de..a0d90b9d0 100644 --- a/app/views/my_modules/protocols.html.erb +++ b/app/views/my_modules/protocols.html.erb @@ -1,7 +1,7 @@ <% provide(:head_title, t("my_modules.protocols.head_title", project: h(@project.name), module: h(@my_module.name)).html_safe) %>