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

Modifications to make blog attachments work without js

parent 62ced02d
......@@ -68,7 +68,13 @@ else {
}
$folder = ArtefactTypeBlogpost::blogfiles_folder_id();
$folder = param_integer('folder', ArtefactTypeBlogpost::blogfiles_folder_id());
$browse = (int) param_variable('browse', 0);
$highlight = null;
if ($file = param_integer('file', 0)) {
$highlight = array($file);
}
$form = pieform(array(
'name' => 'editpost',
......@@ -121,7 +127,8 @@ $form = pieform(array(
'group' => null,
'institution' => null,
'folder' => $folder,
'highlight' => null,
'highlight' => $highlight,
'browse' => $browse,
'config' => array(
'upload' => true,
'uploadagreement' => get_config_plugin('artefact', 'file', 'uploadagreement'),
......@@ -334,7 +341,7 @@ function editpost_cancel_submit() {
}
function editpost_submit(Pieform $form, $values) {
global $SESSION, $USER, $blogpost, $blog;
global $USER, $blogpost, $blog;
// save the post if the user clicked submit or has no js
$submitted = !empty($values['submitpost']);
......@@ -368,20 +375,31 @@ function editpost_submit(Pieform $form, $values) {
$filebrowser['selectedlist'] = $postobj->get_attachments(true);
}
db_commit();
$result['error'] = false;
$result['message'] = get_string('blogpostsaved', 'artefact.blog');
$result['goto'] = get_config('wwwroot') . 'artefact/blog/view/index.php?id=' . $blog;
}
// Filebrowser actions should only come through to here if it's not a js submission.
if (!empty($values['filebrowser']['action']) && !$form->submitted_by_js()) {
if (isset($values['filebrowser']['folder'])) {
$params['folder'] = $values['filebrowser']['folder'];
if ($submitted) {
$result = array(
'error' => false,
'message' => get_string('blogpostsaved', 'artefact.blog'),
'goto' => get_config('wwwroot') . 'artefact/blog/view/index.php?id=' . $blog,
);
$form->reply(PIEFORM_OK, $result);
}
$result = pieform_element_filebrowser_submit($form, $values['filebrowser']);
$result['goto'] = get_config('wwwroot') . 'artefact/blog/post.php?id=' . $blogpost;
}
// Non-js filebrowser submission
$result = array(
'error' => false,
'goto' => get_config('wwwroot') . 'artefact/blog/post.php?id=' . $blogpost,
);
if (isset($values['filebrowser']['browse'])) {
$result['goto'] .= '&browse=1';
}
if (isset($values['filebrowser']['folder'])) {
$result['goto'] .= '&folder=' . $values['filebrowser']['folder'];
}
if (isset($values['filebrowser']['highlight'])) {
$result['goto'] .= '&file=' . $values['filebrowser']['highlight'];
}
$form->reply(empty($result['error']) ? PIEFORM_OK : PIEFORM_ERR, $result);
}
......
......@@ -41,7 +41,6 @@ function pieform_element_filebrowser(Pieform $form, $element) {
$institution = $form->get_property('institution');
$userid = ($group || $institution) ? null : $USER->get('id');
$queryparams = '';
if ($group) {
$groupinfo = array(
'roles' => group_get_role_info($group),
......@@ -60,9 +59,9 @@ function pieform_element_filebrowser(Pieform $form, $element) {
$smarty->assign('folder', $folder);
$smarty->assign('foldername', $path[0]->title);
$smarty->assign('path', array_reverse($path));
$smarty->assign('queryparams', $queryparams);
$smarty->assign('highlight', $element['highlight'][0]);
$smarty->assign('edit', !empty($element['edit']) ? $element['edit'] : -1);
$smarty->assign('browse', (int) $element['browse']);
$config = array_map('intval', $element['config']);
$smarty->assign('config', $config);
if ($config['select']) {
......@@ -126,7 +125,6 @@ function pieform_element_filebrowser_build_path($form, $element, $folder) {
$foldername = $path[0]->title;
$smarty = smarty_core();
$smarty->assign('queryparams', '');
$smarty->assign('path', array_reverse($path));
return array('html' => $smarty->fetch('artefact:file:form/folderpath.tpl'), 'foldername' => $foldername);
}
......@@ -142,14 +140,12 @@ function pieform_element_filebrowser_build_filelist($form, $element, $folder, $h
$group = $form->get_property('group');
$institution = $form->get_property('institution');
$userid = ($group || $institution) ? null : $USER->get('id');
$queryparams = '';
$smarty = smarty_core();
$smarty->assign('edit', -1);
$smarty->assign('highlight', $highlight);
$smarty->assign('editable', (int) $element['config']['edit']);
$smarty->assign('selectable', (int) $element['config']['select']);
$smarty->assign('queryparams', $queryparams);
$filedata = ArtefactTypeFileBase::get_my_files_data($folder, $userid, $group, $institution);
$smarty->assign('filelist', $filedata);
......@@ -191,6 +187,7 @@ function pieform_element_filebrowser_get_value(Pieform $form, $element) {
// try
$element['selectcallback']((int) $keys[0]);
$result['message'] = get_string('fileadded', 'artefact.file');
$result['browse'] = 1;
}
else if (!empty($_POST['unselect']) && is_array($_POST['unselect']) && is_callable($element['unselectcallback'])) {
$keys = array_keys($_POST['unselect']);
......@@ -203,6 +200,9 @@ function pieform_element_filebrowser_get_value(Pieform $form, $element) {
$keys = array_keys($_POST['edit']);
$result['edit'] = (int) $keys[0];
}
else if (!empty($_POST['browse'])) {
$result['browse'] = 1;
}
else if (!empty($_POST['selected']) && is_array($_POST['selected'])) {
// When files are being selected, this element has a real value
$result['selected'] = array_keys($_POST['selected']);
......@@ -269,12 +269,14 @@ function pieform_element_filebrowser_doupdate(Pieform $form, $element, $folder)
return array(
'error' => true,
'message' => get_string('filenamefieldisrequired', 'artefact.file'),
'browse' => 1,
);
}
else if ($element['config']['uploadagreement'] && empty($_POST['notice'])) {
return array(
'error' => true,
'message' => get_string('youmustagreetothecopyrightnotice', 'artefact.file'),
'browse' => 1,
);
}
$result = pieform_element_filebrowser_upload($form, $element, array(
......@@ -283,11 +285,17 @@ function pieform_element_filebrowser_doupdate(Pieform $form, $element, $folder)
'uploadfolder' => $folder ? $folder : null,
'uploadfoldername' => $_POST['foldername'],
));
// If it's a non-js upload, automatically select the newly uploaded file.
$result['browse'] = 1;
if (!$form->submitted_by_js() && !$result['error'] && is_callable($element['selectcallback'])) {
$element['selectcallback']($result['highlight']);
}
}
else if (!empty($_POST['changefolder']) && is_array($_POST['changefolder'])) {
$keys = array_keys($_POST['changefolder']);
$newfolder = (int) $keys[0];
$result = pieform_element_filebrowser_changefolder($form, $element, $newfolder);
$result['browse'] = 1;
$folder = $newfolder;
}
......
......@@ -300,13 +300,17 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
};
this.select_init = function () {
connect(self.form.open_upload_browse, 'onclick', function () {
connect(self.id + '_open_upload_browse', 'onclick', function (e) {
e.stop();
removeElementClass(self.id + '_upload_browse', 'hidden');
addElementClass(this, 'hidden');
return false;
});
connect(self.form.close_upload_browse, 'onclick', function () {
connect(self.id + '_close_upload_browse', 'onclick', function (e) {
e.stop();
addElementClass(self.id + '_upload_browse', 'hidden');
removeElementClass(self.form.open_upload_browse, 'hidden');
removeElementClass(self.id + '_open_upload_browse', 'hidden');
return false;
});
forEach(getElementsByTagAndClassName('button', 'unselect', self.id + '_selectlist'), function (elem) {
connect(elem, 'onclick', self.unselect);
......
......@@ -704,11 +704,16 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
}
}
// Pieforms doesn't seem to like a static class method here
// We only get this far for non-js submissions:
/**
* Submit function for My/Group/Institution/Site files
*
* This function will only be called when javascript is disabled.
*
* Outside the File class because Pieforms doesn't appear to like
* being given static class method as a submit callback.
*/
function files_submit(Pieform $form, $values) {
global $SESSION;
log_debug($values);
// @todo: move group/inst stuff to form defn.
$group = $form->get_property('group');
$institution = $form->get_property('institution');
if ($group) {
......@@ -728,7 +733,7 @@ function files_submit(Pieform $form, $values) {
$params = array();
}
// Updates on the filebrowser for non-js users that need to cause a
// Some updates on the filebrowser element need to set params and
// redirect back to this page.
if (isset($values['filebrowser']['folder'])) {
$params['folder'] = $values['filebrowser']['folder'];
......@@ -750,7 +755,6 @@ function files_submit(Pieform $form, $values) {
$result = $values['filebrowser'];
$result['goto'] = $redirect;
$form->reply(empty($result['error']) ? PIEFORM_OK : PIEFORM_ERR, $result);
}
class ArtefactTypeFile extends ArtefactTypeFileBase {
......
{if $config.select}
{include file="artefact:file:form/selectedlist.tpl" selectedlist=$selectedlist prefix=$prefix}
{include file="artefact:file:form/selectedlist.tpl" selectedlist=$selectedlist prefix=$prefix highlight=$highlight}
{/if}
<script type="text/javascript">
......@@ -9,14 +9,14 @@
<input type="hidden" name="folder" id="{$prefix}_folder" value="{$folder}" />
<input type="hidden" name="foldername" id="{$prefix}_foldername" value="{$foldername}" />
{if $config.select}
<input type="button" class="buttondk" name="open_upload_browse" value="{if $config.selectone}{str tag=selectafile section=artefact.file}{else}{str tag=addafile section=artefact.file}{/if}" />
{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}" />
{/if}
<div id="{$prefix}_upload_browse" class="upload_browse{if $config.select} select hidden{/if}">
<div id="{$prefix}_upload_browse" class="upload_browse{if $config.select} select{if !$browse} hidden{/if}{/if}">
{if $config.select}
<input type="button" class="buttondk" name="close_upload_browse" value="{str tag=cancel}" />
<input type="submit" class="buttondk" name="cancelbrowse" id="{$prefix}_close_upload_browse" value="{str tag=Close}" />
{/if}
<table class="fileupload">
......@@ -77,11 +77,11 @@
{/if}
<div id="{$prefix}_foldernav" class="foldernav">
{include file="artefact:file:form/folderpath.tpl" path=$path queryparams=$queryparams}
{include file="artefact:file:form/folderpath.tpl" path=$path}
</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 queryparams=$queryparams}
{include file="artefact:file:form/filelist.tpl" filelist=$filelist editable=$config.edit selectable=$config.select highlight=$highlight edit=$edit}
</div>
{* Edit form used when js is available *}
......
{foreach from=$path item=f name=path}
{if !$smarty.foreach.path.first}/ {/if}<a href="?folder={$f->id}{$queryparams}" class="changefolder">{$f->title}</a>
{if !$smarty.foreach.path.first}/ {/if}
<button type="submit" class="changefolder link" name="changefolder[{$f->id}]" title="{str tag=gotofolder section=artefact.file arg1=$f->title}" value="{$f->id}">{$f->title|str_shorten:34}</button>
<!--a href="?folder={$f->id}{$queryparams}" class="changefolder">{$f->title}</a-->
{/foreach}
......@@ -11,7 +11,7 @@
</thead>
<tbody>
{foreach from=$selectedlist item=file}
<tr class="r{cycle values=0,1}">
<tr class="r{cycle values=0,1}{if !empty($highlight) && $highlight == $file->id} highlight-file{/if}">
<td>
<img src="{if $file->artefacttype == 'image'}{$WWWROOT}artefact/file/download.php?file={$file->id}&size=20x20{else}{$THEMEURL}images/{$file->artefacttype}.gif{/if}">
</td>
......
......@@ -843,6 +843,9 @@ abstract class ArtefactType {
}
public function attach($attachmentid) {
if (record_exists('artefact_attachment', 'artefact', $this->get('id'), 'attachment', $attachmentid)) {
return;
}
$data = new StdClass;
$data->artefact = $this->get('id');
$data->attachment = $attachmentid;
......
......@@ -47,6 +47,7 @@ $string['showtags'] = 'Show my tags';
$string['errorprocessingform'] = 'There was an error with submitting this form. Please check the marked fields and try again.';
$string['description'] = 'Description';
$string['remove'] = 'Remove';
$string['Close'] = 'Close';
$string['no'] = 'No';
$string['yes'] = 'Yes';
......
......@@ -280,7 +280,6 @@ $string['nocopyableviewsfound'] = 'No Views that you can copy';
$string['noownersfound'] = 'No owners found';
$string['viewsby'] = 'Views by %s';
$string['Preview'] = 'Preview';
$string['close'] = 'Close';
$string['viewscopiedfornewusersmustbecopyable'] = 'You must allow copying before you can set a view to be copied for new users.';
$string['viewscopiedfornewgroupsmustbecopyable'] = 'You must allow copying before you can set a view to be copied for new groups.';
$string['copynewusergroupneedsloggedinaccess'] = 'Views copied for new users or groups must give access to logged-in users.';
......
......@@ -1791,6 +1791,7 @@ tr.uploadform th {
font-size: 18px;
background: url(../images/foldernav.gif) no-repeat left 2px;
}
.foldernav button.link,
.directory-item.folder td.filename button.link,
.directory-item.folder td.filename {
font-weight: bold;
......
......@@ -67,7 +67,7 @@ else {
View::get_templatesearch_data($views);
$strpreview = json_encode(get_string('Preview','view'));
$strclose = json_encode(get_string('close','view'));
$strclose = json_encode(get_string('Close'));
$js = <<<EOF
preview = DIV({'id':'viewpreview', 'class':'hidden'}, DIV({'id':'viewpreviewinner'}, DIV({'id':'viewpreviewclose'}, A({'href':'','id':'closepreview'}, {$strclose})), DIV({'id':'viewpreviewcontent'})));
......
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