Skip to content

Commit

Permalink
[Media] fix: remove 'send file' button
Browse files Browse the repository at this point in the history
  • Loading branch information
Théo David committed Jan 5, 2022
1 parent ea0eb26 commit 662d3e1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
36 changes: 33 additions & 3 deletions core/tpl/digiriskdolibarr_medias_gallery_modal.tpl.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
<?php
if ( ! $error && $action == "uploadPhoto" && ! empty($conf->global->MAIN_UPLOAD_DOC)) {
// Define relativepath and upload_dir
$relativepath = 'digiriskdolibarr/medias';
$upload_dir = $conf->ecm->dir_output . '/' . $relativepath;
if (is_array($_FILES['userfile']['tmp_name'])) $userfiles = $_FILES['userfile']['tmp_name'];
else $userfiles = array($_FILES['userfile']['tmp_name']);


foreach ($userfiles as $key => $userfile) {
if (empty($_FILES['userfile']['tmp_name'][$key])) {
$error++;
if ($_FILES['userfile']['error'][$key] == 1 || $_FILES['userfile']['error'][$key] == 2) {
setEventMessages($langs->trans('ErrorFileSizeTooLarge'), null, 'errors');
} else {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors');
}
}
}
if ( ! $error) {
$generatethumbs = 1;
$res = dol_add_file_process($upload_dir, 0, 1, 'userfile', '', null, '', $generatethumbs);
if ($res > 0) {
$result = $ecmdir->changeNbOfFiles('+');
}
}
}
?>
<!-- START MEDIA GALLERY MODAL -->
<div class="wpeo-modal modal-photo" id="media_gallery" data-id="<?php echo $object->id ?>">
<div class="modal-container wpeo-modal-event">
Expand Down Expand Up @@ -30,9 +58,11 @@
$sectiondir = GETPOST('file', 'alpha') ? GETPOST('file', 'alpha') : GETPOST('section_dir', 'alpha');
print '<!-- Start form to attach new file in digiriskdolibarr_photo_view.tpl.tpl.php sectionid=' . $section . ' sectiondir=' . $sectiondir . ' -->' . "\n";
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
$formfile = new FormFile($db);
$formfile->form_attach_new_file($_SERVER["PHP_SELF"], 'none', 0, 0, 1, 48, null, '', 0, '', 0, $nameforformuserfile, '', $sectiondir, 1);
} else print '&nbsp;';
print '<strong>' . $langs->trans('AddFile') . '</strong>'
?>

<input type="file" id="add_media_to_gallery" class="flat minwidth400 maxwidth200onsmartphone" name="userfile[]" multiple accept>
<?php } else print '&nbsp;';
// End "Add new file" area
?>
<div class="underbanner clearboth"></div>
Expand Down
10 changes: 7 additions & 3 deletions js/digiriskdolibarr.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -1301,24 +1301,28 @@
window.eoxiaJS.mediaGallery.sendPhoto = function( event ) {

event.preventDefault()
let element = $(this).closest('.nowrap');
let files = element.find("input[name='userfile[]']").prop("files");
let files = $(this).prop("files");
let formdata = new FormData();
let elementParent = $(this).closest('.modal-container').find('.ecm-photo-list-content');
let actionContainerSuccess = $('.messageSuccessSendPhoto');
let actionContainerError = $('.messageErrorSendPhoto');
window.eoxiaJS.loader.display($('#media_gallery').find('.modal-content'));

$.each(files, function(index, file) {
console.log(file)
formdata.append("userfile[]", file);
console.log(formdata)

})

$.ajax({
url: document.URL + "&action=uploadPhoto",
type: "POST",
data: formdata,
processData: false,
contentType: false,
success: function ( resp ) {
console.log(document.URL)

$('.wpeo-loader').removeClass('wpeo-loader')
window.eoxiaJS.loader.display(elementParent);
elementParent.load( document.URL + ' .ecm-photo-list');
Expand Down
1 change: 0 additions & 1 deletion lib/digiriskdolibarr_function.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,6 @@ function display_recurse_tree($results)
$digiriskelement->fetch($digiriskelement_id);
$digiriskelement->photo = $filename;
$digiriskelement->update($user, true);
exit;
}

if ( ! $error && $action == "unlinkDigiriskElementFile") {
Expand Down

0 comments on commit 662d3e1

Please sign in to comment.