Uploads Many & RowReorder
Uploads Many & RowReorder
What is the best method to allow a user to reorder multiple uploads? I think it cannot be done in the 'create' or 'edit' form, which would be the best solution I think?
If that is the case would it be best to create a separate datatable view of just the uploads linked to that item and in that table enable the RowReorder plugin?
I am using a link table for my one-to-many join which currently just has two columns, the file identifier and the identifier of the item the file is linked too. Is the appropriate place for a position column in this link table too? So my link table structure would be; position, file_id, linked_item_id
Any thoughts gratefully received.
Thanks
Chris
This question has an accepted answers - jump to answer
Answers
Exactly that.
Ideally yes, the order should be in the link table, but the Editor libraries don't currently play particularly well with other meta data in the link table - they expect just the two pieces of link information. It will delete and create new rows for an edit which causes any meta information to be lost.
The other option is to create or modify the upload plug-in to allow items to rearranged, although to be honest I think that might be fairly tricky to do.
I fear that this one is on the boundary, or just past it, of what the libraries can currently do without a fair amount of alteration.
Allan
So, effectively using a link table does not allow for reordering.
If I remove the link table and do a direct link one-to-many join to a 'files' table and introduce the 'position' column into the directly linked 'files' table will that work better?
I think the user will still be able to do an 'uploads many' from the main 'create / edit' form but if the user wants to reorder the photos I will need to show them a separate datatable which has just the linked photos and RowReorder enabled. In fact if the user wanted to add any additional image specific information, i.e. alt tag or caption, then the data would have to be editable in the image specific child datatable only?
Would that work?
Yes, that would work - the downside is that it wouldn't be possible to reuse the same photo in multiple parent rows (which is the benefit of the link table).
This is without question a limitation in the software at the moment I'm afraid. Meta data just isn't well handled in the link tables.
Allan
Thanks for your reply Allan.
Maybe another option could be to introduce a third table which holds the Meta data on a per file relationship level, i.e. the same file could have different Meta data for each relationship it has in a link table. However, not sure how I would do this right now or if it is even possible, would need to give the structure some thought.
Thanks
Hi Allan. Seems this does not work or I do not have the correct code. When I use a link table the value in the column
iChaletId
is inserted correctly. However, when I use a direct link I thought I could use the same column in the 't_file' table. However, it doesn't get updated. Is that normal behaviour?Thanks
Chris
The table used for the files in the
Upload->db()
shouldn't be used as the Editor table as well. The reason for that is that the file upload is async to the rest of the form, so the file information will already have been written to the database. If you then try to create another row on that same table, the database structure is going to go badly wrong.Have a table just for the file meta information only.
Allan
I have implemented the following solution, for anyone interested or in a similar situation. I didn't have a requirement to be able to reuse the same image multiple times so I could attach position (i.e. the order) directly to the file in the files table.
I noticed that the
rowReorder
plugin does not require the position value to be an exact count from X to Y. I.e. if you have 3 items to reorder you do not need to have positions 1, 2 and 3. If the position values are unique and incremental it does not seem to matter what the gap is between them. So, for example with 3 items to reorder you could have position values 45, 109 and 1005.So I decided the easiest way to implement
rowReorder
without the need for any additionalpostUpload
,postRemove
, etc... code was to simply use a timestamp as the position value like so:That way a unique, incremental value for position automatically gets generated when the file is uploaded using the multi-upload method without any post processing.
If the user wants to reorder the files then they click a custom button within the table which loads a second datatable view showing just the files with the
rowReorder
plugin enabled allowing the user to reorder to the files.I have a very small number of users who have access to add files so for me it is extremely unlikely two users would be uploading images for the same parent item at exactly the same second so
time()
should provide enough uniqueness for me.