User ordering

Run the task new_ui:save_users
This commit is contained in:
chris 2013-09-26 18:59:23 +08:00
parent dc3593c162
commit f81894af90
10 changed files with 125 additions and 12 deletions

View File

@ -241,6 +241,32 @@ class Admin::UsersNewInterfaceController < OrbitMemberController
end end
def edit_order
@users = User.all
end
def update_order
if params[:users].present?
params[:users].values.sort.each do |pair|
to_go = pair[0].to_i
if to_go > 0
user_at_position = User.where(position: to_go - 1).first
user = User.find(pair[1])
if user_at_position && !user_at_position == user
if user.position > user_at_position.position
user.move_above(user_at_position)
else
user.move_below(user_at_position)
end
elsif to_go > User.count
user.move_to_bottom
end
end
end
end
@users = User.all
end
protected protected
def get_tags def get_tags
@sub_role_tags = SubRoleTag.all @sub_role_tags = SubRoleTag.all

View File

@ -1,6 +1,8 @@
class User class User
include Mongoid::Document include Mongoid::Document
include Mongoid::Tree
include Mongoid::Tree::Ordering # use mongoid-tree because mongoid-ordering needs mongoid(~>3.0)
include Mongoid::Timestamps include Mongoid::Timestamps
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable, :validatable #, :timeoutable devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable, :validatable #, :timeoutable

View File

@ -1,7 +1,8 @@
<div class="bottomnav clearfix"> <div class="bottomnav clearfix">
<div class="action pull-right"> <div class="action pull-right">
<% if is_admin? %> <% if is_admin? %>
<%= link_to(new_admin_users_new_interface_path,:class=> "btn btn-primary pull-right") do%> <%= link_to t(:edit_order), edit_order_admin_users_new_interface_index_path, :class => "btn btn-primary" %>
<%= link_to(new_admin_users_new_interface_path,:class=> "btn btn-primary") do %>
<i class="icon-plus"></i><%= t(:add) %> <i class="icon-plus"></i><%= t(:add) %>
<% end -%> <% end -%>
<% end -%> <% end -%>

View File

@ -0,0 +1,15 @@
<%
if user_edit_order.sex == 'male'
@user_sex = 'gender-man'
elsif user_edit_order.sex == 'female'
@user_sex = 'gender-woman'
else
@user_sex = 'gender-none'
end
%>
<tr id="<%= dom_id user_edit_order %>">
<td class="<%= @user_sex %>"></td>
<td><%= link_to user_edit_order.position + 1, '#', class: 'edit_position', 'data-user-id' => user_edit_order.id %></td>
<td><%= link_to user_edit_order.name, admin_users_new_interface_path(user_edit_order) %></td>
<td><%= user_edit_order.email %></td>
</tr>

View File

@ -0,0 +1,56 @@
<% content_for :side_bar do %>
<%= render :partial => 'admin/users_new_interface/side_bar' %>
<% end %>
<div id="list-view">
<table id="member-list" class="table main-list">
<thead>
<tr class="sort-header">
<th class="gender"></th>
<th class="span3"><a href="#"><%= t(:position) %></a></th>
<th class="span4"><a href="#"><%= t(:name) %></a></th>
<th><a href="#"><%= t(:email) %></a></th>
</tr>
</thead>
<tbody>
<%= render partial: "user_edit_order", collection: @users %>
</tbody>
</table>
</div>
<div class="bottomnav clearfix">
<div class="action pull-right">
<%= link_to t(:update_), '#', class: "btn btn-primary pull-right" %>
</div>
</div>
<% content_for :page_specific_javascript do %>
<script>
$(function(){
var _userPosition = [];
$('#member-list').on(clickEvent, '.edit_position', function(e){
var $input = $('<input type="text">');
$(this).after($input);
$(this).hide();
$input.val($(this).text()).attr('id', $(this).data('user-id'));
e.preventDefault();
});
$('.bottomnav').on(clickEvent, '.btn', function(e) {
$('#member-list tbody input').each(function() {
_userPosition.push([$(this).val(), $(this).attr('id')])
});
e.preventDefault();
$.ajax({
url: '<%= update_order_admin_users_new_interface_index_path %>',
type: 'POST',
dataType: 'script',
data: {users: _userPosition}
}).done(function() {
_userPosition = [];
console.log(_userPosition)
});
});
});
</script>
<% end %>

View File

@ -0,0 +1 @@
$('#list-view table tbody').html("<%= j render partial: 'user_edit_order', collection: @users %>")

View File

@ -16,6 +16,7 @@ en:
deselect_all: Deselect all deselect_all: Deselect all
detail: Detail detail: Detail
edit_category: Edit Categorie edit_category: Edit Categorie
edit_order: Edit order
editing: editing:
tag: Editing tag tag: Editing tag
file: file:
@ -37,6 +38,7 @@ en:
no_date: No date no_date: No date
no_file: No file no_file: No file
path: Path path: Path
position: Position
previous: Previous previous: Previous
remove: Remove remove: Remove
remove_default: Remove default remove_default: Remove default

View File

@ -16,6 +16,7 @@ zh_tw:
deselect_all: 取消全選 deselect_all: 取消全選
detail: 細節 detail: 細節
edit_category: 編輯類別 edit_category: 編輯類別
edit_order: 編輯排序
editing: editing:
tag: 編輯標籤 tag: 編輯標籤
file: file:
@ -37,6 +38,7 @@ zh_tw:
no_date: 無日期 no_date: 無日期
no_file: 無檔案 no_file: 無檔案
path: 路徑 path: 路徑
position: 排序
previous: 上一頁 previous: 上一頁
remove: 移除 remove: 移除
remove_default: 移除預設 remove_default: 移除預設

View File

@ -214,6 +214,10 @@ Orbit::Application.routes.draw do
member do member do
get 'temp_edit' get 'temp_edit'
end end
collection do
get 'edit_order'
post 'update_order'
end
match "edit_passwd" => "users_new_interface#edit_passwd" ,:as => :edit_passwd match "edit_passwd" => "users_new_interface#edit_passwd" ,:as => :edit_passwd
end end

View File

@ -91,4 +91,8 @@ namespace :new_ui do
end end
end end
task :save_users => :environment do
User.all.each(&:save)
end
end end