some update for list of pages

This commit is contained in:
Harry Bomrah 2014-12-01 19:12:18 +08:00
parent f68ee92d5a
commit 03f44469df
1 changed files with 11 additions and 9 deletions

View File

@ -24,8 +24,8 @@
<td><%= format_value page.page_contexts.last.updated_at rescue nil %></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><%= User.find(page.page_contexts.last.update_user_id).user_name rescue nil %></td>
<td> <td>
<%= select_tag("category_id",options_for_select(@categories, (page.category_id.to_s rescue "")), prompt: "Select a category", class: "category_select", style: "margin-bottom:0;") %> <%= select_tag("category_id",options_for_select(@categories, (page.category_id.to_s rescue "")), prompt: "Select a category", class: "category_select", style: "margin-bottom:0; width:150px;") %>
<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> <button <%= !page.category_id.nil? ? "data-page-category-id=#{page.category_id.to_s}" : "" %> data-page-id="<%= page.id.to_s %>" class="btn btn-primary save_category hide">Save</button>
</td> </td>
</tr> </tr>
<% end %> <% end %>
@ -41,21 +41,23 @@
<script type="text/javascript"> <script type="text/javascript">
(function(){ (function(){
var category_id = null, var category_id = null,
button = $("button#save_category"); buttons = $("button.save_category");
$("select.category_select").on("change",function(){ $("select.category_select").on("change",function(){
category_id = $(this).val() category_id = $(this).val();
button = $(this).parent().find("button");
if(category_id != ""){ if(category_id != ""){
if(button.data("page-category-id") != category_id){ if(button.data("page-category-id") != category_id){
$("button#save_category").removeClass("hide"); button.removeClass("hide");
}else{ }else{
$("button#save_category").addClass("hide"); button.addClass("hide");
} }
}else{ }else{
$("button#save_category").addClass("hide"); button.addClass("hide");
} }
}) })
button.on("click",function(){ buttons.on("click",function(){
var page_id = $(this).data("page-id"); var page_id = $(this).data("page-id"),
button = $(this);
if(category_id != null){ if(category_id != null){
$.ajax({ $.ajax({
url : "/admin/page_contents/save_category", url : "/admin/page_contents/save_category",