mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 14:19:53 +01:00
deleting groups works now! finally!!!
This commit is contained in:
parent
745f600f60
commit
927ec9678f
5 changed files with 59 additions and 2 deletions
|
@ -57,3 +57,33 @@ $(document).on "keyup", "input#new-group-name", (evt) ->
|
|||
showNotification "An error occurred, a developer should check the console for details", false
|
||||
complete: (jqxhr, status) ->
|
||||
btn.button "reset"
|
||||
|
||||
|
||||
($ document).on "click", "a#delete-group", (ev) ->
|
||||
ev.preventDefault()
|
||||
btn = $(this)
|
||||
group = btn[0].dataset.group
|
||||
|
||||
swal
|
||||
title: "Really delete this group?"
|
||||
text: "You will not be able to recover this group."
|
||||
type: "warning"
|
||||
showCancelButton: true
|
||||
confirmButtonColor: "#DD6B55"
|
||||
confirmButtonText: "Delete"
|
||||
closeOnConfirm: true
|
||||
, ->
|
||||
$.ajax
|
||||
url: '/ajax/destroy_group'
|
||||
type: 'POST'
|
||||
data:
|
||||
group: group
|
||||
dataType: 'json'
|
||||
success: (data, status, jqxhr) ->
|
||||
if data.success
|
||||
($ "li.list-group-item#group-#{group}").slideUp()
|
||||
showNotification data.message, data.success
|
||||
error: (jqxhr, status, error) ->
|
||||
console.log jqxhr, status, error
|
||||
showNotification "An error occurred, a developer should check the console for details", false
|
||||
complete: (jqxhr, status) ->
|
||||
|
|
|
@ -35,6 +35,31 @@ class Ajax::GroupController < ApplicationController
|
|||
@render = render_to_string(partial: 'user/modal_group_item', locals: { group: group, user: target_user })
|
||||
end
|
||||
|
||||
def destroy
|
||||
@status = :err
|
||||
@success = false
|
||||
|
||||
unless user_signed_in?
|
||||
@status = :noauth
|
||||
@message = "requires authentication"
|
||||
return
|
||||
end
|
||||
|
||||
params.require :group
|
||||
|
||||
begin
|
||||
Group.where(user: current_user, name: params[:group]).first.destroy!
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
@status = :notfound
|
||||
@message = "Could not find group."
|
||||
return
|
||||
end
|
||||
|
||||
@status = :okay
|
||||
@success = true
|
||||
@message = "Successfully created group."
|
||||
end
|
||||
|
||||
def membership
|
||||
@status = :err
|
||||
@success = false
|
||||
|
|
1
app/views/ajax/group/destroy.json.jbuilder
Normal file
1
app/views/ajax/group/destroy.json.jbuilder
Normal file
|
@ -0,0 +1 @@
|
|||
json.partial! 'ajax/shared/status'
|
|
@ -1,4 +1,4 @@
|
|||
%li.list-group-item
|
||||
%li.list-group-item{id: "group-#{group.name}"}
|
||||
.media
|
||||
.pull-left.j2-table
|
||||
%input.input--center{type: :checkbox, name: 'gm-group-check', data: { group: group.name, user: user.screen_name }, checked: user.member_of?(group), autocomplete: 'off'}
|
||||
|
@ -7,6 +7,6 @@
|
|||
.list-group-item-text.text-muted.j2-up
|
||||
%span{id: "#{group.name}-members"}= group.members.count
|
||||
members ·
|
||||
%a.j2-delete{href: "#", id: "#{group.name}-delete"}
|
||||
%a.j2-delete#delete-group{href: "#", data: { group: group.name }}
|
||||
%i.fa.fa-close
|
||||
Delete
|
||||
|
|
|
@ -76,6 +76,7 @@ Rails.application.routes.draw do
|
|||
match '/destroy_comment', to: 'comment#destroy', via: :post, as: :destroy_comment
|
||||
match '/report', to: 'report#create', via: :post, as: :report
|
||||
match '/create_group', to: 'group#create', via: :post, as: :create_group
|
||||
match '/destroy_group', to: 'group#destroy', via: :post, as: :destroy_group
|
||||
match '/group_membership', to: 'group#membership', via: :post, as: :group_membership
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue