Merge lp:~wallyworld/launchpad/more-mochikit-fallout into lp:launchpad

Proposed by Ian Booth on 2012-01-17
Status: Merged
Approved by: William Grant on 2012-01-17
Approved revision: no longer in the source branch.
Merged at revision: 14681
Proposed branch: lp:~wallyworld/launchpad/more-mochikit-fallout
Merge into: lp:launchpad
Diff against target: 191 lines (+78/-44)
5 files modified
lib/lp/app/javascript/comment.js (+3/-3)
lib/lp/code/javascript/util.js (+60/-0)
lib/lp/code/templates/branch-form-macros.pt (+5/-22)
lib/lp/code/templates/branch-listing.pt (+5/-11)
lib/lp/code/templates/daily-builds-listing.pt (+5/-8)
To merge this branch: bzr merge lp:~wallyworld/launchpad/more-mochikit-fallout
Reviewer Review Type Date Requested Status
William Grant code 2012-01-17 Approve on 2012-01-17
Review via email: mp+88814@code.launchpad.net

Commit Message

Fix last remaining (hopefully) fallout from removing mochikit.

Description of the Change

Fix last remaining (hopefully) fallout from removing mochikit.

1. Port more connect() calls found in TAL to use Y.on()
2. Fix a trim() call -> Y.Lang.trim()
3. Fix a selector in comment.js div#add-comment-form -> #add-comment-form

Tested locally.

As a side effect of the embedded js rework, a previously reported XSS bug was also fixed.

To post a comment you must log in.
William Grant (wgrant) wrote :

update_branch_unique_name needs to use set('text'), but apart from that this is great.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/app/javascript/comment.js'
2--- lib/lp/app/javascript/comment.js 2012-01-12 10:40:07 +0000
3+++ lib/lp/app/javascript/comment.js 2012-01-17 07:27:24 +0000
4@@ -21,7 +21,7 @@
5 initializer: function() {
6 this.submit_button = this.get_submit();
7 this.comment_input = Y.one(
8- 'div#add-comment-form [id="field.comment"]');
9+ '#add-comment-form [id="field.comment"]');
10 this.lp_client = new Y.lp.client.Launchpad();
11 this.error_handler = new Y.lp.client.ErrorHandler();
12 this.error_handler.clearProgressUI = Y.bind(
13@@ -41,7 +41,7 @@
14 * @method get_submit
15 */
16 get_submit: function(){
17- return Y.one('div#add-comment-form input[id="field.actions.save"]');
18+ return Y.one('#add-comment-form input[id="field.actions.save"]');
19 },
20 /**
21 * Implementation of Widget.renderUI.
22@@ -64,7 +64,7 @@
23 * @method validate
24 */
25 validate: function() {
26- return trim(this.comment_input.get('value')) !== '';
27+ return Y.Lang.trim(this.comment_input.get('value')) !== '';
28 },
29 /**
30 * Make the widget enabled or disabled.
31
32=== added file 'lib/lp/code/javascript/util.js'
33--- lib/lp/code/javascript/util.js 1970-01-01 00:00:00 +0000
34+++ lib/lp/code/javascript/util.js 2012-01-17 07:27:24 +0000
35@@ -0,0 +1,60 @@
36+/* Copyright 2012 Canonical Ltd. This software is licensed under the
37+ * GNU Affero General Public License version 3 (see the file LICENSE).
38+ *
39+ * Control enabling/disabling form elements on the +new-recipe page.
40+ *
41+ * @module Y.lp.code.util
42+ * @requires node
43+ */
44+YUI.add('lp.code.util', function(Y) {
45+var ns = Y.namespace('lp.code.util');
46+
47+var update_branch_unique_name = function() {
48+ var unique_name = Y.one("#branch-unique-name");
49+ var owner = Y.one("[id='field.owner']").get('value');
50+ var name = Y.one("[id='field.name']").get('value');
51+ if (name == '') {
52+ name = '<name>';
53+ }
54+ var branch_name = "~" + owner + "/" + target_name + "/" + name;
55+ unique_name.set('text', branch_name);
56+};
57+
58+var hookUpBranchFieldFunctions = function () {
59+ var owner = Y.one("[id='field.owner']");
60+ owner.on('keyup', update_branch_unique_name);
61+ owner.on('change', update_branch_unique_name);
62+ var name = Y.one("[id='field.name']");
63+ name.on('keyup', update_branch_unique_name);
64+ name.on('change', update_branch_unique_name);
65+ Y.one('#branch-unique-name-div').setStyle('display', 'block');
66+ update_branch_unique_name();
67+};
68+
69+var hookUpBranchFilterSubmission = function() {
70+ var submit_filter = function (e) {
71+ Y.DOM.byId('filter_form').submit();
72+ };
73+
74+ Y.one("[id='field.lifecycle']").on('change', submit_filter);
75+ var sortby = Y.one("[id='field.sort_by']");
76+ if (Y.Lang.isValue(sortby)) {
77+ sortby.on('change', submit_filter)
78+ }
79+};
80+
81+var hookUpDailyBuildsFilterSubmission = function() {
82+ var submit_filter = function (e) {
83+ Y.DOM.byId('filter_form').submit();
84+ };
85+
86+ Y.one("[id='field.when_completed_filter']").on(
87+ 'change', submit_filter);
88+};
89+
90+ns.hookUpBranchFieldFunctions = hookUpBranchFieldFunctions;
91+ns.hookUpBranchFilterSubmission = hookUpBranchFilterSubmission;
92+ns.hookUpDailyBuildsFilterSubmission = hookUpDailyBuildsFilterSubmission;
93+
94+}, "0.1", {"requires": ["node", "dom"]});
95+
96
97=== modified file 'lib/lp/code/templates/branch-form-macros.pt'
98--- lib/lp/code/templates/branch-form-macros.pt 2011-11-26 04:03:29 +0000
99+++ lib/lp/code/templates/branch-form-macros.pt 2012-01-17 07:27:24 +0000
100@@ -17,28 +17,11 @@
101
102 <script type="text/javascript">
103 //<![CDATA[
104-function update_branch_unique_name()
105-{
106- var unique_name = document.getElementById("branch-unique-name")
107- var owner = document.getElementById("field.owner")
108- var name = document.getElementById("field.name").value
109- if (name == '') {
110- name = '&lt;name&gt;'
111- }
112- var branch_name = "~" + owner.value + "/" + target_name + "/" + name
113- unique_name.innerHTML = branch_name
114-}
115-
116-function hookUpBranchFieldFunctions()
117-{
118- connect('field.owner', 'onkeyup', update_branch_unique_name);
119- connect('field.owner', 'onchange', update_branch_unique_name);
120- connect('field.name', 'onkeyup', update_branch_unique_name);
121- update_branch_unique_name();
122- document.getElementById("branch-unique-name-div").style.display = "block";
123-}
124-
125-registerLaunchpadFunction(hookUpBranchFieldFunctions);
126+LPS.use('lp.code.util', function(Y) {
127+ Y.on('domready', function(e) {
128+ Y.lp.code.util.hookUpBranchFieldFunctions(Y);
129+ }, window);
130+});
131
132 //]]>
133 </script>
134
135=== modified file 'lib/lp/code/templates/branch-listing.pt'
136--- lib/lp/code/templates/branch-listing.pt 2012-01-04 16:27:21 +0000
137+++ lib/lp/code/templates/branch-listing.pt 2012-01-17 07:27:24 +0000
138@@ -17,16 +17,6 @@
139 </form>
140
141 <script type="text/javascript">
142-function submit_filter() {
143- getElement('filter_form').submit();
144-}
145-
146-function hookUpFilterSubmission () {
147- connect('field.lifecycle', 'onchange', submit_filter);
148- if (getElement('field.sort_by')) {
149- connect('field.sort_by', 'onchange', submit_filter);
150- }
151-}
152 function show_commit(id) {
153 var div = document.getElementById('branch-log-' + id);
154 if (div) {
155@@ -45,7 +35,11 @@
156 <tal:comment
157 tal:condition="not: request/features/ajax.batch_navigator.enabled"
158 replace='structure string:&lt;script type="text/javascript"&gt;
159- registerLaunchpadFunction(hookUpFilterSubmission);
160+ LPS.use("lp.code.util", function(Y) {
161+ Y.on("domready", function(e) {
162+ Y.lp.code.util.hookUpBranchFilterSubmission(Y);
163+ }, window);
164+ });
165 &lt;/script&gt;'/>
166
167 <tal:needs-batch condition="context/has_multiple_pages">
168
169=== modified file 'lib/lp/code/templates/daily-builds-listing.pt'
170--- lib/lp/code/templates/daily-builds-listing.pt 2011-03-02 13:22:31 +0000
171+++ lib/lp/code/templates/daily-builds-listing.pt 2012-01-17 07:27:24 +0000
172@@ -29,14 +29,11 @@
173 </form>
174
175 <script type="text/javascript">
176- function submit_filter() {
177- getElement('filter_form').submit();
178- }
179-
180- function hookUpFilterSubmission () {
181- connect('field.when_completed_filter', 'onchange', submit_filter);
182- }
183- registerLaunchpadFunction(hookUpFilterSubmission);
184+ LPS.use("lp.code.util", function(Y) {
185+ Y.on("domready", function(e) {
186+ Y.lp.code.util.hookUpDailyBuildsFilterSubmission(Y);
187+ }, window);
188+ });
189 </script>
190
191 <tal:block tal:condition="not:dailybuilds">