Opened 12 years ago
Closed 11 years ago
#24753 closed defect (bug) (fixed)
Create Gallery Page Shows Wrong Selection
Reported by: | miqrogroove | Owned by: | markjaquith |
---|---|---|---|
Milestone: | 3.6 | Priority: | normal |
Severity: | normal | Version: | 3.6 |
Component: | Media | Keywords: | has-patch needs-testing |
Focuses: | Cc: |
Description
In 3.6 RC1:
- Click the Add Media button on the dashboard.
- Click one of the images on the Insert Media modal page.
- Click "Create Gallery".
- Click another image.
Expected behavior:
The two images in the selection should appear to be selected
Actual behavior:
There are two images in the selection at the bottom of the window, but only one image appears to be selected.
When clicking the other image, nothing happens. Only the images other than the one originally selected can be added to or removed from the gallery.
If you click the "Create a new gallery" button and then click "Add to Gallery", that first-selected image appears as an available image, as though it hasn't been added to the gallery already.
Attachments (3)
Change History (11)
#5
@
11 years ago
- Owner set to markjaquith
- Resolution set to fixed
- Status changed from new to closed
In 24771:
#7
@
11 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Just found out that the patch I submitted introduced a few sub-optimal operations. This is just a really minor issue.
Basically attachment.get() is called all the time (because attrs needs to be parsed before comparison with attachment.attributes). Apologies!
Attached is a fix for this. Hope it's not too late.
I can confirm that this is a regression, introduced by [24110].
[24110] was not an appropriate fix for #24094.
The rationale behind removing
parse()
for Attachments collection was incorrect (I'm quoting):Getting fetch responses will cause Backbone.Collection to run the responses through
Collection._prepareModel()
, which will:Model.parse()
.So in
Attachments.parse()
, we're getting a Model object out of the response by fetching a complete model out of theAttachments.all
cache (by callingAttachment.get()
). So repeated calls toAttachments.parse()
was not caused here.The reason why
Attachments.parse()
was there was to prevent new Model objects from being created unnecessarily! Removing that creates this regression where each view has their own attachment models pointing to the same attachment in the database (same post_IDs but differentcid
), which causes this unexpected UI behavior (because throughoutmedia-views.js
, we're comparing models betweenViews
andSelection
using===
, which implies thecid
must match as well).The original issue with blank item in #24094 was caused by these changes in Backbone JS 1.0.0:
sync
will be triggered automatically after fetch success, anderror
will be triggered automatically after fetch error. See this diff:https://github.com/jashkenas/backbone/compare/0.9.10...1.0.0#L6R436
Collection.add()
is now a wrapper forCollection.set()
, which basically replacesCollection.update()
in 0.9.10 as well. The difference is,Attachments.parse()
should expect to be passed in these kinds of value, besides an array of non-Model JSON objects:The original bug in #24094 was caused because
Attachments.parse()
did not take into account the fact that it can be passed a single Model (not an array), so the_.map()
call inside it will pick apart that single Model's attributes and cause anundefined
variable to be added to the collection (which explains for the blank second item in the Media grid).Removing
Attachments.parse()
in [24110], in turn, caused this regression, where Attachments.all is now basically useless. Each view will now has duplicates of the same Model, but with differentcid
. As a result, you can't deselect / select an item that has already been selected in a different view.The solution for this would be (at least to preserve the original behavior before [24110]:
bindSyncEvents()
as this is not necessary any more.Attachments.parse()
function, but this time makes sure it accounts for the single Model argument.I'm sorry if this comment sounds cryptic, but it is indeed a very complicated issue. I'm sure Koopersmith will understand what I mean though, and will be able to provide a much easier to understand explanation :)
Working on a patch for this.