Merge lp:~adiroiban/launchpad/bug-540105 into lp:launchpad
| Status: | Merged |
|---|---|
| Approved by: | Edwin Grubbs on 2010-03-18 |
| Approved revision: | no longer in the source branch. |
| Merged at revision: | not available |
| Proposed branch: | lp:~adiroiban/launchpad/bug-540105 |
| Merge into: | lp:launchpad |
| Diff against target: |
338 lines (+152/-55) 5 files modified
lib/canonical/launchpad/javascript/translations/pofile.js (+54/-40) lib/lp/app/templates/base-layout-macros.pt (+3/-0) lib/lp/translations/templates/pofile-translate.pt (+26/-8) lib/lp/translations/templates/translationmessage-translate.pt (+17/-7) lib/lp/translations/windmill/tests/test_pofile_translate.py (+52/-0) |
| To merge this branch: | bzr merge lp:~adiroiban/launchpad/bug-540105 |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Edwin Grubbs (community) | code | 2010-03-17 | Approve on 2010-03-18 |
|
Review via email:
|
|||
Commit Message
Move independent functionality in different JS sandboxes and fix
pofile.js updateNotificat
Description of the Change
= Bug 540105 =
I noticed this behaviour in edge:
When entering text in the input box for a translation, this textbox does no longer get the focus by automatically selecting the checkbox dot on its left.
This leads to translators not noticing it, pressing "Save" and loosing all their translations.
== Proposed fix ==
Move independent functionality in different JS sandboxes and fix
pofile.js updateNotificat
== Pre-implementation notes ==
This branch is a hotfix for this problem.
I have opened bug 540216 and working on improving the general test coverage for pofile.js code.
== Implementation details ==
I have also fixes some other lint warnings.
== Tests ==
lp-test -t pofile_
== Demo and Q/A ==
Login as admin and go to:
https:/
In the "New translation" field, enter some text. The radio button before the text field should be now selected.
= Launchpad lint =
Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.
Linting changed files:
lib/canonical
== JSLint notices ==
No handlers could be found for logger "bzr"
jslint: Lint found in '/home/
Line 303 character 18: Be careful when making functions within a loop. Consider putting the function in a closure.
},
Line 310 character 18: Be careful when making functions within a loop. Consider putting the function in a closure.
}, '#' + fields[key], 'down:68+
Line 316 character 18: Be careful when making functions within a loop. Consider putting the function in a closure.
}, '#' + fields[key], 'down:48+
jslint: 1 file to lint.
| Adi Roiban (adiroiban) wrote : | # |
Hi,
> Hi Adi,
>
> This is a good improvement. I ran into an annoying problem running the tests.
> The tests use the combined javascript file, but "make jsbuild" was not getting
> run automatically. I also noticed that translationmess
> pofile-translate.pt load pofile.js directly, when the <script> tag really
> should be added to lib/lp/
> the other js files in the ${lp_js} directory.
I have moved the pofile.js inclusing in base-layout-
> Since I was confused by some of your changes that I don't think were
> necessary, I'm marking this
> needs-fixing
Thanks for the review
[snip]
> > var notice = Y.one('
> >+ if (!notice) {
>
>
> Since Y.one() is expected to return null when the element is not found,
> the preferred if-statement is:
> if (notice !== null)
Thanks for this remark.
I have changed the if statement to explicitly test agains null.
Same for the other cases.
[snip]
> >+ LPS.use(
> > Y.on('domready', Y.lp.pofile.
> >- Y.on('domready', Y.lp.pofile.
> >+ });
> >+
> >+ LPS.use(
>
>
> Why are you calling LPS.use(
> should have no effect unless there is something seriously wrong with
> lp.pofile.
I moved them back in the same sandbox.
I split independent functions in different sandboxes so that the failure of one function to not affect the others.
Here is the latest diff:
=== modified file 'lib/canonical/
--- lib/canonical/
+++ lib/canonical/
@@ -59,7 +59,7 @@
self.updateNot
var notice = Y.one('
- if (!notice) {
+ if (notice == null) {
// We have no notice container on this page, this is why there is
// nothing more to be done by this function.
return;
@@ -71,7 +71,7 @@
// Check the cookie to see if the user has already dismissed
// the notification box for this session.
var already_seen = Y.Cookie.
- if (already_seen) {
+ if (already_seen !== null) {
notice.
}
@@ -79,7 +79,7 @@
// Cancel button starts out hidden. If user has JavaScript,
// then we want to show it.
- if (!cancel_button) {
+ if (cancel_button == null) {
// No cancel button was found to attach the action.
return;
}
@@ -94,7 +94,7 @@
self.setFocus = function(field) {
// if there is nofield, do nothing
- if (Y.one('#' + field)) {
+ if (Y.one('#' + field) !== null) {
Y.one('#' + field).focus();
}
};
@@ -151,7 +151,7 @@
// Copy plural text if needed
- if (Y.one('#' + translation_plural + '1')) {
+ if (Y.one('#' + translation_plural + '1') !== null) {
| Edwin Grubbs (edwin-grubbs) wrote : | # |
> > Why are you calling LPS.use(
> > should have no effect unless there is something seriously wrong with
> > lp.pofile.
> I moved them back in the same sandbox.
> I split independent functions in different sandboxes so that the failure of
> one function to not affect the others.
Hi Adi,
All your changes look good. Now I understand what you were trying to do with the separate LPS calls. Since I wasn't completely certain how far up the stack an exception goes before it continues running the rest of the javascript in the page, I played around with it a little bit. Apparently, an exception halts execution of a <script> block, so you would have to have multiple <script> blocks around each LPS.use() in order to ensure that the following code is run despite an exception above it. A much clearer way to handle that would be:
LPS.use(
try {
do_something();
} catch (e) {
Y.log(e, "error");
}
do_something_
});
At least in firefox, if you call Y.log() with the second argument as "error", you will get a full stack trace in the console just like a normal uncaught exception.
Using try/catch is completely up to you.
merge-approved
BTW, calling LPS.use() multiple times does not give you separate sandboxes, since you are re-using LPS instead of creating a new YUI() object.
-Edwin
| Adi Roiban (adiroiban) wrote : | # |
I added try/catch statements.
Many thanks for your review.
Do you have time to send this branch to ec2 test and land, or should I ask the ORC?
Here is the latest diff.
=== modified file 'lib/lp/
--- lib/lp/
+++ lib/lp/
@@ -18,12 +18,28 @@
+ try {
+ } catch (e) {
+ Y.log(e, "error");
+ }
+ try {
+ } catch (e) {
+ Y.log(e, "error");
+ }
+ try {
+ } catch (e) {
+ Y.log(e, "error");
+ }
+ try {
});
+ } catch (e) {
+ Y.log(e, "error");
+ }
});
=== modified file 'lib/lp/
--- lib/lp/
+++ lib/lp/
@@ -15,11 +15,23 @@
</style>
<script type="text/
+ try {
+ } catch (e) {
+ Y.log(e, "error");
+ }
+ try {
+ } catch (e) {
+ Y.log(e, "error");
+ }
+ try {
});
+ } catch (e) {
+ Y.log(e, "error");
+ }
});
</script>
</div>
| Adi Roiban (adiroiban) wrote : | # |
Hi Edwin,
I moved the try/catch inside the domready function call.
I did some testing on Firefox and Chromium on Ubuntu Karmic, and without the try/catch, a failing domready function call will prevent the loading of all other domready functions.
Here is the latest review.
=== modified file 'lib/lp/
--- lib/lp/
+++ lib/lp/
@@ -18,31 +18,41 @@
- try {
- Y.on('domready', Y.lp.pofile.
- } catch (e) {
- Y.log(e, "error");
- }
- try {
- Y.on('domready', Y.lp.pofile.
- } catch (e) {
- Y.log(e, "error");
- }
- try {
- Y.on('domready', Y.lp.pofile.
- } catch (e) {
- Y.log(e, "error");
- }
- try {
- Y.on('domready', function(e) {
- Y.lp.pofile.
- });
- } catch (e) {
- Y.log(e, "error");
- }
+
+ Y.on('domready', function(e) {
+ try {
+ Y.lp.pofile.
+ } catch (e) {
+ Y.log(e, "error");
+ }
+ });
+
+ Y.on('domready', function(e) {
+ try {
+ Y.lp.pofile.
+ } catch (e) {
+ Y.log(e, "error");
+ }
+ });
+
+ Y.on('domready', function(e) {
+ try {
+ Y.lp.pofile.
+ } catch (e) {
+ Y.log(e, "error");
+ }
+ });
+
+ Y.on('domready', function(e) {
+ try {
+ Y.lp.pofile.
+ } catch (e) {
+ Y.log(e, "error");
+ }
+ });
+
});
-
</script>
</div>
<div metal:fill-
=== modified file 'lib/lp/
--- lib/lp/
+++ lib/lp/
@@ -15,23 +15,29 @@
</style>
<script type="text/
- try {
- Y.on('domready', Y.lp.pofile.
- } catch (e) {
- Y.log(e, "error");
- }
- try {
- Y.on('domready', Y.lp.pofile.
- } catch (e) {
- Y.log(e, "error");
- }
- try {
- Y.on('domready', function(e) {
- Y.lp.pofile.
- });
- } catch (e) {
- Y.log(e, "error");
- }
+ Y.on('domready', function(e) {
+ try {
+ Y.lp.pofile.
+ } catch (e) {
+ Y.log(e, "error");
...
| Adi Roiban (adiroiban) wrote : | # |
Hi Edwin and thanks for the review!
I moved the try/catch in a single domready block, declared link as a local varibaled and used === to compare for null.
Here is the latests diff:
=== modified file 'lib/canonical/
--- lib/canonical/
+++ lib/canonical/
@@ -59,7 +59,7 @@
self.updateNot
var notice = Y.one('
- if (notice == null) {
+ if (notice === null) {
// We have no notice container on this page, this is why there is
// nothing more to be done by this function.
return;
@@ -79,7 +79,7 @@
// Cancel button starts out hidden. If user has JavaScript,
// then we want to show it.
- if (cancel_button == null) {
+ if (cancel_button === null) {
// No cancel button was found to attach the action.
return;
}
@@ -197,6 +197,7 @@
var initializeGloba
Y.
+ var link;
// Shift+Alt+s - Save form
if (e.shiftKey && e.altKey && e.keyCode == 83) {
=== modified file 'lib/lp/
--- lib/lp/
+++ lib/lp/
@@ -25,25 +25,19 @@
} catch (e) {
}
- });
- Y.on('domready', function(e) {
try {
} catch (e) {
}
- });
- Y.on('domready', function(e) {
try {
} catch (e) {
}
- });
- Y.on('domready', function(e) {
try {
} catch (e) {
=== modified file 'lib/lp/
--- lib/lp/
+++ lib/lp/
@@ -21,17 +21,13 @@
} catch (e) {
}
- });
- Y.on('domready', function(e) {
try {
} catch (e) {
}
- });
- Y.on('domready', function(e) {
try {
} catch (e) {

Hi Adi,
This is a good improvement. I ran into an annoying problem running the tests. age-translate. pt and app/templates/ base-layout- macros. pt next to all
The tests use the combined javascript file, but "make jsbuild" was not getting
run automatically. I also noticed that translationmess
pofile-translate.pt load pofile.js directly, when the <script> tag really
should be added to lib/lp/
the other js files in the ${lp_js} directory.
Since I was confused by some of your changes that I don't think were
necessary, I'm marking this
needs-fixing
-Edwin
>=== modified file 'lib/canonical/ launchpad/ javascript/ translations/ pofile. js' launchpad/ javascript/ translations/ pofile. js 2010-02-25 12:56:45 +0000 launchpad/ javascript/ translations/ pofile. js 2010-03-17 17:36:08 +0000 'display' , 'none'); ficationBox = function(e) { .important- notice- container' );
>--- lib/canonical/
>+++ lib/canonical/
>@@ -55,10 +55,15 @@
> node.setStyle(
> });
> hide_anim.run();
>-}
>+};
>
> self.updateNoti
> var notice = Y.one('
>+ if (!notice) {
Since Y.one() is expected to return null when the element is not found,
the preferred if-statement is:
if (notice !== null)
>+ // We have no notice container on this page, this is why there is one('.important -notice- balloon' ); notice_ cookie = ('translation- docs-for- ' + cookie) ; notice- cancel- button' );
>+ // nothing more to be done by this function.
>+ return;
>+ }
> var balloon = notice.
> var dismiss_
> documentation_
>@@ -74,6 +79,10 @@
> '.important-
> // Cancel button starts out hidden. If user has JavaScript,
> // then we want to show it.
>+ if (!cancel_button) {
Same here.
>+ // No cancel button was found to attach the action. button. setStyle( 'visibility' , 'visible'); button. on('click' , function(e) { #batchnav_ next')) { location. assign( link.get( 'href') ) #batchnav_ next');
>+ return;
>+ }
> cancel_
> cancel_
> e.halt();
>@@ -202,30 +211,34 @@
> }
> // Shift+Alt+n - Go to next page in batch
> if (e.shiftKey && e.altKey && e.keyCode == 78) {
>- if (link = Y.one('
>- window.
>+ link = Y.one('
>+ if (link){
Same for these if-statements.
>+ window. location. assign( link.get( 'href') ); #batchnav_ previous' )){ location. assign( link.get( 'href') ) #batchnav_ previous' ); location. assign( link.get( 'href') ); #batchnav_ first') ){ location. assign( link.get( 'href') ) #batchnav_ first') ; location. assign( link.get( 'href') ); #batchnav_ last')) {
> }
> }
> // Shift+Alt+p - Go to previous page in batch
> if (e.shiftKey && e.altKey && e.keyCode == 80) {
>- if (link = Y.one('
>- window.
>+ link = Y.one('
>+ if (link){
>+ window.
> }
> }
> // Shift+Alt+a - Go to first page in batch
> if (e.shiftKey && e.altKey && e.keyCode == 65) {
>- if (link = Y.one('
>- window.
>+ link = Y.one('
>+ if (link){
>+ window.
> }
> }
> // Shift+Alt+l - Go to last page in batch
> if (e.shiftKey && e.altKey && e.keyCode == 76) {
>- if (link = Y.one('
>- ...