General developer forum

Can JS find out when a file has been added in a filemanager?

 
Picture of Dave Balch
Can JS find out when a file has been added in a filemanager?
Core developersParticularly helpful MoodlersPlugin developers

Hi,

I'm trying to build a mod where the user adds a file using a filemanager widget, which is then immediately used on the page via Javascript.

Currently I have a form with a filemanager, and a button for the user to press; they DnD an image file, then press the button (which runs JS to: look at the filemanager form field, fetch the draft file path and image size, then load it onto the page in a JS widget).

Currently I don't know when a file is added, so they could press the button when there's no file available. I'd like to avoid this - and ideally avoid the user having to press the button at all. I'm hoping the filemanager can fire a JS event (or maybe run a callback) when a file is added - but I can't find any support for this.

My searching for existing info on this only turned up https://moodle.org/mod/forum/discuss.php?d=313972

Any suggestions on how to approach this?

Cheers,
Dave.

 
Average of ratings: -
Picture of Darko Miletić
Re: Can JS find out when a file has been added in a filemanager?
Core developersParticularly helpful Moodlers

The only way to get this behavior would be to add new event fired whenever a file was added to the system. With such an event in place you could create a custom plug-in with listener that would in turn fire whatever JavaScript thing you want.


 
Average of ratings: -
Picture of Dave Balch
Re: Can JS find out when a file has been added in a filemanager?
Core developersParticularly helpful MoodlersPlugin developers

Thanks for the reply.

> add new event fired whenever a file was added to the system

Ok, I thought that would be the approach to take, but just to clarify: do you mean by modifying the core filemanager code?

 
Average of ratings: -
Picture of Darko Miletić
Re: Can JS find out when a file has been added in a filemanager?
Core developersParticularly helpful Moodlers

Yes. You need to modify the core.

 
Average of ratings: Useful (1)
Picture of Dave Balch
Re: Can JS find out when a file has been added in a filemanager?
Core developersParticularly helpful MoodlersPlugin developers

Thanks for the confirmation smile

 
Average of ratings: -