Skip to content

Commit

Permalink
MDL-33099 Javascript: Deprecate the ajaxenabled function
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Feb 17, 2014
1 parent 692d247 commit af64bc6
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 84 deletions.
1 change: 0 additions & 1 deletion admin/settings/appearance.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@
$ADMIN->add('appearance', $temp);

$temp = new admin_settingpage('ajax', new lang_string('ajaxuse'));
$temp->add(new admin_setting_configcheckbox('enableajax', new lang_string('enableajax', 'admin'), new lang_string('configenableajax', 'admin'), 1));
$temp->add(new admin_setting_configcheckbox('useexternalyui', new lang_string('useexternalyui', 'admin'), new lang_string('configuseexternalyui', 'admin'), 0));
$temp->add(new admin_setting_configcheckbox('yuicomboloading', new lang_string('yuicomboloading', 'admin'), new lang_string('configyuicomboloading', 'admin'), 1));
$setting = new admin_setting_configcheckbox('cachejs', new lang_string('cachejs', 'admin'), new lang_string('cachejs_help', 'admin'), 1);
Expand Down
5 changes: 1 addition & 4 deletions blocks/course_overview/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ public function course_overview($courses, $overviews) {
// Intialise string/icon etc if user is editing and courses > 1
if ($this->page->user_is_editing() && (count($courses) > 1)) {
$userediting = true;
// If ajaxenabled then include DND JS and replace link with move image.
if (ajaxenabled()) {
$this->page->requires->js_init_call('M.block_course_overview.add_handles');
}
$this->page->requires->js_init_call('M.block_course_overview.add_handles');

// Check if course is moving
$ismovingcourse = optional_param('movecourse', FALSE, PARAM_BOOL);
Expand Down
6 changes: 1 addition & 5 deletions course/format/formatlegacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ public function get_view_url($section, $options = array()) {
*
* The returned object's property (boolean)capable indicates that
* the course format supports Moodle course ajax features.
* The property (array)testedbrowsers can be used as a parameter for {@link ajaxenabled()}.
*
* @return stdClass
*/
Expand All @@ -162,9 +161,6 @@ public function supports_ajax() {
if (isset($formatsupport->capable)) {
$ajaxsupport->capable = $formatsupport->capable;
}
if (is_array($formatsupport->testedbrowsers)) {
$ajaxsupport->testedbrowsers = $formatsupport->testedbrowsers;
}
}
return $ajaxsupport;
}
Expand Down Expand Up @@ -360,4 +356,4 @@ public function update_course_format_options($data, $oldcourse = null) {
}
return $this->update_format_options($data);
}
}
}
2 changes: 0 additions & 2 deletions course/format/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,13 @@ public function get_section_name($section) {
*
* The returned object's property (boolean)capable indicates that
* the course format supports Moodle course ajax features.
* The property (array)testedbrowsers can be used as a parameter for {@link ajaxenabled()}.
*
* @return stdClass
*/
public function supports_ajax() {
// no support by default
$ajaxsupport = new stdClass();
$ajaxsupport->capable = false;
$ajaxsupport->testedbrowsers = array();
return $ajaxsupport;
}

Expand Down
2 changes: 0 additions & 2 deletions course/format/topics/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,12 @@ public function get_view_url($section, $options = array()) {
*
* The returned object's property (boolean)capable indicates that
* the course format supports Moodle course ajax features.
* The property (array)testedbrowsers can be used as a parameter for {@link ajaxenabled()}.
*
* @return stdClass
*/
public function supports_ajax() {
$ajaxsupport = new stdClass();
$ajaxsupport->capable = true;
$ajaxsupport->testedbrowsers = array('MSIE' => 6.0, 'Gecko' => 20061111, 'Safari' => 531, 'Chrome' => 6.0);
return $ajaxsupport;
}

Expand Down
3 changes: 3 additions & 0 deletions course/format/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ This files describes API changes for course formats

Overview of this plugin type at http://docs.moodle.org/dev/Course_formats

=== 2.7 ===
* The ->testedbrowsers array no longer needs to be defined in supports_ajax().

=== 2.6 ===

* core_course_renderer::course_section_cm_edit_actions has two new optional arguments and now uses and action_menu component.
Expand Down
2 changes: 0 additions & 2 deletions course/format/weeks/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,12 @@ public function get_view_url($section, $options = array()) {
*
* The returned object's property (boolean)capable indicates that
* the course format supports Moodle course ajax features.
* The property (array)testedbrowsers can be used as a parameter for {@link ajaxenabled()}.
*
* @return stdClass
*/
public function supports_ajax() {
$ajaxsupport = new stdClass();
$ajaxsupport->capable = true;
$ajaxsupport->testedbrowsers = array('MSIE' => 6.0, 'Gecko' => 20061111, 'Safari' => 531, 'Chrome' => 6.0);
return $ajaxsupport;
}

Expand Down
6 changes: 0 additions & 6 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2333,7 +2333,6 @@ function course_format_uses_sections($format) {
*
* The returned object's property (boolean)capable indicates that
* the course format supports Moodle course ajax features.
* The property (array)testedbrowsers can be used as a parameter for {@see ajaxenabled()}.
*
* @param string $format
* @return stdClass
Expand Down Expand Up @@ -3119,11 +3118,6 @@ function course_page_type_list($pagetype, $parentcontext, $currentcontext) {
function course_ajax_enabled($course) {
global $CFG, $PAGE, $SITE;

// Ajax must be enabled globally
if (!$CFG->enableajax) {
return false;
}

// The user must be editing for AJAX to be included
if (!$PAGE->user_is_editing()) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion course/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@ protected function coursecat_subcategories(coursecat_helper $chelper, $coursecat
protected function coursecat_include_js() {
global $CFG;
static $jsloaded = false;
if (!$jsloaded && $CFG->enableajax) {
if (!$jsloaded) {
// We must only load this module once.
$this->page->requires->yui_module('moodle-course-categoryexpander',
'Y.Moodle.course.categoryexpander.init');
Expand Down
6 changes: 2 additions & 4 deletions course/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,8 @@
redirect($CFG->wwwroot .'/');
}

$ajaxenabled = ajaxenabled();

$completion = new completion_info($course);
if ($completion->is_enabled() && $ajaxenabled) {
if ($completion->is_enabled()) {
$PAGE->requires->string_for_js('completion-title-manual-y', 'completion');
$PAGE->requires->string_for_js('completion-title-manual-n', 'completion');
$PAGE->requires->string_for_js('completion-alt-manual-y', 'completion');
Expand Down Expand Up @@ -251,7 +249,7 @@
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();

if ($completion->is_enabled() && $ajaxenabled) {
if ($completion->is_enabled()) {
// 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
31 changes: 8 additions & 23 deletions group/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,11 @@
require('tabs.php');

$disabled = 'disabled="disabled"';
$ajaxenabled = ajaxenabled();
if ($ajaxenabled) {
// Some buttons are enabled if single group selected
$showaddmembersform_disabled = $singlegroup ? '' : $disabled;
$showeditgroupsettingsform_disabled = $singlegroup ? '' : $disabled;
$deletegroup_disabled = count($groupids)>0 ? '' : $disabled;
} else {
// Do not disable buttons. The buttons work based on the selected group,
// which you can change without reloading the page, so it is not appropriate
// to disable them if no group is selected.
$showaddmembersform_disabled = '';
$showeditgroupsettingsform_disabled = '';
$deletegroup_disabled = '';
}

// Some buttons are enabled if single group selected.
$showaddmembersform_disabled = $singlegroup ? '' : $disabled;
$showeditgroupsettingsform_disabled = $singlegroup ? '' : $disabled;
$deletegroup_disabled = count($groupids) > 0 ? '' : $disabled;

echo $OUTPUT->heading(format_string($course->shortname, true, array('context' => $context)) .' '.$strgroups, 3);
echo '<form id="groupeditform" action="index.php" method="post">'."\n";
Expand All @@ -179,11 +170,7 @@
echo "<td>\n";
echo '<p><label for="groups"><span id="groupslabel">'.get_string('groups').':</span><span id="thegrouping">&nbsp;</span></label></p>'."\n";

if ($ajaxenabled) { // TODO: move this to JS init!
$onchange = 'M.core_group.membersCombo.refreshMembers();';
} else {
$onchange = '';
}
$onchange = 'M.core_group.membersCombo.refreshMembers();';

echo '<select name="groups[]" multiple="multiple" id="groups" size="15" class="select" onchange="'.$onchange.'"'."\n";
echo ' onclick="window.status=this.selectedIndex==-1 ? \'\' : this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n";
Expand Down Expand Up @@ -276,10 +263,8 @@
echo '</div>'."\n";
echo '</form>'."\n";

if ($ajaxenabled) {
$PAGE->requires->js_init_call('M.core_group.init_index', array($CFG->wwwroot, $courseid));
$PAGE->requires->js_init_call('M.core_group.groupslist', array($preventgroupremoval));
}
$PAGE->requires->js_init_call('M.core_group.init_index', array($CFG->wwwroot, $courseid));
$PAGE->requires->js_init_call('M.core_group.groupslist', array($preventgroupremoval));

echo $OUTPUT->footer();

Expand Down
2 changes: 0 additions & 2 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@
$string['configeditordictionary'] = 'This value will be used if aspell doesn\'t have dictionary for users own language.';
$string['configeditorfontlist'] = 'Select the fonts that should appear in the editor\'s drop-down list.';
$string['configemailchangeconfirmation'] = 'Require an email confirmation step when users change their email address in their profile.';
$string['configenableajax'] = 'This setting controls the use of AJAX across the site. AJAX is required for certain functionality such as drag and drop.';
$string['configenablecalendarexport'] = 'Enable exporting or subscribing to calendars.';
$string['configenablecomments'] = 'Enable comments';
$string['configenablecourserequests'] = 'This will allow any user to request a course be created.';
Expand Down Expand Up @@ -459,7 +458,6 @@
* Alternative text (optional) - String identifier and component of the alternative text of the emoticon.';
$string['emoticonsreset'] = 'Reset emoticons setting to default values';
$string['emptysettingvalue'] = 'Empty';
$string['enableajax'] = 'Enable AJAX';
$string['enableblogs'] = 'Enable blogs';
$string['enablecalendarexport'] = 'Enable calendar export';
$string['enablecomments'] = 'Enable comments';
Expand Down
28 changes: 0 additions & 28 deletions lib/ajax/ajaxlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,6 @@ function user_preference_allow_ajax_update($name, $paramtype) {
$USER->ajax_updatable_user_prefs[$name] = $paramtype;
}

/**
* Returns whether ajax is enabled/allowed or not.
* @param array $browsers optional list of alowed browsers, empty means use default list
* @return bool
*/
function ajaxenabled(array $browsers = null) {
global $CFG;

if (!empty($browsers)) {
$valid = false;
foreach ($browsers as $brand => $version) {
if (core_useragent::check_browser_version($brand, $version)) {
$valid = true;
}
}

if (!$valid) {
return false;
}
}

if (!empty($CFG->enableajax)) {
return true;
} else {
return false;
}
}

/**
* Starts capturing output whilst processing an AJAX request.
*
Expand Down
12 changes: 12 additions & 0 deletions lib/deprecatedlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4266,3 +4266,15 @@ function can_use_html_editor() {
debugging('can_use_html_editor has been deprecated please update your code to assume it returns true.', DEBUG_DEVELOPER);
return true;
}

/**
* Returns whether ajax is enabled/allowed or not.
* @param array $browsers optional list of alowed browsers, empty means use default list
* @return bool
* @deprecated since 2.7 MDL-33099 - please do not use this function any more.
* @todo MDL-44088 This will be removed in Moodle 2.9.
*/
function ajaxenabled(array $browsers = null) {
debugging('ajaxenabled() is deprecated.', DEBUG_DEVELOPER);
return true;
}
1 change: 1 addition & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ DEPRECATIONS:
* The constants FRONTPAGECOURSELIST, FRONTPAGETOPICONLY & FRONTPAGECOURSELIMIT have been removed.
* Various cm_info methods have been deprecated in favour of their read-only properties (get_url(), get_content(), get_extra_classes(),
get_on_click(), get_custom_data(), get_after_link, get_after_edit_icons)
* The ajaxenabled function has been deprecated and always returns true. All code should be fully functional in Javascript.

YUI:
* The lightbox attribute for moodle-core-notification-dialogue has been
Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@

//Adding the javascript module for the items dragdrop.
if (count($feedbackitems) > 1) {
if ($do_show == 'edit' and $CFG->enableajax) {
if ($do_show == 'edit') {
$PAGE->requires->strings_for_js(array(
'pluginname',
'move_item',
Expand Down
4 changes: 1 addition & 3 deletions rating/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1002,9 +1002,7 @@ public function initialise_rating_javascript(moodle_page $page) {
return true;
}

if (!empty($CFG->enableajax)) {
$page->requires->js_init_call('M.core_rating.init');
}
$page->requires->js_init_call('M.core_rating.init');
$done = true;

return true;
Expand Down

0 comments on commit af64bc6

Please sign in to comment.