Commit 7103c383 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Eval js to rewrite task titles after block configuration (bug #845534)



When a plans block is first added to the page, the javascript overlay of
the task titles was not evaluated.  This is fixed by moving javascript
functions for the plans block into a new javascript file and pulling the
script onto the page with the same method used by the configuration form
javascript.  A new get_instance_inline_javascript method is added to
initialise the block when it's first configured.

Change-Id: I148a1e8a667c26fe58b3f915768ada4743718c5b
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 9496078b
function rewriteTaskTitles(blockid) {
forEach(
getElementsByTagAndClassName('a', 'task-title', 'tasktable_' + blockid),
function(element) {
connect(element, 'onclick', function(e) {
e.stop();
var description = getFirstElementByTagAndClassName('div', 'task-desc', element.parentNode);
toggleElementClass('hidden', description);
});
}
);
}
function TaskPager(blockid) {
var self = this;
paginatorProxy.addObserver(self);
connect(self, 'pagechanged', partial(rewriteTaskTitles, blockid));
}
......@@ -54,6 +54,14 @@ class PluginBlocktypePlans extends PluginBlocktype {
return '';
}
public static function get_instance_javascript(BlockInstance $bi) {
return array('js/plansblock.js');
}
public static function get_instance_inline_javascript(BlockInstance $bi) {
return 'rewriteTaskTitles(' . $bi->get('id') . ');';
}
public static function render_instance(BlockInstance $instance, $editing=false) {
global $exporter;
......
......@@ -19,34 +19,13 @@
{if $tasks.pagination_js}
<script>
{literal}
function rewriteTaskTitles() {
forEach(
{/literal}
getElementsByTagAndClassName('a', 'task-title','tasktable_{$blockid}'),
{literal}
function(element) {
connect(element, 'onclick', function(e) {
e.stop();
var description = getFirstElementByTagAndClassName('div', 'task-desc', element.parentNode);
toggleElementClass('hidden', description);
});
}
);
}
addLoadEvent(function() {{/literal}
{$tasks.pagination_js|safe}
removeElementClass('plans_page_container', 'hidden');
{literal}}{/literal});
function TaskPager_{$blockid}() {literal}{
var self = this;
paginatorProxy.addObserver(self);
connect(self, 'pagechanged', rewriteTaskTitles);
}
{/literal}
var taskPager_{$blockid} = new TaskPager_{$blockid}();
addLoadEvent(rewriteTaskTitles);
var taskPager_{$blockid} = new TaskPager({$blockid});
addLoadEvent(partial(rewriteTaskTitles, {$blockid}));
</script>
{/if} {* pagination_js *}
{else}
......
......@@ -92,6 +92,12 @@ abstract class PluginBlocktype extends Plugin {
return array();
}
/**
* Inline js to be executed when a block is rendered.
*/
public static function get_instance_inline_javascript(BlockInstance $instance) {
}
/**
* If this blocktype contains artefacts, and uses the artefactchooser
* Pieform element to choose them, this method must return the definition
......@@ -606,7 +612,6 @@ class BlockInstance {
*/
public function render_editing($configure=false, $new=false, $jsreply=false) {
safe_require('blocktype', $this->get('blocktype'));
$js = '';
$movecontrols = array();
$blocktypeclass = generate_class_name('blocktype', $this->get('blocktype'));
......@@ -624,6 +629,9 @@ class BlockInstance {
else {
try {
$content = call_static_method(generate_class_name('blocktype', $this->get('blocktype')), 'render_instance', $this, true);
$jsfiles = call_static_method($blocktypeclass, 'get_instance_javascript', $this);
$inlinejs = call_static_method($blocktypeclass, 'get_instance_inline_javascript', $this);
$js = $this->get_get_javascript_javascript($jsfiles) . $inlinejs;
}
catch (NotFoundException $e) {
// Whoops - where did the image go? There is possibly a bug
......@@ -635,6 +643,7 @@ class BlockInstance {
. 'Original error follows:');
log_debug($e->getMessage());
$content = '';
$js = '';
}
if (!defined('JSON') && !$jsreply) {
......
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