mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
ENHANCEMENT Simplifying creation logic of new languages in CMS by reloading complete interface, rather than refreshing partial interface, language dropdown etc.
API CHANGE Removed CMSMain->switchlanguage() git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@70307 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
f855a7512f
commit
fd65285cfc
@ -502,6 +502,7 @@ JS;
|
|||||||
$originalItem = DataObject::get_by_id($className,$suffix);
|
$originalItem = DataObject::get_by_id($className,$suffix);
|
||||||
Translatable::set_reading_lang($this->Lang);
|
Translatable::set_reading_lang($this->Lang);
|
||||||
$translation = $originalItem->getTranslation($this->Lang);
|
$translation = $originalItem->getTranslation($this->Lang);
|
||||||
|
if(!$translation) $translation = $originalItem->createTranslation($this->Lang);
|
||||||
if($setID) $translation->ID = $id;
|
if($setID) $translation->ID = $id;
|
||||||
return $translation;
|
return $translation;
|
||||||
}
|
}
|
||||||
@ -1426,43 +1427,6 @@ HTML;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Switch the cms language and reload the site tree
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function switchlanguage($lang, $donotcreate = null) {
|
|
||||||
//is it's a clean switch (to an existing language deselect the current page)
|
|
||||||
if (is_string($lang)) $dontunloadPage = true;
|
|
||||||
$lang = (is_string($lang) ? $lang : urldecode($this->urlParams['ID']));
|
|
||||||
|
|
||||||
$this->Lang = $lang;
|
|
||||||
Translatable::set_reading_lang($lang);
|
|
||||||
|
|
||||||
Translatable::set_reading_lang(Translatable::default_lang());
|
|
||||||
$siteTree = $this->getSiteTreeFor("SiteTree");
|
|
||||||
Translatable::set_reading_lang($lang);
|
|
||||||
|
|
||||||
if ($lang != Translatable::default_lang()) {
|
|
||||||
// FormResponse::add("$('addpage').getElementsByTagName('button')[0].disabled=true;");
|
|
||||||
// FormResponse::add("$('Form_AddPageOptionsForm').getElementsByTagName('div')[1].getElementsByTagName('input')[0].disabled=true;");
|
|
||||||
FormResponse::add("$('Translating_Message').innerHTML = 'Translating mode - ".i18n::get_language_name($lang)."';");
|
|
||||||
FormResponse::add("Element.removeClassName('Translating_Message','nonTranslating');");
|
|
||||||
} else {
|
|
||||||
Translatable::set_reading_lang(Translatable::default_lang());
|
|
||||||
// FormResponse::add("$('addpage').getElementsByTagName('button')[0].disabled=false;");
|
|
||||||
// FormResponse::add("$('Form_AddPageOptionsForm').getElementsByTagName('div')[1].getElementsByTagName('input')[0].disabled=false;");
|
|
||||||
FormResponse::add("Element.addClassName('Translating_Message','nonTranslating');");
|
|
||||||
}
|
|
||||||
$rootLink = $this->Link() . '0';
|
|
||||||
FormResponse::add("$('sitetree').parentNode.innerHTML ='". ereg_replace("[\n]","\\\n",$siteTree) ."';");
|
|
||||||
FormResponse::add("SiteTree.applyTo('#sitetree');");
|
|
||||||
|
|
||||||
FormResponse::add("$('sitetree').observeMethod('SelectionChanged', $('LangSelector_holder').onSelectionChanged.bind($('LangSelector_holder')));");
|
|
||||||
if (!isset($dontunloadPage)) FormResponse::add("node = $('sitetree').getTreeNodeByIdx(0); node.selectTreeNode();");
|
|
||||||
|
|
||||||
return FormResponse::respond();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new translation from an existing item, switch to this language and reload the tree.
|
* Create a new translation from an existing item, switch to this language and reload the tree.
|
||||||
*/
|
*/
|
||||||
@ -1472,51 +1436,28 @@ HTML;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$langCode = $_REQUEST['newlang'];
|
$langCode = $_REQUEST['newlang'];
|
||||||
$langName = i18n::get_language_name($langCode);
|
|
||||||
$originalLangID = $_REQUEST['ID'];
|
$originalLangID = $_REQUEST['ID'];
|
||||||
|
|
||||||
$record = $this->getRecord($originalLangID);
|
$record = $this->getRecord($originalLangID);
|
||||||
$temporalID = "new-$record->RecordClassName-$record->ParentID-$originalLangID";
|
|
||||||
Session::set($temporalID . '_originalLangID',$originalLangID);
|
|
||||||
|
|
||||||
$tree = $this->switchlanguage($langCode, $originalLangID);
|
$this->Lang = $langCode;
|
||||||
|
Translatable::set_reading_lang($langCode);
|
||||||
FormResponse::add(<<<JS
|
|
||||||
if (Element.hasClassName('LangSelector_holder','onelang')) {
|
|
||||||
Element.removeClassName('LangSelector_holder','onelang');
|
|
||||||
$('treepanes').resize();
|
|
||||||
}
|
|
||||||
if ($('LangSelector').options['$langCode'] == undefined) {
|
|
||||||
var option = document.createElement("option");
|
|
||||||
option.text = '$langName';
|
|
||||||
option.value = '$langCode';
|
|
||||||
$('LangSelector').options.add(option);
|
|
||||||
}
|
|
||||||
JS
|
|
||||||
);
|
|
||||||
FormResponse::add("$('LangSelector').selectValue('$langCode');");
|
|
||||||
|
|
||||||
// creating a record in-memory, which means setting the $Lang property
|
// creating a record in-memory, which means setting the $Lang property
|
||||||
// will have no effect as the record is loaded through another javascript
|
// will have no effect as the record is loaded through another javascript
|
||||||
// call and CMSMain->getitem(). The CMS submits the currently selected language
|
// call and CMSMain->getitem(). The CMS submits the currently selected language
|
||||||
// through javascript, which will cause $Lang to be written to the database.
|
// through javascript, which will cause $Lang to be written to the database.
|
||||||
// @todo Explicitly set $Lang property for in-memory object so we don't need javascript modifying GET-calls to save the new object
|
// @todo Explicitly set $Lang property for in-memory object so we don't need javascript modifying GET-calls to save the new object
|
||||||
$newrecord = clone $record;
|
$translatedRecord = $record->createTranslation($langCode);
|
||||||
$newrecord->ID = $temporalID;
|
|
||||||
$newrecord->Lang = $langCode;
|
|
||||||
|
|
||||||
//FormResponse::add("$('sitetree').getTreeNodeByIdx($originalLangID).selectTreeNode();");
|
$url = sprintf(
|
||||||
|
"%s/%d/?lang=%s",
|
||||||
// @todo New node is currently added at the end of the tree,
|
$this->Link('show'),
|
||||||
// rather than replacing the position of the original page
|
$translatedRecord->ID,
|
||||||
FormResponse::add(<<<JS
|
$langCode
|
||||||
var oldNode = $('sitetree').getTreeNodeByIdx($record->ID);
|
);
|
||||||
var oldParentNode = $('sitetree').getTreeNodeByIdx($record->ParentID);
|
FormResponse::add(sprintf('window.location.href = "%s";', $url));
|
||||||
oldParentNode.removeTreeNode(oldNode);
|
return FormResponse::respond();
|
||||||
JS
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->returnItemToUser($newrecord);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user