Yes, it is probably the easiest way for a developer. But because of certain reasons I don’t want to use this method.
There must be a way how to use File manager in modules...
When I include a default RTE to the page in a way described here
http://modxcms.com/forums/index.php/topic,6450.msg87778.html#msg87778 and prepend it with some javascript needed by File manager my code looks like this:
echo '<script type="text/javascript">var modVariables = [];
function setVariableModified(fieldName){
var i, isDirty, mv = modVariables;
for(i=0;i<mv.length;i++){
if (mv[i]==fieldName) {
isDirty=true;
}
}
if (!isDirty) {
mv[mv.length]=fieldName;
var f = document.forms[\'mutate\'];
f.variablesmodified.value=mv.join(",");
}
}
function setLink(lId) {
if (!allowLinkSelection) {
window.location.href="index.php?a=3&id="+lId;
return;
}
else {
documentDirty=true;
document.mutate.ta.value=lId;
}
}
// END ADDED BY S BRENNAN
// Added for RTE selection
function changeRTE(){
var whichEditor = document.getElementById(\'which_editor\');
if (whichEditor){
for (var i=0; i<whichEditor.length; i++){
if (whichEditor[i].selected){
newEditor = whichEditor[i].value;
break;
}
}
}
var dropTemplate = document.getElementById(\'template\');
if (dropTemplate){
for (var i=0; i<dropTemplate.length; i++){
if (dropTemplate[i].selected){
newTemplate = dropTemplate[i].value;
break;
}
}
}
documentDirty=false;
document.mutate.a.value = 27;
document.mutate.newtemplate.value = newTemplate;
document.mutate.which_editor.value = newEditor;
document.mutate.submit();
}
function resetParameters() {
document.mutate.params.value = "";
lastmod[lastsp]="";
showParameters();
}
</script>';
include_once($modx->config['base_path'].'manager/includes/tmplvars.inc.php');
$event_output = $modx->invokeEvent("OnRichTextEditorInit", array('editor'=>$modx->config['which_editor'], 'elements'=>array('tvmailMessage')));
if(is_array($event_output)) {
$editor_html = implode("",$event_output);
}
// Get HTML for the textarea, last parameters are default_value, elements, value
$rte_html = renderFormElement('richtext', 'mailMessage', '', '', $newsletter);
echo $rte_html;
echo $editor_html;
// MY MOD: renders input field and button
echo renderFormElement('image', 'product_main_img', '', '', '', '');
When clicking on the button, File manager loads properly, I can go through all folders and can see the files. But when trying to insert a file by clicking on it I get the following error in FireBug:
document.mutate has no properties
var c = document.mutate[lastImageCtrl];
index.php (line 171)
Does anybody know how to correct it so it could insert the image’s address into the input field?