Skip to content

Commit

Permalink
user-selector MDL-21537 Refactored JS to make use of YUI3
Browse files Browse the repository at this point in the history
 *  YUI3 used instead of YUI2, converted all YUI2 components to YUI3 equivalents.
 * Renamed user/selector/script.js to module.js
 * Converted uses of the the user selector to YUI3 + the new events
  • Loading branch information
Sam Hemelryk committed Mar 23, 2010
1 parent 5997775 commit 456e485
Show file tree
Hide file tree
Showing 5 changed files with 419 additions and 584 deletions.
18 changes: 10 additions & 8 deletions admin/roles/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,17 @@ M.core_role.init_cap_table_filter = function(Y, tableid, strsearch, strclear) {


M.core_role.init_add_assign_page = function(Y) {
var addselect = user_selector.get('addselect');
document.getElementById('add').disabled = addselect.is_selection_empty();
addselect.subscribe('selectionchanged', function(isempty) {
document.getElementById('add').disabled = isempty;
var add = Y.one('#add');
var addselect = M.core_user.get_user_selector('addselect');
add.set('disabled', addselect.is_selection_empty());
addselect.on('user_selector:selectionchanged', function(isempty) {
add.set('disabled', isempty);
});

var removeselect = user_selector.get('removeselect');
document.getElementById('remove').disabled = removeselect.is_selection_empty();
removeselect.subscribe('selectionchanged', function(isempty) {
document.getElementById('remove').disabled = isempty;
var remove = Y.one('#remove');
var removeselect = M.core_user.get_user_selector('removeselect');
remove.set('disabled', removeselect.is_selection_empty());
removeselect.on('user_selector:selectionchanged', function(isempty) {
remove.set('disabled', isempty);
});
};
20 changes: 11 additions & 9 deletions group/clientlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,19 @@ function updateUserSummary() {
return(true);
}

function init_add_remove_members_page() {
var addselect = user_selector.get('addselect');
document.getElementById('add').disabled = addselect.is_selection_empty();
addselect.subscribe('selectionchanged', function(isempty) {
document.getElementById('add').disabled = isempty;
function init_add_remove_members_page(Y) {
var add = Y.one('#add');
var addselect = M.core_user.get_user_selector('addselect');
add.set('disabled', addselect.is_selection_empty());
addselect.on('user_selector:selectionchanged', function(isempty) {
add.set('disabled', isempty);
});

var removeselect = user_selector.get('removeselect');
document.getElementById('remove').disabled = removeselect.is_selection_empty();
removeselect.subscribe('selectionchanged', function(isempty) {
document.getElementById('remove').disabled = isempty;
var remove = Y.one('#remove');
var removeselect = M.core_user.get_user_selector('removeselect');
remove.set('disabled', removeselect.is_selection_empty());
removeselect.on('user_selector:selectionchanged', function(isempty) {
remove.set('disabled', isempty);
});

addselect = document.getElementById('addselect');
Expand Down
89 changes: 42 additions & 47 deletions user/selector/lib.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
<?php

///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Code for ajax user selectors.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package userselector
* @package user
* @copyright 1999 onwards Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
Expand All @@ -43,32 +36,43 @@
* specified.
*/
abstract class user_selector_base {
/** The control name (and id) in the HTML. */
/** @var string The control name (and id) in the HTML. */
protected $name;
/** Extra fields to search on and return in addition to firstname and lastname. */
/** @var array Extra fields to search on and return in addition to firstname and lastname. */
protected $extrafields;
/** Whether the conrol should allow selection of many users, or just one. */
/** @var boolean Whether the conrol should allow selection of many users, or just one. */
protected $multiselect = true;
/** The height this control should have, in rows. */
/** @var int The height this control should have, in rows. */
protected $rows = USER_SELECTOR_DEFAULT_ROWS;
/** A list of userids that should not be returned by this control. */
/** @var array A list of userids that should not be returned by this control. */
protected $exclude = array();
/** A list of the users who are selected. */
/** @var array|null A list of the users who are selected. */
protected $selected = null;
/** When the search changes, do we keep previously selected options that do
/** @var boolean When the search changes, do we keep previously selected options that do
* not match the new search term? */
protected $preserveselected = false;
/** If only one user matches the search, should we select them automatically. */
/** @var boolean If only one user matches the search, should we select them automatically. */
protected $autoselectunique = false;
/** When searching, do we only match the starts of fields (better performace)
/** @var boolean When searching, do we only match the starts of fields (better performace)
* or do we match occurrences anywhere? */
protected $searchanywhere = false;
// This is used by get selected users,
/** @var mixed This is used by get selected users */
protected $validatinguserids = null;

// Used to ensure we only output the search options for one user selector on
// each page.
/** @var boolean Used to ensure we only output the search options for one user selector on
* each page. */
private static $searchoptionsoutput = false;

/** @var array JavaScript YUI3 Module definition */
protected static $jsmodule = array(
'name' => 'user_selector',
'fullpath' => '/user/selector/module.js',
'requires' => array('node', 'event-custom', 'datasource', 'json'),
'strings' => array(
array('previouslyselectedusers', 'moodle', '%%SEARCHTERM%%'),
array('nomatchingusers', 'moodle', '%%SEARCHTERM%%'),
array('none', 'moodle')
));


// Public API ==============================================================
Expand Down Expand Up @@ -103,12 +107,6 @@ public function __construct($name, $options = array()) {
$this->preserveselected = $this->initialise_option('userselector_preserveselected', $this->preserveselected);
$this->autoselectunique = $this->initialise_option('userselector_autoselectunique', $this->autoselectunique);
$this->searchanywhere = $this->initialise_option('userselector_searchanywhere', $this->searchanywhere);

// Required JavaScript code.
$PAGE->requires->yui2_lib('json');
$PAGE->requires->yui2_lib('connection');
$PAGE->requires->yui2_lib('datasource');
$PAGE->requires->js('/user/selector/script.js');
}

/**
Expand Down Expand Up @@ -225,7 +223,7 @@ public function display($return = false) {
$output .= $this->option_checkbox('searchanywhere', $this->searchanywhere, get_string('userselectorsearchanywhere'));
$output .= print_collapsible_region_end(true);

$PAGE->requires->js_function_call('new user_selector_options_tracker');
$PAGE->requires->js_init_call('M.core_user.init_user_selector_options_tracker', array(), false, self::$jsmodule);
user_selector_base::$searchoptionsoutput = true;
}
$output .= "</div>\n</div>\n\n";
Expand Down Expand Up @@ -638,10 +636,7 @@ protected function initialise_javascript($search) {
$USER->userselectors[$hash] = $options;

// Initialise the selector.
$PAGE->requires->js_function_call('new user_selector', array($this->name, $hash, $this->extrafields,
$search, get_string('previouslyselectedusers', '', '%%SEARCHTERM%%'),
get_string('nomatchingusers', '', '%%SEARCHTERM%%'), get_string('none'), $OUTPUT->pix_url('i/loading')));

$PAGE->requires->js_init_call('M.core_user.init_user_selector', array($this->name, $hash, $this->extrafields, $search), false, self::$jsmodule);
return $output;
}
}
Expand Down
Loading

0 comments on commit 456e485

Please sign in to comment.