Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Allow to switch between the page and file picker in TinyMCE (see #6974)
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Sep 24, 2014
1 parent 76b898a commit 5e7299d
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 25 deletions.
35 changes: 19 additions & 16 deletions assets/contao/js/core-uncompressed.js
Expand Up @@ -856,8 +856,8 @@ var Backend =
this.hide();
});
M.addButton(Contao.lang.apply, 'btn primary', function() {
var val = [],
frm = window.frames['simple-modal-iframe'];
var frm = window.frames['simple-modal-iframe'],
val = [], inp, i;
if (frm === undefined) {
alert('Could not find the SimpleModal frame');
return;
Expand All @@ -866,8 +866,8 @@ var Backend =
alert(Contao.lang.picker);
return; // see #5704
}
var inp = frm.document.getElementById('tl_listing').getElementsByTagName('input');
for (var i=0; i<inp.length; i++) {
inp = frm.document.getElementById('tl_listing').getElementsByTagName('input');
for (i=0; i<inp.length; i++) {
if (!inp[i].checked || inp[i].id.match(/^check_all_/)) continue;
if (!inp[i].id.match(/^reset_/)) val.push(inp[i].get('value'));
}
Expand Down Expand Up @@ -910,6 +910,15 @@ var Backend =
* @param {object} win The window object
*/
openModalBrowser: function(field_name, url, type, win) {
var file = 'file.php',
swtch = (type == 'file' ? '&amp;switch=1' : ''),
isLink = (url.indexOf('{{link_url::') != -1);
if (type == 'file' && (url == '' || isLink)) {
file = 'page.php';
}
if (isLink) {
url = url.replace(/^\{\{link_url::([0-9]+)\}\}$/, '$1');
}
var M = new SimpleModal({
'width': 768,
'btn_ok': Contao.lang.close,
Expand All @@ -922,34 +931,28 @@ var Backend =
this.hide();
});
M.addButton(Contao.lang.apply, 'btn primary', function() {
var frms = window.frames,
frm, val, prev, i;
for (i=0; i<frms.length; i++) {
if (frms[i].name == 'simple-modal-iframe') {
frm = frms[i];
break;
}
}
if (frm === null) {
var frm = window.frames['simple-modal-iframe'],
val, inp, i;
if (frm === undefined) {
alert('Could not find the SimpleModal frame');
return;
}
var inp = frm.document.getElementById('tl_listing').getElementsByTagName('input');
inp = frm.document.getElementById('tl_listing').getElementsByTagName('input');
for (i=0; i<inp.length; i++) {
if (inp[i].checked && !inp[i].id.match(/^reset_/)) {
val = inp[i].get('value');
break;
}
}
if (type == 'file') {
if (!isNaN(val)) {
val = '{{link_url::' + val + '}}';
}
win.document.getElementById(field_name).value = val;
this.hide();
});
M.show({
'title': win.document.getElement('div.mce-title').get('text'),
'contents': '<iframe src="contao/' + ((type == 'file') ? 'page.php' : 'file.php') + '?table=tl_content&amp;field=singleSRC&amp;value=' + ((type == 'file') ? url.replace('{{link_url::', '').replace('}}', '') : url) + '" name="simple-modal-iframe" width="100%" height="' + (window.getSize().y-180).toInt() + '" frameborder="0"></iframe>',
'contents': '<iframe src="contao/' + file + '?table=tl_content&amp;field=singleSRC&amp;value=' + url + swtch + '" name="simple-modal-iframe" width="100%" height="' + (window.getSize().y-180).toInt() + '" frameborder="0"></iframe>',
'model': 'modal'
});
},
Expand Down
2 changes: 1 addition & 1 deletion assets/contao/js/core.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions system/docs/CHANGELOG.md
Expand Up @@ -4,6 +4,9 @@ Contao Open Source CMS changelog
Version 3.4.0-beta1 (2014-10-XX)
--------------------------------

### Improved
Allow to switch between the page and file picker in TinyMCE (see #6974).

### Improved
Show a message if logging in is required to comment (see #7031).

Expand Down
6 changes: 6 additions & 0 deletions system/modules/core/controllers/BackendFile.php
Expand Up @@ -143,6 +143,12 @@ public function run()
$this->Template->managerHref = 'contao/main.php?do=files&amp;popup=1';
$this->Template->breadcrumb = $GLOBALS['TL_DCA']['tl_files']['list']['sorting']['breadcrumb'];

if (\Input::get('switch'))
{
$this->Template->switch = $GLOBALS['TL_LANG']['MSC']['filePicker'];
$this->Template->switchHref = str_replace('contao/file.php', 'contao/page.php', ampersand(\Environment::get('request')));
}

\Config::set('debugMode', false);
$this->Template->output();
}
Expand Down
6 changes: 6 additions & 0 deletions system/modules/core/controllers/BackendPage.php
Expand Up @@ -133,6 +133,12 @@ public function run()
$this->Template->managerHref = 'contao/main.php?do=page&amp;popup=1';
$this->Template->breadcrumb = $GLOBALS['TL_DCA']['tl_page']['list']['sorting']['breadcrumb'];

if (\Input::get('switch'))
{
$this->Template->switch = $GLOBALS['TL_LANG']['MSC']['pagePicker'];
$this->Template->switchHref = str_replace('contao/page.php', 'contao/file.php', ampersand(\Environment::get('request')));
}

\Config::set('debugMode', false);
$this->Template->output();
}
Expand Down
6 changes: 6 additions & 0 deletions system/modules/core/languages/en/default.xlf
Expand Up @@ -1247,6 +1247,12 @@ This e-mail has been generated by Contao. You can not reply to it directly.
<trans-unit id="MSC.resetSelected">
<source>Reset selection</source>
</trans-unit>
<trans-unit id="MSC.filePicker">
<source>Switch to file picker</source>
</trans-unit>
<trans-unit id="MSC.pagePicker">
<source>Switch to page picker</source>
</trans-unit>
<trans-unit id="MSC.fileManager">
<source>Open the file manager</source>
</trans-unit>
Expand Down
9 changes: 7 additions & 2 deletions system/modules/core/templates/backend/be_picker.html5
Expand Up @@ -35,9 +35,14 @@

<div id="container">
<div id="main">
<?php if ($this->managerHref): ?>
<?php if ($this->managerHref || $this->switchHref): ?>
<div id="manager">
<a href="<?php echo $this->managerHref; ?>" class="open" title="<?php echo specialchars($this->manager); ?>"><?php echo $this->manager; ?></a>
<?php if ($this->switchHref): ?>
<a href="<?php echo $this->switchHref; ?>" class="open"><?php echo $this->switch; ?></a>
<?php endif; ?>
<?php if ($this->managerHref): ?>
<a href="<?php echo $this->managerHref; ?>" class="open"><?php echo $this->manager; ?></a>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ($this->addSearch): ?>
Expand Down
17 changes: 17 additions & 0 deletions system/modules/core/widgets/FileSelector.php
Expand Up @@ -405,6 +405,23 @@ protected function convertValuesToPaths()
$this->varValue = array();
}

if (empty($this->varValue))
{
return;
}

// TinyMCE will pass the path instead of the ID
if (strncmp($this->varValue[0], \Config::get('uploadPath') . '/', strlen(\Config::get('uploadPath')) + 1) === 0)
{
return;
}

// Ignore the numeric IDs when in switch mode (TinyMCE)
if (\Input::get('switch'))
{
return;
}

$objFiles = \FilesModel::findMultipleByIds($this->varValue);

if ($objFiles !== null)
Expand Down
2 changes: 1 addition & 1 deletion system/themes/default/main.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions system/themes/default/src/main.css
Expand Up @@ -1138,11 +1138,11 @@ ul.sortable li:hover .dirname {
padding:3px 3px 4px;
}
#manager .open {
padding:2px 0 3px 20px;
padding:2px 15px 3px 20px;
background:url("images/manager.gif") left center no-repeat;
}
#manager .close {
padding:2px 0 3px 20px;
padding:2px 15px 3px 20px;
background:url("images/back.gif") left center no-repeat;
}
.ace_editor {
Expand Down
2 changes: 1 addition & 1 deletion system/themes/flexible/main.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions system/themes/flexible/src/main.css
Expand Up @@ -1147,11 +1147,11 @@ ul.sortable li:hover .dirname {
padding:3px 3px 4px;
}
#manager .open {
padding:2px 0 3px 20px;
padding:2px 15px 3px 20px;
background:url("images/manager.gif") left center no-repeat;
}
#manager .close {
padding:2px 0 3px 20px;
padding:2px 15px 3px 20px;
background:url("images/back.gif") left center no-repeat;
}
.ace_editor {
Expand Down

0 comments on commit 5e7299d

Please sign in to comment.