Class: Caboose::BlockTypesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Caboose::BlockTypesController
- Defined in:
- app/controllers/caboose/block_types_controller.rb
Instance Method Summary collapse
-
#admin_create ⇒ Object
POST /admin/block-types.
-
#admin_delete ⇒ Object
DELETE /admin/block-types/:id.
-
#admin_edit ⇒ Object
GET /admin/block-types/:id/edit.
-
#admin_field_type_options ⇒ Object
GET /admin/block-types/field-type-options.
-
#admin_index ⇒ Object
GET /admin/block-types.
-
#admin_new ⇒ Object
GET /admin/block-types/new GET /admin/block-types/:id/new.
-
#admin_options ⇒ Object
GET /admin/block-types/options.
-
#admin_show ⇒ Object
GET /admin/block-types/:id.
-
#admin_store_details ⇒ Object
GET /admin/block-types/store/:block_type_summary_id.
-
#admin_store_download ⇒ Object
GET /admin/block-types/store/:block_type_summary_id/download.
-
#admin_store_index ⇒ Object
GET /admin/block-types/store.
-
#admin_tree_options ⇒ Object
GET /admin/block-types/tree-options.
- #admin_tree_options_helper(options, bt, prefix) ⇒ Object
-
#admin_update ⇒ Object
PUT /admin/block-types/:id.
-
#admin_value_options ⇒ Object
GET /admin/block-types/:id/options.
-
#api_block_type ⇒ Object
GET /caboose/block-types/:name.
-
#api_block_type_list ⇒ Object
GET /caboose/block-types.
Methods inherited from ApplicationController
#before_action, #before_before_action, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in
Instance Method Details
#admin_create ⇒ Object
POST /admin/block-types
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/controllers/caboose/block_types_controller.rb', line 40 def admin_create return unless user_is_allowed('pages', 'add') resp = Caboose::StdClass.new({ 'error' => nil, 'redirect' => nil }) bt = BlockType.new( :parent_id => params[:parent_id] ? params[:parent_id] : nil, :name => params[:name].downcase.gsub(' ', '_'), :description => params[:name], :field_type => params[:field_type], :allow_child_blocks => true ) bt.save # Send back the response resp.redirect = "/admin/block-types/#{bt.id}/edit" render :json => resp end |
#admin_delete ⇒ Object
DELETE /admin/block-types/:id
100 101 102 103 104 105 106 107 |
# File 'app/controllers/caboose/block_types_controller.rb', line 100 def admin_delete return unless user_is_allowed('pages', 'delete') BlockType.find(params[:id]).destroy resp = StdClass.new({ 'redirect' => "/admin/block-types" }) render :json => resp end |
#admin_edit ⇒ Object
GET /admin/block-types/:id/edit
33 34 35 36 37 |
# File 'app/controllers/caboose/block_types_controller.rb', line 33 def admin_edit return unless user_is_allowed('pages', 'edit') @block_type = BlockType.find(params[:id]) render :layout => 'caboose/admin' end |
#admin_field_type_options ⇒ Object
GET /admin/block-types/field-type-options
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/controllers/caboose/block_types_controller.rb', line 110 def return unless user_is_allowed('pages', 'edit') = [ { 'value' => 'checkbox' , 'text' => 'Checkbox' }, { 'value' => 'checkbox_multiple' , 'text' => 'Checkbox (multiple)' }, { 'value' => 'image' , 'text' => 'Image' }, { 'value' => 'file' , 'text' => 'File' }, { 'value' => 'richtext' , 'text' => 'Rich Text' }, { 'value' => 'select' , 'text' => 'Multiple choice (select box)' }, { 'value' => 'text' , 'text' => 'Textbox' }, { 'value' => 'textarea' , 'text' => 'Textarea' }, { 'value' => 'block' , 'text' => 'Block' } ] render :json => end |
#admin_index ⇒ Object
GET /admin/block-types
10 11 12 13 14 |
# File 'app/controllers/caboose/block_types_controller.rb', line 10 def admin_index return if !user_is_allowed('pages', 'view') @block_types = BlockType.where("parent_id is null or parent_id = 0").reorder(:name).all render :layout => 'caboose/admin' end |
#admin_new ⇒ Object
GET /admin/block-types/new GET /admin/block-types/:id/new
25 26 27 28 29 30 |
# File 'app/controllers/caboose/block_types_controller.rb', line 25 def admin_new return unless user_is_allowed('pages', 'add') @block_type = BlockType.new @parent_id = params[:id] render :layout => 'caboose/admin' end |
#admin_options ⇒ Object
GET /admin/block-types/options
140 141 142 143 144 145 146 |
# File 'app/controllers/caboose/block_types_controller.rb', line 140 def return unless user_is_allowed('pages', 'edit') = BlockType.where("parent_id is null").reorder(:name).all.collect do |bt| { 'value' => bt.id, 'text' => bt.description } end render :json => end |
#admin_show ⇒ Object
GET /admin/block-types/:id
17 18 19 20 21 |
# File 'app/controllers/caboose/block_types_controller.rb', line 17 def admin_show return if !user_is_allowed('pages', 'view') block_type = BlockType.find(params[:id]) render :json => block_type end |
#admin_store_details ⇒ Object
GET /admin/block-types/store/:block_type_summary_id
188 189 190 191 192 |
# File 'app/controllers/caboose/block_types_controller.rb', line 188 def admin_store_details return unless user_is_allowed('blocktypestore', 'add') @block_type_summary = BlockTypeSummary::find(params[:block_type_summary_id]) render :layout => 'caboose/admin' end |
#admin_store_download ⇒ Object
GET /admin/block-types/store/:block_type_summary_id/download
195 196 197 198 199 200 201 202 203 |
# File 'app/controllers/caboose/block_types_controller.rb', line 195 def admin_store_download return unless user_is_allowed('blocktypestore', 'add') bts = BlockTypeSummary::find(params[:block_type_summary_id]) bts.source.refresh(bts.name) resp = StdClass.new('success' => 'The block type has been downloaded successfully.') render :json => resp end |
#admin_store_index ⇒ Object
GET /admin/block-types/store
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'app/controllers/caboose/block_types_controller.rb', line 170 def admin_store_index return unless user_is_allowed('blocktypestore', 'add') @pager = PageBarGenerator.new(params, { 'block_type_source_id' => '', 'name_like' => '', 'description_like' => '' },{ 'model' => 'Caboose::BlockTypeSummary', 'sort' => 'block_type_source_id, name', 'desc' => false, 'base_url' => '/admin/block-types/store', 'use_url_params' => false }) @block_type_summaries = @pager.items render :layout => 'caboose/admin' end |
#admin_tree_options ⇒ Object
GET /admin/block-types/tree-options
149 150 151 152 153 154 155 156 |
# File 'app/controllers/caboose/block_types_controller.rb', line 149 def return unless user_is_allowed('pages', 'edit') = [] BlockType.where("parent_id is null or parent_id = 0").reorder(:name).all.each do |bt| (, bt, '') end render :json => end |
#admin_tree_options_helper(options, bt, prefix) ⇒ Object
158 159 160 161 162 163 |
# File 'app/controllers/caboose/block_types_controller.rb', line 158 def (, bt, prefix) << { 'value' => bt.id, 'text' => "#{prefix}#{bt.description}" } bt.children.each do |bt2| (, bt2, " - #{prefix}") end end |
#admin_update ⇒ Object
PUT /admin/block-types/:id
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 92 93 94 95 96 97 |
# File 'app/controllers/caboose/block_types_controller.rb', line 63 def admin_update return unless user_is_allowed('pages', 'edit') resp = StdClass.new({'attributes' => {}}) bt = BlockType.find(params[:id]) save = true params.each do |k,v| case k when 'parent_id' then bt.parent_id = v when 'name' then bt.name = v when 'description' then bt.description = v when 'is_global' then bt.is_global = v when 'icon' then bt.icon = v when 'block_type_category_id' then bt.block_type_category_id = v when 'render_function' then bt.render_function = v when 'use_render_function' then bt.use_render_function = v when 'use_render_function_for_layout' then bt.use_render_function_for_layout = v when 'allow_child_blocks' then bt.allow_child_blocks = v when 'default_child_block_type_id' then bt.default_child_block_type_id = v when 'name' then bt.name = v when 'field_type' then bt.field_type = v when 'default' then bt.default = v when 'width' then bt.width = v when 'height' then bt.height = v when 'fixed_placeholder' then bt.fixed_placeholder = v when 'options' then bt. = v when 'options_function' then bt. = v when 'options_url' then bt. = v end end resp.success = save && bt.save render :json => resp end |
#admin_value_options ⇒ Object
GET /admin/block-types/:id/options
127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/controllers/caboose/block_types_controller.rb', line 127 def return unless user_is_allowed('pages', 'edit') bt = BlockType.find(params[:id]) = [] if bt. = bt. elsif bt. = bt..strip.split("\n").collect { |line| { 'value' => line, 'text' => line }} end render :json => end |
#api_block_type ⇒ Object
GET /caboose/block-types/:name
218 219 220 221 222 |
# File 'app/controllers/caboose/block_types_controller.rb', line 218 def api_block_type bt = BlockType.where(:name => params[:name]).first render :json => { 'error' => 'Invalid block type.' } if bt.nil? render :json => bt.api_hash end |
#api_block_type_list ⇒ Object
GET /caboose/block-types
210 211 212 213 214 215 |
# File 'app/controllers/caboose/block_types_controller.rb', line 210 def api_block_type_list arr = BlockType.where("parent_id is null and share = ?", true).reorder(:name).all.collect do |bt| { 'name' => bt.name, 'description' => bt.description } end render :json => arr end |