Class: Occams::Admin::Cms::FilesController
- Inherits:
-
BaseController
- Object
- BaseController
- Occams::Admin::Cms::FilesController
- Includes:
- ActionView::Helpers::NumberHelper, ReorderAction
- Defined in:
- app/controllers/occams/admin/cms/files_controller.rb
Instance Method Summary collapse
Methods included from ReorderAction
Instance Method Details
#create ⇒ Object
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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/controllers/occams/admin/cms/files_controller.rb', line 53 def create categories_scope = @site.categories.of_type('Occams::Cms::File') if params[:categories] ids = categories_scope.where(label: params[:categories]).pluck(:id) @file.category_ids = ids end # Automatically tagging upload if it's done through redactor if params[:source] == 'redactor' category = categories_scope.find_or_create_by(label: 'wysiwyg') @file.category_ids = [category.id] end @file.save! case params[:source] when 'plupload' render partial: 'file', object: @file when 'redactor' render json: { filelink: url_for(@file.), filename: @file..filename } else flash[:success] = I18n.t('occams.admin.cms.files.created') redirect_to action: :edit, id: @file end rescue ActiveRecord::RecordInvalid case params[:source] when 'plupload' render body: @file.errors..to_sentence, status: :unprocessable_entity when 'redactor' render body: nil, status: :unprocessable_entity else flash.now[:danger] = I18n.t('occams.admin.cms.files.creation_failure') render action: :new end end |
#destroy ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'app/controllers/occams/admin/cms/files_controller.rb', line 107 def destroy @file.destroy respond_to do |format| format.js format.html do flash[:success] = I18n.t('occams.admin.cms.files.deleted') redirect_to action: :index end end end |
#edit ⇒ Object
93 94 95 |
# File 'app/controllers/occams/admin/cms/files_controller.rb', line 93 def edit render end |
#index ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/occams/admin/cms/files_controller.rb', line 13 def index files_scope = @site.files. case params[:source] # Integration with Redactor 1.0 Wysiwyg when 'redactor' file_scope = files_scope.limit(100).order(:position) file_hashes = case params[:type] when 'image' file_scope.with_images.collect do |file| { thumb: url_for(file..variant(combine_options: Occams::Cms::File::VARIANT_SIZE[:redactor])), image: url_for(file.), title: file.label } end else file_scope.collect do |file| { title: file.label, name: file..filename, link: url_for(file.), size: number_to_human_size(file..byte_size) } end end render json: file_hashes else files_scope = files_scope .includes(:categories) .for_category(params[:categories]) .order('occams_cms_files.position') @files = occams_paginate(files_scope, per_page: 50) end end |
#new ⇒ Object
49 50 51 |
# File 'app/controllers/occams/admin/cms/files_controller.rb', line 49 def new render end |
#update ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'app/controllers/occams/admin/cms/files_controller.rb', line 97 def update if @file.update(file_params) flash[:success] = I18n.t('occams.admin.cms.files.updated') redirect_to action: :edit, id: @file else flash.now[:danger] = I18n.t('occams.admin.cms.files.update_failure') render action: :edit end end |