Skip to content

Commit

Permalink
Slight tidy up for how the JS is included and initialised.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjhunt committed Nov 4, 2008
1 parent cca4c12 commit cf0a341
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions user/selector/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ abstract class user_selector_base {
*/
public function __construct($name, $options = array()) {
global $CFG;

// Initialise member variables from constructor arguments.
$this->name = $name;
if (isset($options['extrafields'])) {
$this->extrafields = $options['extrafields'];
Expand All @@ -93,9 +95,15 @@ public function __construct($name, $options = array()) {
if (isset($options['exclude']) && is_array($options['exclude'])) {
$this->exclude = $options['exclude'];
}

// Read the user prefs / optional_params that we use.
$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.
require_js(array('yui_yahoo', 'yui_event', 'yui_json', 'yui_connection', 'yui_datasource'));
require_js('user/selector/script.js');
}

/**
Expand Down Expand Up @@ -191,13 +199,13 @@ public function display($return = false) {
$output .= $this->option_checkbox('autoselectunique', $this->autoselectunique, get_string('userselectorautoselectunique'));
$output .= $this->option_checkbox('searchanywhere', $this->searchanywhere, get_string('userselectorsearchanywhere'));
$output .= print_collapsible_region_end(true);
$output .= print_js_call('new user_selector_options_tracker', array(), true);
user_selector_base::$searchoptionsoutput = true;
$optionsoutput = true;
}
$output .= "</div>\n</div>\n\n";

// Initialise the ajax functionality.
$output .= $this->initialise_javascript($optionsoutput);
$output .= $this->initialise_javascript();

// Return or output it.
if ($return) {
Expand Down Expand Up @@ -541,14 +549,10 @@ private function option_checkbox($name, $on, $label) {
* @param boolean $optiontracker if true, initialise JavaScript for updating the user prefs.
* @return any HTML needed here.
*/
protected function initialise_javascript($optiontracker) {
protected function initialise_javascript() {
global $USER;
$output = '';

// Required JavaScript code.
require_js(array('yui_yahoo', 'yui_event', 'yui_json', 'yui_connection', 'yui_datasource'));
require_js('user/selector/script.js');

// Put the options into the session, to allow search.php to respond to the ajax requests.
$options = $this->get_options();
$hash = md5(serialize($options));
Expand All @@ -559,11 +563,6 @@ protected function initialise_javascript($optiontracker) {
$this->extrafields, get_string('previouslyselectedusers', '', '%%SEARCHTERM%%'),
get_string('nomatchingusers', '', '%%SEARCHTERM%%')), true);

// Initialise the options tracker, if they are our responsibility.
if ($optiontracker) {
$output .= print_js_call('new user_selector_options_tracker', array(), true);
}

return $output;
}
}
Expand Down

0 comments on commit cf0a341

Please sign in to comment.