Commit 1eb646b2 authored by Richard Mansfield's avatar Richard Mansfield Committed by Gerrit Code Review
Browse files

Merge changes Idc81123d,I148a1e8a,I42dba842

* changes:
  Fix test for internal js files in block javascript
  Eval js to rewrite task titles after block configuration (bug #845534)
  Use function to process get_instance_config_javascript js (bug #845534)
parents 768c0261 0837cb0e
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) {
......@@ -891,22 +900,7 @@ class BlockInstance {
$configjs = call_static_method($blocktypeclass, 'get_instance_config_javascript', $this);
if (is_array($configjs)) {
foreach ($configjs as &$jsfile) {
if (strpos($jsfile, 'http://') === false) {
if ($this->artefactplugin) {
$jsfile = 'artefact/' . $this->artefactplugin . '/blocktype/' .
$this->blocktype . '/' . $jsfile;
}
else {
$jsfile = 'blocktype/' . $this->blocktype . '/' . $jsfile;
}
$jsfile = '$j.getScript("' . get_config('wwwroot') . $jsfile . '");';
}
else {
$jsfile = '$j.getScript("' . $jsfile . '");';
}
}
$js .= implode('', $configjs);
$js = $this->get_get_javascript_javascript($configjs);
}
else if (is_string($configjs)) {
$js .= $configjs;
......@@ -1269,4 +1263,26 @@ class BlockInstance {
}
return $this->temp[$key][$id];
}
/**
* Returns javascript to grab & eval javascript from files on the web
*/
public function get_get_javascript_javascript($jsfiles) {
foreach ($jsfiles as &$jsfile) {
if (stripos($jsfile, 'http://') === false && stripos($jsfile, 'https://') === false) {
if ($this->artefactplugin) {
$jsfile = 'artefact/' . $this->artefactplugin . '/blocktype/' .
$this->blocktype . '/' . $jsfile;
}
else {
$jsfile = 'blocktype/' . $this->blocktype . '/' . $jsfile;
}
$jsfile = '$j.getScript("' . get_config('wwwroot') . $jsfile . '");';
}
else {
$jsfile = '$j.getScript("' . $jsfile . '");';
}
}
return implode('', $jsfiles);
}
}
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