|
class Admin::ArtworksController < Admin::AdminController
|
|
simple_rest_support
|
|
|
|
before_filter :load_form_data, :only => [:new, :create, :edit, :update]
|
|
before_filter :load_data, :only => [:index]
|
|
|
|
SELECTION_ACTION_LIST = [[_('Associate with Tag'), 'associate_with_tag'], [_('Delete'), 'delete']]
|
|
|
|
def artworks_selection
|
|
if Hash[SELECTION_ACTION_LIST].values.include? params['artworks_selection_action']
|
|
@action = "selection_" + params['artworks_selection_action']
|
|
|
|
artworks_ids = params['artworks_selection_ids'].collect {|x| x.to_i }
|
|
@selection = Artwork.find(artworks_ids)
|
|
|
|
render :action => @action
|
|
else
|
|
render_404
|
|
end
|
|
end
|
|
|
|
def selection_associate_with_tag
|
|
artwork_list = params['artworks_selection_ids'].collect {|x| Artwork.find(x.to_i) }
|
|
tag_list = params['tags_selection_ids'].collect {|x| Tag.find(x.to_i) }
|
|
|
|
artwork_list.each do |artwork|
|
|
artwork.tags += tag_list
|
|
end
|
|
|
|
redirect_to :action => "index"
|
|
end
|
|
|
|
def search
|
|
find_model(true)
|
|
|
|
if params[:action] == "search" and not params[:search_pattern].blank?
|
|
load_data([ "title LIKE ?", "%#{params[:search_pattern]}%"])
|
|
flash[:notice] = _("Nothing found") if @artworks.empty?
|
|
else
|
|
flash[:warning] = _("Empty search pattern !")
|
|
load_data
|
|
end
|
|
render :action => 'index'
|
|
end
|
|
|
|
protected
|
|
|
|
private
|
|
|
|
def load_data(conditions = [])
|
|
# work around 'sortable-list' plugin not enforcing default sort
|
|
params[:sort] ||= "title ASC"
|
|
|
|
@artworks = resource_model.paginate(:all, :conditions => conditions, :include => [:artwork_set, :artwork_group], :order => params[:sort], :page => params[:page])
|
|
@selection_action_list = SELECTION_ACTION_LIST
|
|
end
|
|
|
|
def load_form_data
|
|
@artwork_sets = ArtworkSet.find(:all, :order => "name ASC")
|
|
@artwork_materials = ArtworkMaterial.find(:all, :order => "name ASC")
|
|
@artwork_conditions = ArtworkCondition.find(:all, :order => "position ASC")
|
|
@artwork_placement_reasons = ArtworkPlacementReason.find(:all, :order => "name ASC")
|
|
@artwork_supports = ArtworkSupport.find(:all, :order => "name ASC")
|
|
@tags = Tag.find(:all, :order => "name ASC")
|
|
end
|
|
end
|