page module or orbit 4.5 working fine

This commit is contained in:
Harry Bomrah 2014-05-06 17:20:15 +08:00
parent 90ce30d3ea
commit 4e9968f58f
12 changed files with 190 additions and 5 deletions

View File

@ -1,4 +1,34 @@
class Admin::PageContentsController < ApplicationController
class Admin::PageContentsController < OrbitAdminController
def index
@pages = Page.where(:module=>"page_content")
@table_fields = ["Name","Version","Updated At","Last Modified By"]
end
def show
@page_context = PageContext.find(params[:id])
end
def new
@page = Page.find(params[:page_id])
@page_content = PageContext.new
end
def create
@page_content = PageContext.new(update_params)
@page_content.update_user_id = current_user.id
@page_content.save
redirect_to admin_page_contents_path
end
def view
@table_fields = ["Name","Version","Updated At","Last Modified By"]
@page = Page.find(params[:id])
@page_contexts = @page.page_contexts.desc(:version)
end
private
def update_params
params.require(:page_context).permit!
end
end

View File

@ -0,0 +1,9 @@
class PageContentsController < OrbitAdminController
def index
params = OrbitHelper.params
page = Page.where(:page_id => params[:page_id]).first
{
"html" => page.page_contexts.last.content
}
end
end

View File

@ -0,0 +1,27 @@
# encoding: utf-8
class PageContext
include Mongoid::Document
include Mongoid::Timestamps
include Impressionist::Impressionable
is_impressionable :counter_cache => { :column_name => :view_count }
field :update_user_id
field :version, :type => Integer , :default => 0
field :view_count, :type => Integer, :default => 0
field :content, localize: true
field :archived, :type => Boolean, :default => false
# field :current, :type => Boolean, :default => false
belongs_to :page
def pp_object
page.title
end
def title
self.page.title
end
end

View File

@ -1,2 +1,27 @@
<h1>Admin::PageContents#index</h1>
<p>Find me in app/views/admin/page_contents/index.html.erb</p>
<table class="table main-list">
<thead>
<tr class="sort-header">
<% @table_fields.each do |f| %>
<%= thead(f) %>
<% end %>
</tr>
</thead>
<tbody>
<% @pages.each do |page| %>
<tr>
<td>
<a href="/<%= I18n.locale %><%= page.url %>" target="_blank"><%= page.name %></a>
<div class="quick-edit">
<ul class="nav nav-pills">
<li><a href="/admin/page_contents/new?page_id=<%= page.id.to_s %>"><%= t(:edit) %></a></li>
</ul>
</div>
</td>
<td><a href="/admin/page_contents/<%= page.id.to_s %>/view" ><%= page.page_contexts.last.version %></a></td>
<td><%= format_value page.page_contexts.last.updated_at %></td>
<td><%= User.find(page.page_contexts.last.update_user_id).user_name %></td>
</tr>
<% end %>
</tbody>
</table>

View File

@ -0,0 +1,40 @@
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "lib/main-forms" %>
<% end %>
<%= form_for @page_content, :url => {:action => :create}, :html => {:class => 'form-horizontal main-forms'} do |f| %>
<fieldset>
<div class="input-area">
<div class="nav-name"><strong>Language</strong></div>
<ul class="nav nav-pills language-nav">
<% I18n.available_locales.each_with_index do |locale, i| %>
<li <%= (i == 0 ? 'class=active' : '') %>>
<a href=".<%= locale %>" data-toggle="tab"><%= t(locale.to_s) %></a>
</li>
<% end %>
</ul>
<div class="tab-content language-area">
<!-- Language Tabs -->
<% I18n.available_locales.each_with_index do |locale, i| %>
<div class="tab-pane fade in <%= (i == 0 ? 'active' : '') %> <%= locale %>">
<div class="control-group input-content">
<%= f.fields_for :content_translations do |con| %>
<%= label_tag(locale, "Content", :class=>"control-label muted") %>
<div class="controls">
<div class="textarea">
<%= con.text_area locale, :class => "ckeditor input-block-level", :value => (@page.page_contexts.last.content_translations[locale] rescue nil)%>
</div>
</div>
<% end %>
</div>
</div>
<% end %>
</div>
<div class="form-actions">
<%= f.hidden_field :page_id, :value=>@page.id.to_s %>
<%= f.hidden_field :version, :value=>(@page.page_contexts.last.version + 1)%>
<%= f.submit t("page_content.save"), :class=> "btn btn-primary bt-form-save" %>
</div>
</div>
</fieldset>
<% end %>

View File

@ -0,0 +1 @@
<%= @page_context.content.html_safe %>

View File

@ -0,0 +1,28 @@
<table class="table main-list">
<thead>
<tr class="sort-header">
<% @table_fields.each do |f| %>
<%= thead(f) %>
<% end %>
</tr>
</thead>
<tbody>
<% @page_contexts.each do |page| %>
<% if page.version > 0 %>
<tr>
<td>
<%= @page.name %>
<div class="quick-edit">
<ul class="nav nav-pills">
<li><a href="/admin/page_contents/<%= page.id.to_s %>"><%= t(:show) %></a></li>
</ul>
</div>
</td>
<td><%= page.version %></td>
<td><%= format_value page.updated_at %></td>
<td><%= User.find(page.update_user_id).user_name rescue nil %></td>
</tr>
<% end %>
<% end %>
</tbody>
</table>

View File

@ -0,0 +1,2 @@
<% data = action_data %>
<%= data["html"].html_safe %>

10
config/locales/en.yml Normal file
View File

@ -0,0 +1,10 @@
en:
page_content:
page: Page content
save: Save
create_page_content_success: Page content was successfully created
editing_page_content: Editing page content
frontend:
page: Front-end page
update_page_content_success: Page content was successfully updated

9
config/locales/zh_tw.yml Normal file
View File

@ -0,0 +1,9 @@
zh_tw:
page_content:
context: 內文
create_page_content_success: 建立頁面內容成功
editing_page_content: 編輯頁面內容
frontend:
page: 頁面前台
update_page_content_success: 更新頁面內容成功

View File

@ -4,7 +4,11 @@ Rails.application.routes.draw do
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
namespace :admin do
resources :page_contents
resources :page_contents do
member do
get "view" => "page_contents#view"
end
end
end
end

View File

@ -10,7 +10,7 @@ module PageContent
side_bar do
head_label_i18n 'page_content.page', icon_class: "icons-newspaper"
available_for [:admin,:manager,:sub_manager]
active_for_controllers ({:private=>['page_content']})
active_for_controllers (['admin/page_contents'])
head_link_path "admin_page_contents_path"
end
end