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

Display textbox notes as read-only in config form (bug #736665)



When configuring a textbox that includes an html artefact owned by
someone other than the view owner, it must be made clear to the user
that the textbox cannot be edited within the current view.

In this case, the sanitised html from the artefactchooser is
displayed inside a grey box in the config form, and the tinymce editor
is hidden.

A help file has been added to explain why the user cannot edit the
selected artefact.

(When tinymce includes an toggle for its read-only mode, this can be
simplified)

Change-Id: I81b44928b7ac83ffaebba04d4ab34d3964743bf4
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent d61a6b45
......@@ -33,3 +33,4 @@ $string['blockcontent'] = 'Block Content';
$string['usecontentfromanothertextbox'] = 'Use content from another text box';
$string['textusedinotherblocks'] = 'If you edit the text of this block, it will also be changed in %s other block(s) where it appears.';
$string['managealltextboxcontent'] = 'Manage all textbox content';
$string['readonlymessage'] = 'The text you have selected is not editable on this page.';
<h3>Reusable textbox content</h3>
<p>It is possible to include the same textbox content in several
blocks, and these blocks can appear on different pages. Updating the
text in one block will also change it in all other pages in which it
appears. You can see a list of all the pages on which a particular
note is contained in your Notes area under the Content menu.</p>
<p>When you are editing a group or institution page, remember that
other group or institution members may have inserted this text inside
their own pages. If you edit it here, it will be updated on their
pages too.</p>
<h3>Read-only textbox content</h3>
<p>You can sometimes include a textbox note on a page even when the
note is owned by someone other than the page's owner. For example,
you may have permission to include notes belonging to one of your
groups inside your own personal page.</p>
<p>If you include such content, it will be updated automatically on
your page whenever it is changed by the owner. If you want to update
it yourself, you must do that through a page with the same owner as
the note.</p>
......@@ -113,25 +113,37 @@ class PluginBlocktypeTextbox extends PluginBlocktype {
$blockid = $instance->get('id');
return <<<EOF
function updateTextContent(a) {
tinyMCE.activeEditor.setContent(a.description);
setNodeAttribute('instconf_title', 'value', a.title);
var blockcountmsg = $('instconf_otherblocksmsg_container');
if (blockcountmsg && $('textbox_blockcount')) {
var otherblockcount = 0;
if (a.blocks && a.blocks.length > 0) {
for (var i = 0; i < a.blocks.length; i++) {
if (a.blocks[i] != {$blockid}) {
otherblockcount++;
tinyMCE.activeEditor.setContent(a.description);
$('instconf_textreadonly_display').innerHTML = a.safedescription;
if (a.editable == 1) {
addElementClass('instconf_textreadonly_container', 'hidden');
addElementClass('instconf_readonlymsg_container', 'hidden');
removeElementClass('instconf_text_container', 'hidden');
var blockcountmsg = $('instconf_otherblocksmsg_container');
if (blockcountmsg && $('textbox_blockcount')) {
var otherblockcount = 0;
if (a.blocks && a.blocks.length > 0) {
for (var i = 0; i < a.blocks.length; i++) {
if (a.blocks[i] != {$blockid}) {
otherblockcount++;
}
}
}
if (otherblockcount) {
replaceChildNodes('textbox_blockcount', otherblockcount);
removeElementClass(blockcountmsg, 'hidden');
}
else {
addElementClass(blockcountmsg, 'hidden');
}
}
if (otherblockcount) {
replaceChildNodes('textbox_blockcount', otherblockcount);
removeElementClass(blockcountmsg, 'hidden');
}
else {
addElementClass(blockcountmsg, 'hidden');
}
}
else {
addElementClass('instconf_text_container', 'hidden');
addElementClass('instconf_otherblocksmsg_container', 'hidden');
removeElementClass('instconf_textreadonly_container', 'hidden');
removeElementClass('instconf_readonlymsg_container', 'hidden');
}
}
connect('chooseartefactlink', 'onclick', function(e) {
......@@ -147,33 +159,44 @@ EOF;
}
public static function instance_config_form($instance) {
global $USER;
$instance->set('artefactplugin', 'internal');
$configdata = $instance->get('configdata');
if (!$height = get_config('blockeditorheight')) {
$cfheight = param_integer('cfheight', 0);
$height = $cfheight ? $cfheight * 0.7 : 150;
}
$otherblockcount = 0;
$readonly = false;
$text = '';
$view = $instance->get_view();
if (!empty($configdata['artefactid'])) {
if ($blocks = get_column('view_artefact', 'block', 'artefact', $configdata['artefactid'])) {
$blocks = array_unique($blocks);
$otherblockcount = count($blocks) - 1;
}
$artefactid = $configdata['artefactid'];
try {
$text = $instance->get_artefact_instance($configdata['artefactid'])->get('description');
$artefact = $instance->get_artefact_instance($artefactid);
$readonly = $artefact->get('owner') !== $view->get('owner')
|| $artefact->get('group') !== $view->get('group')
|| $artefact->get('institution') !== $view->get('institution')
|| !$USER->can_edit_artefact($artefact);
$text = $artefact->get('description');
if ($blocks = get_column('view_artefact', 'block', 'artefact', $artefactid)) {
$blocks = array_unique($blocks);
$otherblockcount = count($blocks) - 1;
}
}
catch (ArtefactNotFoundException $e) {
unset($artefactid);
unset($blocks);
$otherblockcount = 0;
}
}
$otherblocksmsg = '<span id="textbox_blockcount">' . $otherblockcount . '</span>';
$otherblocksmsg = get_string('textusedinotherblocks', 'blocktype.internal/textbox', $otherblocksmsg);
$view = $instance->get_view();
$manageurl = get_config('wwwroot') . 'artefact/internal/notes.php';
if ($group = $view->get('group')) {
$manageurl .= '?group=' . $group;
......@@ -186,17 +209,32 @@ EOF;
// Add a message whenever this text appears in some other block
'otherblocksmsg' => array(
'type' => 'html',
'class' => $otherblockcount ? '' : 'hidden',
'value' => '<div class="message info">' . $otherblocksmsg . '</div>',
'class' => 'message info' . (($otherblockcount && !$readonly) ? '' : ' hidden'),
'value' => $otherblocksmsg,
'help' => true,
),
// Add a message whenever this text cannot be edited here
'readonlymsg' => array(
'type' => 'html',
'class' => 'message info' . ($readonly ? '' : ' hidden'),
'value' => get_string('readonlymessage', 'blocktype.internal/textbox'),
'help' => true,
),
'text' => array(
'type' => 'wysiwyg',
'class' => $readonly ? 'hidden' : '',
'title' => get_string('blockcontent', 'blocktype.internal/textbox'),
'width' => '100%',
'height' => $height . 'px',
'defaultvalue' => isset($text) ? $text : '',
'defaultvalue' => $text,
'rules' => array('maxlength' => 65536),
),
'textreadonly' => array(
'type' => 'html',
'class' => $readonly ? '' : 'hidden',
'width' => '100%',
'value' => '<div id="instconf_textreadonly_display">' . $text . '</div>',
),
'chooseartefact' => array(
'type' => 'html',
'class' => 'nojs-hidden-block',
......@@ -267,7 +305,10 @@ EOF;
unset($values['text']);
unset($values['otherblocksmsg']);
unset($values['readonlymsg']);
unset($values['textreadonly']);
unset($values['chooseartefact']);
unset($values['managenotes']);
// Pass back a list of any other blocks that need to be rendered
// due to this change.
......
......@@ -1154,6 +1154,7 @@ div.ok, div.error {
padding: 2px 5px 2px 25px;
}
/* upload file message */
.message.info,
div.info {
padding: 2px 5px;
background: #e7f1c3;
......
......@@ -604,6 +604,14 @@ ul.artefactchooser-subtabs li.current a:active {
#instconf_artefactids_selectlist td input.button {
font-size: .9167em;
}
#instconf_textreadonly_display {
background: #eee;
border: 1px solid #888;
margin: .5em 0;
padding: .5em;
height: 10em;
overflow-y: auto;
}
/* pagination */
.ac-pagination {
......
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