Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Ajax user selector: Difference between revisions

From MoodleDocs
(New page: {{Moodle 2.0}}This is a proposal for a new user selector to be used on the assign roles and manage group memebers page, and also in two new reports I am writing for Moodle 2.0 to do with d...)
 
No edit summary
Line 12: Line 12:


The selector will be available either as a stand alone HTML control, or as a formslib component.
The selector will be available either as a stand alone HTML control, or as a formslib component.
There will be options for selecting one or many users.


===With JavaScript off===
===With JavaScript off===


[[Image:Userselector.png|right]] It will work very much like it does at the moment:
[[Image:Userselector.png|right|Moodle 1.9 user selector]] It will work very much like it does at the moment:


It will be a list box that either lists users, or says that the list is too long and you should search. There will be a search box below with a search button to do the searching.
It will be a list box that either lists users, or says that the list is too long and you should search. There will be a search box below with a search button to do the searching.
Line 29: Line 31:
===HTML element names===
===HTML element names===


Suppose that the developers asks for a user selector with name myuserselector. Then in the list box (<select>) will have name="myuserselector". The search text box will have name="myuserselector_searchtext", the search button name="myuserselector_dosearch" and the sort buttons name="myuserselector_sort_lastname", name="myuserselector_sort_email", etc.
Suppose that the developers asks for a user selector with name myuserselector. Then in the list box (<select>) will have name="myuserselector[]" or name="myuserselector" depending on whether we are doing multiple or single selection. The search text box will have name="myuserselector_searchtext", the search button name="myuserselector_dosearch" and the sort buttons name="myuserselector_sort_lastname", name="myuserselector_sort_email", etc.


==Code architecture==
==Code architecture==


===Class based===
The code for a user selector will be wrapped up in a class. There will be a base class user_selector_base which does the common work. Sub classes will just be responsible for implementing the method that searches the database and


===Security===


One issue with ajax interfaces is how you check permissions in the context of an ajax request, which often gives you very little context at all.


==API==
==API==
===For users===
<pre><nowiki>
require_once($CFG->dirroot);
// ...
$userselector = new group_memebers_user_selector(<i>some options</i>);
$userselector->exclude_users();
</nowiki></pre>


===For subclasses===
===For subclasses===


===For users===
 
 
 
==Where the code lives==
 
I propose to put the code in a new user/selector folder. The code will consist of
;lib.php
:containing all the standard selector classes
;script.js
:the JavaScript
;


==See also==
==See also==


* [http://moodle.org/mod/forum/discuss.php?d=XXX Forum thread for discussing this design]
* [http://moodle.org/mod/forum/discuss.php?d=XXX Forum thread for discussing this design]

Revision as of 04:59, 24 October 2008

Moodle 2.0

This is a proposal for a new user selector to be used on the assign roles and manage group memebers page, and also in two new reports I am writing for Moodle 2.0 to do with displaying a user's roles and permissions.

The aim is to improve usability compared to the existing interface.

New configuration options

There will be an new admin option to control which fields are searched when selecting users, in addition to fullname. Three other options will be available: email, idnumber and username.

I know Petr will disapprove of username appearing on the list, because revealing usernames has security implications. However, I know several institutions that want this functionality, and I think we should supply it rather than making lots of different people hack the code. I will, however add a suitable warning to the description of this option. By default, only email will be selected, as at present.--Tim Hunt

User interface

The selector will be available either as a stand alone HTML control, or as a formslib component.

There will be options for selecting one or many users.

With JavaScript off

Moodle 1.9 user selector

It will work very much like it does at the moment:

It will be a list box that either lists users, or says that the list is too long and you should search. There will be a search box below with a search button to do the searching.

The list of users may be displayed in opt-groups, depending on where this control appears. For example, on the group members page, users are grouped by role.

There will be a new feature, some controls to to allow you to choose the sort order.

With JavaScript on

The search button will dissappear, and user searching and sorting will be done with Ajax.

HTML element names

Suppose that the developers asks for a user selector with name myuserselector. Then in the list box (<select>) will have name="myuserselector[]" or name="myuserselector" depending on whether we are doing multiple or single selection. The search text box will have name="myuserselector_searchtext", the search button name="myuserselector_dosearch" and the sort buttons name="myuserselector_sort_lastname", name="myuserselector_sort_email", etc.

Code architecture

The code for a user selector will be wrapped up in a class. There will be a base class user_selector_base which does the common work. Sub classes will just be responsible for implementing the method that searches the database and

Security

One issue with ajax interfaces is how you check permissions in the context of an ajax request, which often gives you very little context at all.

API

For users

require_once($CFG->dirroot);
// ...
$userselector = new group_memebers_user_selector(<i>some options</i>);
$userselector->exclude_users();

For subclasses

Where the code lives

I propose to put the code in a new user/selector folder. The code will consist of

lib.php
containing all the standard selector classes
script.js
the JavaScript

See also