From 93961341f2fce9e293d0dc325caf7aee6d8c878b Mon Sep 17 00:00:00 2001 From: Yves Trublin Date: Fri, 20 Mar 2015 17:46:50 +0700 Subject: [PATCH 1/5] Make it work with Translatable module Added a dropdown selection language in filters. Not a perfect solution... but it works. --- code/ModelAdmin/SEOEditorAdmin.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/code/ModelAdmin/SEOEditorAdmin.php b/code/ModelAdmin/SEOEditorAdmin.php index 14342c3..b5ac983 100644 --- a/code/ModelAdmin/SEOEditorAdmin.php +++ b/code/ModelAdmin/SEOEditorAdmin.php @@ -45,6 +45,8 @@ public function init() parent::init(); Requirements::css('silverstripe-seo-editor/css/seo-editor.css'); Requirements::javascript('silverstripe-seo-editor/javascript/seo-editor.js'); + + if(class_exists('Translatable')) Requirements::javascript('silverstripe-seo-editor/javascript/SEOEditor.Translatable.js'); } /** @@ -62,6 +64,25 @@ public function getSearchContext() CheckboxField::create('RemoveEmptyMetaTitles', 'Remove Empty MetaTitles'), CheckboxField::create('RemoveEmptyMetaDescriptions', 'Remove Empty MetaDescriptions') ); + + if(class_exists('Translatable')) { + $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', + _t('CMSMain.LANGUAGEDROPDOWNLABEL', 'Language') + ); + $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()) + ); + } + $fields->insertBefore($field, 'Title'); + } $context->setFields($fields); $filters = array( @@ -73,7 +94,8 @@ public function getSearchContext() $context->setFilters($filters); // Namespace fields, for easier detection if a search is present - foreach ($context->getFields() as $field) $field->setName(sprintf('q[%s]', $field->getName())); + foreach ($context->getFields() as $field) + if($field->getName() != 'locale') $field->setName(sprintf('q[%s]', $field->getName())); foreach ($context->getFilters() as $filter) $filter->setFullName(sprintf('q[%s]', $filter->getFullName())); return $context; @@ -256,4 +278,4 @@ private function removeEmptyAttributes(SS_List $list, $type) } -} \ No newline at end of file +} From a1117f8e4bc13b9ad2cd3089c11d89d7240e43a5 Mon Sep 17 00:00:00 2001 From: Yves Trublin Date: Fri, 20 Mar 2015 17:49:08 +0700 Subject: [PATCH 2/5] Make it work with Translatable module --- javascript/SEOEditor.Translatable.js | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 javascript/SEOEditor.Translatable.js diff --git a/javascript/SEOEditor.Translatable.js b/javascript/SEOEditor.Translatable.js new file mode 100644 index 0000000..3b513d2 --- /dev/null +++ b/javascript/SEOEditor.Translatable.js @@ -0,0 +1,30 @@ +/** + * File: SEOEditor.Translatable.js + */ +(function($) { + $.entwine('ss', function($){ + /** + * whenever a new value is selected, reload the whole CMS in the new locale + */ + $('.SEOEditorAdmin #Form_SearchForm_locale').entwine({ + onchange: function(e) { + // Get new locale code + locale = {locale: $(e.target).val()}; + + // Check existing url + search = /locale=[^&]*/; + url = document.location.href; + if(url.match(search)) { + // Replace locale code + url = url.replace(search, $.param(locale)); + } else { + // Add locale code + url = $.path.addSearchParams(url, locale); + } + $('.cms-container').loadPanel(url); + return false; + } + }); + + }); +}(jQuery)); From fc6e453ac29510baa062854052fde93a9dc28d4a Mon Sep 17 00:00:00 2001 From: Yves Trublin Date: Sat, 21 Mar 2015 13:41:26 +0700 Subject: [PATCH 3/5] Update seo-editor.js --- javascript/seo-editor.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/javascript/seo-editor.js b/javascript/seo-editor.js index ca73357..708c246 100644 --- a/javascript/seo-editor.js +++ b/javascript/seo-editor.js @@ -11,7 +11,14 @@ var $this = $(this); var id = $this.closest('tr').attr('data-id'); - var url = $this.closest('.ss-gridfield').attr('data-url') + "/update/" + id; + var preURL = $this.closest('.ss-gridfield').attr('data-url'); + var url; + + if(preURL.indexOf('?') != -1) + url = preURL.substr(0, preURL.indexOf('?')) + "/update/" + id + preURL.substr(preURL.indexOf('?')); + else + url = preURL + "/update/" + id; + var data = $this.attr('name') + '=' + $(this).val(); statusMessage('Saving changes', 'good'); @@ -40,4 +47,4 @@ }); -}(jQuery)); \ No newline at end of file +}(jQuery)); From dada9084304425822a6cf9961aa2a5cc6a42e3d5 Mon Sep 17 00:00:00 2001 From: Yves Trublin Date: Fri, 20 Mar 2015 17:49:08 +0700 Subject: [PATCH 4/5] Make it work with Translatable module --- javascript/SEOEditor.Translatable.js | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 javascript/SEOEditor.Translatable.js diff --git a/javascript/SEOEditor.Translatable.js b/javascript/SEOEditor.Translatable.js new file mode 100644 index 0000000..3b513d2 --- /dev/null +++ b/javascript/SEOEditor.Translatable.js @@ -0,0 +1,30 @@ +/** + * File: SEOEditor.Translatable.js + */ +(function($) { + $.entwine('ss', function($){ + /** + * whenever a new value is selected, reload the whole CMS in the new locale + */ + $('.SEOEditorAdmin #Form_SearchForm_locale').entwine({ + onchange: function(e) { + // Get new locale code + locale = {locale: $(e.target).val()}; + + // Check existing url + search = /locale=[^&]*/; + url = document.location.href; + if(url.match(search)) { + // Replace locale code + url = url.replace(search, $.param(locale)); + } else { + // Add locale code + url = $.path.addSearchParams(url, locale); + } + $('.cms-container').loadPanel(url); + return false; + } + }); + + }); +}(jQuery)); From d5012f8154141c0043a426f32f212573089f01f2 Mon Sep 17 00:00:00 2001 From: Yves Trublin Date: Sat, 21 Mar 2015 13:41:26 +0700 Subject: [PATCH 5/5] Update seo-editor.js --- javascript/seo-editor.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/javascript/seo-editor.js b/javascript/seo-editor.js index ca73357..708c246 100644 --- a/javascript/seo-editor.js +++ b/javascript/seo-editor.js @@ -11,7 +11,14 @@ var $this = $(this); var id = $this.closest('tr').attr('data-id'); - var url = $this.closest('.ss-gridfield').attr('data-url') + "/update/" + id; + var preURL = $this.closest('.ss-gridfield').attr('data-url'); + var url; + + if(preURL.indexOf('?') != -1) + url = preURL.substr(0, preURL.indexOf('?')) + "/update/" + id + preURL.substr(preURL.indexOf('?')); + else + url = preURL + "/update/" + id; + var data = $this.attr('name') + '=' + $(this).val(); statusMessage('Saving changes', 'good'); @@ -40,4 +47,4 @@ }); -}(jQuery)); \ No newline at end of file +}(jQuery));