Issue Details (XML | Word | Printable)

Key: MDL-16695
Type: Sub-task Sub-task
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Tim Hunt
Reporter: Tim Hunt
Votes: 0
Watchers: 2
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle
MDL-16583

Make a new requirements_manager to hold the implementation of requrie_js and friends

Created: 26/Sep/08 12:29 PM   Updated: 12/Jun/09 11:14 AM
Return to search
Component/s: Lib
Affects Version/s: 2.0
Fix Version/s: 2.0

File Attachments: 1. Text File page_requirements_manager.patch (64 kB)
2. Text File page_requirements_manager.patch (62 kB)


Participants: Penny Leach and Tim Hunt
Security Level: None
Resolved date: 12/Jun/09
Affected Branches: MOODLE_20_STABLE
Fixed Branches: MOODLE_20_STABLE


 Description  « Hide
This will help with storing lists of scripts, etc. and allow us to get the output without nasty hacks like the current $extracthtml argument to require_js.

 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Tim Hunt made changes - 10/Apr/09 01:19 PM
Field Original Value New Value
Summary Make a new page_resource_tracker to hold the implementation of requrie_js and friends Make a new requirements_manager to hold the implementation of requrie_js and friends
Tim Hunt added a comment - 11/Jun/09 05:11 PM
OK, here is a patch that implements a page_requirements_manager class, with unit tests and plenty of inline documentation.

I have not yet rewritten require_js and friends to use it, and then deprecated them. Nor have I changed print_header and friends to get the data from the class. I first want to know that the way I have made this class and its API is sensible.

Draft commit comment:

ajaxlib: MDL-16695 New page_requirements_manager class, soon to replace require_js

This new class does the work that require_js used to do, and more.
It can track a number of different things that may be required to
be output somewhere on the page, including:

  • Links to JS files
  • Links to CSS files
  • Links to YUI libraries (this class knows about the dependancies between the different libs).
  • Skip links that go from the top of <body> to various places in the content.
  • Calls to JavaScript functions (for example to initialise things)
  • Bits of data from PHP that need to be available to JavaScript
  • As a special case of that, an easy way to pass language strings to JS.

The new API looks like
$PAGE->requires->css('mod/mymod/styles.css');
$PAGE->requires->js('mod/mymod/script.js');
$PAGE->requires->js('mod/mymod/small_but_urgent.js')->in_head();
$PAGE->requires->js_function_call('init_mymod', array($data))->on_dom_ready();
$PAGE->requires is the canonical instances of this new class.

The commit also includes unit tests.


Tim Hunt made changes - 11/Jun/09 05:11 PM
Attachment page_requirements_manager.patch [ 17624 ]
Penny Leach added a comment - 11/Jun/09 06:27 PM
we had a long conversation about this in jabber, but to make it official (other than all my tiny nitpicking):

Well Done Tim, Excellent Work Tim. Gold Star.


Tim Hunt added a comment - 11/Jun/09 06:49 PM
OK, revised version of the patch is attached, benefiting from all Penny's detailed comments. Most of the changes are in the comments.

I will probably commit tomorrow morning, if there are no objections.


Tim Hunt made changes - 11/Jun/09 06:49 PM
Attachment page_requirements_manager.patch [ 17628 ]
Tim Hunt made changes - 11/Jun/09 06:54 PM
Attachment page_requirements_manager.patch [ 17628 ]
Tim Hunt made changes - 11/Jun/09 07:06 PM
Attachment page_requirements_manager.patch [ 17629 ]
tjhunt committed 4 files to 'Moodle CVS' - 12/Jun/09 11:13 AM
ajaxlib: MDL-16695 New page_requirements_manager class. Soon to replace require_js.

This new class does the work that require_js used to do, and more.
It can track a number of different things that may be required to
be output somewhere on the page, including:

    * Links to JS files
    * Links to CSS files
    * Links to YUI libraries (this class knows about the dependancies between the different libs).
    * Skip links that go from the top of <body> to various places in the content.
    * Calls to JavaScript functions (for example to initialise things)
    * Bits of data from PHP that need to be available to JavaScript
    * As a special case of that, an easy way to pass language strings to JS.

The new API looks like

$PAGE->requires->css('mod/mymod/styles.css');
$PAGE->requires->js('mod/mymod/script.js');
$PAGE->requires->js('mod/mymod/small_but_urgent.js')->in_head();
$PAGE->requires->js_function_call('init_mymod', array($data))->on_dom_ready();

$PAGE->requires is the canonical instances of this new class.

The commit also includes unit tests, and hopefully the PHP doc comments are
clear enough that it is easy to understand.
MODIFY lib/ajax/ajaxlib.php   Rev. 1.54    (+1099 -1 lines)
MODIFY lib/ajax/simpletest/testajaxlib.php   Rev. 1.4    (+385 -30 lines)
MODIFY lang/en_utf8/access.php   Rev. 1.12    (+2 -1 lines)
MODIFY lib/pagelib.php   Rev. 1.118    (+15 -0 lines)
Tim Hunt added a comment - 12/Jun/09 11:14 AM
OK. Committed.

I'm sorry Penny, but in the end life was too short to do the boiler-plate change in a different commit.


Tim Hunt made changes - 12/Jun/09 11:14 AM
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
tjhunt committed 36 files to 'Moodle CVS' - 12/Jun/09 08:13 PM
ajaxlib/require_js: MDL-16693 $PAGE->requires->... deprecates require_js etc.

There is a new implementation of require_js in lib/deprecatedlib.php,
based on $PAGE->requires.

There were a few other recently introduced functions in lib/weblib.php,
namely print_js_call, print_delayed_js_call, print_js_config and
standard_js_config. These have been removed, since they were never in
a stable branch, and all the places that used them have been changed
to use the newer $PAGE->requires->... methods.

get_require_js_code is also gone, and the evil places that were calling
it, even though it is an internal function, have been fixed.

Also, I made some minor improvements to the code I committed yesterday
for MDL-16695.

All that remains is to update all the places in core code that are
still using require_js.

(This commit also fixes the problem where the admin tree would not
start with the right categories expanded.)
MODIFY lib/questionlib.php   Rev. 1.197    (+2 -2 lines)
MODIFY lib/form/dateselector.php   Rev. 1.16    (+2 -2 lines)
MODIFY repository/lib.php   Rev. 1.180    (+6 -4 lines)
MODIFY lib/form/datetimeselector.php   Rev. 1.18    (+2 -2 lines)
MODIFY lib/deprecatedlib.php   Rev. 1.111    (+35 -0 lines)
MODIFY lib/formslib.php   Rev. 1.178    (+6 -9 lines)
MODIFY group/members.php   Rev. 1.19    (+3 -3 lines)
MODIFY mod/quiz/attempt.php   Rev. 1.162    (+9 -4 lines)
MODIFY question/editlib.php   Rev. 1.120    (+9 -7 lines)
MODIFY lib/ajax/simpletest/testajaxlib.php   Rev. 1.5    (+4 -13 lines)
MODIFY mod/quiz/edit.php   Rev. 1.153    (+3 -3 lines)
MODIFY lib/pagelib.php   Rev. 1.119    (+1 -1 lines)
MODIFY question/type/questiontype.php   Rev. 1.126    (+5 -5 lines)
MODIFY lib/recaptchalib.php   Rev. 1.10    (+1 -1 lines)
MODIFY message/refresh.php   Rev. 1.19    (+8 -5 lines)
MODIFY mod/quiz/review.php   Rev. 1.90    (+2 -2 lines)
MODIFY admin/xmldb/Attic/javascript.php   Rev. 1.6    (+9 -11 lines)
MODIFY course/view.php   Rev. 1.127    (+17 -35 lines)
MODIFY mod/forum/lib.php   Rev. 1.792    (+2 -2 lines)
MODIFY lib/ajax/ajaxlib.php   Rev. 1.55    (+57 -110 lines)
MODIFY lib/weblib.php   Rev. 1.1262    (+24 -273 lines)
MODIFY blocks/admin_tree/block_admin_tree.php   Rev. 1.42    (+12 -12 lines)
MODIFY mod/quiz/quiz.js   Rev. 1.17    (+1 -1 lines)
MODIFY admin/roles/lib.php   Rev. 1.23    (+5 -5 lines)
MODIFY admin/roles/assign.php   Rev. 1.98    (+4 -4 lines)
MODIFY user/selector/lib.php   Rev. 1.20    (+12 -7 lines)
MODIFY lib/filelib.php   Rev. 1.151    (+1 -1 lines)
MODIFY mod/chat/gui_ajax/index.php   Rev. 1.10    (+4 -4 lines)
MODIFY lib/moodlelib.php   Rev. 1.1213    (+3 -4 lines)
MODIFY calendar/lib.php   Rev. 1.231    (+6 -3 lines)
MODIFY course/completion.js   Rev. 1.6    (+1 -7 lines)
MODIFY mod/quiz/attemptlib.php   Rev. 1.39    (+4 -7 lines)
MODIFY admin/report/spamcleaner/index.php   Rev. 1.6    (+3 -3 lines)
MODIFY admin/report/capability/index.php   Rev. 1.11    (+4 -4 lines)
MODIFY question/export.php   Rev. 1.51    (+2 -2 lines)
MODIFY mod/quiz/accessrules.php   Rev. 1.22    (+3 -2 lines)
Mitsuhiro Yoshida committed 17 files to 'Lang CVS' - 13/Jun/09 01:44 AM
MDL-16695 Translated a new string for page_requirements_manager class.
MDL-19182 Splitting auth.php lang file into multiple files based on en_utf8 split.
MODIFY ja_utf8/README   Rev. 1.1013    (+1 -1 lines)
ADD ja_utf8/auth_manual.php   Rev. 1.1    (+0 -0 lines)
MODIFY ja_utf8/access.php   Rev. 1.16    (+2 -1 lines)
ADD ja_utf8/auth_shibboleth.php   Rev. 1.1    (+0 -0 lines)
ADD ja_utf8/auth_pop3.php   Rev. 1.1    (+0 -0 lines)
ADD ja_utf8/auth_pam.php   Rev. 1.1    (+0 -0 lines)
ADD ja_utf8/auth_cas.php   Rev. 1.1    (+0 -0 lines)
MODIFY ja_utf8/auth_mnet.php   Rev. 1.4    (+9 -1 lines)
ADD ja_utf8/auth_none.php   Rev. 1.1    (+0 -0 lines)
ADD ja_utf8/auth_radius.php   Rev. 1.1    (+0 -0 lines)
ADD ja_utf8/auth_ldap.php   Rev. 1.1    (+0 -0 lines)
ADD ja_utf8/auth_db.php   Rev. 1.1    (+0 -0 lines)
ADD ja_utf8/auth_nntp.php   Rev. 1.1    (+0 -0 lines)
ADD ja_utf8/auth_imap.php   Rev. 1.1    (+0 -0 lines)
ADD ja_utf8/auth_nologin.php   Rev. 1.1    (+0 -0 lines)
ADD ja_utf8/auth_fc.php   Rev. 1.1    (+0 -0 lines)
ADD ja_utf8/auth_email.php   Rev. 1.1    (+0 -0 lines)
Dongsheng Cai committed 1 file to 'Moodle CVS' - 15/Jun/09 01:06 PM
"MDL-16695, fixed yui js files path"
MODIFY lib/ajax/ajaxlib.php   Rev. 1.59    (+2 -2 lines)
tjhunt committed 1 file to 'Moodle CVS' - 17/Jun/09 06:29 PM
javascript: MDL-16695 print_footer('empty'); was not printing the necessary end of page code.
MODIFY lib/weblib.php   Rev. 1.1267    (+3 -1 lines)
tjhunt committed 1 file to 'Moodle CVS' - 19/Jun/09 04:02 PM
javascript: MDL-16695 print_footer('empty'); I had the wrong type of quotes.
Thanks to Dongsheng for noticing.
MODIFY lib/weblib.php   Rev. 1.1268    (+1 -1 lines)
martignoni committed 1 file to 'Lang CVS' - 26/Jun/09 03:27 AM
MDL-16695 New string added
MODIFY fr_utf8/access.php   Rev. 1.12    (+2 -1 lines)