Class: Humpyard::ElementsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Humpyard::ElementsController
- Defined in:
- app/controllers/humpyard/elements_controller.rb
Overview
Humpyard::ElementController is the controller for editing your elements
Instance Method Summary collapse
-
#create ⇒ Object
Create a new element.
-
#destroy ⇒ Object
Destroy an element.
-
#edit ⇒ Object
Dialog content for an existing element.
-
#inline_edit ⇒ Object
Inline edit content for an existing element.
-
#move ⇒ Object
Move an element.
-
#new ⇒ Object
Dialog content for a new element.
-
#show ⇒ Object
Render a given element.
-
#update ⇒ Object
Update an existing element.
Instance Method Details
#create ⇒ Object
Create a new element
24 25 26 27 28 29 30 31 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 57 58 59 60 |
# File 'app/controllers/humpyard/elements_controller.rb', line 24 def create @element = Humpyard::config.element_types[params[:type]].new params[:element] unless can? :create, @element.element render :json => { :status => :failed }, :status => 403 return end if @element.save @prev = Humpyard::Element.find_by_id(params[:prev_id]) @next = Humpyard::Element.find_by_id(params[:next_id]) do_move(@element, @prev, @next) = { :element => "hy-id-#{@element.element.id}", :url => humpyard_element_path(@element.element), :parent => @element.container ? "hy-id-#{@element.container.id}" : "hy-content-#{@element.page_yield_name}" } [:before] = "hy-id-#{@next.id}" if @next [:after] = "hy-id-#{@prev.id}" if not @next and @prev render :json => { :status => :ok, :dialog => :close, :insert => [] } else render :json => { :status => :failed, :errors => @element.errors } end end |
#destroy ⇒ Object
Destroy an element
147 148 149 150 151 152 153 154 155 156 |
# File 'app/controllers/humpyard/elements_controller.rb', line 147 def destroy @element = Humpyard::Element.find_by_id(params[:id]) if can? :destroy, @element @element.destroy else @error = "You have no permission to delete this element (id: #{@element.class}:#{params[:id]})" render :error end end |
#edit ⇒ Object
Dialog content for an existing element
72 73 74 75 76 77 78 |
# File 'app/controllers/humpyard/elements_controller.rb', line 72 def edit @element = Humpyard::Element.find(params[:id]).content_data :update, @element.element render :partial => 'edit' end |
#inline_edit ⇒ Object
Inline edit content for an existing element
63 64 65 66 67 68 69 |
# File 'app/controllers/humpyard/elements_controller.rb', line 63 def inline_edit @element = Humpyard::Element.find(params[:id]).content_data :update, @element.element render :partial => 'inline_edit' end |
#move ⇒ Object
Move an element
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'app/controllers/humpyard/elements_controller.rb', line 116 def move @element = Humpyard::Element.find(params[:id]) if @element unless can? :update, @element render :json => { :status => :failed }, :status => 403 return end @element.update_attributes( :container => Humpyard::Element.find_by_id(params[:container_id]), :page_yield_name => params[:yield_name] ) @prev = Humpyard::Element.find_by_id(params[:prev_id]) @next = Humpyard::Element.find_by_id(params[:next_id]) do_move(@element, @prev, @next) render :json => { :status => :ok } else render :json => { :status => :failed }, :status => 404 end end |
#new ⇒ Object
Dialog content for a new element
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/controllers/humpyard/elements_controller.rb', line 7 def new @element = Humpyard::config.element_types[params[:type]].new( :page_id => params[:page_id], :container_id => params[:container_id].to_i > 0 ? params[:container_id].to_i : nil, :page_yield_name => params[:yield_name].blank? ? 'main' : params[:yield_name], :shared_state => 0) :create, @element.element @element_type = params[:type] @prev = Humpyard::Element.find_by_id(params[:prev_id]) @next = Humpyard::Element.find_by_id(params[:next_id]) render :partial => 'edit' end |
#show ⇒ Object
Render a given element
159 160 161 162 163 164 165 |
# File 'app/controllers/humpyard/elements_controller.rb', line 159 def show @element = Humpyard::Element.find(params[:id]) :read, @element render :partial => 'show', :locals => {:element => @element} end |
#update ⇒ Object
Update an existing element
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/controllers/humpyard/elements_controller.rb', line 81 def update @element = Humpyard::Element.find(params[:id]) if @element unless can? :update, @element render :json => { :status => :failed }, :status => 403 return end if @element.content_data.update_attributes params[:element] render :json => { :status => :ok, :dialog => :close, :replace => [ { :element => "hy-id-#{@element.id}", :url => humpyard_element_path(@element) } ] } else render :json => { :status => :failed, :errors => @element.content_data.errors } end else render :json => { :status => :failed }, :status => 404 end end |