Skip to content

Commit

Permalink
[WIP] fix media_set parents display and popup
Browse files Browse the repository at this point in the history
  • Loading branch information
Franco Sellitto committed May 10, 2012
1 parent 11df04d commit 066a901
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 57 deletions.
32 changes: 14 additions & 18 deletions app/assets/javascripts/mediaset-popup/mediaset-popup.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,18 @@ load_children = (target)->
console.log "ERROR LOADING"
data:
with:
media_set:
media_resources:
type: true
image:
as:"base64"
size:"small"
children: true
image:
as:"base64"
size:"small"
type: "GET"

load_parents = (target)->
if $(target).data("loaded_parents")?
setup_parents(target, $(target).data("loaded_parents"))
else
$.ajax
url: "/media_sets/"+target.tmplItem().data.id+".json"
url: "/media_resources/"+target.tmplItem().data.id+".json"
beforeSend: (request, settings) ->
#before
success: (data, status, request) ->
Expand All @@ -75,22 +73,20 @@ load_parents = (target)->
console.log "ERROR LOADING"
data:
with:
media_set:
parent_sets:
type: true
image:
as:"base64"
size:"small"
parents: true
image:
as:"base64"
size:"small"
type: "GET"

setup_children = (target, data)->
if $(target).data("popup")?
# remove loading
$($(target).data("popup")).find(".children .loading").remove()
# setup resources
media_entries = (resource for resource in data.media_resources when resource.type is "media_entry")
media_sets = (resource for resource in data.media_resources when resource.type is "media_set")
resources = data.media_resources[0...6]
media_entries = (resource for resource in data.children when resource.type is "media_entry")
media_sets = (resource for resource in data.children when resource.type is "media_set")
resources = data.children[0...6]
displayed_media_entries = (resource for resource in resources when resource.type is "media_entry")
displayed_media_sets = (resource for resource in resources when resource.type is "media_set")
for resource in resources
Expand All @@ -106,14 +102,14 @@ setup_parents = (target, data)->
# remove loading
$($(target).data("popup")).find(".parents .loading").remove()
# setup resources
resources = data.parent_sets[0...3]
resources = data.parents[0...3]
displayed_media_sets = (resource for resource in resources when resource.type is "media_set")
for resource in resources
do (resource) ->
$($(target).data("popup")).find(".parents").append $.tmpl("tmpl/mediaset-popup/resource", resource)
# setup text
$($(target).data("popup")).find(".parents").append $("<div class='text'></div>")
if resources? then $($(target).data("popup")).find(".parents .text").append("<p>"+(data.parent_sets.length-displayed_media_sets.length)+" weitere Sets</p>")
if resources? then $($(target).data("popup")).find(".parents .text").append("<p>"+(data.parents.length-displayed_media_sets.length)+" weitere Sets</p>")

open_popup = (target)->
# close all other mediaset popups
Expand Down
1 change: 1 addition & 0 deletions app/controllers/media_sets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def show(with = params[:with],
paginate({:page => page, :per_page => per_page})

@can_edit_set = current_user.authorized?(:edit, @media_set)
@parents = @media_set.parent_sets.accessible_by_user(current_user)
@pagination = { :page => resources.current_page,
:per_page => resources.per_page,
:total => resources.total_entries,
Expand Down
35 changes: 1 addition & 34 deletions app/views/media_sets/_show.json.rjson
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,4 @@ if (with || nil)
end
end

=begin
[:id, :user_id, :created_at, :updated_at].each do |k|
h[k] = @media_set.send(k)
end

h[:owner_id] = @media_set.user_id

h[:media_entries] = @media_entries.map do |media_entry|
render :partial => "media_entries/show.json.rjson", :locals => {:media_entry => media_entry}
end

###############################################################

json[:is_set] = true # TODO use :type instead of :is_set # TODO drop as default
if(with = options[:with])
if(with[:media_set] and with[:media_set].is_a?(Hash))
if with[:media_set].has_key?(:child_sets) and (with[:media_set][:child_sets].is_a?(Hash) or not with[:media_set][:child_sets].to_i.zero?)
json[:child_sets] = child_sets.accessible_by_user(options[:current_user]).as_json(:with => {:media_set => with[:media_set][:media_sets]})
end
if with[:media_set].has_key?(:parent_sets) and (with[:media_set][:parent_sets].is_a?(Hash) or not with[:media_set][:parent_sets].to_i.zero?)
json[:parent_sets] = parent_sets.accessible_by_user(options[:current_user]).as_json({:with => {:media_set => with[:media_set][:parent_sets]}}.merge(:current_user => options[:current_user]))
end
if with[:media_set].has_key?(:media_entries) and (with[:media_set][:media_entries].is_a?(Hash) or not with[:media_set][:media_entries].to_i.zero?)
json[:media_entries] = media_entries.accessible_by_user(options[:current_user]).as_json(:with => {:media_entry => with[:media_set][:media_entries]})
end
# child media_resources


end
end

=end

h
h
4 changes: 2 additions & 2 deletions app/views/media_sets/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
.inner
.media_set_highlights_shadow.left
.media_set_highlights_shadow.right
- unless (@parents = @media_set.parent_sets).empty?
- unless @parents.empty?
%div.page_title_left.set_parents_title
.icon_set_parents
= _("Set enthalten in")
Expand All @@ -99,7 +99,7 @@
= render :partial => "media_entries/index"

:ruby
with = {:type => true,
with = {:media_type => true,
:image=>{:as=>"base64", :size=>"large"},
:meta_data => {:meta_context_names => ["core"]}}

Expand Down
4 changes: 1 addition & 3 deletions app/views/upload/set_media_sets.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

:javascript
$(document).ready(function () {
json = #{begin
@media_entries.as_json(user: current_user, with_thumb: true, with: {media_resource: {type: 1, image:{as:"base64"}}})
end.to_json}
json = #{@media_entries.as_json(user: current_user, with_thumb: true, with: {media_resource: {type: 1, image:{as:"base64"}}}).to_json}
$("#results").html($.tmpl("tmpl/media_resource/image", json));
});

0 comments on commit 066a901

Please sign in to comment.