From: tjhunt Date: Thu, 6 Nov 2008 06:09:14 +0000 (+0000) Subject: user selector: MDL-16966 Nicer handling of the situation where there are no users... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=9d07ec29dc1f518151d7d0f942267b4b028fbd44;p=moodle.git 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. --- diff --git a/user/selector/lib.php b/user/selector/lib.php index 2a6ad70e37..08982573db 100644 --- a/user/selector/lib.php +++ b/user/selector/lib.php @@ -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; } diff --git a/user/selector/script.js b/user/selector/script.js index dd8bac2978..b83fde31c3 100644 --- a/user/selector/script.js +++ b/user/selector/script.js @@ -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.