parent
							
								
									dc3593c162
								
							
						
					
					
						commit
						f81894af90
					
				| 
						 | 
				
			
			@ -241,6 +241,32 @@ class Admin::UsersNewInterfaceController <  OrbitMemberController
 | 
			
		|||
 | 
			
		||||
  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
 | 
			
		||||
  def get_tags
 | 
			
		||||
    @sub_role_tags = SubRoleTag.all
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,8 @@
 | 
			
		|||
class User
 | 
			
		||||
  
 | 
			
		||||
  include Mongoid::Document
 | 
			
		||||
  include Mongoid::Tree
 | 
			
		||||
  include Mongoid::Tree::Ordering # use mongoid-tree because mongoid-ordering needs mongoid(~>3.0)
 | 
			
		||||
  include Mongoid::Timestamps
 | 
			
		||||
 | 
			
		||||
  devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable, :validatable #, :timeoutable
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,8 @@
 | 
			
		|||
<div class="bottomnav clearfix">
 | 
			
		||||
  <div class="action pull-right">
 | 
			
		||||
    <% 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) %>
 | 
			
		||||
      <% end -%>
 | 
			
		||||
    <% end -%>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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>
 | 
			
		||||
| 
						 | 
				
			
			@ -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 %>
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
$('#list-view table tbody').html("<%= j render partial: 'user_edit_order', collection: @users %>")
 | 
			
		||||
| 
						 | 
				
			
			@ -16,6 +16,7 @@ en:
 | 
			
		|||
  deselect_all: Deselect all
 | 
			
		||||
  detail: Detail
 | 
			
		||||
  edit_category: Edit Categorie
 | 
			
		||||
  edit_order: Edit order
 | 
			
		||||
  editing:
 | 
			
		||||
    tag: Editing tag
 | 
			
		||||
  file:
 | 
			
		||||
| 
						 | 
				
			
			@ -37,6 +38,7 @@ en:
 | 
			
		|||
  no_date: No date
 | 
			
		||||
  no_file: No file
 | 
			
		||||
  path: Path
 | 
			
		||||
  position: Position
 | 
			
		||||
  previous: Previous
 | 
			
		||||
  remove: Remove
 | 
			
		||||
  remove_default: Remove default
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,6 +16,7 @@ zh_tw:
 | 
			
		|||
  deselect_all: 取消全選
 | 
			
		||||
  detail: 細節
 | 
			
		||||
  edit_category: 編輯類別
 | 
			
		||||
  edit_order: 編輯排序
 | 
			
		||||
  editing:
 | 
			
		||||
    tag: 編輯標籤
 | 
			
		||||
  file:
 | 
			
		||||
| 
						 | 
				
			
			@ -37,6 +38,7 @@ zh_tw:
 | 
			
		|||
  no_date: 無日期
 | 
			
		||||
  no_file: 無檔案
 | 
			
		||||
  path: 路徑
 | 
			
		||||
  position: 排序
 | 
			
		||||
  previous: 上一頁
 | 
			
		||||
  remove: 移除
 | 
			
		||||
  remove_default: 移除預設
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -214,6 +214,10 @@ Orbit::Application.routes.draw do
 | 
			
		|||
      member do
 | 
			
		||||
        get 'temp_edit'
 | 
			
		||||
      end
 | 
			
		||||
      collection do
 | 
			
		||||
        get 'edit_order'
 | 
			
		||||
        post 'update_order'
 | 
			
		||||
      end
 | 
			
		||||
      match "edit_passwd" => "users_new_interface#edit_passwd" ,:as => :edit_passwd
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -91,4 +91,8 @@ namespace :new_ui do
 | 
			
		|||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  task :save_users => :environment do
 | 
			
		||||
    User.all.each(&:save)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue