1

Topic: Insert multiple files in one go

I have played with the standalone demo and want to know if its possible to insert more than one file at a time.
From the demo it looks like you can only insert one, which means i would need to open the filemanager for every file i want to insert.

Ideally, it would be good to insert multiple files by selecting them using the checkboxes, is this possible?

2

Re: Insert multiple files in one go

The file manager can insert multiple files. You will how ever get these files as an javascript object with path, url and so forth. So you need to handle the output and insert them to specific form elements your self but it's easy if you have basic JS skills. The imagemanager can only insert one image at the time.

Best regards,
Spocke - Main developer of TinyMCE

3

Re: Insert multiple files in one go

Great. I assume i need to use a callback.. could you point me in the direction of the wiki page which would help me through this?

4

Re: Insert multiple files in one go

It's kind of poorly documented. But check the last example on this page and it's source. One of the data properties contains all the selected files. You can use console.dir(data); to display it's contents if you use Firebug with Firefox. Or just ask me if you get stuck on it.

http://tinymce.moxiecode.com/examples_fm/example_03.php

Best regards,
Spocke - Main developer of TinyMCE

5

Re: Insert multiple files in one go

I am struggling in getting it to work, this is what i have so far:

<a href='javascript:mcFileManager.open("entryform","field_id_22","","",{remove_script_host:true , oninsert:customInsert });'>
    <img src='/img/insertfile.gif' border='0' style='margin-left:4px; position:relative; top:5px;' />
</a>

<script type="text/javascript">function customInsert(data) {alert('Focused file: ' + data.focusedFile.url + ", Size: " + data.focusedFile.size);}</script>

I get no js error or alert.

Is what i have done correct?

6

Re: Insert multiple files in one go

Figured it, needed to use .browse, not .open.

7

Re: Insert multiple files in one go

Yes, browse has replaced the old open method.

Best regards,
Spocke - Main developer of TinyMCE

8

Re: Insert multiple files in one go

If anyone else needs sample code (untested, but enought to get you started):

<script type="text/javascript">

    function customInsert(data) {
         console.dir(data); // used in firebug - very useful
         jQuery.each(data.files, function(){ // I used jquery, mpdify for your own needs
                        alert(this.url);           
         });
    }

</script>

And the link to open:

<a href='javascript:mcFileManager.browse({oninsert:customInsert});'>[BROWSE[</a>

9

Re: Insert multiple files in one go

Nice, thanks bohboh.

Best regards,
Spocke - Main developer of TinyMCE

10

Re: Insert multiple files in one go

Hi Spocke,

I have both the image and file managers, and have integrated them both as standalone modules and as part of the TinyMCE text editor. My problem occurs when the user inserts an image, which is launched with an oninsert: callback function. I want the user to be able to switch to file manager to take advantage of the multiple insert option, but when they do the callback function is "forgotten" so the dialog doesn't actually complete the insert process. If the user switches back to image manager then the insert callback does get triggered. Is there any way to pass the oninsert callback from one view to the other?

Thanks in advance!
Mike

11

Re: Insert multiple files in one go

And this happens on the latest version as well. Made some modifications to that.

Best regards,
Spocke - Main developer of TinyMCE