Here are the Windmill tests and the changes in the pofile and translation +message javascript initialization. === modified file 'lib/lp/translations/windmill/tests/test_pofile_translate.py' --- lib/lp/translations/windmill/tests/test_pofile_translate.py 2010-03-17 17:33:04 +0000 +++ lib/lp/translations/windmill/tests/test_pofile_translate.py 2010-03-22 23:02:19 +0000 @@ -50,3 +50,132 @@ # Check that the associated radio button is selected. client.asserts.assertChecked(id=radiobutton_id) + + def _check_reset_translation_select( + self, client, checkbox, singular_select, singular_current, + plural_select=None): + """Checks that the new translation select radio buttons are checked + when ticking 'Someone should review this translation' checkbox. + """ + + client.waits.forElement( + id=checkbox, timeout=constants.FOR_ELEMENT) + client.waits.forElement( + id=singular_select, timeout=constants.FOR_ELEMENT) + if plural_select is not None: + client.waits.forElement( + id=plural_select, timeout=constants.FOR_ELEMENT) + + # Check that initialy the checkbox is not checked and + # that the radio buttons are not selected. + client.asserts.assertNotChecked(id=checkbox) + client.asserts.assertNotChecked(id=singular_select) + client.asserts.assertChecked(id=singular_current) + if plural_select is not None: + client.asserts.assertNotChecked(id=plural_select) + + # Check the checkbox + client.click(id=checkbox) + + # Check that the checkbox and the new translation radio buttons are + # selected. + client.asserts.assertChecked(id=checkbox) + client.asserts.assertChecked(id=singular_select) + client.asserts.assertNotChecked(id=singular_current) + if plural_select is not None: + client.asserts.assertChecked(id=plural_select) + + # We select the current translation for the singular form. + client.click(id=singular_current) + + # Then then we uncheck the 'Someone needs to review this translation' + # checkbox. + client.click(id=checkbox) + + # Unchecking the 'Someone needs to review this translation' checkbox + # will not change the state of the radio buttons. + client.asserts.assertNotChecked(id=checkbox) + client.asserts.assertNotChecked(id=singular_select) + client.asserts.assertChecked(id=singular_current) + if plural_select is not None: + client.asserts.assertChecked(id=plural_select) + + def test_pofile_reset_translation_select(self): + """Test for automatically selecting new translation when + 'Someone needs to review this translations' is checked. + """ + client = self.client + user = lpuser.TRANSLATIONS_ADMIN + + # Go to the zoom in page for a translation with plural forms. + self.client.open( + url='http://translations.launchpad.dev:8085/' + 'ubuntu/hoary/+source/evolution/+pots/' + 'evolution-2.2/es/15/+translate') + self.client.waits.forPageLoad(timeout=constants.PAGE_LOAD) + user.ensure_login(self.client) + + checkbox = u'msgset_144_force_suggestion' + singular_select = u'msgset_144_es_translation_0_new_select' + singular_current = u'msgset_144_es_translation_0_radiobutton' + plural_select = u'msgset_144_es_translation_1_new_select' + self._check_reset_translation_select( + client, + checkbox=checkbox, + singular_select=singular_select, + singular_current=singular_current, + plural_select=plural_select) + + # Go to the zoom in page for a translation without plural forms. + self.client.open( + url='http://translations.launchpad.dev:8085/' + 'ubuntu/hoary/+source/evolution/+pots/' + 'evolution-2.2/es/19/+translate') + self.client.waits.forPageLoad(timeout=constants.PAGE_LOAD) + user.ensure_login(self.client) + + checkbox = u'msgset_148_force_suggestion' + singular_select = u'msgset_148_es_translation_0_new_select' + singular_current = u'msgset_148_es_translation_0_radiobutton' + self._check_reset_translation_select( + client, + checkbox=checkbox, + singular_select=singular_select, + singular_current=singular_current) + + # Go to the zoom out page for some translations. + self.client.open( + url='http://translations.launchpad.dev:8085/' + 'ubuntu/hoary/+source/evolution/+pots/' + 'evolution-2.2/es/+translate') + self.client.waits.forPageLoad(timeout=constants.PAGE_LOAD) + user.ensure_login(self.client) + + checkbox = u'msgset_130_force_suggestion' + singular_select = u'msgset_130_es_translation_0_new_select' + singular_current = u'msgset_130_es_translation_0_radiobutton' + self._check_reset_translation_select( + client, + checkbox=checkbox, + singular_select=singular_select, + singular_current=singular_current) + + # Ensure that the other radio buttons are not changed + client.asserts.assertNotChecked( + id=u'msgset_131_es_translation_0_new_select') + client.asserts.assertNotChecked( + id=u'msgset_132_es_translation_0_new_select') + client.asserts.assertNotChecked( + id=u'msgset_133_es_translation_0_new_select') + client.asserts.assertNotChecked( + id=u'msgset_134_es_translation_0_new_select') + client.asserts.assertNotChecked( + id=u'msgset_135_es_translation_0_new_select') + client.asserts.assertNotChecked( + id=u'msgset_136_es_translation_0_new_select') + client.asserts.assertNotChecked( + id=u'msgset_137_es_translation_0_new_select') + client.asserts.assertNotChecked( + id=u'msgset_138_es_translation_0_new_select') + client.asserts.assertNotChecked( + id=u'msgset_139_es_translation_0_new_select') === modified file 'lib/lp/translations/templates/pofile-translate.pt' --- lib/lp/translations/templates/pofile-translate.pt 2010-03-22 17:44:53 +0000 +++ lib/lp/translations/templates/pofile-translate.pt 2010-03-22 23:59:59 +0000 @@ -18,33 +18,7 @@ registerLaunchpadFunction(insertAllExpansionButtons); LPS.use('lp.pofile', function(Y) { - - Y.on('domready', function(e) { - try { - Y.lp.pofile.updateNotificationBox(); - } catch (e) { - Y.log(e, "error"); - } - - try { - Y.lp.pofile.setupSuggestionDismissal(); - } catch (e) { - Y.log(e, "error"); - } - - try { - Y.lp.pofile.initializeKeyBindings(); - } catch (e) { - Y.log(e, "error"); - } - - try { - Y.lp.pofile.setFocus(autofocus_field); - } catch (e) { - Y.log(e, "error"); - } - }); - + Y.on('domready', Y.lp.pofile.initializePOFile); }); === modified file 'lib/lp/translations/templates/translationmessage-translate.pt' --- lib/lp/translations/templates/translationmessage-translate.pt 2010-03-22 17:44:53 +0000 +++ lib/lp/translations/templates/translationmessage-translate.pt 2010-03-22 23:59:52 +0000 @@ -15,25 +15,7 @@ === modified file 'lib/canonical/launchpad/javascript/translations/pofile.js' --- lib/canonical/launchpad/javascript/translations/pofile.js 2010-03-22 17:44:53 +0000 +++ lib/canonical/launchpad/javascript/translations/pofile.js 2010-03-23 00:18:02 +0000 @@ -13,7 +13,7 @@ * Function to disable/enable all suggestions as they are marked/unmarked * for dismission. */ -self.setupSuggestionDismissal = function(e) { +var setupSuggestionDismissal = function(e) { all_dismiss_boxes = Y.all('.dismiss_action'); if (all_dismiss_boxes !== null) { all_dismiss_boxes.each(function(checkbox) { @@ -57,7 +57,8 @@ hide_anim.run(); }; -self.updateNotificationBox = function(e) { + +var updateNotificationBox = function(e) { var notice = Y.one('.important-notice-container'); if (notice === null) { // We have no notice container on this page, this is why there is @@ -92,7 +93,7 @@ }; -self.setFocus = function(field) { +var setFocus = function(field) { // if there is nofield, do nothing if (Y.one('#' + field) !== null) { Y.one('#' + field).focus(); @@ -101,7 +102,7 @@ var setNextFocus = function(e, field) { - self.setFocus(field); + setFocus(field); // stopPropagation() and preventDefault() e.halt(); }; @@ -111,8 +112,8 @@ // Original singular test is focused first to make sure // it is visible when scrolling up - self.setFocus(original); - self.setFocus(field); + setFocus(original); + setFocus(field); // stopPropagation() and preventDefault() e.halt(); }; @@ -204,11 +205,11 @@ } // Shift+Alt+f - Go to search field if (e.shiftKey && e.altKey && e.keyCode == 70) { - self.setFocus('search_box'); + setFocus('search_box'); } // Shift+Alt+b - Go to first translation field if (e.shiftKey && e.altKey && e.keyCode == 66) { - self.setFocus(fields[0]); + setFocus(fields[0]); } // Shift+Alt+n - Go to next page in batch if (e.shiftKey && e.altKey && e.keyCode == 78) { @@ -338,11 +339,7 @@ }; -/** - * Initialize event-key bindings such as moving to the next or previous - * field, or copying original text - */ -self.initializeKeyBindings = function(e) { +var initializeKeyBindings = function(e) { if (translations_order.length < 1) { // If no translations fiels are displayed on the page @@ -358,5 +355,97 @@ initializeFieldsKeyBindings(fields); }; + +var initializeResetBehavior = function (fields) { + for (var key = 0; key < fields.length; key++) { + var html_parts = fields[key].split('_'); + var msgset_id = html_parts[0] + '_' + html_parts[1]; + var node = Y.one('#' + msgset_id + '_force_suggestion'); + if (node === null) { + // If we don't have a force_suggestion checkbox associated with + // this field, just continue to the next field. + break; + } + Y.on( + 'click', + function (e, translation_id) { + if (this === null) { + // Don't do nothing if we don't have a context object. + return; + } + if (this.get('checked') == true) { + var select = Y.one('#' + translation_id + '_select'); + if (select !== null) { + select.set('checked', true); + } + } + }, + node , node, fields[key] + ); + } +}; + +/** + * Initialize common Javascript code for POFile and TranslationMessage + * +translate pages. + * + * This will add event-key bindings such as moving to the next or previous + * field, or copying original text. + * It will also initializing the reset checkbox behavior and will show the + * error notifications. + */ + +var initializeBaseTranslate = function () { + try { + setupSuggestionDismissal(); + } catch (e) { + Y.log(e, "error"); + } + + try { + initializeKeyBindings(); + } catch (e) { + Y.log(e, "error"); + } + + try { + var fields = translations_order.split(' '); + initializeResetBehavior(fields); + } catch (e) { + Y.log(e, "error"); + } + + try { + setFocus(autofocus_field); + } catch (e) { + Y.log(e, "error"); + } +} + +/** + * Initialize Javascript code for a POFile +translate page. + * + * This will initialize the base code and will also show the guidelines + * if needeed. + */ +self.initializePOFile = function(e) { + try { + updateNotificationBox(); + } catch (e) { + Y.log(e, "error"); + } + initializeBaseTranslate(); +}; + +/** + * Initialize Javascript code for a TranslationMessage +translate page. + * + * This will initialize the base code. + */ +self.initializeTranslationMessage = function(e) { + initializeBaseTranslate(); +}; + + }, "0.1", {"requires": ["event", "event-key", "node", "cookie", "anim"]});