added categories for pages
This commit is contained in:
parent
4d2007e560
commit
4d8c331b67
|
@ -1,9 +1,10 @@
|
|||
class Admin::PageContentsController < OrbitAdminController
|
||||
before_action ->(module_app = @app_title) { set_variables module_app }
|
||||
def index
|
||||
@table_fields = [:page_id, :name,:version,:update_at,:last_modified]
|
||||
@table_fields = [:page_id, :name,:version,:update_at,:last_modified, :category]
|
||||
@filter_fields = {}
|
||||
@pages = Page.where(:module=>"page_content").order_by(sort)
|
||||
|
||||
@categories = @module_app.categories.collect{|c| [c.title, c.id]}
|
||||
@pages = search_data(@pages,[:name, :page_id]).page(params[:page]).per(10)
|
||||
|
||||
render :partial => "index" if request.xhr?
|
||||
|
@ -35,6 +36,17 @@ class Admin::PageContentsController < OrbitAdminController
|
|||
@page_contexts = @page.page_contexts.desc(:version)
|
||||
end
|
||||
|
||||
def save_category
|
||||
page_id = params[:page_id]
|
||||
category_id = params[:category_id]
|
||||
page = Page.find(page_id) rescue nil
|
||||
if !page.nil?
|
||||
page.category_id = category_id
|
||||
page.save
|
||||
end
|
||||
render :json => {"success" => true}.to_json
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_params
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
<td><a href="/admin/page_contents/<%= page.id.to_s %>/view" ><%= page.page_contexts.last.version rescue nil %></a></td>
|
||||
<td><%= format_value page.page_contexts.last.updated_at rescue nil %></td>
|
||||
<td><%= User.find(page.page_contexts.last.update_user_id).user_name rescue nil %></td>
|
||||
<td>
|
||||
<%= select_tag("category_id",options_for_select(@categories, (page.category_id.to_s rescue "")), prompt: "Select a category", class: "category_select") %>
|
||||
<button <%= !page.category_id.nil? ? "data-page-category-id=#{page.category_id.to_s}" : "" %> data-page-id="<%= page.id.to_s %>" id="save_category" class="btn btn-primary hide">Save</button>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
@ -33,3 +37,37 @@
|
|||
content_tag :div, paginate(@pages), class: "pagination pagination-centered"
|
||||
end
|
||||
%>
|
||||
|
||||
<script type="text/javascript">
|
||||
(function(){
|
||||
var category_id = null,
|
||||
button = $("button#save_category");
|
||||
$("select.category_select").on("change",function(){
|
||||
category_id = $(this).val()
|
||||
if(category_id != ""){
|
||||
if(button.data("page-category-id") != category_id){
|
||||
$("button#save_category").removeClass("hide");
|
||||
}else{
|
||||
$("button#save_category").addClass("hide");
|
||||
}
|
||||
}else{
|
||||
$("button#save_category").addClass("hide");
|
||||
}
|
||||
})
|
||||
button.on("click",function(){
|
||||
var page_id = $(this).data("page-id");
|
||||
if(category_id != null){
|
||||
$.ajax({
|
||||
url : "/admin/page_contents/save_category",
|
||||
dataType : "json",
|
||||
type: "post",
|
||||
data : {"category_id" : category_id, "page_id" : page_id}
|
||||
}).done(function(data){
|
||||
if(data.success){
|
||||
button.addClass("hide");
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})();
|
||||
</script>
|
|
@ -3,6 +3,7 @@ en:
|
|||
page_content:
|
||||
page: Page content
|
||||
save: Save
|
||||
all: All
|
||||
create_page_content_success: Page content was successfully created
|
||||
editing_page_content: Editing page content
|
||||
frontend:
|
||||
|
|
|
@ -4,6 +4,7 @@ zh_tw:
|
|||
context: 內文
|
||||
create_page_content_success: 建立頁面內容成功
|
||||
editing_page_content: 編輯頁面內容
|
||||
all: All
|
||||
frontend:
|
||||
page: 頁面前台
|
||||
update_page_content_success: 更新頁面內容成功
|
|
@ -9,6 +9,7 @@ Rails.application.routes.draw do
|
|||
get "view" => "page_contents#view"
|
||||
end
|
||||
end
|
||||
post "/page_contents/save_category" => "page_contents#save_category"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,12 +6,27 @@ module PageContent
|
|||
base_url File.expand_path File.dirname(__FILE__)
|
||||
frontend_enabled
|
||||
authorizable
|
||||
categorizable
|
||||
|
||||
side_bar do
|
||||
head_label_i18n 'page_content.page', icon_class: "icons-newspaper"
|
||||
available_for "users"
|
||||
active_for_controllers (['admin/page_contents'])
|
||||
head_link_path "admin_page_contents_path"
|
||||
|
||||
context_link 'page_content.all',
|
||||
:link_path=>"admin_page_contents_path" ,
|
||||
:priority=>1,
|
||||
:active_for_action=>{'admin/page_contents'=>"index"},
|
||||
:available_for => 'users'
|
||||
|
||||
context_link 'categories',
|
||||
:link_path=>"admin_module_app_categories_path" ,
|
||||
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'page_content').id}",
|
||||
:priority=>3,
|
||||
:active_for_action=>{'admin/page_contents'=>'categories'},
|
||||
:active_for_category => 'PageContent',
|
||||
:available_for => 'managers'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue