Commit 66ce0ed8 authored by jonnybradley's avatar jonnybradley

[bp/r65992][ENH] trackers: Add a description input box for "upload in modal"...

[bp/r65992][ENH] trackers: Add a description input box for "upload in modal" files fields - needs testing and maybe fixing for other modes
parent 401fdc79
......@@ -21,9 +21,41 @@ class Services_File_Controller
$this->utilities = new Services_File_Utilities;
}
/**
* Call to prepare the upload in modal dialg, and then after the upload has happened
* Here we add a description if that's enabled
*
* @param JitFilter $input
* @return array
* @throws Exception
*/
function action_uploader($input)
{
$gal_info = $this->checkTargetGallery($input);
$filegallib = TikiLib::lib('filegal');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($input->offsetExists('description')) {
$files = $input->asArray('file');
$descriptions = $input->asArray('description');
foreach ($files as $c => $file) {
$fileInfo = $filegallib->get_file_info($file);
if (isset($descriptions[$c])) {
$filegallib->update_file(
$fileInfo['fileId'],
$fileInfo['filename'],
$descriptions[$c],
$fileInfo['asuser']
);
}
}
}
}
return [
'title' => tr('File Upload'),
......@@ -33,21 +65,25 @@ class Services_File_Controller
'uploadInModal' => $input->uploadInModal->int(),
'files' => $this->getFilesInfo((array) $input->file->int()),
'image_max_size_x' => $input->image_max_size_x->text(),
'image_max_size_y' => $input->image_max_size_y->text()
'image_max_size_y' => $input->image_max_size_y->text(),
'addDecriptionOnUpload' => $input->addDecriptionOnUpload->int(),
];
}
function action_upload($input)
{
if ($input->files->asArray()) {
return;
return [];
}
$gal_info = $this->checkTargetGallery($input);
$fileId = $input->fileId->int();
$asuser = $input->user->text();
if (empty($asuser)) {
$asuser = $GLOBALS['user'];
}
if (! $input->imagesize->word()) {
$image_x = $input->image_max_size_x->text();
$image_y = $input->image_max_size_y->text();
......
......@@ -157,9 +157,16 @@ class Tracker_Field_Files extends Tracker_Field_Abstract implements Tracker_Fiel
'filter' => 'text',
'legacy_index' => 13,
],
'addDecriptionOnUpload' => [
'name' => tr('Add Descriptions'),
'description' => tr('Add descriptions on uploaded files.'),
'filter' => 'alpha',
'default' => 'n',
'options' => [
'n' => tr('No'),
'y' => tr('Yes'),
],
],
],
],
];
......@@ -306,7 +313,8 @@ class Tracker_Field_Files extends Tracker_Field_Abstract implements Tracker_Fiel
}
return $this->renderTemplate('trackerinput/files.tpl', $context, [
'replaceFile' => 'y' == $this->getOption('replace', 'n')
'replaceFile' => 'y' == $this->getOption('replace', 'n'),
'addDecriptionOnUpload' => $this->getOption('addDecriptionOnUpload') === 'y' ? 1 : 0,
]);
}
......
......@@ -55,14 +55,28 @@
$li.append(' (' + (message ? message : tr('uploading failed')) + ')');
};
this.addFile = function (fileId, file) {
var $li = $('<li>').appendTo($list);
// called for "upload in modal" tracker Files fields when file dropped or picked from the file dialog
var $li = $('<li>').addClass("row margin-bottom-md").appendTo($list);
$("<div>").addClass("col-sm-12").text(file.name)
.prepend($.fileTypeIcon(fileId, file).css("margin-right", "1em"))
.appendTo($li);
$li
.text(file.name)
.prepend($.fileTypeIcon(fileId, file));
$('<input type="hidden" name="file[]">')
.attr('value', fileId)
.appendTo($li)
.appendTo($li);
if ($list.data("adddescription")) {
$("<label>")
.addClass("control-label col-sm-4")
.text(tr("Description"))
.appendTo($li);
$("<div>").addClass("col-sm-12")
.append($('<textarea name="description[]">')
.addClass("form-control col-sm-8")
)
.appendTo($li);
}
};
};
......
......@@ -29,7 +29,7 @@
</p>
</form>
<form class="file-uploader-result" method="post" action="{service controller=file action=uploader galleryId=$galleryId}">
<ul class="list-unstyled">
<ul class="list-unstyled" data-adddescription="{$addDecriptionOnUpload}">
</ul>
<div class="submit">
......
......@@ -30,10 +30,14 @@
{wikiplugin _name='vimeo' fromFieldId=$field.fieldId|escape fromItemId=$item.itemId|escape galleryId=$field.galleryId|escape}{/wikiplugin}
{else}
{if $field.options_map.uploadInModal neq 'n'}
<a href="{service controller=file action=uploader uploadInModal=1 galleryId=$field.galleryId limit=$field.limit|default:100 type=$field.filter image_max_size_x=$field.image_x image_max_size_y=$field.image_y}" class="btn btn-default upload-files">{if $field.limit !== 1}{tr}Upload Files{/tr}{else}{tr}Upload File{/tr}{/if}</a>
<a href="{service controller=file action=uploader uploadInModal=1 galleryId=$field.galleryId limit=$field.limit|default:100 type=$field.filter image_max_size_x=$field.image_x image_max_size_y=$field.image_y addDecriptionOnUpload=$data.addDecriptionOnUpload}" class="btn btn-default upload-files">
{if $field.limit !== 1}{tr}Upload Files{/tr}{else}{tr}Upload File{/tr}{/if}
</a>
{else}
<div class="upload-files-inline-form"></div>
<a href="{service controller=file action=uploader uploadInModal=0 galleryId=$field.galleryId limit=$field.limit|default:100 type=$field.filter image_max_size_x=$field.image_x image_max_size_y=$field.image_y}" class="btn btn-default upload-files-inline">{if $field.limit !== 1}{tr}Upload Files{/tr}{else}{tr}Upload File{/tr}{/if}</a>
<a href="{service controller=file action=uploader uploadInModal=0 galleryId=$field.galleryId limit=$field.limit|default:100 type=$field.filter image_max_size_x=$field.image_x image_max_size_y=$field.image_y addDecriptionOnUpload=$data.addDecriptionOnUpload}" class="btn btn-default upload-files-inline">
{if $field.limit !== 1}{tr}Upload Files{/tr}{else}{tr}Upload File{/tr}{/if}
</a>
{/if}
{/if}
{if $context.canBrowse}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment