This commit is contained in:
zmagod 2017-06-09 09:49:57 +02:00
parent c6bb20039b
commit 33b996ffee
7 changed files with 21 additions and 31 deletions

View file

@ -611,7 +611,6 @@
} }
}); });
newStepHandler(); newStepHandler();
} }
} }

View file

@ -19,7 +19,7 @@
success: function(data) { success: function(data) {
var $form = $(data.html); var $form = $(data.html);
animateSpinner(null, false); animateSpinner(null, false);
$('#results').prepend($form) $('#results').prepend($form);
_formAjaxResultAsset($form); _formAjaxResultAsset($form);
Results.initCancelFormButton($form, initNewResultAsset); Results.initCancelFormButton($form, initNewResultAsset);
Results.toggleResultEditButtons(false); Results.toggleResultEditButtons(false);

View file

@ -1,19 +1,17 @@
(function(global) { (function(global) {
'use strict'; 'use strict';
// Module to handle file uploading in Results // Module to handle file uploading in Steps
global.DragNDropSteps = (function() { global.DragNDropSteps = (function() {
var droppedFiles = []; var droppedFiles = [];
var filesValid = true; var filesValid = true;
var totalSize = 0; var totalSize = 0;
function init(files, action) { function init(files) {
for(var i = 0; i < files.length; i++) { for(var i = 0; i < files.length; i++) {
droppedFiles.push(files[i]); droppedFiles.push(files[i]);
} }
if(action === 'select') { listItems();
listItems();
}
} }
// return the status of files if they are ready to submit // return the status of files if they are ready to submit
@ -38,7 +36,7 @@
dragNdropAssetsInit('steps'); dragNdropAssetsInit('steps');
} }
// appent the files to the form before submit // append the files to the form before submit
function appendFilesToForm(ev) { function appendFilesToForm(ev) {
var regex = /step\[assets_attributes\]\[[0-9]*\]\[id\]/; var regex = /step\[assets_attributes\]\[[0-9]*\]\[id\]/;
var prevEls = $('input').filter(function() { var prevEls = $('input').filter(function() {
@ -59,10 +57,11 @@
} }
function _validateFilesSize(file) { 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>"; 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 ''; return '';
} }
@ -178,10 +177,7 @@
fd.append(file_name, droppedFiles[i]); fd.append(file_name, droppedFiles[i]);
fd.append('results_names[' + i + ']', result_names[i]); fd.append('results_names[' + i + ']', result_names[i]);
} }
droppedFiles = []; destroyAll();
isValid = true;
totalSize = 0;
_dragNdropAssetsOff();
return fd; return fd;
} }
@ -191,10 +187,11 @@
} }
function _validateFilesSize(file) { 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>"; 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 ''; return '';
} }
@ -259,7 +256,7 @@
}); });
} }
function uploadResultAssets(button) { function processResult(button) {
if(isValid && _filerAndCheckFiles()) { if(isValid && _filerAndCheckFiles()) {
animateSpinner(); animateSpinner();
$.ajax({ $.ajax({
@ -313,7 +310,7 @@
destroyAll: destroyAll, destroyAll: destroyAll,
filesStatus: filesStatus, filesStatus: filesStatus,
validateTextSize: validateTextSize, validateTextSize: validateTextSize,
uploadResultAssets: uploadResultAssets processResult: processResult
}); });
})(); })();
@ -340,7 +337,6 @@
var files = e.originalEvent.dataTransfer.files; var files = e.originalEvent.dataTransfer.files;
if(location === 'steps') { if(location === 'steps') {
DragNDropSteps.init(files); DragNDropSteps.init(files);
DragNDropSteps.listItems();
} else { } else {
DragNDropResults.init(files); DragNDropResults.init(files);
} }

View file

@ -44,6 +44,9 @@ $color-milano-red: #a70b05;
// Colors for specific intents // Colors for specific intents
$color-visited-link: #23527c; $color-visited-link: #23527c;
// Overlay shade for drag'n dropdown
$color-drag-overlay: rgba(0, 0, 0, .4);
//============================================================================== //==============================================================================
// Other // Other
//============================================================================== //==============================================================================

View file

@ -1268,11 +1268,11 @@ ul.content-module-activities {
.new-asset-box { .new-asset-box {
border: 1px solid $color-silver; border: 1px solid $color-silver;
border-radius: 2px; border-radius: 2px;
font-size: 2rem;
margin-bottom: 20px; margin-bottom: 20px;
margin-top: 20px; margin-top: 20px;
padding-bottom: 30px; padding-bottom: 30px;
padding-top: 30px; padding-top: 30px;
font-size: 2rem;
} }
.dnd-error { .dnd-error {
@ -1280,7 +1280,7 @@ ul.content-module-activities {
} }
.is-dragover { .is-dragover {
background: rgba(0,0,0,0.4); background: $color-drag-overlay;
bottom: 0; bottom: 0;
display: none; display: none;
height: 100%; height: 100%;

View file

@ -9,18 +9,10 @@
</label> </label>
</div> </div>
<br /> <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" <button type="button"
class="btn btn-primary save-result" class="btn btn-primary save-result"
data-href="<%= my_module_result_assets_path(format: :json) %>" 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" <button type="button"
class="btn btn-default cancel-new" class="btn btn-default cancel-new"
onClick="DragNDropResults.destroyAll()"> onClick="DragNDropResults.destroyAll()">

View file

@ -45,7 +45,7 @@
<div class="text-center new-asset-box"> <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> <%=t 'assets.drag_n_drop.label_html' %> <label><span class="btn btn-primary"><%=t 'assets.drag_n_drop.browse_label' %></span>
<input type="file" <input type="file"
onchange="DragNDropSteps.init(this.files, 'select')" onchange="DragNDropSteps.init(this.files)"
id="drag-n-drop-assets" id="drag-n-drop-assets"
style="display: none" multiple> style="display: none" multiple>
</label> </label>