Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

API CHANGE Replaced CMSMain->LangSelector() with CMSMain->LangForm() …

…to provide more accessible backend and properly wrap existing <select> tag in a form

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92728 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
commit 01d06dd47e068899a262934c7257f6550f383149 1 parent 2796a37
@chillu chillu authored
View
60 code/CMSMain.php
@@ -1353,23 +1353,51 @@ function providePermissions() {
}
/**
- * Returns all languages with languages already used appearing first.
- * Called by the SSViewer when rendering the template.
- */
- function LangSelector() {
- $member = Member::currentUser();
- $dropdown = new LanguageDropdownField(
- 'LangSelector',
- 'Language',
- array(),
- 'SiteTree',
- 'Locale-English',
- singleton('SiteTree')
+ * Returns a form with all languages with languages already used appearing first.
+ *
+ * @return Form
+ */
+ function LangForm() {
+ $member = Member::currentUser(); //check to see if the current user can switch langs or not
+ if(Permission::checkMember($member, 'VIEW_LANGS')) {
+ $field = new LanguageDropdownField(
+ 'Locale',
+ // TODO i18n
+ 'Language',
+ array(),
+ 'SiteTree',
+ 'Locale-English',
+ singleton('SiteTree')
+ );
+ $field->setValue(Translatable::get_current_locale());
+ } else {
+ // user doesn't have permission to switch langs
+ // so just show a string displaying current language
+ $field = new LiteralField(
+ 'Locale',
+ i18n::get_locale_name( Translatable::get_current_locale())
+ );
+ }
+
+ $form = new Form(
+ $this,
+ 'LangForm',
+ new FieldSet(
+ $field
+ ),
+ new FieldSet(
+ new FormAction('selectlang', _t('CMSMain_left.ss.GO','Go'))
+ )
);
- $dropdown->setValue(Translatable::get_current_locale());
- return $dropdown;
- }
-
+ $form->unsetValidator();
+
+ return $form;
+ }
+
+ function selectlang($data, $form) {
+ return $this;
+ }
+
/**
* Determine if there are more than one languages in our site tree.
*
View
3  code/LeftAndMain.php
@@ -290,9 +290,6 @@ function init() {
'cms/javascript/CMSMain_left.js',
'cms/javascript/CMSMain_right.js',
'cms/javascript/SideTabs.js',
- 'cms/javascript/SideReports.js',
- 'cms/javascript/LangSelector.js',
- 'cms/javascript/TranslationTab.js',
)
);
View
7 css/cms_left.css
@@ -490,3 +490,10 @@ form#SideReportForm label.left {
border-top: 1px solid #CCCCCC;
padding: 3px 0 3px 7px;
}
+ #LangSelector_holder .Actions {
+ display: none;
+ }
+ #LangSelector_holder label.left {
+ margin-left: 0;
+ width: auto;
+ }
View
4 javascript/CMSMain.Translatable.js
@@ -4,7 +4,7 @@
* @class Dropdown with languages above CMS tree, causing a redirect upon translation
* @name ss.CMSMain.LangSelector
*/
- $('.CMSMain #LangSelector').concrete('ss', function($){
+ $('.CMSMain #Form_LangForm').concrete('ss', function($){
return/** @lends ss.CMSMain.LangSelector */{
onmatch: function() {
var self = this;
@@ -16,7 +16,7 @@
});
// whenever a new value is selected, reload the whole CMS in the new locale
- this.bind('change', function(e) {
+ this.find(':input[name=Locale]').bind('change', function(e) {
document.location = 'admin/?locale=' + $(e.target).val();
return false;
});
View
2  templates/Includes/CMSMain_TreeTools.ss
@@ -42,6 +42,6 @@
<% if IsTranslatableEnabled %>
<div id="LangSelector_holder">
- Language: $LangSelector
+ $LangForm
</div>
<% end_if %>
Please sign in to comment.
Something went wrong with that request. Please try again.