Commit 483912a8 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Allow editing of file artefact metadata during block configuration


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 9447f507
......@@ -113,6 +113,9 @@ function pieform_element_filebrowser(Pieform $form, $element) {
$config['browsehelp'] = $element['browsehelp'];
}
$config['showtags'] = !empty($config['tag']) ? (int) $userid : 0;
$config['editmeta'] = (int) ($userid && !$config['edit'] && !empty($config['tag']));
$smarty->assign('config', $config);
$filters = isset($element['filters']) ? $element['filters'] : null;
......@@ -218,6 +221,8 @@ function pieform_element_filebrowser_build_filelist($form, $element, $folder, $h
$selectable = (int) $element['config']['select'];
$selectfolders = (int) !empty($element['config']['selectfolders']);
$publishing = (int) !empty($element['config']['publishing']);
$showtags = !empty($element['config']['tag']) ? (int) $userid : 0;
$editmeta = (int) ($userid && !$editable && !empty($element['config']['tag']));
$querybase = $element['page'] . (strpos($element['page'], '?') === false ? '?' : '&');
$prefix = $form->get_name() . '_' . $element['name'];
......@@ -230,6 +235,8 @@ function pieform_element_filebrowser_build_filelist($form, $element, $folder, $h
$smarty->assign('selectable', $selectable);
$smarty->assign('selectfolders', $selectfolders);
$smarty->assign('publishing', $publishing);
$smarty->assign('showtags', $showtags);
$smarty->assign('editmeta', $editmeta);
$smarty->assign('filelist', $filedata);
$smarty->assign('querybase', $querybase);
$smarty->assign('prefix', $prefix);
......
......@@ -25,7 +25,7 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
self.upload_init();
}
self.browse_init();
if (self.config.edit) {
if (self.config.edit || self.config.editmeta) {
self.edit_init();
}
}
......@@ -190,13 +190,15 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
if (!hasElementClass(editrow, 'hidden')) {
addElementClass(editrow, 'hidden');
// Reconnect the old edit button to open the form
forEach(getElementsByTagAndClassName('input', null, editrow.previousSibling), function (elem) {
var name = getNodeAttribute(elem, 'name').match(new RegExp('^' + self.id + "_([a-z]+)\\[(\\d+)\\]$"));
if (name && name[1] && name[1] == 'edit') {
disconnectAll(elem);
connect(elem, 'onclick', self.edit_form);
}
});
if (editrow.previousSibling) {
forEach(getElementsByTagAndClassName('input', null, editrow.previousSibling), function (elem) {
var name = getNodeAttribute(elem, 'name').match(new RegExp('^' + self.id + "_([a-z]+)\\[(\\d+)\\]$"));
if (name && name[1] && name[1] == 'edit') {
disconnectAll(elem);
connect(elem, 'onclick', self.edit_form);
}
});
}
}
}
......@@ -239,7 +241,7 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
this.edit_init = function () { augment_tags_control(self.id + '_edit_tags'); }
this.browse_init = function () {
if (self.config.edit) {
if (self.config.edit || self.config.editmeta) {
forEach(getElementsByTagAndClassName('input', null, 'filelist'), function (elem) {
var name = getNodeAttribute(elem, 'name').match(new RegExp('^' + self.id + "_([a-z]+)\\[(\\d+)\\]$"));
if (name && name[1]) {
......@@ -291,14 +293,16 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
});
connect(self.id + '_edit_artefact', 'onclick', self.edit_submit);
// IE doesn't like it when Mochikit has droppables registered without elements attached.
forEach(Draggables.drags, function (drag) { drag.destroy(); });
forEach(Droppables.drops, function (drop) { drop.destroy(); });
forEach(getElementsByTagAndClassName('div', 'icon-drag', 'filelist'), function (elem) {
self.make_icon_draggable(elem);
});
forEach(getElementsByTagAndClassName('tr', 'folder', 'filelist'), self.make_row_droppable);
if (self.config.edit) {
// IE doesn't like it when Mochikit has droppables registered without elements attached.
forEach(Draggables.drags, function (drag) { drag.destroy(); });
forEach(Droppables.drops, function (drop) { drop.destroy(); });
forEach(getElementsByTagAndClassName('div', 'icon-drag', 'filelist'), function (elem) {
self.make_icon_draggable(elem);
});
forEach(getElementsByTagAndClassName('tr', 'folder', 'filelist'), self.make_row_droppable);
}
}
forEach(getElementsByTagAndClassName('a', 'changeowner', self.id + '_upload_browse'), function (elem) {
connect(elem, 'onclick', function (e) {
......@@ -537,7 +541,7 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
// Only update the file listing if the user hasn't changed folders yet
if (data.newlist && (data.folder == self.folderid || data.changedfolder)) {
self.filedata = data.newlist.data;
if (self.config.edit) {
if (self.config.edit || self.config.editmeta) {
replaceChildNodes(self.id + '_edit_placeholder', removeElement(self.id + '_edit_row'));
}
$(self.id+'_filelist_container').innerHTML = data.newlist.html;
......
......@@ -660,6 +660,7 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
'uploadagreement' => get_config_plugin('artefact', 'file', 'uploadagreement'),
'createfolder' => false,
'edit' => false,
'tag' => true,
'select' => true,
'alwaysopen' => true,
'publishing' => true,
......
.filelist .tag-edit.submit {
border: 0;
background: transparent;
color: #6e8e00;
cursor: pointer;
}
......@@ -92,7 +92,7 @@
</div>
<div id="{$prefix}_filelist_container">
{include file="artefact:file:form/filelist.tpl" prefix=$prefix filelist=$filelist editable=$config.edit selectable=$config.select highlight=$highlight edit=$edit querybase=$querybase groupinfo=$groupinfo owner=$tabs.owner ownerid=$tabs.ownerid selectfolders=$config.selectfolders}
{include file="artefact:file:form/filelist.tpl" prefix=$prefix filelist=$filelist editable=$config.edit selectable=$config.select highlight=$highlight edit=$edit querybase=$querybase groupinfo=$groupinfo owner=$tabs.owner ownerid=$tabs.ownerid selectfolders=$config.selectfolders showtags=$config.showtags editmeta=$config.editmeta}
</div>
{* Edit form used when js is available *}
......
......@@ -7,8 +7,16 @@
<th></th>
<th>{str tag=Name section=artefact.file}</th>
<th>{str tag=Description section=artefact.file}</th>
{if !$showtags && !$editmeta}
<th>{str tag=Size section=artefact.file}</th>
<th>{str tag=Date section=artefact.file}</th>
{/if}
{if $showtags}
<th>{str tag=tags}</th>
{/if}
{if $editmeta}
<th></th>
{/if}
<th></th>
</tr>
</thead>
......@@ -36,8 +44,20 @@
{/if}
</td>
<td>{$file->description|escape}</td>
{if !$showtags && !$editmeta}
<td>{tif $file->size ?: ''}</td>
<td>{tif $file->mtime ?: ''}</td>
{/if}
{if $showtags}
<td>{if $file->tags}<span class="tags">{list_tags tags=$file->tags owner=$showtags}</span>{/if}</td>
{/if}
{if $editmeta}
<td>
{if !$file->isparent}
{if !isset($file->can_edit) || $file->can_edit !== 0}<input type="submit" class="tag-edit submit" name="{$prefix}_edit[{$file->id}]" value="{str tag=edit}" />{/if}
{/if}
</td>
{/if}
<td class="right">
{if $editable && !$file->isparent}
{if $file->artefacttype == 'archive'}<a href="{$WWWROOT}artefact/file/extract.php?file={$file->id}">{str tag=Unzip section=artefact.file}</a>{/if}
......
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