Commit 766ef005 authored by Robert Lyon's avatar Robert Lyon
Browse files

Displaying textbox attachments to view/artefact.php page (Bug #1279943)



- and getting the notes page to display the attachment count

-- now cherry-picked on earlier expander fixing patches and having the
new html format

- also fixed bugs:
-- where expander was not closing after editing block on view/blocks.php page
-- where block edit was not keeping attached the attachments that
were attached when adding attacments via notes page.
-- where block edit was dropping attachments from all textbox
instances of the same artefact if one selected to 'use content from
another text box' - now the editor should auto 'select' the attachments
related to the textbox chosen.

Change-Id: I97101c2065a4daff22f82bb472c37d46d60e4c08
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 92d5f084
......@@ -20,7 +20,7 @@
</td>
<td class="filedescription">{$file->description}</td>
<td class="right s">
<input type="submit" class="button submit unselect" name="{$prefix}_unselect[{$file->id}]" value="{str tag=remove}" />
<input type="submit" class="button submit unselect" name="{$prefix}_unselect[{$file->id}]" value="{str tag=remove}" id="{$prefix}_unselect_{$file->id}" />
<input type="hidden" class="hidden" id="{$prefix}_selected[{$file->id}]" name="{$prefix}_selected[{$file->id}]" value="{$file->id}">
</td>
</tr>
......
......@@ -107,7 +107,7 @@ class PluginBlocktypeTextbox extends PluginBlocktype {
'selectjscallback' => 'updateTextContent',
'getblocks' => true,
'ownerinfo' => true,
'returnfields' => array('id', 'title', 'description', 'tags', 'license', 'licensor', 'licensorurl', 'safedescription', 'safetags', 'safelicense', 'editable'),
'returnfields' => array('id', 'title', 'description', 'tags', 'license', 'licensor', 'licensorurl', 'safedescription', 'safetags', 'safelicense', 'editable', 'attachments'),
'artefacttypes' => array('html'),
'template' => 'artefact:internal:html-artefactchooser-element.tpl',
);
......@@ -180,6 +180,19 @@ function updateTextContent(a) {
jQuery(blockcountmsg).addClass('hidden');
}
}
if (typeof a.attachments != 'undefined') {
// remove any attached files
for (var key in instconf_artefactids.selecteddata) {
signal($('instconf_artefactids_unselect_' + key), 'onclick', instconf_artefactids.unselect);
}
// add in ones we need
if (a.attachments.length > 0) {
for (var i = 0; i < a.attachments.length; i++) {
instconf_artefactids.add_to_selected_list(a.attachments[i]);
}
}
}
}
else {
addElementClass('instconf_text_header', 'hidden');
......
......@@ -258,6 +258,18 @@ function editnote_submit(Pieform $form, array $values) {
}
}
}
// need to update the block_instances where this artefact is used - so they have
// the correct configuration artefactids
if ($blocks = get_column('view_artefact', 'block', 'artefact', $artefact->get('id'))) {
require_once(get_config('docroot') . 'blocktype/lib.php');
foreach ($blocks as $block) {
$bi = new BlockInstance($block);
$configdata = $bi->get('configdata');
$configdata['artefactids'] = $new;
$bi->set('configdata', $configdata);
$bi->commit();
}
}
db_commit();
$result = array(
......
......@@ -724,4 +724,38 @@ class ArtefactTypeHtml extends ArtefactType {
'_default' => get_config('wwwroot') . 'artefact/internal/editnote.php?id=' . $id,
);
}
public function render_self($options) {
$smarty = smarty_core();
$smarty->assign('title', $this->get('title'));
$smarty->assign('owner', $this->get('owner'));
$smarty->assign('tags', $this->get('tags'));
$smarty->assign('description', $this->get('description'));
if (!empty($options['details']) and get_config('licensemetadata')) {
$smarty->assign('license', render_license($this));
}
else {
$smarty->assign('license', false);
}
$attachments = $this->get_attachments();
if ($attachments) {
$this->add_to_render_path($options);
require_once(get_config('docroot') . 'artefact/lib.php');
foreach ($attachments as &$attachment) {
$f = artefact_instance_from_id($attachment->id);
$attachment->size = $f->describe_size();
$attachment->iconpath = $f->get_icon(array('id' => $attachment->id, 'viewid' => isset($options['viewid']) ? $options['viewid'] : 0));
$attachment->viewpath = get_config('wwwroot') . 'view/artefact.php?artefact=' . $attachment->id . '&view=' . (isset($options['viewid']) ? $options['viewid'] : 0);
$attachment->downloadpath = get_config('wwwroot') . 'artefact/file/download.php?file=' . $attachment->id;
if (isset($options['viewid'])) {
$attachment->downloadpath .= '&view=' . $options['viewid'];
}
}
$smarty->assign('attachments', $attachments);
}
return array(
'html' => $smarty->fetch('artefact.tpl'),
'javascript'=>''
);
}
}
......@@ -28,7 +28,13 @@
<table class="attachments fullwidth">
<thead class="expandable-head">
<tr>
<th colspan="2"><a class="toggle" href="#">{str tag=attachedfiles section=artefact.blog}</a></th>
<td colspan="2">
<a class="toggle" href="#">{str tag=attachedfiles section=artefact.blog}</a>
<span class="fr">
<img class="fl" src="{theme_url filename='images/attachment.png'}" alt="{str tag=attachments section=artefact.blog}">
{$n->files|count}
</span>
</td>
</tr>
</thead>
<tbody class="expandable-body">
......
......@@ -23,6 +23,10 @@ function setupExpanders(element) {
});
}
function removeExpanders(element) {
element.find(".expandable-head a.expandable").removeClass('expandable');
}
jQuery(document).ready(function() {
setupExpanders($j('body'));
});
......@@ -1232,6 +1232,8 @@
event.preventDefault();
removeConfigureBlocks();
showMediaPlayers();
removeExpanders($('#blockinstance_' + blockinstanceId));
setupExpanders($('body'));
button.focus();
});
});
......@@ -1512,6 +1514,7 @@ function blockConfigSuccess(form, data) {
ViewManager.replaceConfigureBlock(val);
});
}
setupExpanders($j('body'));
}
function blockConfigError(form, data) {
......
......@@ -3083,6 +3083,13 @@ class View {
$returnartefacts[$artefact->id]['safedescription'] = clean_html($artefact->description);
continue;
}
if ($f == 'attachments') {
// Check if the artefact has attachments - we need to update the instance config form
// to have those attachments selected.
$attachment_ids = get_column('artefact_attachment','attachment', 'artefact', $artefact->id);
$returnartefacts[$artefact->id]['attachments'] = $attachment_ids;
continue;
}
$returnartefacts[$artefact->id][$f] = $artefact->$f;
}
}
......
......@@ -50,6 +50,9 @@ thead th {
.expandable-head a.toggle:hover, .expandable-head a.toggle:focus {
text-decoration: none;
}
.expandable-head td {
background-color: #DDDDDD;
}
/******************** Forms ********************/
/* fieldset */
fieldset {
......
......@@ -523,6 +523,7 @@ td.icon-container img {
}
.expandable-head th {
font-size: 1em;
white-space: normal;
}
.expandable-head a.toggle {
font-weight: bold;
......
......@@ -207,6 +207,7 @@ ul.artefactchooser-subtabs li.current a:active {
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
margin-top: 5px;
}
/* feedback */
#feedbacktable .commentrightwrap {
......@@ -268,3 +269,6 @@ ul.artefactchooser-subtabs li.current a:active {
-moz-border-radius: 5px;
border-radius: 5px;
}
.artefactlicense {
margin-top: 8px;
}
<h2>{$title}</h2>
<h3 class="title">{$title}</h3>
{if $tags}<p class="tags s"><label>{str tag=tags}:</label> {list_tags owner=$owner tags=$tags}</p>{/if}
<p>{$description|clean_html|safe}</p>
{if isset($attachments)}
<table class="cb attachments fullwidth">
<thead class="expandable-head">
<tr>
<td colspan="2">
<a class="toggle" href="#">{str tag=attachedfiles section=artefact.blog}</a>
<span class="fr">
<img class="fl" src="{theme_url filename='images/attachment.png'}" alt="{str tag=attachments section=artefact.blog}">
{$attachments|count}
</span>
</td>
</tr>
</thead>
<tbody class="expandable-body">
{if $artefact->get('tags')}<div class="tags"><label>{str tag=tags}:</label> {list_tags owner=$artefact->get('owner') tags=$artefact->get('tags')}</div>{/if}
{foreach from=$attachments item=item}
<tr class="{cycle values='r0,r1'}">
{if $icons}<td class="icon-container"><img src="{$item->iconpath}" alt=""></td>{/if}
<td><a href="{$item->viewpath}">{$item->title}</a>
({$item->size}) - <strong><a href="{$item->downloadpath}">{str tag=Download section=artefact.file}</a></strong>
<br>{$item->description}</td>
</tr>
{/foreach}
</tbody>
</table>
{/if}
{if $license}
<div class="artefactlicense">
{$license|safe}
</div>
{/if}
<div class="cb"></div>
\ No newline at end of file
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