Commit cfec3b19 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Prefix filebrowser post params with pieform element id

parent 4d388e99
......@@ -152,6 +152,7 @@ function pieform_element_filebrowser_build_filelist($form, $element, $folder, $h
$filedata = ArtefactTypeFileBase::get_my_files_data($folder, $userid, $group, $institution);
$smarty->assign('filelist', $filedata);
$smarty->assign('querybase', $element['page'] . (strpos($element['page'], '?') === false ? '?' : '&'));
$smarty->assign('prefix', $form->get_name() . '_' . $element['name']);
return array(
'data' => $filedata,
......@@ -181,11 +182,13 @@ function pieform_element_filebrowser_get_value(Pieform $form, $element) {
return $result;
}
$prefix = $form->get_name() . '_' . $element['name'];
// We only care about the following when js is off:
if (!$form->submitted_by_js()) {
$select = param_variable('select', null);
$unselect = param_variable('unselect', null);
$edit = param_variable('edit', null);
$select = param_variable($prefix . '_select', null);
$unselect = param_variable($prefix . '_unselect', null);
$edit = param_variable($prefix . '_edit', null);
if (is_array($select) && is_callable($element['selectcallback'])) {
$keys = array_keys($select);
// try
......@@ -204,13 +207,13 @@ function pieform_element_filebrowser_get_value(Pieform $form, $element) {
$keys = array_keys($edit);
$result['edit'] = (int) $keys[0];
}
else if (param_variable('browse', 0) && !param_variable('cancelbrowse', 0)) {
else if (param_variable('browse', 0) && !param_variable($prefix . '_cancelbrowse', 0)) {
$result['browse'] = 1;
}
}
if (!is_array($result)) {
$selected = param_variable('selected', null);
$selected = param_variable($prefix . '_selected', null);
if (is_array($selected)) {
// When files are being selected, this element has a real value
$result['selected'] = array_keys($selected);
......@@ -226,15 +229,17 @@ function pieform_element_filebrowser_get_value(Pieform $form, $element) {
function pieform_element_filebrowser_doupdate(Pieform $form, $element) {
$result = null;
$delete = param_variable('delete', null);
$prefix = $form->get_name() . '_' . $element['name'];
$delete = param_variable($prefix . '_delete', null);
if (is_array($delete)) {
$keys = array_keys($delete);
return pieform_element_filebrowser_delete($form, $element, (int) ($keys[0]));
}
$update = param_variable('update', null);
$update = param_variable($prefix . '_update', null);
if (is_array($update)) {
$edit_title = param_variable('edit_title');
$edit_title = param_variable($prefix . '_edit_title');
if (!strlen($edit_title)) {
return array(
'error' => true,
......@@ -245,14 +250,14 @@ function pieform_element_filebrowser_doupdate(Pieform $form, $element) {
$data = array(
'artefact' => (int) ($keys[0]),
'title' => $edit_title,
'description' => param_variable('edit_description'),
'tags' => param_variable('edit_tags'),
'description' => param_variable($prefix . '_edit_description'),
'tags' => param_variable($prefix . '_edit_tags'),
'folder' => $element['folder'],
);
if ($form->get_property('group')) {
$data['permissions'] = array('admin' => (object) array('view' => true, 'edit' => true, 'republish' => true));
foreach ($_POST as $k => $v) {
if (preg_match('/^permission:([a-z]+):([a-z]+)$/', $k, $m)) {
if (preg_match('/^' . $prefix . '_permission:([a-z]+):([a-z]+)$/', $k, $m)) {
$data['permissions'][$m[1]]->{$m[2]} = (bool) $v;
}
}
......@@ -260,18 +265,18 @@ function pieform_element_filebrowser_doupdate(Pieform $form, $element) {
return pieform_element_filebrowser_update($form, $element, $data);
}
$move = param_variable('move', null);
$move = param_variable($prefix . '_move', null);
if (!empty($move)) {
return pieform_element_filebrowser_move($form, $element, array(
'artefact' => (int) $move,
'newparent' => param_integer('moveto'),
'newparent' => param_integer($prefix . '_moveto'),
'folder' => $element['folder'],
));
}
$createfolder = param_variable('createfolder', null);
$createfolder = param_variable($prefix . '_createfolder', null);
if (!empty($createfolder)) {
$createfolder_name = param_variable('createfolder_name');
$createfolder_name = param_variable($prefix . '_createfolder_name');
if (!strlen($createfolder_name)) {
return array(
'error' => true,
......@@ -284,7 +289,7 @@ function pieform_element_filebrowser_doupdate(Pieform $form, $element) {
));
}
$upload = param_variable('upload', null);
$upload = param_variable($prefix . '_upload', null);
if (!empty($upload)) {
if (!isset($_FILES['userfile']['name'])) {
return array(
......@@ -293,7 +298,7 @@ function pieform_element_filebrowser_doupdate(Pieform $form, $element) {
'browse' => 1,
);
}
else if ($element['config']['uploadagreement'] && param_boolean($notice, false)) {
else if ($element['config']['uploadagreement'] && param_boolean($prefix . '_notice', false)) {
return array(
'error' => true,
'message' => get_string('youmustagreetothecopyrightnotice', 'artefact.file'),
......@@ -302,9 +307,9 @@ function pieform_element_filebrowser_doupdate(Pieform $form, $element) {
}
$result = pieform_element_filebrowser_upload($form, $element, array(
'userfile' => $_FILES['userfile'],
'uploadnumber' => param_integer('uploadnumber'),
'uploadnumber' => param_integer($prefix . '_uploadnumber'),
'uploadfolder' => $element['folder'] ? $element['folder'] : null,
'uploadfoldername' => param_variable('foldername'),
'uploadfoldername' => param_variable($prefix . '_foldername'),
));
// If it's a non-js upload, automatically select the newly uploaded file.
$result['browse'] = 1;
......@@ -314,7 +319,7 @@ function pieform_element_filebrowser_doupdate(Pieform $form, $element) {
return $result;
}
$newfolder = param_variable('changefolder', null);
$newfolder = param_variable($prefix . '_changefolder', null);
if (!is_null($newfolder) && is_numeric($newfolder)) {
$result = pieform_element_filebrowser_changefolder($form, $element, $newfolder);
$result['browse'] = 1;
......
......@@ -13,7 +13,7 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
if (!self.form) {
alert('eek');
}
self.foldername = self.form.foldername.value;
self.foldername = $(self.id + '_foldername').value;
if (self.config.select) {
self.select_init();
}
......@@ -31,8 +31,13 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
setNodeAttribute(self.id + '_userfile', 'disabled', true);
addElementClass(self.id + '_uploadcancel', 'hidden');
}
if (!self.form.upload) {
appendChildNodes(self.form, INPUT({'type':'hidden','name':'upload','value':0}));
if (!$(self.id + '_upload')) {
appendChildNodes(self.form, INPUT({
'type': 'hidden',
'name': self.id + '_upload',
'id' : self.id + '_upload',
'value':0
}));
}
self.upload_connectbuttons();
}
......@@ -88,17 +93,24 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
}
self.upload_presubmit();
self.form.upload.value = 1;
$(self.id + '_upload').value = 1;
signal(self.form, 'onsubmit');
self.form.submit();
// $(self.id + '_userfile').value = ''; // Won't work in IE
replaceChildNodes(self.id + '_userfile_container', INPUT({'type':'file', 'class':'file', 'id':self.id+'_userfile', 'name':'userfile', 'size':40}));
replaceChildNodes(self.id + '_userfile_container', INPUT({
'type':'file',
'class':'file',
'id':self.id+'_userfile',
'name':'userfile',
'size':40
}));
connect(self.id + '_userfile', 'onchange', self.upload_submit);
self.form.upload.value = 0;
$(self.id + '_upload').value = 0;
return false;
}
this.fileexists = function (filename, id) {
logDebug(id);
for (var i in self.filedata) {
if (self.filedata[i].title == filename && (!id || i != id)) {
return true;
......@@ -140,7 +152,7 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
if (name == '') {
message = get_string('namefieldisrequired');
}
else if (self.fileexists(name, this.name.replace(/^update\[(\d+)\]$/, '$1'))) {
else if (self.fileexists(name, this.name.replace(/.*_update\[(\d+)\]$/, '$1'))) {
message = get_string('filewithnameexists', name);
}
}
......@@ -170,7 +182,7 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
this.edit_form = function (e) {
e.stop();
// In IE, this.value is set to the button text
var id = getNodeAttribute(this, 'name').replace(/^edit\[(\d+)\]$/, '$1');
var id = getNodeAttribute(this, 'name').replace(/.*_edit\[(\d+)\]$/, '$1');
addElementClass(self.id + '_edit_row', 'hidden');
$(self.id + '_edit_heading').innerHTML = self.filedata[id].artefacttype == 'folder' ? get_string('editfolder') : get_string('editfile');
$(self.id + '_edit_title').value = self.filedata[id].title;
......@@ -184,7 +196,7 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
}
});
// $(self.id + '_edit_artefact').value = id; // Changes button text in IE
setNodeAttribute(self.id + '_edit_artefact', 'name', 'update[' + id + ']');
setNodeAttribute(self.id + '_edit_artefact', 'name', self.id + '_update[' + id + ']');
var edit_row = removeElement(self.id + '_edit_row');
var this_row = getFirstParentByTagAndClassName(this, 'tr');
insertSiblingNodesAfter(this_row, edit_row);
......@@ -205,7 +217,7 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
this.browse_init = function () {
if (self.config.edit) {
forEach(getElementsByTagAndClassName('button', null, 'filelist'), function (elem) {
var name = getNodeAttribute(elem, 'name').match(/^([a-z]+)\[(\d+)\]$/);
var name = getNodeAttribute(elem, 'name').match(new RegExp('^' + self.id + "_([a-z]+)\\[(\\d+)\\]$"));
if (name[1] == 'edit') {
connect(elem, 'onclick', self.edit_form);
}
......@@ -258,12 +270,12 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
accept: ['icon-drag-current'],
hoverclass: 'folderhover',
ondrop: function (dragged, dropped) {
self.form.move.value = dragged.id.replace(/^.*drag:(\d+)$/, '$1');
self.form.moveto.value = dropped.id.replace(/^file:(\d+)$/, '$1');
$(self.id + '_move').value = dragged.id.replace(/^.*drag:(\d+)$/, '$1');
$(self.id + '_moveto').value = dropped.id.replace(/^file:(\d+)$/, '$1');
signal(self.form, 'onsubmit');
self.form.submit();
self.form.move.value = '';
self.form.moveto.value = '';
$(self.id + '_move').value = '';
$(self.id + '_moveto').value = '';
}
});
};
......@@ -343,7 +355,7 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
forEach(getElementsByTagAndClassName('button', 'select', 'filelist'), function (elem) {
connect(elem, 'onclick', function (e) {
e.stop();
var id = this.name.replace(/^select\[(\d+)\]$/, '$1');
var id = this.name.replace(/.*_select\[(\d+)\]$/, '$1');
if (!self.selecteddata[id]) {
self.add_to_selected_list(id);
}
......@@ -363,7 +375,7 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
forEach(rows, function (r) { removeElementClass(r, 'highlight-file'); });
}
// var remove = BUTTON({'type':'submit', 'class':'button small unselect', 'name':'unselect[' + id + ']', 'value':id}, get_string('remove')); // IE problem ?
var remove = INPUT({'type': 'submit', 'class':'button small unselect', 'name':'unselect[' + id + ']', 'value':get_string('remove')});
var remove = INPUT({'type': 'submit', 'class':'button small unselect', 'name':self.id+'_unselect[' + id + ']', 'value':get_string('remove')});
connect(remove, 'onclick', self.unselect);
if (self.filedata[id].artefacttype == 'image') {
var imgsrc = self.config.wwwroot + 'artefact/file/download.php?file=' + id + '&size=20x20';
......@@ -376,7 +388,7 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
TD(null, self.filedata[id].title),
TD(null, self.filedata[id].description),
TD(null, self.filedata[id].tags.join(', ')),
TD(null, remove, INPUT({'type':'hidden', 'name':'selected[' + id + ']', 'value':id}))
TD(null, remove, INPUT({'type':'hidden', 'name':self.id+'_selected[' + id + ']', 'value':id}))
));
self.selecteddata[id] = {
'id': id,
......@@ -391,7 +403,7 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
this.unselect = function (e) {
e.stop();
var id = this.name.replace(/^unselect\[(\d+)\]$/, '$1');
var id = this.name.replace(/.*_unselect\[(\d+)\]$/, '$1');
delete self.selecteddata[id];
removeElement(getFirstParentByTagAndClassName(this, 'tr'));
var rows = getElementsByTagAndClassName('tr', null, getFirstElementByTagAndClassName('tbody', null, self.id + '_selectlist'));
......
......@@ -9,11 +9,11 @@
</tr>
<tr>
<th><label>{str tag=name}</label></th>
<td><input type="text" class="text" name="edit_title" id="{$prefix}_edit_title" value="{$fileinfo->title}" size="40" /></td>
<td><input type="text" class="text" name="{$prefix}_edit_title" id="{$prefix}_edit_title" value="{$fileinfo->title}" size="40" /></td>
</tr>
<tr>
<th><label>{str tag=description}</label></th>
<td><input type="text" class="text" name="edit_description" id="{$prefix}_edit_description" value="{$fileinfo->description}" size="40" /></td>
<td><input type="text" class="text" name="{$prefix}_edit_description" id="{$prefix}_edit_description" value="{$fileinfo->description}" size="40" /></td>
</tr>
<tr>
<th><label>{str tag=tags}</label></th>
......@@ -22,7 +22,7 @@
<table class="help-wrapper">
<tbody>
<tr>
<td><input name="edit_tags" size="40" id="{$prefix}_edit_tags" value="{foreach from=$fileinfo->tags item=tag name=tags}{if !$smarty.foreach.tags.first}, {/if}{$tag}{/foreach}" /></td>
<td><input name="{$prefix}_edit_tags" size="40" id="{$prefix}_edit_tags" value="{foreach from=$fileinfo->tags item=tag name=tags}{if !$smarty.foreach.tags.first}, {/if}{$tag}{/foreach}" /></td>
<td class="helpcontainer"><span>{contextualhelp plugintype='artefact' pluginname='file' section='tags'}</span></td>
</tr>
</tbody>
......@@ -47,11 +47,11 @@
<td>{$role->display}</td>
{if $fileinfo}
{foreach from=$fileinfo->permissions.$r item=permvalue key=permname}
<td><input type="checkbox" class="permission" name="permission:{$r}:{$permname}"{if $permvalue} checked{/if}{if $r == 'admin'} disabled{/if} /></td>
<td><input type="checkbox" class="permission" name="{$prefix}_permission:{$r}:{$permname}"{if $permvalue} checked{/if}{if $r == 'admin'} disabled{/if} /></td>
{/foreach}
{else}
{foreach from=$groupinfo.perms.$r item=permvalue key=permname}
<td><input type="checkbox" class="permission" name="permission:{$r}:{$permname}" {if $r == 'admin'} checked disabled{/if}/></td>
<td><input type="checkbox" class="permission" name="{$prefix}_permission:{$r}:{$permname}" {if $r == 'admin'} checked disabled{/if}/></td>
{/foreach}
{/if}
</tr>
......@@ -63,9 +63,9 @@
{/if}
<tr>
<td colspan=2>
<button type="submit" name="update[{$fileinfo->id}]" id="{$prefix}_edit_artefact" value="{$fileinfo->id}">{str tag=savechanges section=artefact.file}</button>
<button type="submit" name="{$prefix}_update[{$fileinfo->id}]" id="{$prefix}_edit_artefact" value="{$fileinfo->id}">{str tag=savechanges section=artefact.file}</button>
<input type="button" class="button hidden" name="replace" value="{str tag=overwrite}" />
<input type="submit" class="button" name="canceledit" id="{$prefix}_edit_cancel" value="{str tag=cancel}" />
<input type="submit" class="button" name="{$prefix}_canceledit" id="{$prefix}_edit_cancel" value="{str tag=cancel}" />
</td>
</tr>
<tr><td colspan=2 id="{$prefix}_edit_messages"></td></tr>
......
......@@ -7,8 +7,8 @@
</script>
<input type="hidden" name="folder" id="{$prefix}_folder" value="{$folder}" />
<input type="hidden" name="changefolder" id="{$prefix}_changefolder" value="" />
<input type="hidden" name="foldername" id="{$prefix}_foldername" value="{$foldername}" />
<input type="hidden" name="{$prefix}_changefolder" id="{$prefix}_changefolder" value="" />
<input type="hidden" name="{$prefix}_foldername" id="{$prefix}_foldername" value="{$foldername}" />
{if $config.select && !$browse}
<input type="submit" class="buttondk" id="{$prefix}_open_upload_browse" name="browse" value="{if $config.selectone}{str tag=selectafile section=artefact.file}{else}{str tag=addafile section=artefact.file}{/if}" />
......@@ -17,19 +17,19 @@
<div id="{$prefix}_upload_browse" class="upload_browse{if $config.select} select{if !$browse} hidden{/if}{/if}">
{if $config.select}
<input type="submit" class="buttondk" name="cancelbrowse" id="{$prefix}_close_upload_browse" value="{str tag=Close}" />
<input type="submit" class="buttondk" name="{$prefix}_cancelbrowse" id="{$prefix}_close_upload_browse" value="{str tag=Close}" />
{/if}
<table class="fileupload">
<tbody>
{if $config.upload}
<tr><td><input type="hidden" name="uploadnumber" id="{$prefix}_uploadnumber" value="1" /></td></tr>
<tr><td><input type="hidden" name="{$prefix}_uploadnumber" id="{$prefix}_uploadnumber" value="1" /></td></tr>
<tr><td colspan=2 id="{$prefix}_upload_messages"></td></tr>
{if $config.uploadagreement}
<tr id="{$prefix}_agreement" class="uploadform">
<th><label>{str tag='uploadfile' section='artefact.file'}</label></th>
<td colspan=2>
<input type="checkbox" name="notice" id="{$prefix}_notice" />
<input type="checkbox" name="{$prefix}_notice" id="{$prefix}_notice" />
{$agreementtext}
</td>
</tr>
......@@ -37,21 +37,16 @@
<th><label>{str tag='File' section='artefact.file'}</label></th>
<td>
<div id="{$prefix}_userfile_container"><input type="file" class="file" id="{$prefix}_userfile" name="userfile" size="40" /></div>
<noscript><input type="submit" class="submit" name="upload" id="{$prefix}_upload" value="{str tag=upload section=artefact.file}" /></noscript>
<noscript><input type="submit" class="submit" name="{$prefix}_upload" id="{$prefix}_upload" value="{str tag=upload section=artefact.file}" /></noscript>
<script>setNodeAttribute('{$prefix}_userfile', 'disabled', true);</script>
</td>
</tr>
<tr class="uploadform">
<td colspan=2>
<input type="button" class="button hidden" name="uploadcancel" id="{$prefix}_uploadcancel" value="{str tag=cancel}" />
</td>
</tr>
{else}
<tr>
<th><label>{str tag='uploadfile' section='artefact.file'}</label></th>
<td>
<div id="{$prefix}_userfile_container"><input type="file" class="file" id="{$prefix}_userfile" name="userfile" size="40" /></div>
<noscript><input type="submit" class="submit" name="upload" id="{$prefix}_upload" value="{str tag=upload section=artefact.file}" /></noscript>
<noscript><input type="submit" class="submit" name="{$prefix}_upload" id="{$prefix}_upload" value="{str tag=upload section=artefact.file}" /></noscript>
</td>
</tr>
{/if}
......@@ -61,8 +56,8 @@
<tr>
<th><label>{str tag='createfolder' section='artefact.file'}</label></th>
<td>
<input type="text" class="text" name="createfolder_name" id="{$prefix}_createfolder_name" size="40" />
<input type="submit" class="submit" name="createfolder" id="{$prefix}_createfolder" value="{str tag=createfolder section=artefact.file}" />
<input type="text" class="text" name="{$prefix}_createfolder_name" id="{$prefix}_createfolder_name" size="40" />
<input type="submit" class="submit" name="{$prefix}_createfolder" id="{$prefix}_createfolder" value="{str tag=createfolder section=artefact.file}" />
</td>
</tr>
<tr>
......@@ -73,8 +68,8 @@
</table>
{if $config.edit}
<input type="hidden" name="move" value="" />
<input type="hidden" name="moveto" value="" />
<input type="hidden" name="{$prefix}_move" id="{$prefix}_move" value="" />
<input type="hidden" name="{$prefix}_moveto" id="{$prefix}_moveto" value="" />
{/if}
<div id="{$prefix}_foldernav" class="foldernav">
......@@ -82,14 +77,14 @@
</div>
<div id="{$prefix}_filelist_container">
{include file="artefact:file:form/filelist.tpl" filelist=$filelist editable=$config.edit selectable=$config.select highlight=$highlight edit=$edit querybase=$querybase}
{include file="artefact:file:form/filelist.tpl" prefix=$prefix filelist=$filelist editable=$config.edit selectable=$config.select highlight=$highlight edit=$edit querybase=$querybase}
</div>
{* Edit form used when js is available *}
{if $edit <= 0}
<table class="hidden">
<tbody id="{$prefix}_edit_placeholder">
{include file="artefact:file:form/editfile.tpl"}
{include file="artefact:file:form/editfile.tpl" prefix=$prefix}
</tbody>
</table>
{/if}
......
......@@ -36,16 +36,16 @@
<td>{$file->mtime}</td>
<td>
{if $editable && !$file->isparent}
{if !isset($file->can_edit) || $file->can_edit !== 0}<button type="submit" name="edit[{$file->id}]" value="{$file->id}">{str tag=edit}</button>{/if}
{if $file->childcount == 0}<button type="submit" name="delete[{$file->id}]" value="{$file->id}">{str tag=delete}</button>{/if}
{if !isset($file->can_edit) || $file->can_edit !== 0}<button type="submit" name="{$prefix}_edit[{$file->id}]" value="{$file->id}">{str tag=edit}</button>{/if}
{if $file->childcount == 0}<button type="submit" name="{$prefix}_delete[{$file->id}]" value="{$file->id}">{str tag=delete}</button>{/if}
{/if}
{if $selectable && $file->artefacttype != 'folder'}
<button type="submit" class="select small" name="select[{$file->id}]" value="{$file->id}">{str tag=select}</button>
<button type="submit" class="select small" name="{$prefix}_select[{$file->id}]" value="{$file->id}">{str tag=select}</button>
{/if}
</td>
</tr>
{if $edit == $file->id}
{include file="artefact:file:form/editfile.tpl" fileinfo=$file}
{include file="artefact:file:form/editfile.tpl" prefix=$prefix fileinfo=$file}
{/if}
{/foreach}
</tbody>
......
......@@ -19,8 +19,8 @@
<td>{$file->description}</td>
<td>{$file->tags}</td>
<td>
<button type="submit" class="button small unselect" name="unselect[{$file->id}]" value="{$file->id}">{str tag=remove}</button>
<input type="hidden" name="selected[{$file->id}]" value="{$file->id}">
<button type="submit" class="button small unselect" name="{$prefix}_unselect[{$file->id}]" value="{$file->id}">{str tag=remove}</button>
<input type="hidden" name="{$prefix}_selected[{$file->id}]" value="{$file->id}">
</td>
</tr>
{/foreach}
......
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