mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
bfojcapell: javascript files for multilingual support
(merged from branches/gsoc) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@42130 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
e4fedc6bad
commit
d1dafb9ff1
79
javascript/LangSelector.js
Executable file
79
javascript/LangSelector.js
Executable file
@ -0,0 +1,79 @@
|
||||
var _TRANSLATING_LANG = null;
|
||||
LangSelector = Class.create();
|
||||
LangSelector.prototype = {
|
||||
|
||||
initialize: function() {
|
||||
this.selector = $('LangSelector');
|
||||
//this.selector.addEventListener("click", this.a, null);
|
||||
|
||||
if(this.selector) this.selector.holder = this;
|
||||
if(this.selector.selectedIndex != 0) {
|
||||
this.showlangtree();
|
||||
_TRANSLATING_LANG = this.selector.value;
|
||||
}
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
if(this.selector) this.selector.holder = null;
|
||||
this.selector = null;
|
||||
},
|
||||
|
||||
onshow: function() {
|
||||
if(this.selector.value) this.showlangtree();
|
||||
},
|
||||
|
||||
onchange: function() {
|
||||
if (this.selector.value != _TRANSLATING_LANG) {
|
||||
if (this.selector.selectedIndex != 0) _TRANSLATING_LANG = this.selector.value;
|
||||
else _TRANSLATING_LANG = null;
|
||||
this.showlangtree();
|
||||
}
|
||||
},
|
||||
|
||||
selectValue: function(lang) {
|
||||
this.selector.value = lang;
|
||||
if (this.selector.value != lang) {
|
||||
var newLang = document.createElement('option');
|
||||
newLang.text = lang;
|
||||
newLang.value = lang;
|
||||
try {
|
||||
this.selector.add(newLang, null); // standards compliant
|
||||
} catch(ex) {
|
||||
this.selector.add(newLang); // IE only
|
||||
}
|
||||
this.selector.value = lang;
|
||||
}
|
||||
},
|
||||
|
||||
showlangtree: function() {
|
||||
$('sitetree').innerHTML=' <img src="cms/images/network-save.gif> loading...';
|
||||
if(this.selector.value) {
|
||||
new Ajax.Request('admin/switchlanguage/' + this.selector.value, {
|
||||
method : 'post',
|
||||
onSuccess: Ajax.Evaluator,
|
||||
onFailure : Ajax.Evaluator
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
LangSelector.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');
|
22
javascript/TranslationTab.js
Executable file
22
javascript/TranslationTab.js
Executable file
@ -0,0 +1,22 @@
|
||||
Behaviour.register({
|
||||
'div.inlineformaction input#Form_EditForm_createtranslation': {
|
||||
onclick: function() {
|
||||
|
||||
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 = baseHref() + 'admin/' + this.name.substring(7) + '?ID=' + $('Form_EditForm_ID').value + '&newlang=' +
|
||||
$('Form_EditForm_NewTransLang').value + '&ajax=1';
|
||||
|
||||
new Ajax.Request( url, {
|
||||
onSuccess: Ajax.Evaluator,
|
||||
onFailure: Ajax.Evaluator
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user