mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
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
This commit is contained in:
parent
4082561e5d
commit
0d5ee9d775
@ -83,6 +83,10 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
||||
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 @@ JS;
|
||||
/**
|
||||
* 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 @@ JS;
|
||||
$translatedRecord->ID,
|
||||
$langCode
|
||||
);
|
||||
FormResponse::add(sprintf('window.location.href = "%s";', $url));
|
||||
return FormResponse::respond();
|
||||
|
||||
return Director::redirect($url);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -231,8 +231,6 @@ class LeftAndMain extends Controller {
|
||||
|
||||
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');
|
||||
|
||||
|
50
javascript/CMSMain.Translatable.js
Executable file
50
javascript/CMSMain.Translatable.js
Executable file
@ -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));
|
@ -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');
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user