From cf8356d472a564c24e6a4c064fa01505d992de19 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 11 Jul 2019 16:03:11 +0800 Subject: [PATCH] management project package add delete action --- .../project_packages_controller.rb | 3 ++- .../_project_package_list.html.erb | 4 +-- .../project_packages/index.html.erb | 26 +++++++++++++++++++ app/views/users/_project_package.html.erb | 2 +- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/app/controllers/managements/project_packages_controller.rb b/app/controllers/managements/project_packages_controller.rb index 4daa32bb..3ea574c0 100644 --- a/app/controllers/managements/project_packages_controller.rb +++ b/app/controllers/managements/project_packages_controller.rb @@ -42,7 +42,8 @@ class Managements::ProjectPackagesController < Managements::BaseController end def destroy - + ProjectPackage.find(params[:id]).destroy + render json: { status: 0 } end private diff --git a/app/views/managements/project_packages/_project_package_list.html.erb b/app/views/managements/project_packages/_project_package_list.html.erb index 9edd1fc7..4dab9d3d 100644 --- a/app/views/managements/project_packages/_project_package_list.html.erb +++ b/app/views/managements/project_packages/_project_package_list.html.erb @@ -17,7 +17,7 @@ <% if @packages.present? %> <% @packages.each_with_index do |package, index| %> - + <%= (@obj_pages.page - 1) * @obj_pages.per_page + index + 1 %> <%= link_to package.title, project_package_path(package), target: '_blank', @@ -30,7 +30,7 @@ <%= package.created_at.strftime('%Y-%m-%d %H:%M') %> <%= package.published_at.try(:strftime, '%Y-%m-%d %H:%M') || '--' %> <%= package.deadline_at.try(:strftime, '%Y-%m-%d %H:%M') || '--' %> - + <%= link_to '删除', 'javascript:void(0)', class: 'delete-btn', data: { id: package.id } %> <% end %> <% else %> diff --git a/app/views/managements/project_packages/index.html.erb b/app/views/managements/project_packages/index.html.erb index ff58fef7..01f38b7b 100644 --- a/app/views/managements/project_packages/index.html.erb +++ b/app/views/managements/project_packages/index.html.erb @@ -36,6 +36,11 @@ $(".management-project-packages-form").submit(); }); + $('#managements-project-packages-list').on('click', '.delete-btn', function(){ + var id = $(this).data("id"); + op_confirm_tip_1("是否确认删除?", "deleteProjectPackage(" + id + ");") + }); + var locale = { clearText: '清除', clearStatus: '清除已选日期', @@ -86,4 +91,25 @@ form.submit(); } + + function deleteProjectPackage(id){ + $.ajax({ + type: "DELETE", + url: "<%= managements_project_packages_path %>/" + id, + success: function (data) { + $('.popupAll').remove(); + + if(data && data.status == 0){ + $('#managements-project-packages-list .project-package-item.project-package-' + id).remove(); + + if($('#managements-project-packages-list .project-package-item').length == 0){ + $.ajax({ dataType: 'script', url: "<%= raw managements_project_packages_path(params.except(:controller, :action)) %>" }); + } + } else { + notice_box(data.message); + } + } + }); + return true; + } \ No newline at end of file diff --git a/app/views/users/_project_package.html.erb b/app/views/users/_project_package.html.erb index 00e69709..db21fd0a 100644 --- a/app/views/users/_project_package.html.erb +++ b/app/views/users/_project_package.html.erb @@ -130,7 +130,7 @@ $('.project-packages-list .project-package-item.project-package-' + id).remove(); if($('.project-packages-list .project-package-item').length == 0){ - $.ajax({ dataType: 'script', url: "<%= user_path(@user, params.except(:controller, :action)) %>" }); + $.ajax({ dataType: 'script', url: "<%= raw user_path(@user, params.except(:controller, :action)) %>" }); } } else { notice_box(data.message);