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

Commit 930f397

Browse files
committed
Allow to switch between the page and file picker in TinyMCE (see #6974)
1 parent 76b898a commit 930f397

File tree

12 files changed

+73
-27
lines changed

12 files changed

+73
-27
lines changed

assets/contao/js/core-uncompressed.js

+19-16
Original file line numberDiff line numberDiff line change
@@ -856,8 +856,8 @@ var Backend =
856856
this.hide();
857857
});
858858
M.addButton(Contao.lang.apply, 'btn primary', function() {
859-
var val = [],
860-
frm = window.frames['simple-modal-iframe'];
859+
var frm = window.frames['simple-modal-iframe'],
860+
val = [], inp, i;
861861
if (frm === undefined) {
862862
alert('Could not find the SimpleModal frame');
863863
return;
@@ -866,8 +866,8 @@ var Backend =
866866
alert(Contao.lang.picker);
867867
return; // see #5704
868868
}
869-
var inp = frm.document.getElementById('tl_listing').getElementsByTagName('input');
870-
for (var i=0; i<inp.length; i++) {
869+
inp = frm.document.getElementById('tl_listing').getElementsByTagName('input');
870+
for (i=0; i<inp.length; i++) {
871871
if (!inp[i].checked || inp[i].id.match(/^check_all_/)) continue;
872872
if (!inp[i].id.match(/^reset_/)) val.push(inp[i].get('value'));
873873
}
@@ -910,6 +910,15 @@ var Backend =
910910
* @param {object} win The window object
911911
*/
912912
openModalBrowser: function(field_name, url, type, win) {
913+
var file = 'file.php',
914+
swtch = (type == 'file' ? '&amp;switch=1' : ''),
915+
isLink = (url.indexOf('{{link_url::') != -1);
916+
if (type == 'file' && (url == '' || isLink)) {
917+
file = 'page.php';
918+
}
919+
if (isLink) {
920+
url = url.replace(/^\{\{link_url::([0-9]+)\}\}$/, '$1');
921+
}
913922
var M = new SimpleModal({
914923
'width': 768,
915924
'btn_ok': Contao.lang.close,
@@ -922,34 +931,28 @@ var Backend =
922931
this.hide();
923932
});
924933
M.addButton(Contao.lang.apply, 'btn primary', function() {
925-
var frms = window.frames,
926-
frm, val, prev, i;
927-
for (i=0; i<frms.length; i++) {
928-
if (frms[i].name == 'simple-modal-iframe') {
929-
frm = frms[i];
930-
break;
931-
}
932-
}
933-
if (frm === null) {
934+
var frm = window.frames['simple-modal-iframe'],
935+
val, inp, i;
936+
if (frm === undefined) {
934937
alert('Could not find the SimpleModal frame');
935938
return;
936939
}
937-
var inp = frm.document.getElementById('tl_listing').getElementsByTagName('input');
940+
inp = frm.document.getElementById('tl_listing').getElementsByTagName('input');
938941
for (i=0; i<inp.length; i++) {
939942
if (inp[i].checked && !inp[i].id.match(/^reset_/)) {
940943
val = inp[i].get('value');
941944
break;
942945
}
943946
}
944-
if (type == 'file') {
947+
if (!isNaN(val)) {
945948
val = '{{link_url::' + val + '}}';
946949
}
947950
win.document.getElementById(field_name).value = val;
948951
this.hide();
949952
});
950953
M.show({
951954
'title': win.document.getElement('div.mce-title').get('text'),
952-
'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>',
955+
'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>',
953956
'model': 'modal'
954957
});
955958
},

assets/contao/js/core.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

system/docs/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Contao Open Source CMS changelog
44
Version 3.4.0-beta1 (2014-10-XX)
55
--------------------------------
66

7+
### Improved
8+
Allow to switch between the page and file picker in TinyMCE (see #6974).
9+
710
### Improved
811
Show a message if logging in is required to comment (see #7031).
912

system/modules/core/controllers/BackendFile.php

+6
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ public function run()
143143
$this->Template->managerHref = 'contao/main.php?do=files&amp;popup=1';
144144
$this->Template->breadcrumb = $GLOBALS['TL_DCA']['tl_files']['list']['sorting']['breadcrumb'];
145145

146+
if (\Input::get('switch'))
147+
{
148+
$this->Template->switch = $GLOBALS['TL_LANG']['MSC']['filePicker'];
149+
$this->Template->switchHref = str_replace('contao/file.php', 'contao/page.php', ampersand(\Environment::get('request')));
150+
}
151+
146152
\Config::set('debugMode', false);
147153
$this->Template->output();
148154
}

system/modules/core/controllers/BackendPage.php

+6
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ public function run()
133133
$this->Template->managerHref = 'contao/main.php?do=page&amp;popup=1';
134134
$this->Template->breadcrumb = $GLOBALS['TL_DCA']['tl_page']['list']['sorting']['breadcrumb'];
135135

136+
if (\Input::get('switch'))
137+
{
138+
$this->Template->switch = $GLOBALS['TL_LANG']['MSC']['pagePicker'];
139+
$this->Template->switchHref = str_replace('contao/page.php', 'contao/file.php', ampersand(\Environment::get('request')));
140+
}
141+
136142
\Config::set('debugMode', false);
137143
$this->Template->output();
138144
}

system/modules/core/languages/en/default.xlf

+6
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,12 @@ This e-mail has been generated by Contao. You can not reply to it directly.
12471247
<trans-unit id="MSC.resetSelected">
12481248
<source>Reset selection</source>
12491249
</trans-unit>
1250+
<trans-unit id="MSC.filePicker">
1251+
<source>Switch to file picker</source>
1252+
</trans-unit>
1253+
<trans-unit id="MSC.pagePicker">
1254+
<source>Switch to page picker</source>
1255+
</trans-unit>
12501256
<trans-unit id="MSC.fileManager">
12511257
<source>Open the file manager</source>
12521258
</trans-unit>

system/modules/core/templates/backend/be_picker.html5

+7-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,14 @@
3535

3636
<div id="container">
3737
<div id="main">
38-
<?php if ($this->managerHref): ?>
38+
<?php if ($this->managerHref || $this->switchHref): ?>
3939
<div id="manager">
40-
<a href="<?php echo $this->managerHref; ?>" class="open" title="<?php echo specialchars($this->manager); ?>"><?php echo $this->manager; ?></a>
40+
<?php if ($this->switchHref): ?>
41+
<a href="<?php echo $this->switchHref; ?>" class="open"><?php echo $this->switch; ?></a>
42+
<?php endif; ?>
43+
<?php if ($this->managerHref): ?>
44+
<a href="<?php echo $this->managerHref; ?>" class="open"><?php echo $this->manager; ?></a>
45+
<?php endif; ?>
4146
</div>
4247
<?php endif; ?>
4348
<?php if ($this->addSearch): ?>

system/modules/core/widgets/FileSelector.php

+17
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,23 @@ protected function convertValuesToPaths()
405405
$this->varValue = array();
406406
}
407407

408+
if (empty($this->varValue))
409+
{
410+
return;
411+
}
412+
413+
// TinyMCE will pass the path instead of the ID
414+
if (strncmp($this->varValue[0], \Config::get('uploadPath') . '/', strlen(\Config::get('uploadPath')) + 1) === 0)
415+
{
416+
return;
417+
}
418+
419+
// Ignore the numeric IDs when in switch mode (TinyMCE)
420+
if (\Input::get('switch'))
421+
{
422+
return;
423+
}
424+
408425
$objFiles = \FilesModel::findMultipleByIds($this->varValue);
409426

410427
if ($objFiles !== null)

system/themes/default/main.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

system/themes/default/src/main.css

+3-3
Original file line numberDiff line numberDiff line change
@@ -1138,11 +1138,11 @@ ul.sortable li:hover .dirname {
11381138
padding:3px 3px 4px;
11391139
}
11401140
#manager .open {
1141-
padding:2px 0 3px 20px;
1142-
background:url("images/manager.gif") left center no-repeat;
1141+
padding: 2px 15px 3px 20px;
1142+
background: url("images/manager.gif") left center no-repeat;
11431143
}
11441144
#manager .close {
1145-
padding:2px 0 3px 20px;
1145+
padding:2px 15px 3px 20px;
11461146
background:url("images/back.gif") left center no-repeat;
11471147
}
11481148
.ace_editor {

system/themes/flexible/main.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

system/themes/flexible/src/main.css

+3-3
Original file line numberDiff line numberDiff line change
@@ -1147,11 +1147,11 @@ ul.sortable li:hover .dirname {
11471147
padding:3px 3px 4px;
11481148
}
11491149
#manager .open {
1150-
padding:2px 0 3px 20px;
1151-
background:url("images/manager.gif") left center no-repeat;
1150+
padding: 2px 15px 3px 20px;
1151+
background: url("images/manager.gif") left center no-repeat;
11521152
}
11531153
#manager .close {
1154-
padding:2px 0 3px 20px;
1154+
padding:2px 15px 3px 20px;
11551155
background:url("images/back.gif") left center no-repeat;
11561156
}
11571157
.ace_editor {

0 commit comments

Comments
 (0)