Class: Caboose::BlockTypeSourcesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Caboose::BlockTypeSourcesController
- Defined in:
- app/controllers/caboose/block_type_sources_controller.rb
Instance Method Summary collapse
-
#admin_create ⇒ Object
POST /admin/block-type-sources.
-
#admin_delete ⇒ Object
DELETE /admin/block-type-sources/:id.
-
#admin_edit ⇒ Object
GET /admin/block-type-sources/:id.
-
#admin_index ⇒ Object
GET /admin/block-type-sources.
-
#admin_new ⇒ Object
GET /admin/block-type-sources/new.
-
#admin_options ⇒ Object
GET /admin/block-type-sources/options.
-
#admin_refresh ⇒ Object
GET /admin/block-type-sources/:id/refresh.
-
#admin_update ⇒ Object
PUT /admin/block-type-sources/:id.
Methods inherited from ApplicationController
#admin_add, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_json, #admin_json_single, #before_action, #before_before_action, #hashify_query_string, #init_cart, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #under_construction_or_forwarding_domain?, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in
Instance Method Details
#admin_create ⇒ Object
POST /admin/block-type-sources
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/caboose/block_type_sources_controller.rb', line 29 def admin_create return unless user_is_allowed('blocktypesources', 'add') resp = Caboose::StdClass.new max_priority = BlockTypeSource.maximum(:priority) max_priority = 0 if max_priority.nil? bts = BlockTypeSource.new( :name => params[:name], :priority => max_priority + 1, :active => true ) bts.save # Send back the response resp.redirect = "/admin/block-types/store/sources/#{bts.id}/edit" render :json => resp end |
#admin_delete ⇒ Object
DELETE /admin/block-type-sources/:id
70 71 72 73 74 75 76 77 |
# File 'app/controllers/caboose/block_type_sources_controller.rb', line 70 def admin_delete return unless user_is_allowed('blocktypesources', 'delete') BlockTypeSource.find(params[:id]).destroy resp = StdClass.new({ 'redirect' => "/admin/block-types/store/sources" }) render :json => resp end |
#admin_edit ⇒ Object
GET /admin/block-type-sources/:id
22 23 24 25 26 |
# File 'app/controllers/caboose/block_type_sources_controller.rb', line 22 def admin_edit return unless user_is_allowed('blocktypesources', 'edit') @block_type_source = BlockTypeSource.find(params[:id]) render :layout => 'caboose/admin' end |
#admin_index ⇒ Object
GET /admin/block-type-sources
9 10 11 12 13 |
# File 'app/controllers/caboose/block_type_sources_controller.rb', line 9 def admin_index return if !user_is_allowed('blocktypesources', 'view') @block_type_sources = BlockTypeSource.reorder("priority, name").all render :layout => 'caboose/admin' end |
#admin_new ⇒ Object
GET /admin/block-type-sources/new
16 17 18 19 |
# File 'app/controllers/caboose/block_type_sources_controller.rb', line 16 def admin_new return unless user_is_allowed('blocktypesources', 'add') render :layout => 'caboose/admin' end |
#admin_options ⇒ Object
GET /admin/block-type-sources/options
95 96 97 98 99 100 101 |
# File 'app/controllers/caboose/block_type_sources_controller.rb', line 95 def return unless user_is_allowed('blocktypesources', 'edit') = BlockType.reorder(:name).all.collect do |bts| { 'value' => bts.id, 'text' => bts.name } end render :json => end |
#admin_refresh ⇒ Object
GET /admin/block-type-sources/:id/refresh
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/controllers/caboose/block_type_sources_controller.rb', line 80 def admin_refresh return unless user_is_allowed('blocktypesources', 'edit') resp = StdClass.new bts = BlockTypeSource.find(params[:id]) if bts.refresh_summaries resp.success = "Block types from the source have been refreshed successfully." else resp.error = "There was an error refreshing block types from the source." end render :json => resp end |
#admin_update ⇒ Object
PUT /admin/block-type-sources/:id
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/controllers/caboose/block_type_sources_controller.rb', line 48 def admin_update return unless user_is_allowed('blocktypesources', 'edit') resp = StdClass.new({'attributes' => {}}) bts = BlockTypeSource.find(params[:id]) save = true params.each do |k,v| case k when 'name' then bts.name = v when 'url' then bts.url = v when 'token' then bts.token = v when 'priority' then bts.priority = v when 'active' then bts.active = v end end resp.success = save && bts.save render :json => resp end |