From f97a55e16438e0408b2b5939fcc03b7bb42e97d2 Mon Sep 17 00:00:00 2001
From: lizanle <491823689@qq.com>
Date: Thu, 20 Aug 2015 14:01:33 +0800
Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=BA=93=20=E5=88=A0?=
=?UTF-8?q?=E9=99=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/users_controller.rb | 9 ++++-
app/views/users/_resources_list.html.erb | 2 +-
app/views/users/user_resource.html.erb | 47 +++++++++++++++++-------
3 files changed, 42 insertions(+), 16 deletions(-)
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 76ce9efaf..f62286973 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -823,9 +823,16 @@ class UsersController < ApplicationController
end
end
- # 删除用户资源
+ # 删除用户资源,分为批量删除 和 单个删除
def user_resource_delete
+ if params[:resource_id].present?
Attachment.delete(params[:resource_id])
+ elsif params[:checkbox1].present?
+ params[:checkbox1].each do |id|
+ Attachment.delete(id)
+ end
+ end
+
#@attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') ").order("created_on desc")
if(params[:type].nil? || params[:type] == "1") #全部
if User.current.id.to_i == params[:id].to_i
diff --git a/app/views/users/_resources_list.html.erb b/app/views/users/_resources_list.html.erb
index 7a18a037b..62e819b43 100644
--- a/app/views/users/_resources_list.html.erb
+++ b/app/views/users/_resources_list.html.erb
@@ -3,7 +3,7 @@
<% attachments.each do |attach| %>
+
<%= render :partial => 'upload_resource' ,:locals => {:user=>@user}%>
@@ -182,7 +186,7 @@ $(".resourcesList").click(function(e) {
//只要有一个选中了就是true
function checkboxSelected(){
selected = false;
- $("#resources_list").find("input[name='checkbox1']").each(function(){
+ $("#resources_list").find("input[name='checkbox1[]']").each(function(){
if($(this).attr('checked') == true){
selected = true;
}
@@ -192,7 +196,7 @@ $(".resourcesList").click(function(e) {
//只有全选才是true
function checkboxAllSelected(){
allSelected = true;
- $("#resources_list").find("input[name='checkbox1']").each(function(){
+ $("#resources_list").find("input[name='checkbox1[]']").each(function(){
if($(this).attr('checked') == undefined){
allSelected = false;
}
@@ -202,7 +206,7 @@ $(".resourcesList").click(function(e) {
//只有全部不选才是true
function checkboxAllDeselected(){
allDeselected = true;
- $("#resources_list").find("input[name='checkbox1']").each(function(){
+ $("#resources_list").find("input[name='checkbox1[]']").each(function(){
if($(this).attr('checked') == 'checked'){
allDeselected = false;
}
@@ -223,27 +227,42 @@ $(".resourcesList").click(function(e) {
//获取当前checkbox选中的数目
function getCheckBoxSeletedCount(){
var i = 0;
- $("#resources_list").find("input[name='checkbox1']").each(function(){
+ $("#resources_list").find("input[name='checkbox1[]']").each(function(){
if($(this).attr('checked') == 'checked'){
i ++;
}
});
return i;
}
- $("#checkboxAll").click(function(e){
+ //全选反选
+ function all_select(){
- if($(this).attr('checked')){
- $("#resources_list").find("input[name='checkbox1']").each(function(){
+ if($("#checkboxAll").attr('checked')){
+ $("#resources_list").find("input[name='checkbox1[]']").each(function(){
$(this).attr('checked',true);
});
- $("#res_count").html('<%= @attachments.size%>');
+ $("#res_count").html(getCheckBoxSeletedCount());
}else{
- $("#resources_list").find("input[name='checkbox1']").each(function(){
+ $("#resources_list").find("input[name='checkbox1[]']").each(function(){
$(this).attr('checked',false);
});
$("#res_count").html(0);
}
- });
+ }
+ //批量删除
+ function batch_delete(){
+ var data = $("#resources_list_form").serialize();
+ if(data != "" && confirm('确认要删除这些资源吗?')) {
+ $.post(
+ '<%= user_resource_delete_user_path(@user)%>',
+ $("#resources_list_form").serialize(),//只会对选中的控件进行序列化提交
+ function (data) {
+
+ }
+ );
+ }
+
+ }
function show_send(){
$("#contextMenu").hide();