management project package add delete action

project_pack
p31729568 5 years ago
parent a0214ff811
commit cf8356d472

@ -42,7 +42,8 @@ class Managements::ProjectPackagesController < Managements::BaseController
end end
def destroy def destroy
ProjectPackage.find(params[:id]).destroy
render json: { status: 0 }
end end
private private

@ -17,7 +17,7 @@
<tbody> <tbody>
<% if @packages.present? %> <% if @packages.present? %>
<% @packages.each_with_index do |package, index| %> <% @packages.each_with_index do |package, index| %>
<tr> <tr class="project-package-item project-package-<%= package.id %>">
<td><%= (@obj_pages.page - 1) * @obj_pages.per_page + index + 1 %></td> <td><%= (@obj_pages.page - 1) * @obj_pages.per_page + index + 1 %></td>
<td class="edu-txt-left"> <td class="edu-txt-left">
<%= link_to package.title, project_package_path(package), target: '_blank', <%= link_to package.title, project_package_path(package), target: '_blank',
@ -30,7 +30,7 @@
<td><%= package.created_at.strftime('%Y-%m-%d %H:%M') %></td> <td><%= package.created_at.strftime('%Y-%m-%d %H:%M') %></td>
<td><%= package.published_at.try(:strftime, '%Y-%m-%d %H:%M') || '--' %></td> <td><%= package.published_at.try(:strftime, '%Y-%m-%d %H:%M') || '--' %></td>
<td><%= package.deadline_at.try(:strftime, '%Y-%m-%d %H:%M') || '--' %></td> <td><%= package.deadline_at.try(:strftime, '%Y-%m-%d %H:%M') || '--' %></td>
<td></td> <td> <%= link_to '删除', 'javascript:void(0)', class: 'delete-btn', data: { id: package.id } %></td>
</tr> </tr>
<% end %> <% end %>
<% else %> <% else %>

@ -36,6 +36,11 @@
$(".management-project-packages-form").submit(); $(".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 = { var locale = {
clearText: '清除', clearText: '清除',
clearStatus: '清除已选日期', clearStatus: '清除已选日期',
@ -86,4 +91,25 @@
form.submit(); 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;
}
</script> </script>

@ -130,7 +130,7 @@
$('.project-packages-list .project-package-item.project-package-' + id).remove(); $('.project-packages-list .project-package-item.project-package-' + id).remove();
if($('.project-packages-list .project-package-item').length == 0){ 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 { } else {
notice_box(data.message); notice_box(data.message);

Loading…
Cancel
Save