Skip to content

Commit

Permalink
Modify group upload files
Browse files Browse the repository at this point in the history
  • Loading branch information
itstructure committed Aug 4, 2019
1 parent bdc0b67 commit ccfb904
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 80 deletions.
163 changes: 84 additions & 79 deletions src/assets/source/js/uploadmanager.js
Expand Up @@ -39,87 +39,12 @@ $(document).ready(function() {
workspace.html(oldHtml + newHtml);
});

/**
* Single upload file.
*/
window.workspace.on("click", '[role="upload-file"]', function(e) {
e.preventDefault();

var fileNumber = $(this).attr('data-file-number'),
fileBlock = $(this).parents('[role="file-block"]'),
progressBlock = fileBlock.find('[role="progress-block"]'),
buttonBlockUpload = fileBlock.find('[role="button-block-upload"]'),
buttonBlockDelete = fileBlock.find('[role="button-block-delete"]'),
url = window.uploadManagerContainer.attr('data-send-url'),
fileAttributeName = window.uploadManagerContainer.attr('data-file-attribute-name'),
subDir = window.fileManagerModalContainer.attr("data-sub-dir"),
owner = window.fileManagerModalContainer.attr("data-owner"),
ownerId = window.fileManagerModalContainer.attr("data-owner-id"),
ownerAttribute = window.fileManagerModalContainer.attr("data-owner-attribute"),
neededFileType = window.fileManagerModalContainer.attr("data-needed-file-type"),
file = window.preparedFiles[fileNumber],
fileType = file.type,
params = {
_csrf: window.yii.getCsrfToken(),
title: fileBlock.find('[role="file-title"]').val(),
description: fileBlock.find('[role="file-description"]').val()
},
paramsFiles = {};
paramsFiles[fileAttributeName] = file;
params.files = paramsFiles;

if (fileType.split('/')[0] == 'image') {
params.alt = fileBlock.find('[role="file-alt"]').val();
}
var fileNumber = $(this).attr('data-file-number');

if (subDir && subDir != '') {
params.subDir = subDir;
}

if (owner && owner != '') {
params.owner = owner;
}

if (ownerId && ownerId != '') {
params.ownerId = ownerId;
}

if (ownerAttribute && ownerAttribute != '') {
params.ownerAttribute = ownerAttribute;
}

if (neededFileType && neededFileType != '') {
params.neededFileType = neededFileType;
}

AJAX(url, 'POST', params, true, function () {
setAjaxLoader(progressBlock, 1000);

}, function(data) {

if (data.meta.status == 'success') {
clearContainer(progressBlock);
clearContainer(buttonBlockUpload);
buttonBlockDelete.css('display', 'block');

if (data.data.files && data.data.files[0]) {
fileBlock.find('[role="delete-file-button"]').attr('data-file-id', data.data.files[0].id);
}

$(fileBlock.find('[role="file-title"]')).attr('disabled', 'disabled');
$(fileBlock.find('[role="file-description"]')).attr('disabled', 'disabled');

if (fileType.split('/')[0] == 'image') {
$(fileBlock.find('[role="file-alt"]')).attr('disabled', 'disabled');
}

} else {
showPopup(progressBlock, data.data.errors, true, 0);
}

}, function(data, xhr) {
showPopup(progressBlock, data.message, true, 0);
});
upload_file(fileNumber);
});

/**
Expand All @@ -129,7 +54,7 @@ $(document).ready(function() {
e.preventDefault();

var fileNumber = $(this).attr('data-file-number'),
fileBlock = $(this).parents('[role="file-block"]'),
fileBlock = $(this).parents('[role="file-block-'+fileNumber+'"]'),
progressBlock = fileBlock.find('[role="progress-block"]'),
url = window.uploadManagerContainer.attr('data-delete-url'),
params = {
Expand Down Expand Up @@ -160,7 +85,7 @@ $(document).ready(function() {
e.preventDefault();

var fileNumber = $(this).attr('data-file-number'),
fileBlock = $(this).parents('[role="file-block"]');
fileBlock = $(this).parents('[role="file-block-'+fileNumber+'"]');

delete window.preparedFiles[fileNumber];

Expand Down Expand Up @@ -241,4 +166,84 @@ $(document).ready(function() {
return (kbSize/1024).toFixed(2) + ' MB';
}
}

/**
* Single upload file.
*/
function upload_file(fileNumber) {
var fileBlock = $('[role="file-block-'+fileNumber+'"]'),
progressBlock = fileBlock.find('[role="progress-block"]'),
buttonBlockUpload = fileBlock.find('[role="button-block-upload"]'),
buttonBlockDelete = fileBlock.find('[role="button-block-delete"]'),
url = window.uploadManagerContainer.attr('data-send-url'),
fileAttributeName = window.uploadManagerContainer.attr('data-file-attribute-name'),
subDir = window.fileManagerModalContainer.attr("data-sub-dir"),
owner = window.fileManagerModalContainer.attr("data-owner"),
ownerId = window.fileManagerModalContainer.attr("data-owner-id"),
ownerAttribute = window.fileManagerModalContainer.attr("data-owner-attribute"),
neededFileType = window.fileManagerModalContainer.attr("data-needed-file-type"),
file = window.preparedFiles[fileNumber],
fileType = file.type,
params = {
_csrf: window.yii.getCsrfToken(),
title: fileBlock.find('[role="file-title"]').val(),
description: fileBlock.find('[role="file-description"]').val()
},
paramsFiles = {};
paramsFiles[fileAttributeName] = file;
params.files = paramsFiles;

if (fileType.split('/')[0] == 'image') {
params.alt = fileBlock.find('[role="file-alt"]').val();
}

if (subDir && subDir != '') {
params.subDir = subDir;
}

if (owner && owner != '') {
params.owner = owner;
}

if (ownerId && ownerId != '') {
params.ownerId = ownerId;
}

if (ownerAttribute && ownerAttribute != '') {
params.ownerAttribute = ownerAttribute;
}

if (neededFileType && neededFileType != '') {
params.neededFileType = neededFileType;
}

AJAX(url, 'POST', params, true, function () {
setAjaxLoader(progressBlock, 1000);

}, function(data) {

if (data.meta.status == 'success') {
clearContainer(progressBlock);
clearContainer(buttonBlockUpload);
buttonBlockDelete.css('display', 'block');

if (data.data.files && data.data.files[0]) {
fileBlock.find('[role="delete-file-button"]').attr('data-file-id', data.data.files[0].id);
}

$(fileBlock.find('[role="file-title"]')).attr('disabled', 'disabled');
$(fileBlock.find('[role="file-description"]')).attr('disabled', 'disabled');

if (fileType.split('/')[0] == 'image') {
$(fileBlock.find('[role="file-alt"]')).attr('disabled', 'disabled');
}

} else {
showPopup(progressBlock, data.data.errors, true, 0);
}

}, function(data, xhr) {
showPopup(progressBlock, data.message, true, 0);
});
}
});
2 changes: 1 addition & 1 deletion src/views/managers/_fileBlock.php
Expand Up @@ -3,7 +3,7 @@
use Itstructure\MFUploader\Module;
?>

<tr role="file-block">
<tr role="file-block-{fileNumber}">
<td>
<table width="100%">
<tbody>
Expand Down

0 comments on commit ccfb904

Please sign in to comment.