Skip to content
Browse files

ENHANCEMENT Migrated translation dropdown javascript to concrete and …

…renamed js include from LangSelector.js to CMSMain.Translatable.js

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92644 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
1 parent 4082561 commit 0d5ee9d775e3167127ffbe78b48bdfd634671d61 @chillu chillu committed Nov 21, 2009
Showing with 59 additions and 87 deletions.
  1. +9 −5 code/CMSMain.php
  2. +0 −2 code/LeftAndMain.php
  3. +50 −0 javascript/CMSMain.Translatable.js
  4. +0 −58 javascript/LangSelector.js
  5. +0 −22 javascript/TranslationTab.js
View
14 code/CMSMain.php
@@ -83,6 +83,10 @@ public function init() {
Requirements::javascript(CMS_DIR . '/javascript/CMSMain.js');
Requirements::javascript(CMS_DIR . '/javascript/CMSMain_left.js');
Requirements::javascript(CMS_DIR . '/javascript/CMSMain_right.js');
+
+ Requirements::javascript(CMS_DIR . '/javascript/CMSMain.Translatable.js');
+
+ Requirements::css(CMS_DIR . '/css/CMSMain.css');
}
/**
@@ -1245,9 +1249,9 @@ function duplicatewithchildren() {
/**
* Create a new translation from an existing item, switch to this language and reload the tree.
*/
- function createtranslation () {
- $langCode = Convert::raw2sql($_REQUEST['newlang']);
- $originalLangID = (int)$_REQUEST['ID'];
+ function createtranslation($request) {
+ $langCode = Convert::raw2sql($request->getVar('newlang'));
+ $originalLangID = (int)$request->getVar('ID');
$record = $this->getRecord($originalLangID);
@@ -1267,8 +1271,8 @@ function createtranslation () {
$translatedRecord->ID,
$langCode
);
- FormResponse::add(sprintf('window.location.href = "%s";', $url));
- return FormResponse::respond();
+
+ return Director::redirect($url);
}
/**
View
2 code/LeftAndMain.php
@@ -231,8 +231,6 @@ function init() {
Requirements::javascript(CMS_DIR . '/javascript/SideTabs.js');
Requirements::javascript(CMS_DIR . '/javascript/SideReports.js');
- Requirements::javascript(CMS_DIR . '/javascript/LangSelector.js');
- Requirements::javascript(CMS_DIR . '/javascript/TranslationTab.js');
Requirements::themedCSS('typography');
View
50 javascript/CMSMain.Translatable.js
@@ -0,0 +1,50 @@
+(function($) {
+
+ /**
+ * @class Dropdown with languages above CMS tree, causing a redirect upon translation
+ * @name ss.CMSMain.LangSelector
+ */
+ $('.CMSMain #LangSelection').concrete('ss', function($){
+ return/** @lends ss.CMSMain.LangSelector */{
+ onmatch: function() {
+ var self = this;
+ this.bind('change', function(e) {
+ document.location = 'admin/?locale=' + $(e.target).val();
+ return false;
+ });
+ }
+ }
+ });
+
+ /**
+ * Loads /admin/createtranslation, which will create the new record,
+ * and redirect to an edit form.
+ *
+ * @class Dropdown in "Translation" tab in CMS forms, with button to
+ * trigger translating the currently loaded record.
+ * @name ss.CMSMain.createtranslation
+ * @requires jquery.metadata
+ */
+ $('.CMSMain .createTranslation').concrete('ss', function($){
+ return/** @lends ss.CMSMain.createtranslation */{
+ onmatch: function() {
+ var self = this;
+
+ this.find(':input[name=action_createtranslation]').bind('click', function(e) {
+ var form = self.parents('form');
+ // redirect to new URL
+ // TODO This should really be a POST request
+
+ document.location.href = $('base').attr('href') +
+ jQuery(self).metadata().url +
+ '?ID=' + form.find(':input[name=ID]').val() +
+ '&newlang=' + self.find(':input[name=NewTransLang]').val() +
+ '&locale=' + form.find(':input[name=Locale]').val();
+
+ return false;
+ });
+ }
+ }
+ });
+
+}(jQuery));
View
58 javascript/LangSelector.js
@@ -1,58 +0,0 @@
-var _TRANSLATING_LANG = null;
-
-/**
- *
- */
-LangSelectorClass = Class.create();
-LangSelectorClass.prototype = {
-
- initialize: function() {
- if(this.selectedIndex != 0) {
- _TRANSLATING_LANG = this.value;
- }
- },
-
- onchange: function(e, val) {
- if(this.value != _TRANSLATING_LANG) {
- _TRANSLATING_LANG = this.value;
- document.location = 'admin/?locale=' + this.value;
- }
- },
-
- selectValue: function(lang) {
- this.value = lang;
- if(this.value != lang) {
- var newLang = document.createElement('option');
- newLang.text = lang;
- newLang.value = lang;
- try {
- this.add(newLang, null); // standards compliant
- } catch(ex) {
- this.add(newLang); // IE only
- }
- this.value = lang;
- }
- }
-};
-LangSelectorClass.applyTo('#LangSelector');
-
-/**
- *
- */
-TranslatorCreator = Class.create();
-TranslatorCreator.prototype = {
-
- onSelectionChanged: function(selectedNode) {
- if(_TRANSLATING_LANG && Element.hasClassName(selectedNode,'untranslated')) {
- $start = confirm('Would you like to start a translation for this page?');
- if($start) Element.removeClassName(selectedNode,'untranslated');
- return $start;
- }
- },
-
- initialize: function() {
- $('sitetree').observeMethod('SelectionChanged', this.onSelectionChanged.bind(this));
- }
-
-}
-TranslatorCreator.applyTo('#LangSelector_holder');
View
22 javascript/TranslationTab.js
@@ -1,22 +0,0 @@
-Behaviour.register({
- 'input#Form_EditForm_createtranslation': {
- onclick: function(e) {
- var st = $('sitetree');
- var originalID = st.getIdxOf(st.firstSelected());
- if(originalID && originalID.substr(0,3) == 'new') {
- alert("You have to save a page before translating it");
- } else {
- var url = jQuery('base').attr('href') + 'admin/' + this.name.substring(7) + '?ID=' + $('Form_EditForm_ID').value + '&newlang=' +
- $('Form_EditForm_NewTransLang').value + '&ajax=1';
- url += "&locale=" + $('Form_EditForm_Locale').value;
-
- new Ajax.Request( url, {
- onSuccess: Ajax.Evaluator,
- onFailure: Ajax.Evaluator
- });
-
- return false;
- }
- }
- }
-});

0 comments on commit 0d5ee9d

Please sign in to comment.
Something went wrong with that request. Please try again.