Class: Refinery::Admin::ImagesController
- Inherits:
-
Refinery::AdminController
- Object
- Refinery::AdminController
- Refinery::Admin::ImagesController
- Defined in:
- app/controllers/refinery/admin/images_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
-
#insert ⇒ Object
This renders the image insert dialog.
- #new ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/controllers/refinery/admin/images_controller.rb', line 40 def create @images = [] begin unless params[:image].present? and params[:image][:image].is_a?(Array) @images << (@image = ::Refinery::Image.create(params[:image])) else params[:image][:image].each do |image| @images << (@image = ::Refinery::Image.create({:image => image}.merge(params[:image].except(:image)))) end end rescue Dragonfly::FunctionManager::UnableToHandle logger.warn($!.) @image = ::Refinery::Image.new end unless params[:insert] if @images.all?(&:valid?) flash.notice = t('created', :scope => 'refinery.crudify', :what => "'#{@images.map(&:title).join("', '")}'") if from_dialog? @dialog_successful = true render :nothing => true, :layout => true else redirect_to refinery.admin_images_path end else self.new # important for dialogs render :action => 'new' end else # if all uploaded images are ok redirect page back to dialog, else show current page with error if @images.all?(&:valid?) @image_id = @image.id if @image.persisted? @image = nil end self.insert end end |
#insert ⇒ Object
This renders the image insert dialog
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/refinery/admin/images_controller.rb', line 19 def insert self.new if @image.nil? @url_override = refinery.admin_images_path(request.query_parameters.merge(:insert => true)) if params[:conditions].present? extra_condition = params[:conditions].split(',') extra_condition[1] = true if extra_condition[1] == "true" extra_condition[1] = false if extra_condition[1] == "false" extra_condition[1] = nil if extra_condition[1] == "nil" end find_all_images(({extra_condition[0] => extra_condition[1]} if extra_condition.present?)) search_all_images if searching? paginate_images render :action => "insert" end |
#new ⇒ Object
12 13 14 15 16 |
# File 'app/controllers/refinery/admin/images_controller.rb', line 12 def new @image = ::Refinery::Image.new if @image.nil? @url_override = refinery.admin_images_path(:dialog => from_dialog?) end |
#update ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/controllers/refinery/admin/images_controller.rb', line 79 def update attributes_before_assignment = @image.attributes @image.attributes = params[:image] if @image.valid? && @image.save flash.notice = t( 'refinery.crudify.updated', :what => "'#{@image.title}'" ) unless from_dialog? unless params[:continue_editing] =~ /true|on|1/ redirect_back_or_default refinery.admin_images_path else unless request.xhr? redirect_to :back else render :partial => '/refinery/message' end end else self.index @dialog_successful = true render :index end else @thumbnail = Image.find params[:id] unless request.xhr? render :action => 'edit' else render :partial => '/refinery/admin/error_messages', :locals => { :object => @image, :include_object_name => true } end end end |