Skip to content

Commit

Permalink
ajaxlib/require_js: MDL-16693 $PAGE->requires->... deprecates require…
Browse files Browse the repository at this point in the history
…_js etc.

There is a new implementation of require_js in lib/deprecatedlib.php,
based on $PAGE->requires.

There were a few other recently introduced functions in lib/weblib.php,
namely print_js_call, print_delayed_js_call, print_js_config and
standard_js_config. These have been removed, since they were never in
a stable branch, and all the places that used them have been changed
to use the newer $PAGE->requires->... methods.

get_require_js_code is also gone, and the evil places that were calling
it, even though it is an internal function, have been fixed.

Also, I made some minor improvements to the code I committed yesterday
for MDL-16695.

All that remains is to update all the places in core code that are
still using require_js.

(This commit also fixes the problem where the admin tree would not
start with the right categories expanded.)
  • Loading branch information
tjhunt committed Jun 12, 2009
1 parent 151165e commit cf61552
Show file tree
Hide file tree
Showing 36 changed files with 253 additions and 541 deletions.
6 changes: 3 additions & 3 deletions admin/report/capability/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
}

// Include the required JavaScript.
require_js(array('yui_yahoo','yui_event'));
require_js('admin/report/capability/script.js');
$PAGE->requires->yui_lib('event');
$PAGE->requires->js('admin/report/capability/script.js');
$PAGE->requires->js_function_call('capability_report.cap_filter_init', array(get_string('search')));

// Log.
add_to_log(SITEID, "admin", "report capability", "report/capability/index.php?capability=$capability", $capability);
Expand Down Expand Up @@ -77,7 +78,6 @@
echo '<p><label for="menuroles"> ' . get_string('roleslabel', 'report_capability') . '</label></p>';
choose_from_menu($rolechoices, 'roles[]', $selectedroleids, '', '', '', false, false, 0, '', true, true);
echo '<p><input type="submit" id="settingssubmit" value="' . get_string('getreport', 'report_capability') . '" /></p>';
print_js_call('capability_report.cap_filter_init', array(get_string('search')));
echo '</form>';
print_box_end();

Expand Down
4 changes: 2 additions & 2 deletions admin/report/spamcleaner/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
require_once('../../../config.php');
require_once($CFG->libdir.'/adminlib.php');

require_js(array('yui_dom-event', 'yui_connection', 'yui_json'));

$keyword = optional_param('keyword', '', PARAM_RAW);
$autodetect = optional_param('autodetect', '', PARAM_RAW);
$del = optional_param('del', '', PARAM_RAW);
Expand All @@ -44,6 +42,8 @@

require_login();
admin_externalpage_setup('reportspamcleaner');
$PAGE->requires->yui_lib('json');
$PAGE->requires->yui_lib('connection');

// Implement some AJAX calls

Expand Down
6 changes: 3 additions & 3 deletions admin/roles/assign.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@

require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->dirroot . '/' . $CFG->admin . '/roles/lib.php');
require_js(array('yui_yahoo', 'yui_dom', 'yui_event'));
require_js($CFG->admin . '/roles/roles.js');

define("MAX_USERS_TO_LIST_PER_ROLE", 10);

Expand Down Expand Up @@ -255,6 +253,8 @@
}

/// Print the header and tabs
$PAGE->requires->yui_lib('dom-event');
$PAGE->requires->js($CFG->admin . '/roles/roles.js');
if ($context->contextlevel == CONTEXT_USER) {
$user = $DB->get_record('user', array('id'=>$userid));
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context));
Expand Down Expand Up @@ -355,7 +355,7 @@
</div></form>

<?php
print_js_call('init_add_assign_page');
$PAGE->requires->js_function_call('init_add_assign_page');

if (!empty($errors)) {
$msg = '<p>';
Expand Down
8 changes: 4 additions & 4 deletions admin/roles/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ public function display() {
/// End of the table.
echo "</tbody>\n</table>\n";
if (count($this->capabilities) > capability_table_base::NUM_CAPS_FOR_SEARCH) {
global $CFG;
require_js(array('yui_yahoo', 'yui_dom', 'yui_event'));
require_js($CFG->admin . '/roles/roles.js');
print_js_call('cap_table_filter.init',
global $CFG, $PAGE;
$PAGE->requires->yui_lib('dom-event');
$PAGE->requires->js($CFG->admin . '/roles/roles.js');
$PAGE->requires->js_function_call('cap_table_filter.init',
array($this->id, get_string('filter'), get_string('clear')));
}
}
Expand Down
20 changes: 9 additions & 11 deletions admin/xmldb/javascript.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,23 @@
}

/// We use this globals to be able to generate the proper JavaScripts
global $standard_javascript;
global $standard_javascript, $PAGE;

/// Load XMLDB javascript needed to handle some forms
$action = optional_param('action', '', PARAM_ALPHAEXT);
$postaction = optional_param('postaction', '', PARAM_ALPHAEXT);
/// If the js exists, load it
if ($action) {
$file = $CFG->dirroot . '/'.$CFG->admin.'/xmldb/actions/' . $action . '/' . $action . '.js';
$wwwfile = $CFG->wwwroot . '/'.$CFG->admin.'/xmldb/actions/' . $action . '/' . $action . '.js';
$script = $CFG->admin . '/xmldb/actions/' . $action . '/' . $action . '.js';
$file = $CFG->dirroot . '/' . $script;
if (file_exists($file) && is_readable($file)) {
require_js($wwwfile);
} else {
$PAGE->requires->js($script);
} else if ($postaction) {
/// Try to load the postaction javascript if exists
if ($postaction) {
$file = $CFG->dirroot . '/'.$CFG->admin.'/xmldb/actions/' . $postaction . '/' . $postaction . '.js';
$wwwfile = $CFG->wwwroot . '/'.$CFG->admin.'/xmldb/actions/' . $postaction . '/' . $postaction . '.js';
if (file_exists($file) && is_readable($file)) {
require_js($wwwfile);
}
$script = $CFG->admin . '/xmldb/actions/' . $postaction . '/' . $postaction . '.js';
$file = $CFG->dirroot . '/' . $script;
if (file_exists($file) && is_readable($file)) {
$PAGE->requires->js($script);
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions blocks/admin_tree/block_admin_tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ class block_admin_tree extends block_base {
var $currentdepth;
var $divcounter;
var $tempcontent;
var $pathtosection;
var $expandjavascript;
var $destination;
var $section = null;
var $pathtosection = array();
var $expandnodes = array();

function init() {
$this->title = get_string('administrationsite');
$this->version = 2007101509;
$this->currentdepth = 0;
$this->divcounter = 1;
$this->tempcontent = '';
// TODO
$this->section = (isset($this->page->section) ? $this->page->section : '');
$this->pathtosection = array();
$this->expandnodes = array();
global $PAGE; // TODO change this when there is a proper way for blocks to get stuff into head.
$PAGE->requires->yui_lib('event');
}

function applicable_formats() {
Expand Down Expand Up @@ -119,6 +118,7 @@ function get_content() {
require_once($CFG->libdir.'/adminlib.php');
$adminroot = admin_get_root(false, false); // settings not required - only pages

$this->section = $this->page->url->param('section');
if ($current = $adminroot->locate($this->section, true)) {
$this->pathtosection = $current->path;
array_pop($this->pathtosection);
Expand All @@ -133,13 +133,13 @@ function get_content() {
}

if ($this->tempcontent !== '') {
require_js(array('yui_yahoo','yui_event'));
require_js('blocks/admin_tree/admintree.js');
$this->page->requires->js('blocks/admin_tree/admintree.js');
$this->page->requires->js_function_call('admin_tree.init',
array($this->divcounter - 1, $this->expandnodes, $CFG->pixpath,
get_string('folderopened'), get_string('folderclosed')));

$this->content = new object();
$this->content->text = '<div class="admintree">' . $this->tempcontent . "</div>\n";
$this->content->text .= print_js_call('admin_tree.init',
array($this->divcounter - 1, $this->expandnodes, $CFG->pixpath,
get_string('folderopened'), get_string('folderclosed')), true);

// only do search if you have moodle/site:config
if (has_capability('moodle/site:config',get_context_instance(CONTEXT_SYSTEM)) ) {
Expand Down
7 changes: 5 additions & 2 deletions calendar/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1178,8 +1178,11 @@ function calendar_session_vars($course=null) {
}

function calendar_overlib_html() {
require_js('calendar/overlib.cfg.php');
return '<div id="overDiv" style="position: absolute; visibility: hidden; z-index:1000;"></div>';
global $PAGE;
$output = '';
$output .= $PAGE->requires->js('calendar/overlib.cfg.php')->asap();
$output .= '<div id="overDiv" style="position: absolute; visibility: hidden; z-index:1000;"></div>';
return $output;
}

function calendar_set_referring_course($courseid) {
Expand Down
8 changes: 1 addition & 7 deletions course/completion.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
var completion_strsaved, completion_strtitley, completion_strtitlen,
completion_stralty, completion_straltn;
var completion_wwwroot;

function completion_init() {
// Check the reload-forcing
var changeDetector=document.getElementById('completion_dynamic_change');
Expand Down Expand Up @@ -90,9 +86,7 @@ function completion_toggle(e) {
YAHOO.util.Event.preventDefault(e);
// By setting completion_wwwroot you can cause it to use absolute path
// otherwise script assumes it is called from somewhere in /course
var target=completion_wwwroot
? completion_wwwroot+'/course/togglecompletion.php'
: 'togglecompletion.php';
var target = moodle_cfg.wwwroot + '/course/togglecompletion.php';
YAHOO.util.Connect.asyncRequest('POST',target,
{success:completion_handle_response,failure:completion_handle_failure,scope:this},
'id='+this.cmid+'&completionstate='+this.otherState+'&fromajax=1');
Expand Down
50 changes: 16 additions & 34 deletions course/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,27 +161,10 @@
// Course-based switches

if (ajaxenabled($CFG->ajaxtestedbrowsers)) { // Browser, user and site-based switches

require_js(array('yui_yahoo',
'yui_dom',
'yui_event',
'yui_dragdrop',
'yui_connection',
'ajaxcourse_blocks',
'ajaxcourse_sections'));

if (debugging('', DEBUG_DEVELOPER)) {
require_js(array('yui_logger'));

$bodytags = 'onload = "javascript:
show_logger = function() {
var logreader = new YAHOO.widget.LogReader();
logreader.newestOnTop = false;
logreader.setTitle(\'Moodle Debug: YUI Log Console\');
};
show_logger();
"';
}
$PAGE->requires->yui_lib('dragdrop');
$PAGE->requires->yui_lib('connection');
$PAGE->requires->js('lib/ajax/block_classes.js');
$PAGE->requires->js('lib/ajax/section_classes.js');

// Okay, global variable alert. VERY UGLY. We need to create
// this object here before the <blockname>_print_block()
Expand All @@ -195,6 +178,17 @@

$CFG->blocksdrag = $useajax; // this will add a new class to the header so we can style differently

$completion = new completion_info($course);
if ($completion->is_enabled() && ajaxenabled()) {
$PAGE->requires->yui_lib('connection');
$PAGE->requires->js('course/completion.js');
$PAGE->requires->data_for_js('completion_strsaved', get_string('saved', 'completion'));
$PAGE->requires->data_for_js('completion_strtitley', get_string('completion-title-manual-y', 'completion'));
$PAGE->requires->data_for_js('completion_strtitlen', get_string('completion-title-manual-n', 'completion'));
$PAGE->requires->data_for_js('completion_stralty', get_string('completion-alt-manual-y', 'completion'));
$PAGE->requires->data_for_js('completion_straltn', get_string('completion-alt-manual-n', 'completion'));
}

// The "Editing On" button will be appearing only in the "main" course screen
// (i.e., no breadcrumbs other than the default one added inside this function)
$buttons = switchroles_form($course->id);
Expand All @@ -207,19 +201,7 @@
print_header($title, $course->fullname, $navigation, '', '', true,
$buttons, user_login_string($course, $USER), false, $bodytags);

$completion=new completion_info($course);
if($completion->is_enabled() && ajaxenabled()) {
require_js(array('yui_yahoo','yui_event','yui_connection','yui_dom'));
// Need to do this after the header because it requires the YUI stuff
// to be loaded already
require_js('course/completion.js');
print_js_config(array(
'completion_strsaved' => get_string('saved','completion'),
'completion_strtitley' => get_string('completion-title-manual-y','completion'),
'completion_strtitlen' => get_string('completion-title-manual-n','completion'),
'completion_stralty' => get_string('completion-alt-manual-y','completion'),
'completion_straltn' => get_string('completion-alt-manual-n','completion'),
));
if ($completion->is_enabled() && ajaxenabled()) {
// This value tracks whether there has been a dynamic change to the page.
// It is used so that if a user does this - (a) set some tickmarks, (b)
// go to another page, (c) clicks Back button - the page will
Expand Down
4 changes: 2 additions & 2 deletions group/members.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
require_once(dirname(__FILE__) . '/lib.php');
require_once($CFG->dirroot . '/user/selector/lib.php');
require_once($CFG->dirroot . '/course/lib.php');
require_js('group/clientlib.js');

$groupid = required_param('group', PARAM_INT);

Expand Down Expand Up @@ -82,6 +81,8 @@
$navlinks[] = array('name' => $stradduserstogroup, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);

$PAGE->requires->js('group/clientlib.js');
$PAGE->requires->js_function_call('init_add_remove_members_page');
print_header("$course->shortname: $strgroups", $course->fullname, $navigation, '', '', true, '', user_login_string($course, $USER));
check_theme_arrows();
?>
Expand Down Expand Up @@ -123,6 +124,5 @@
</div>

<?php
print_js_call('init_add_remove_members_page');
print_footer($course);
?>
Loading

0 comments on commit cf61552

Please sign in to comment.