Class: Caboose::PageBlocksController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Caboose::PageBlocksController
- Defined in:
- app/controllers/caboose/page_blocks_controller.rb
Instance Method Summary collapse
-
#admin_create ⇒ Object
POST /admin/pages/:page_id/blocks.
-
#admin_delete ⇒ Object
DELETE /admin/pages/:page_id/blocks/:id.
-
#admin_edit ⇒ Object
GET /admin/pages/:page_id/blocks/:id/edit.
-
#admin_index ⇒ Object
GET /admin/pages/:page_id/blocks.
-
#admin_new ⇒ Object
GET /admin/pages/:page_id/blocks/new.
-
#admin_render ⇒ Object
GET /admin/pages/:page_id/blocks/:id/render.
-
#admin_render_all ⇒ Object
GET /admin/pages/:page_id/blocks/render.
-
#admin_show ⇒ Object
GET /admin/pages/:page_id/blocks/:id.
-
#admin_update ⇒ Object
PUT /admin/pages/:page_id/blocks/:id.
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/pages/:page_id/blocks
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'app/controllers/caboose/page_blocks_controller.rb', line 99 def admin_create return unless user_is_allowed('pages', 'add') resp = Caboose::StdClass.new({ 'error' => nil, 'redirect' => nil }) b = PageBlock.new b.page_id = params[:page_id].to_i b.page_block_type_id = params[:page_block_type_id] if !params[:index].nil? b.sort_order = params[:index].to_i elsif params[:after_id] b2 = PageBlock.find(params[:after_id].to_i) b.sort_order = b2.sort_order + 1 end i = b.sort_order + 1 PageBlock.where("page_id = ? and sort_order >= ?", b.page_id, b.sort_order).reorder(:sort_order).each do |b2| b2.sort_order = i b2.save i = i + 1 end # Save the block b.save # Send back the response resp.block = b render :json => resp end |
#admin_delete ⇒ Object
DELETE /admin/pages/:page_id/blocks/:id
154 155 156 157 158 159 160 161 |
# File 'app/controllers/caboose/page_blocks_controller.rb', line 154 def admin_delete return unless user_is_allowed('pages', 'delete') PageBlock.find(params[:id]).destroy resp = StdClass.new({ 'redirect' => "/admin/pages/#{params[:page_id]}/edit" }) render :json => resp end |
#admin_edit ⇒ Object
GET /admin/pages/:page_id/blocks/:id/edit
89 90 91 92 93 94 95 96 |
# File 'app/controllers/caboose/page_blocks_controller.rb', line 89 def admin_edit return unless user_is_allowed('pages', 'edit') @page = Page.find(params[:page_id]) PageBlock.create_field_values(params[:id]) @block = PageBlock.find(params[:id]) #render "caboose/page_blocks/admin_edit_#{@block.block_type}", :layout => 'caboose/modal' render :layout => 'caboose/modal' end |
#admin_index ⇒ Object
GET /admin/pages/:page_id/blocks
10 11 12 13 14 |
# File 'app/controllers/caboose/page_blocks_controller.rb', line 10 def admin_index return if !user_is_allowed('pages', 'view') blocks = PageBlock.where(:page_id => params[:page_id]).reorder(:sort_order) render :json => blocks end |
#admin_new ⇒ Object
GET /admin/pages/:page_id/blocks/new
17 18 19 20 21 22 |
# File 'app/controllers/caboose/page_blocks_controller.rb', line 17 def admin_new return unless user_is_allowed('pages', 'add') @page = Page.find(params[:page_id]) @block = PageBlock.new(:page_id => params[:page_id]) render :layout => 'caboose/admin' end |
#admin_render ⇒ Object
GET /admin/pages/:page_id/blocks/:id/render
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/caboose/page_blocks_controller.rb', line 32 def admin_render return unless user_is_allowed('pages', 'edit') b = PageBlock.find(params[:id]) bt = b.page_block_type if bt.nil? bt = PageBlockType.where(:name => 'richtext').first b.page_block_type_id = bt.id b.save end html = nil if bt.use_render_function && bt.render_function html = b.render_from_function(params[:empty_text], true) else html = render_to_string({ :partial => "caboose/page_blocks/#{b.page_block_type.name}", :locals => { :block => b, :empty_text => params[:empty_text], :editing => true } }) end render :json => html end |
#admin_render_all ⇒ Object
GET /admin/pages/:page_id/blocks/render
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 |
# File 'app/controllers/caboose/page_blocks_controller.rb', line 59 def admin_render_all return unless user_is_allowed('pages', 'edit') p = Page.find(params[:page_id]) blocks = p.page_blocks.collect do |b| bt = b.page_block_type if bt.nil? bt = PageBlockType.where(:name => 'richtext').first b.page_block_type_id = bt.id b.save end html = nil if bt.use_render_function && bt.render_function html = b.render_from_function(params[:empty_text], true) else html = render_to_string({ :partial => "caboose/page_blocks/#{bt.name}", :locals => { :block => b, :empty_text => params[:empty_text], :editing => true } }) end { :id => b.id, :page_block_type_id => bt.id, :sort_order => b.sort_order, :html => html } end render :json => blocks end |
#admin_show ⇒ Object
GET /admin/pages/:page_id/blocks/:id
25 26 27 28 29 |
# File 'app/controllers/caboose/page_blocks_controller.rb', line 25 def admin_show return unless user_is_allowed('pages', 'edit') block = PageBlock.find(params[:id]) render :json => block end |
#admin_update ⇒ Object
PUT /admin/pages/:page_id/blocks/:id
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'app/controllers/caboose/page_blocks_controller.rb', line 134 def admin_update return unless user_is_allowed('pages', 'edit') resp = StdClass.new({'attributes' => {}}) b = PageBlock.find(params[:id]) obj = b.object save = true user = logged_in_user b.block_type_definition[:attributes].each do |attrib| obj[attrib[:name]] = params[attrib[:name]] if params[attrib[:name]] end b.value = JSON.generate(obj) resp.success = save && b.save render :json => resp end |