]> git.mjollnir.org Git - moodle.git/commitdiff
user selector: MDL-16966 Nicer handling of the situation where there are no users...
authortjhunt <tjhunt>
Thu, 6 Nov 2008 06:09:14 +0000 (06:09 +0000)
committertjhunt <tjhunt>
Thu, 6 Nov 2008 06:09:14 +0000 (06:09 +0000)
A slight improvement of a patch by Dan Poltawski.

user/selector/lib.php
user/selector/script.js

index 2a6ad70e37f031e756e8f65dcb03d98550bfdeb7..08982573db80dcec47d83c265959209569faabc1 100644 (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;
     }
index dd8bac2978f56bec23999ba64c1bb26e04aadd14..b83fde31c3ba23ac0b9d0080a203ef707b77ae08 100644 (file)
  * @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.