Commit 8d3d737e authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Fixes for javascript when first adding a plans block to a page



When a plans block is first dropped on a page, the javascript is not
loaded and initialised correctly.  This commit makes the following
changes:

- Rewrites the task title links after the callback from getScript
- Sets the block's artefactplugin so the js file is found correctly
- Removes any onclick from task titles before rewriting (in case
  there are two plans blocks on a page)
- Hides the pagination on first load, as the paginator object is not
  present at that point.

Change-Id: I40a04f66b3b8c2818f660c42b898b97cbdedb1f5
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 0f33a092
......@@ -2,6 +2,7 @@ function rewriteTaskTitles(blockid) {
forEach(
getElementsByTagAndClassName('a', 'task-title', 'tasktable_' + blockid),
function(element) {
disconnectAll(element);
connect(element, 'onclick', function(e) {
e.stop();
var description = getFirstElementByTagAndClassName('div', 'task-desc', element.parentNode);
......
......@@ -55,11 +55,13 @@ class PluginBlocktypePlans extends PluginBlocktype {
}
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') . ');';
$blockid = $bi->get('id');
return array(
array(
'file' => 'js/plansblock.js',
'initjs' => "rewriteTaskTitles($blockid);",
)
);
}
public static function render_instance(BlockInstance $instance, $editing=false) {
......@@ -110,6 +112,7 @@ class PluginBlocktypePlans extends PluginBlocktype {
}
public static function instance_config_form($instance) {
$instance->set('artefactplugin', 'plans');
$configdata = $instance->get('configdata');
$form = array();
......
......@@ -14,14 +14,14 @@
</tbody>
</table>
{if $tasks.pagination}
<div id="plans_page_container">{$tasks.pagination|safe}</div>
<div id="plans_page_container_{$blockid}" class="hidden">{$tasks.pagination|safe}</div>
{/if}
{if $tasks.pagination_js}
<script>
{literal}
addLoadEvent(function() {{/literal}
{$tasks.pagination_js|safe}
removeElementClass('plans_page_container', 'hidden');
removeElementClass('plans_page_container_{$blockid}', 'hidden');
{literal}}{/literal});
var taskPager_{$blockid} = new TaskPager({$blockid});
......
......@@ -1704,6 +1704,7 @@ class View {
$blockinstance
);
foreach($instancejs as &$jsfile) {
$jsfile = (is_array($jsfile) && isset($jsfile['file'])) ? $jsfile['file'] : $jsfile;
if(strpos($jsfile, 'http://') === false) {
if($artefactplugin = get_field('blocktype_installed', 'artefactplugin', 'name', $pluginname)) {
$jsfile = 'artefact/' . $artefactplugin . '/blocktype/' .
......
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