Sha256: d1485cc8caa8e4ed6e887c9e19870b78e96c1bbad09869ac267c0cc0349053d9

Contents?: true

Size: 1.07 KB

Versions: 21

Compression:

Stored size: 1.07 KB

Contents

require_dependency "push_type/admin_controller"

module PushType
  class WysiwygMediaController < AdminController

    before_filter :load_assets, only: :index
    before_filter :build_asset, only: :create

    def index
      respond_to do |format|
        format.json { render json: view_context.wysiwyg_assets_hash(@assets) }
      end
    end

    def create
      respond_to do |format|
        format.json { render json: create_asset }
        # For IE9
        format.html { render text: create_asset.to_json }
      end
    end

    private

    def load_assets
      query = PushType::Asset.not_trash.page(params[:page]).per(12)
      @assets = params[:filter] == 'image' ? query.image : query.not_image
    end

    def build_asset
      @asset = PushType::Asset.new asset_params.merge(uploader: push_type_user)
    end

    def create_asset
      if @asset.save
        { link: main_app.media_url(@asset.file_uid) }
      else
        { error: @asset.errors.full_messages.first }
      end
    end

    def asset_params
      params.fetch(:asset, {}).permit(:file)
    end

  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
push_type_wysiwyg-0.7.0 app/controllers/push_type/wysiwyg_media_controller.rb
push_type_wysiwyg-0.7.0.beta.1 app/controllers/push_type/wysiwyg_media_controller.rb
push_type_wysiwyg-0.6.0 app/controllers/push_type/wysiwyg_media_controller.rb
push_type_wysiwyg-0.6.0.beta.4 app/controllers/push_type/wysiwyg_media_controller.rb
push_type_wysiwyg-0.6.0.beta.3 app/controllers/push_type/wysiwyg_media_controller.rb
push_type_wysiwyg-0.6.0.beta.2 app/controllers/push_type/wysiwyg_media_controller.rb
push_type_wysiwyg-0.6.0.beta.1 app/controllers/push_type/wysiwyg_media_controller.rb
push_type_wysiwyg-0.5.3 app/controllers/push_type/wysiwyg_media_controller.rb
push_type_wysiwyg-0.5.2 app/controllers/push_type/wysiwyg_media_controller.rb
push_type_wysiwyg-0.5.1 app/controllers/push_type/wysiwyg_media_controller.rb
push_type_wysiwyg-0.5.0 app/controllers/push_type/wysiwyg_media_controller.rb
push_type_wysiwyg-0.5.0.alpha.5 app/controllers/push_type/wysiwyg_media_controller.rb
push_type_wysiwyg-0.5.0.alpha.4 app/controllers/push_type/wysiwyg_media_controller.rb
push_type_wysiwyg-0.5.0.alpha.3 app/controllers/push_type/wysiwyg_media_controller.rb
push_type_wysiwyg-0.5.0.alpha.2 app/controllers/push_type/wysiwyg_media_controller.rb
push_type_wysiwyg-0.5.0.alpha.1 app/controllers/push_type/wysiwyg_media_controller.rb
push_type_wysiwyg-0.4.0 app/controllers/push_type/wysiwyg_media_controller.rb
push_type_wysiwyg-0.4.0.beta.3 app/controllers/push_type/wysiwyg_media_controller.rb
push_type_wysiwyg-0.3.3 app/controllers/push_type/wysiwyg_media_controller.rb
push_type_wysiwyg-0.3.1 app/controllers/push_type/wysiwyg_media_controller.rb