mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-21 07:26:15 +08:00
refactor
This commit is contained in:
parent
c6bb20039b
commit
33b996ffee
|
@ -611,7 +611,6 @@
|
|||
}
|
||||
});
|
||||
newStepHandler();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
success: function(data) {
|
||||
var $form = $(data.html);
|
||||
animateSpinner(null, false);
|
||||
$('#results').prepend($form)
|
||||
$('#results').prepend($form);
|
||||
_formAjaxResultAsset($form);
|
||||
Results.initCancelFormButton($form, initNewResultAsset);
|
||||
Results.toggleResultEditButtons(false);
|
||||
|
|
|
@ -1,19 +1,17 @@
|
|||
(function(global) {
|
||||
'use strict';
|
||||
|
||||
// Module to handle file uploading in Results
|
||||
// Module to handle file uploading in Steps
|
||||
global.DragNDropSteps = (function() {
|
||||
var droppedFiles = [];
|
||||
var filesValid = true;
|
||||
var totalSize = 0;
|
||||
|
||||
function init(files, action) {
|
||||
function init(files) {
|
||||
for(var i = 0; i < files.length; i++) {
|
||||
droppedFiles.push(files[i]);
|
||||
}
|
||||
if(action === 'select') {
|
||||
listItems();
|
||||
}
|
||||
listItems();
|
||||
}
|
||||
|
||||
// return the status of files if they are ready to submit
|
||||
|
@ -38,7 +36,7 @@
|
|||
dragNdropAssetsInit('steps');
|
||||
}
|
||||
|
||||
// appent the files to the form before submit
|
||||
// append the files to the form before submit
|
||||
function appendFilesToForm(ev) {
|
||||
var regex = /step\[assets_attributes\]\[[0-9]*\]\[id\]/;
|
||||
var prevEls = $('input').filter(function() {
|
||||
|
@ -59,10 +57,11 @@
|
|||
}
|
||||
|
||||
function _validateFilesSize(file) {
|
||||
if((file.size/1048576) > <%= Constants::FILE_MAX_SIZE_MB %> && filesValid) {
|
||||
var maxSize = file.size/1048576;
|
||||
if(maxSize > <%= Constants::FILE_MAX_SIZE_MB %> && filesValid) {
|
||||
return "<p><%= I18n.t 'general.file.size_exceeded', file_size: Constants::FILE_MAX_SIZE_MB %></p>";
|
||||
}
|
||||
totalSize += parseInt(file.size/1048576);
|
||||
totalSize += parseInt(maxSize);
|
||||
return '';
|
||||
}
|
||||
|
||||
|
@ -178,10 +177,7 @@
|
|||
fd.append(file_name, droppedFiles[i]);
|
||||
fd.append('results_names[' + i + ']', result_names[i]);
|
||||
}
|
||||
droppedFiles = [];
|
||||
isValid = true;
|
||||
totalSize = 0;
|
||||
_dragNdropAssetsOff();
|
||||
destroyAll();
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
@ -191,10 +187,11 @@
|
|||
}
|
||||
|
||||
function _validateFilesSize(file) {
|
||||
if((file.size/1048576) > <%= Constants::FILE_MAX_SIZE_MB %> && isValid) {
|
||||
var maxSize = file.size/1048576;
|
||||
if(maxSize > <%= Constants::FILE_MAX_SIZE_MB %> && isValid) {
|
||||
return "<p><%= I18n.t 'general.file.size_exceeded', file_size: Constants::FILE_MAX_SIZE_MB %></p>";
|
||||
}
|
||||
totalSize += parseInt(file.size/1048576);
|
||||
totalSize += parseInt(maxSize);
|
||||
return '';
|
||||
}
|
||||
|
||||
|
@ -259,7 +256,7 @@
|
|||
});
|
||||
}
|
||||
|
||||
function uploadResultAssets(button) {
|
||||
function processResult(button) {
|
||||
if(isValid && _filerAndCheckFiles()) {
|
||||
animateSpinner();
|
||||
$.ajax({
|
||||
|
@ -313,7 +310,7 @@
|
|||
destroyAll: destroyAll,
|
||||
filesStatus: filesStatus,
|
||||
validateTextSize: validateTextSize,
|
||||
uploadResultAssets: uploadResultAssets
|
||||
processResult: processResult
|
||||
});
|
||||
})();
|
||||
|
||||
|
@ -340,7 +337,6 @@
|
|||
var files = e.originalEvent.dataTransfer.files;
|
||||
if(location === 'steps') {
|
||||
DragNDropSteps.init(files);
|
||||
DragNDropSteps.listItems();
|
||||
} else {
|
||||
DragNDropResults.init(files);
|
||||
}
|
||||
|
|
|
@ -44,6 +44,9 @@ $color-milano-red: #a70b05;
|
|||
// Colors for specific intents
|
||||
$color-visited-link: #23527c;
|
||||
|
||||
// Overlay shade for drag'n dropdown
|
||||
$color-drag-overlay: rgba(0, 0, 0, .4);
|
||||
|
||||
//==============================================================================
|
||||
// Other
|
||||
//==============================================================================
|
||||
|
|
|
@ -1268,11 +1268,11 @@ ul.content-module-activities {
|
|||
.new-asset-box {
|
||||
border: 1px solid $color-silver;
|
||||
border-radius: 2px;
|
||||
font-size: 2rem;
|
||||
margin-bottom: 20px;
|
||||
margin-top: 20px;
|
||||
padding-bottom: 30px;
|
||||
padding-top: 30px;
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.dnd-error {
|
||||
|
@ -1280,7 +1280,7 @@ ul.content-module-activities {
|
|||
}
|
||||
|
||||
.is-dragover {
|
||||
background: rgba(0,0,0,0.4);
|
||||
background: $color-drag-overlay;
|
||||
bottom: 0;
|
||||
display: none;
|
||||
height: 100%;
|
||||
|
|
|
@ -9,18 +9,10 @@
|
|||
</label>
|
||||
</div>
|
||||
<br />
|
||||
<%#= bootstrap_form_for(@result, url: my_module_result_assets_path(format: :json), remote: true, multipart: true, data: { type: :json }) do |f| %>
|
||||
<%#= f.text_field :name, style: "margin-top: 10px;" %>
|
||||
<%#= f.fields_for :asset do |ff| %>
|
||||
<%#= ff.file_field :file %>
|
||||
<%# end %>
|
||||
<%#= f.submit t("result_assets.new.create"),
|
||||
class: 'btn btn-primary save-result',
|
||||
onclick: "Results.processResult(event, Results.ResultTypeEnum.FILE, false);" %>
|
||||
<button type="button"
|
||||
class="btn btn-primary save-result"
|
||||
data-href="<%= my_module_result_assets_path(format: :json) %>"
|
||||
onClick="DragNDropResults.uploadResultAssets(this)"><%=t 'result_assets.new.create' %></button>
|
||||
onClick="DragNDropResults.processResult(this)"><%=t 'result_assets.new.create' %></button>
|
||||
<button type="button"
|
||||
class="btn btn-default cancel-new"
|
||||
onClick="DragNDropResults.destroyAll()">
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
<div class="text-center new-asset-box">
|
||||
<%=t 'assets.drag_n_drop.label_html' %> <label><span class="btn btn-primary"><%=t 'assets.drag_n_drop.browse_label' %></span>
|
||||
<input type="file"
|
||||
onchange="DragNDropSteps.init(this.files, 'select')"
|
||||
onchange="DragNDropSteps.init(this.files)"
|
||||
id="drag-n-drop-assets"
|
||||
style="display: none" multiple>
|
||||
</label>
|
||||
|
|
Loading…
Reference in a new issue