Class: DmCms::Admin::CmsPagesController

Inherits:
AdminController
  • Object
show all
Includes:
PermittedParams
Defined in:
app/controllers/dm_cms/admin/cms_pages_controller.rb

Instance Method Summary collapse

Methods included from PermittedParams

#cms_blog_params, #cms_contentitem_params, #cms_page_params, #cms_post_params, #cms_snippet_params, #media_file_params

Instance Method Details

#ajax_sortObject

Given a new parent_id and position, place item in proper place Note that position comes in as 0-based, increment to make 1-based




72
73
74
75
76
77
78
79
# File 'app/controllers/dm_cms/admin/cms_pages_controller.rb', line 72

def ajax_sort
  if can? :manage_content, :all
    @current_page.update_attributes(row_order_position: params[:item][:position], parent_id: params[:item][:parent_id])
  end

  #--- this action will be called via ajax
  render nothing: true
end

#ajax_toggle_permissionObject




123
124
125
126
127
128
129
130
131
132
# File 'app/controllers/dm_cms/admin/cms_pages_controller.rb', line 123

def ajax_toggle_permission
  authorize! :manage_content, :all
  user = User.find(params[:user_id])
  role = params[:role].to_sym
  if user && [:manage_content].include?(role)
    user.has_role?(role, @current_page) ? user.remove_role(role, @current_page) : user.add_role(role, @current_page)
    user.save!
  end
  render nothing: true
end

#create_pageObject




22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/dm_cms/admin/cms_pages_controller.rb', line 22

def create_page
  authorize! :manage_content, :all
  @cms_page = @current_page.children.new(cms_page_params)
  respond_to do |format|
    if @cms_page.save
      format.html { redirect_to admin_cms_page_url(@cms_page), notice: 'Page was successfully created.' }
      format.json { render json: @cms_page, status: :created, location: @cms_page }
    else
      format.html { render action: "new_page" }
      format.json { render json: @cms_page.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject




82
83
84
85
86
# File 'app/controllers/dm_cms/admin/cms_pages_controller.rb', line 82

def destroy
  authorize! :manage_content, :all
  @current_page.destroy
  redirect_to :action => :index
end

#duplicate_pageObject




59
60
61
62
63
64
65
66
67
# File 'app/controllers/dm_cms/admin/cms_pages_controller.rb', line 59

def duplicate_page
  authorize! :manage_content, :all
  new_page = @current_page.duplicate_with_associations
  if new_page.nil?
    redirect_to admin_cms_page_url(@current_page), :flash => { :error => 'A duplicate page already exists' }
  else
    redirect_to edit_admin_cms_page_url(new_page), :flash => { :notice => 'Duplicate page created.  Please customize it.' }
  end
end

#editObject




37
38
39
40
# File 'app/controllers/dm_cms/admin/cms_pages_controller.rb', line 37

def edit
  authorize! :manage_content, @current_page
  @cms_page = @current_page
end

#expire_cache_totalObject

Removes all cache files. This can be used when we’re not sure if the cache file for a changed page has been deleted or not




91
92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/dm_cms/admin/cms_pages_controller.rb', line 91

def expire_cache_total
  #--- expire only items for this account
  key_start = fragment_cache_key(Account.current.id)
  expire_fragment(%r{\A#{key_start}})
  # expire_fragment(%r{\S}) #--- this would expire *all* cache files

  respond_to do |format| 
    format.html { redirect_to({:action => :index}, :notice => 'Page Cache was cleared') } 
    format.js { render :nothing => true }
  end
end

#indexObject




8
9
10
11
12
13
# File 'app/controllers/dm_cms/admin/cms_pages_controller.rb', line 8

def index
  authorize! :access_content_section, :all
  CmsPage.create_default_site if CmsPage.roots.empty?
  # @tree = CmsPage.arrange(order: :position)
  @tree = CmsPage.arrange(order: :row_order)
end

#new_pageObject




16
17
18
19
# File 'app/controllers/dm_cms/admin/cms_pages_controller.rb', line 16

def new_page
  authorize! :manage_content, :all
  @cms_page = CmsPage.new
end

#permissionsObject




104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'app/controllers/dm_cms/admin/cms_pages_controller.rb', line 104

def permissions
  authorize! :manage_content, :all
  if put_or_post?
    if params[:user][:user_id]
      user = User.find(params[:user][:user_id])
      if user
        roles = params[:user].delete(:roles)
        [:manage_content].each do |role|
          roles[role].as_boolean ? user.add_role(role, @current_page) : user.remove_role(role, @current_page)
        end
        user.save!
      end
    end
  end
  @content_managers = User.with_role(:content_manager)
  @content_managers_alacarte = User.with_role(:content_manager_alacarte)
end

#showObject




54
55
56
# File 'app/controllers/dm_cms/admin/cms_pages_controller.rb', line 54

def show
  authorize! :manage_content, @current_page
end

#updateObject




43
44
45
46
47
48
49
50
51
# File 'app/controllers/dm_cms/admin/cms_pages_controller.rb', line 43

def update
  authorize! :manage_content, @current_page
  if @current_page.update_attributes(cms_page_params)
    redirect_to :action => :show, :id => @current_page
   else
    @cms_page = @current_page
    render :action => :edit
   end
end