Commit 166331c2 authored by Benni Mack's avatar Benni Mack Committed by Anja Leichsenring
Browse files

[CLEANUP] Cleanup jumpToUrl() and unused JS in Backend

The jumpToUrl() is defined in every
second module as inline JS. As the
duplicated code is erroneous and
can be shimmed completely, the
function is added to every doc-template
code by default, but can be overriden and
removed completely - which is still the case
in some existing modules.

Additionally the variable "script_ended"
is not used at all anymore, and was removed
as well.

Releases: 6.2
Resolves: #56667
Change-Id: I716611bffce402c5f423c3d64c763d6675a79d14
Reviewed-on: https://review.typo3.org/28180
Reviewed-by: Markus Klein
Tested-by: Markus Klein
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
parent 67755273
......@@ -622,14 +622,17 @@ class EditDocumentController {
$this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/alt_doc.html');
$this->doc->form = '<form action="' . htmlspecialchars($this->R_URI) . '" method="post" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '" name="editform" onsubmit="document.editform._scrollPosition.value=(document.documentElement.scrollTop || document.body.scrollTop); return TBE_EDITOR.checkSubmit(1);">';
$this->doc->getPageRenderer()->loadPrototype();
$this->doc->JScode = $this->doc->wrapScriptTags('
function jumpToUrl(URL,formEl) { //
// override the default jumpToUrl
$this->doc->JScodeArray['jumpToUrl'] = '
function jumpToUrl(URL,formEl) {
if (!TBE_EDITOR.isFormChanged()) {
window.location.href = URL;
} else if (formEl && formEl.type=="checkbox") {
formEl.checked = formEl.checked ? 0 : 1;
}
}
';
$this->doc->JScode = $this->doc->wrapScriptTags('
// Object: TS:
// passwordDummy and decimalSign are used by tbe_editor.js and have to be declared here as
// TS object overwrites the object declared in tbe_editor.js
......
......@@ -424,18 +424,25 @@ class PageLayoutController {
$this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout.html');
// JavaScript:
$this->doc->JScode = '<script type="text/javascript" ' . 'src="' . GeneralUtility::createVersionNumberedFilename(($GLOBALS['BACK_PATH'] . 'js/jsfunc.updateform.js')) . '">' . '</script>';
$this->doc->JScode .= $this->doc->wrapScriptTags('
if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
if (top.fsMod) top.fsMod.navFrameHighlightedID["web"] = "pages' . (int)$this->id . '_"+top.fsMod.currentBank; ' . (int)$this->id . ';
function jumpToUrl(URL,formEl) { //
// override the default jumpToUrl
$this->doc->JScodeArray['jumpToUrl'] = '
function jumpToUrl(URL,formEl) {
if (document.editform && TBE_EDITOR.isFormChanged) { // Check if the function exists... (works in all browsers?)
if (!TBE_EDITOR.isFormChanged()) { //
if (!TBE_EDITOR.isFormChanged()) {
window.location.href = URL;
} else if (formEl) {
if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
}
} else window.location.href = URL;
} else {
window.location.href = URL;
}
}
';
$this->doc->JScode .= $this->doc->wrapScriptTags('
if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
if (top.fsMod) top.fsMod.navFrameHighlightedID["web"] = "pages' . (int)$this->id . '_"+top.fsMod.currentBank; ' . (int)$this->id . ';
' . ($this->popView ? BackendUtility::viewOnClick($this->id, $GLOBALS['BACK_PATH'], BackendUtility::BEgetRootLine($this->id)) : '') . '
function deleteRecord(table,id,url) { //
......
......@@ -197,11 +197,6 @@ class FormsController {
$this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
$this->doc->backPath = $GLOBALS['BACK_PATH'];
$this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/wizard_forms.html');
$this->doc->JScode = $this->doc->wrapScriptTags('
function jumpToUrl(URL,formEl) { //
window.location.href = URL;
}
');
// Setting form tag:
list($rUri) = explode('#', GeneralUtility::getIndpEnv('REQUEST_URI'));
$this->doc->form = '<form action="' . htmlspecialchars($rUri) . '" method="post" name="wizardForm">';
......
......@@ -119,19 +119,26 @@ class RteController {
// Getting the raw record (we need only the pid-value from here...)
$rawRec = BackendUtility::getRecord($this->P['table'], $this->P['uid']);
BackendUtility::fixVersioningPid($this->P['table'], $rawRec);
// Setting JavaScript, including the pid value for viewing:
$this->doc->JScode = $this->doc->wrapScriptTags('
function jumpToUrl(URL,formEl) { //
if (document.editform) {
if (!TBE_EDITOR.isFormChanged()) {
window.location.href = URL;
} else if (formEl) {
if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
}
} else window.location.href = URL;
}
' . ($this->popView ? BackendUtility::viewOnClick($rawRec['pid'], '', BackendUtility::BEgetRootLine($rawRec['pid'])) : '') . '
');
// override the default jumpToUrl
$this->doc->JScodeArray['jumpToUrl'] = '
function jumpToUrl(URL,formEl) {
if (document.editform) {
if (!TBE_EDITOR.isFormChanged()) {
window.location.href = URL;
} else if (formEl) {
if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
}
} else {
window.location.href = URL;
}
}
';
// Setting JavaScript of the pid value for viewing:
if ($this->popView) {
$this->doc->JScode = $this->doc->wrapScriptTags(BackendUtility::viewOnClick($rawRec['pid'], '', BackendUtility::BEgetRootLine($rawRec['pid'])));
}
// Initialize TCeforms - for rendering the field:
$tceforms = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\FormEngine');
// Init...
......
......@@ -136,11 +136,6 @@ class TableController {
$this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
$this->doc->backPath = $GLOBALS['BACK_PATH'];
$this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/wizard_table.html');
$this->doc->JScode = $this->doc->wrapScriptTags('
function jumpToUrl(URL,formEl) { //
window.location.href = URL;
}
');
// Setting form tag:
list($rUri) = explode('#', GeneralUtility::getIndpEnv('REQUEST_URI'));
$this->doc->form = '<form action="' . htmlspecialchars($rUri) . '" method="post" name="wizardForm">';
......
......@@ -88,7 +88,12 @@ class DocumentTemplate {
/**
* @todo Define visibility
*/
public $JScodeArray = array();
public $JScodeArray = array('jumpToUrl' => '
function jumpToUrl(URL) {
window.location.href = URL;
return false;
}
');
// Additional 'page-end' code could be accumulated in this var. It will be outputted at the end of page before </body> and some other internal page-end code.
/**
......
......@@ -69,13 +69,6 @@ class ModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass {
$this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
$this->doc->backPath = $GLOBALS['BACK_PATH'];
$this->doc->form = '<form action="" method="post">';
// JavaScript
$this->doc->JScode = $this->doc->wrapScriptTags('
script_ended = 0;
function jumpToUrl(URL) { //
window.location.href = URL;
}
');
// DBAL page title:
$this->content .= $this->doc->startPage($GLOBALS['LANG']->getLL('title'));
$this->content .= $this->doc->header($GLOBALS['LANG']->getLL('title'));
......
......@@ -311,14 +311,7 @@ class FileListController {
// Generate the list
$this->filelist->generateList();
// Set top JavaScript:
$this->doc->JScode = $this->doc->wrapScriptTags('
if (top.fsMod) top.fsMod.recentIds["file"] = "' . rawurlencode($this->id) . '";
function jumpToUrl(URL) { //
window.location.href = URL;
}
' . $this->filelist->CBfunctions());
$this->doc->JScode = $this->doc->wrapScriptTags('if (top.fsMod) top.fsMod.recentIds["file"] = "' . rawurlencode($this->id) . '";' . $this->filelist->CBfunctions());
// This will return content necessary for the context sensitive clickmenus to work: bodytag events, JavaScript functions and DIV-layers.
$this->doc->getContextMenuCode();
// Setting up the buttons and markers for docheader
......
......@@ -52,7 +52,7 @@ class ContainerViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBacken
* Render start page with \TYPO3\CMS\Backend\Template\DocumentTemplate and pageTitle
*
* @param string $pageTitle title tag of the module. Not required by default, as BE modules are shown in a frame
* @param boolean $enableJumpToUrl If TRUE, includes "jumpTpUrl" javascript function required by ActionMenu. Defaults to TRUE
* @param boolean $enableJumpToUrl If TRUE, includes "jumpTpUrl" javascript function required by ActionMenu. Defaults to TRUE, deprecated, as not needed anymore
* @param boolean $enableClickMenu If TRUE, loads clickmenu.js required by BE context menus. Defaults to TRUE
* @param boolean $loadPrototype specifies whether to load prototype library. Defaults to TRUE
* @param boolean $loadScriptaculous specifies whether to load scriptaculous libraries. Defaults to FALSE
......@@ -74,17 +74,8 @@ class ContainerViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBacken
public function render($pageTitle = '', $enableJumpToUrl = TRUE, $enableClickMenu = TRUE, $loadPrototype = TRUE, $loadScriptaculous = FALSE, $scriptaculousModule = '', $loadExtJs = FALSE, $loadExtJsTheme = TRUE, $extJsAdapter = '', $enableExtJsDebug = FALSE, $addCssFile = NULL, $addJsFile = NULL, $loadJQuery = FALSE, $includeCssFiles = NULL, $includeJsFiles = NULL, $addJsInlineLabels = NULL) {
$doc = $this->getDocInstance();
$pageRenderer = $doc->getPageRenderer();
if ($enableJumpToUrl) {
$doc->JScode .= '
<script language="javascript" type="text/javascript">
script_ended = 0;
function jumpToUrl(URL) {
document.location = URL;
}
' . $doc->redirectUrls() . '
</script>
';
}
$doc->JScode .= $doc->wrapScriptTags($doc->redirectUrls());
// Load various standard libraries
if ($enableClickMenu) {
$doc->loadJavascriptLib('sysext/backend/Resources/Public/JavaScript/clickmenu.js');
......
......@@ -67,11 +67,6 @@ class WizardView extends \TYPO3\CMS\Form\View\Wizard\AbstractWizardView {
$this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
$this->doc->backPath = $GLOBALS['BACK_PATH'];
$this->doc->setModuleTemplate('EXT:form/Resources/Private/Templates/Wizard.html');
$this->doc->JScode = $this->doc->wrapScriptTags('
function jumpToUrl(URL,formEl) {
window.location.href = URL;
}
');
$this->pageRenderer = $this->doc->getPageRenderer();
$this->pageRenderer->enableConcatenateFiles();
$this->pageRenderer->enableCompressCss();
......
......@@ -86,16 +86,7 @@ class PageFunctionsController extends \TYPO3\CMS\Backend\Module\BaseScriptClass
// Main
if ($this->id && $access) {
// JavaScript
$this->doc->JScode = $this->doc->wrapScriptTags('
script_ended = 0;
function jumpToUrl(URL) {
window.location.href = URL;
}
');
$this->doc->postCode = $this->doc->wrapScriptTags('
script_ended = 1;
if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
');
$this->doc->postCode = $this->doc->wrapScriptTags('if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';');
// Setting up the context sensitive menu:
$this->doc->getContextMenuCode();
$this->doc->form = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('web_func')) . '" method="post"><input type="hidden" name="id" value="' . htmlspecialchars($this->id) . '" />';
......
......@@ -68,19 +68,9 @@ class ImportExportController extends \TYPO3\CMS\Backend\Module\BaseScriptClass {
$this->doc->bodyTagId = 'imp-exp-mod';
$this->doc->setModuleTemplate(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('impexp') . '/app/template.html');
$this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
// JavaScript
$this->doc->JScode = $this->doc->wrapScriptTags('
script_ended = 0;
function jumpToUrl(URL) { //
window.location.href = URL;
}
');
// Setting up the context sensitive menu:
$this->doc->getContextMenuCode();
$this->doc->postCode = $this->doc->wrapScriptTags('
script_ended = 1;
if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
');
$this->doc->postCode = $this->doc->wrapScriptTags('if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';');
$this->doc->form = '<form action="' . htmlspecialchars($GLOBALS['MCONF']['_']) . '" method="post" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '"><input type="hidden" name="id" value="' . $this->id . '" />';
$this->content .= $this->doc->header($GLOBALS['LANG']->getLL('title'));
$this->content .= $this->doc->spacer(5);
......
......@@ -82,12 +82,6 @@ class ModuleController {
$this->doc->form = '<form action="" method="post">';
$this->doc->backPath = $GLOBALS['BACK_PATH'];
$this->doc->setModuleTemplate(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('indexed_search') . '/mod/mod_template.html');
// JavaScript
$this->doc->JScodeArray['indexed_search'] = '
script_ended = 0;
function jumpToUrl(URL) {
window.location.href = URL;
}';
$this->doc->tableLayout = array(
'defRow' => array(
'0' => array('<td valign="top" nowrap>', '</td>'),
......
......@@ -97,16 +97,7 @@ class InfoModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass {
)
);
// JavaScript
$this->doc->JScode = $this->doc->wrapScriptTags('
script_ended = 0;
function jumpToUrl(URL) { //
window.location.href = URL;
}
');
$this->doc->postCode = $this->doc->wrapScriptTags('
script_ended = 1;
if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
');
$this->doc->postCode = $this->doc->wrapScriptTags('if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';');
// Setting up the context sensitive menu:
$this->doc->getContextMenuCode();
$this->doc->form = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('web_info')) . '" method="post" name="webinfoForm">';
......
......@@ -55,7 +55,7 @@ class ContainerViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBacken
* Render start page with \TYPO3\CMS\Backend\Template\DocumentTemplate and pageTitle
*
* @param string $pageTitle title tag of the module. Not required by default, as BE modules are shown in a frame
* @param boolean $enableJumpToUrl If TRUE, includes "jumpTpUrl" javascript function required by ActionMenu. Defaults to TRUE
* @param boolean $enableJumpToUrl If TRUE, includes "jumpTpUrl" javascript function required by ActionMenu. Defaults to TRUE, not needed anymore, as it is included all the time
* @param boolean $enableClickMenu If TRUE, loads clickmenu.js required by BE context menus. Defaults to TRUE
* @param boolean $loadPrototype specifies whether to load prototype library. Defaults to TRUE
* @param boolean $loadScriptaculous specifies whether to load scriptaculous libraries. Defaults to FALSE
......@@ -74,17 +74,8 @@ class ContainerViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBacken
public function render($pageTitle = '', $enableJumpToUrl = TRUE, $enableClickMenu = TRUE, $loadPrototype = TRUE, $loadScriptaculous = FALSE, $scriptaculousModule = '', $loadExtJs = FALSE, $loadExtJsTheme = TRUE, $extJsAdapter = '', $enableExtJsDebug = FALSE, $addCssFiles = array(), $addJsFiles = array(), $triggers = array()) {
$doc = $this->getDocInstance();
$pageRenderer = $doc->getPageRenderer();
if ($enableJumpToUrl) {
$doc->JScode .= '
<script language="javascript" type="text/javascript">
script_ended = 0;
function jumpToUrl(URL) {
document.location = URL;
}
' . $doc->redirectUrls() . '
</script>
';
}
$doc->JScode .= $doc->wrapScriptTags($doc->redirectUrls());
if ($enableClickMenu) {
$doc->loadJavascriptLib('sysext/backend/Resources/Public/JavaScript/clickmenu.js');
}
......
......@@ -91,15 +91,6 @@ class ConfigurationView {
$this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
$this->doc->backPath = $BACK_PATH;
$this->doc->setModuleTemplate('EXT:lowlevel/Resources/Private/Templates/config.html');
// JavaScript
$this->doc->JScode = '
<script language="javascript" type="text/javascript">
script_ended = 0;
function jumpToUrl(URL) {
window.location.href = URL;
}
</script>
';
$this->doc->form = '<form action="" method="post">';
}
......
......@@ -94,15 +94,6 @@ class DatabaseIntegrityView {
$this->doc->backPath = $BACK_PATH;
$this->doc->setModuleTemplate('EXT:lowlevel/Resources/Private/Templates/dbint.html');
$this->doc->form = '<form action="" method="post" name="' . $this->formName . '">';
// JavaScript
$this->doc->JScode = '
<script language="javascript" type="text/javascript">
script_ended = 0;
function jumpToUrl(URL) {
window.location.href = URL;
}
</script>
';
$this->doc->table_TABLE = '<table class="t3-table">
<colgroup><col width="24"><col><col width="150"></colgroup>';
$this->doc->tableLayout = array(
......
......@@ -306,6 +306,8 @@ class ElementBrowser {
$this->setParams = $this->curUrlArray['params'] != '-' ? rawurlencode($this->curUrlArray['params']) : '';
// Finally, add the accumulated JavaScript to the template object:
// also unset the default jumpToUrl() function before
unset($this->doc->JScodeArray['jumpToUrl']);
$this->doc->JScode .= $this->doc->wrapScriptTags($this->getJSCode());
}
......
......@@ -352,10 +352,6 @@ class RecordList {
$listUrl = substr($dblist->listURL(), strlen($GLOBALS['BACK_PATH']));
// Add JavaScript functions to the page:
$this->doc->JScode = $this->doc->wrapScriptTags('
function jumpToUrl(URL) { //
window.location.href = URL;
return false;
}
function jumpExt(URL,anchor) { //
var anc = anchor?anchor:"";
window.location.href = URL+(T3_THIS_LOCATION?"&returnUrl="+T3_THIS_LOCATION:"")+anc;
......
......@@ -121,6 +121,8 @@ class BrowseLinks extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
// Add attributes to body tag. Note: getBodyTagAdditions will invoke the hooks
$this->doc->bodyTagAdditions = $this->getBodyTagAdditions();
// Adding RTE JS code
// also unset the default jumpToUrl() function before
unset($this->doc->JScodeArray['jumpToUrl']);
$this->doc->JScodeArray['rtehtmlarea'] = $this->getJSCode();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment