$output .= "</div>\n</div>\n\n";
// Initialise the ajax functionality.
- $output .= $this->initialise_javascript();
+ $output .= $this->initialise_javascript($search);
// Return or output it.
if ($return) {
}
$name = 'userselector_' . $name;
$output = '<p><input type="hidden" name="' . $name . '" value="0" />' .
- '<input type="checkbox" id="' . $name . '" name="' . $name . '" value="1"' . $checked . ' /> ' .
+ // For the benefit of brain-dead IE, the id must be different from the name of the hidden form field above.
+ // It seems that document.getElementById('frog') in IE will return and element with name="frog".
+ '<input type="checkbox" id="' . $name . 'id" name="' . $name . '" value="1"' . $checked . ' /> ' .
'<label for="' . $name . '">' . $label . "</label></p>\n";
user_preference_allow_ajax_update($name, PARAM_BOOL);
return $output;
* @param boolean $optiontracker if true, initialise JavaScript for updating the user prefs.
* @return any HTML needed here.
*/
- protected function initialise_javascript() {
+ protected function initialise_javascript($search) {
global $USER;
$output = '';
$USER->userselectors[$hash] = $options;
// Initialise the selector.
- $output .= print_js_call('new user_selector', array($this->name, $hash,
- $this->extrafields, get_string('previouslyselectedusers', '', '%%SEARCHTERM%%'),
+ $output .= print_js_call('new user_selector', array($this->name, $hash, $this->extrafields,
+ $search, get_string('previouslyselectedusers', '', '%%SEARCHTERM%%'),
get_string('nomatchingusers', '', '%%SEARCHTERM%%')), true);
return $output;
* @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, strprevselected, strnomatchingusers) {
+function user_selector(name, hash, extrafields, lastsearch, strprevselected, strnomatchingusers) {
this.name = name;
this.extrafields = extrafields;
this.strprevselected = strprevselected;
// Hook up the event handler for when the search text changes.
var oself = this;
YAHOO.util.Event.addListener(this.searchfield, "keyup", function(e) { oself.handle_keyup(e) });
- this.lastsearch = this.get_search_text();
+ this.lastsearch = lastsearch;
// Define our custom event.
this.createEvent('selectionchanged');
YAHOO.util.Event.addListener(this.listbox, "click", function(e) { oself.handle_selection_change() });
YAHOO.util.Event.addListener(this.listbox, "change", function(e) { oself.handle_selection_change() });
- // And when the search any substring preference changes. Do an immediate research.
- YAHOO.util.Event.addListener('userselector_searchanywhere', 'click', function(e) { oself.handle_searchanywhere_change() });
+ // And when the search any substring preference changes. Do an immediate re-search.
+ YAHOO.util.Event.addListener('userselector_searchanywhereid', 'click', function(e) { oself.handle_searchanywhere_change() });
// Replace the Clear submit button with a clone that is not a submit button.
var oldclearbutton = document.getElementById(this.name + '_clearbutton');
// Hook up the event handler for the clear button.
YAHOO.util.Event.addListener(this.clearbutton, "click", function(e) { oself.handle_clear() });
+
+ // If the contents of the search box is different from the search that was
+ // done on the server, reload the options. (This happens, for example,
+ // in Firefox. Go to the role assign page - the search box will be blank.
+ // Type something in the search box. Then click reload. The text will stay
+ // in the search box, but the server does not know about the new search term,
+ // so without this line, the list would contain all the users.
+ this.send_query(false);
}
/**
* @return the value of one of the option checkboxes.<b>
*/
user_selector.prototype.get_option = function(name) {
- var checkbox = document.getElementById('userselector_' + name);
+ var checkbox = document.getElementById('userselector_' + name + 'id');
if (checkbox) {
return checkbox.checked;
} else {
*/
function user_selector_options_tracker() {
var oself = this;
- YAHOO.util.Event.addListener('userselector_preserveselected', 'click',
+ YAHOO.util.Event.addListener('userselector_preserveselectedid', 'click',
function(e) { oself.handle_option_change('userselector_preserveselected') });
- YAHOO.util.Event.addListener('userselector_autoselectunique', 'click',
+ YAHOO.util.Event.addListener('userselector_autoselectuniqueid', 'click',
function(e) { oself.handle_option_change('userselector_autoselectunique') });
- YAHOO.util.Event.addListener('userselector_searchanywhere', 'click',
+ YAHOO.util.Event.addListener('userselector_searchanywhereid', 'click',
function(e) { oself.handle_option_change('userselector_searchanywhere') });
}
user_selector_options_tracker.prototype.handle_option_change = function(option) {
- set_user_preference(option, document.getElementById(option).checked);
+ set_user_preference(option, document.getElementById(option + 'id').checked);
}
\ No newline at end of file