Class: ConstructorPages::PagesController
- Inherits:
-
ConstructorCore::AdminController
- Object
- ConstructorCore::AdminController
- ConstructorPages::PagesController
- Includes:
- ConstructorCore::DeviseHelper
- Defined in:
- app/controllers/constructor_pages/pages_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
-
#index ⇒ Object
TODO.
- #move_down ⇒ Object
- #move_up ⇒ Object
- #new ⇒ Object
- #search ⇒ Object
- #show ⇒ Object
- #sitemap ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'app/controllers/constructor_pages/pages_controller.rb', line 129 def create @page = Page.new params[:page] if @page.save redirect_to pages_url, :notice => "Страница «#{@page.name}» успешно добавлена." else render :action => "new" end end |
#destroy ⇒ Object
170 171 172 173 174 175 |
# File 'app/controllers/constructor_pages/pages_controller.rb', line 170 def destroy @page = Page.find(params[:id]) title = @page.name @page.destroy redirect_to pages_url, :notice => "Страница «#{title}» успешно удалена." end |
#edit ⇒ Object
121 122 123 124 125 126 127 |
# File 'app/controllers/constructor_pages/pages_controller.rb', line 121 def edit @page = Page.find(params[:id]) @page.template ||= Template.first @template = @page.template.id @multipart = @page.template.fields.map{|f| f.type_value == "image"}.include?(true) ? true : false end |
#index ⇒ Object
TODO
16 17 18 |
# File 'app/controllers/constructor_pages/pages_controller.rb', line 16 def index @user_signed_in = user_signed_in? end |
#move_down ⇒ Object
187 188 189 190 191 192 193 194 195 |
# File 'app/controllers/constructor_pages/pages_controller.rb', line 187 def move_down from = Page.find(params[:id]) rs = from.right_sibling if not rs.nil? and from.move_possible?(rs) from.move_right end redirect_to :back end |
#move_up ⇒ Object
177 178 179 180 181 182 183 184 185 |
# File 'app/controllers/constructor_pages/pages_controller.rb', line 177 def move_up from = Page.find(params[:id]) ls = from.left_sibling if not ls.nil? and from.move_possible?(ls) from.move_left end redirect_to :back end |
#new ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/constructor_pages/pages_controller.rb', line 25 def new @page = Page.new @template = Template.first.id @multipart = false if params[:page] @parent = Page.find(params[:page]) @page.parent_id = @parent.id if @parent.template.child_id.nil? and !@parent.template.leaf? @template = @parent.template.descendants.first.id else @template = @parent.template.child_id end end end |
#search ⇒ Object
75 76 77 78 79 80 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 114 115 116 117 118 119 |
# File 'app/controllers/constructor_pages/pages_controller.rb', line 75 def search if params[:all].nil? @page = Page.first else @request = '/' + params[:all] @page = Page.where(:full_url => @request).first end instance_variable_set('@'+@page.template.code_name.to_s, @page) what_search = params[:what_search] params_selection = request.query_parameters template = Template.find_by_code_name(what_search.singularize) if template.nil? render :action => "error_404", :layout => false return end @pages = @page.descendants.where(:template_id => template.id) params_selection.each_pair do |code_name, value| if value.numeric? value = value.to_f elsif value.boolean? value = value.to_bool end @pages = @pages.select do |page| if code_name == 'name' page.name == value else page.field(code_name) == value end end end instance_variable_set('@'+template.code_name.pluralize, @pages) @children_of_current_root = Page.children_of(@page.root) @children_of_current_page = Page.children_of(@page) render :template => "templates/#{template.code_name}_search" end |
#show ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/controllers/constructor_pages/pages_controller.rb', line 42 def show if params[:all].nil? @page = Page.first else @request = '/' + params[:all] @page = Page.where(:full_url => @request).first end if @page.nil? or !@page.active render :action => "error_404", :layout => false return end if @page.url != @page.link and !@page.link.empty? redirect_to @page.link end instance_variable_set('@'+@page.template.code_name.to_s, @page) @children_of_current_root = Page.children_of(@page.root) @children_of_current_page = Page.children_of(@page) respond_to do |format| format.html { render :template => "html_templates/#{@page.template.code_name}" } format.json { _template = render_to_string :partial => "json_templates/#{@page.template.code_name}.json.erb", :layout => false, :locals => {@page.template.code_name.to_sym => @page, :page => @page} _js = render_to_string :partial => "js_partials/#{@page.template.code_name}.js" render :json => @page, :self_and_ancestors => @page.self_and_ancestors.map{|a| a.id}, :template => _template.gsub(/\n/, '\\\\n'), :js => _js } end end |
#sitemap ⇒ Object
20 21 22 23 |
# File 'app/controllers/constructor_pages/pages_controller.rb', line 20 def sitemap @pages = Page.all @title = "Карта сайта" end |
#update ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'app/controllers/constructor_pages/pages_controller.rb', line 139 def update @page = Page.find params[:id] @page.template.fields.each do |field| f = "constructor_pages/types/#{field.type_value}_type".classify.constantize.where( :field_id => field.id, :page_id => @page.id).first_or_create if params[:fields] f.value = 0 if field.type_value == 'boolean' if params[:fields][field.type_value] if field.type_value == "date" value = params[:fields][field.type_value][field.id.to_s] f.value = Date.new(value["date(1i)"].to_i, value["date(2i)"].to_i, value["date(3i)"].to_i).to_s else f.value = params[:fields][field.type_value][field.id.to_s] end end f.save end end if @page.update_attributes params[:page] redirect_to pages_url, :notice => "Страница «#{@page.name}» успешно обновлена." else render :action => "edit" end end |