user selector: MDL-16966 Nicer handling of the situation where there are no users at all.

A slight improvement of a patch by Dan Poltawski.
This commit is contained in:
tjhunt
2008-11-06 06:09:14 +00:00
parent fcaa214b6e
commit 9d07ec29dc
2 changed files with 21 additions and 4 deletions
+6 -2
View File
@@ -438,7 +438,11 @@ abstract class user_selector_base {
// only one selected user, set a flag to select them if that option is turned on.
$select = false;
if (empty($groupedusers)) {
$groupedusers = array(get_string('nomatchingusers', '', $search) => array());
if (!empty($search)) {
$groupedusers = array(get_string('nomatchingusers', '', $search) => array());
} else {
$groupedusers = array(get_string('none') => array());
}
} else if ($this->autoselectunique && count($groupedusers) == 1 &&
count(reset($groupedusers)) == 1) {
$select = true;
@@ -563,7 +567,7 @@ abstract class user_selector_base {
// Initialise the selector.
$output .= print_js_call('new user_selector', array($this->name, $hash, $this->extrafields,
$search, get_string('previouslyselectedusers', '', '%%SEARCHTERM%%'),
get_string('nomatchingusers', '', '%%SEARCHTERM%%')), true);
get_string('nomatchingusers', '', '%%SEARCHTERM%%'), get_string('none')), true);
return $output;
}
+15 -2
View File
@@ -11,11 +11,12 @@
* @param Array extrafields extra fields we are displaying for each user in addition to fullname.
* @param String label used for the optgroup of users who are selected but who do not match the current search.
*/
function user_selector(name, hash, extrafields, lastsearch, strprevselected, strnomatchingusers) {
function user_selector(name, hash, extrafields, lastsearch, strprevselected, strnomatchingusers, strnone) {
this.name = name;
this.extrafields = extrafields;
this.strprevselected = strprevselected;
this.strnomatchingusers = strnomatchingusers;
this.strnone = strnone;
this.searchurl = moodle_cfg.wwwroot + '/user/selector/search.php?selectorid=' +
hash + '&sesskey=' + moodle_cfg.sesskey + '&search='
@@ -128,6 +129,14 @@ user_selector.prototype.strprevselected = '';
*/
user_selector.prototype.strnomatchingusers = '';
/**
* Name of the no matching users group when empty.
*
* @property strnone
* @type String
*/
user_selector.prototype.strnone = '';
// Fields that configure the control's behaviour ===============================
/**
@@ -406,7 +415,11 @@ user_selector.prototype.output_options = function(data) {
}
if (nogroups) {
this.output_group(this.insert_search_into_str(this.strnomatchingusers, this.lastsearch), {}, false)
if (this.lastsearch != '') {
this.output_group(this.insert_search_into_str(this.strnomatchingusers, this.lastsearch), {}, false)
} else {
this.output_group(this.strnone, {}, false)
}
}
// If there was only one option matching the search results, select it.