From 2fe61680e33ae167bbe232e9eb360699143c9978 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 3 Sep 2015 19:29:43 +0800 Subject: [PATCH] added delete option.. person making the comment can delete --- app/controllers/admin/tickets_controller.rb | 6 ++ app/views/admin/tickets/_response.html.erb | 14 +-- app/views/admin/tickets/show.html.erb | 103 +++++++++++--------- config/routes.rb | 1 + 4 files changed, 71 insertions(+), 53 deletions(-) diff --git a/app/controllers/admin/tickets_controller.rb b/app/controllers/admin/tickets_controller.rb index 83bbeef..363687d 100644 --- a/app/controllers/admin/tickets_controller.rb +++ b/app/controllers/admin/tickets_controller.rb @@ -209,6 +209,12 @@ class Admin::TicketsController < OrbitAdminController render :json => data.to_json end + def delete_response + response = TicketQueryResponse.find(params[:response_id]) rescue nil + response.destroy if !response.nil? + render :json => {"success" => true}.to_json + end + def tickets_by_category @table_fields = [:ticket_number, :site_name, :subject, :created_at, :tags, :status, :taken_by, :urgent] statuses = params["type"] == "history" ? ["closed"] : ["open","commenced"] diff --git a/app/views/admin/tickets/_response.html.erb b/app/views/admin/tickets/_response.html.erb index ca97823..aff17a4 100644 --- a/app/views/admin/tickets/_response.html.erb +++ b/app/views/admin/tickets/_response.html.erb @@ -14,12 +14,14 @@
<% dt = DateTime.parse(response.created_at.to_s) %> <%= dt.strftime("%d %B %Y - %H:%M") %>
-
- - - Delete - -
+ <% if user.id.to_s == current_user.id.to_s %> +
+ + + Delete + +
+ <% end %>
diff --git a/app/views/admin/tickets/show.html.erb b/app/views/admin/tickets/show.html.erb index 2ca95d4..351c926 100644 --- a/app/views/admin/tickets/show.html.erb +++ b/app/views/admin/tickets/show.html.erb @@ -104,52 +104,48 @@
-
- - - <%= !@ticket.ticket_creater_name.nil? ? @ticket.ticket_creater_name : @ticket.ticket_creater_id %> - - - - <% dt = DateTime.parse(@ticket.created_at.to_s) %> <%= dt.strftime("%d %B %Y - %H:%M") %> - -
-
- <% if @ticket.status != "closed" %> - - -
- - " id="myonoffswitch" data-url="/admin/tickets/<%= @ticket.id.to_s %>/toggleurgent"> - -
- - <% end %> - - - <%= @ticket.status %> - - - - - <%= @ticket.category.title %> - - - - -
+
+ + + <%= !@ticket.ticket_creater_name.nil? ? @ticket.ticket_creater_name : @ticket.ticket_creater_id %> + + + + <% dt = DateTime.parse(@ticket.created_at.to_s) %> <%= dt.strftime("%d %B %Y - %H:%M") %> + +
+
+ <% if @ticket.status != "closed" %> +
+ + " id="myonoffswitch" data-url="/admin/tickets/<%= @ticket.id.to_s %>/toggleurgent"> + +
+ <% end %> + + + <%= @ticket.status %> + + + + + <%= @ticket.category.title %> + + + + +
@@ -319,6 +315,19 @@ $(document).ready(function(){ return false; }) - + $("body").on("click",".ticket-response-delete",function(){ + var el = $(this); + $.ajax({ + url : el.attr("href"), + data : {"response_id" : el.data("response-id")}, + type : "delete", + dataType : "json" + }).done(function(){ + $("div[data-scroll-id=response_" + el.data("response-id") + "]").slideUp(function(){ + $(this).remove(); + }) + }) + return false; + }) diff --git a/config/routes.rb b/config/routes.rb index 5149815..fa6065a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,6 +13,7 @@ Rails.application.routes.draw do namespace :admin do get "tickets/search" => 'tickets#search' post "ticket/submit_response" => 'tickets#submit_response' + delete "ticket/delete_response" => 'tickets#delete_response' get "tickets/category/:category_id" => 'tickets#tickets_by_category' get "tickets/my_tickets" => 'tickets#my_tickets' post "comments/read" => 'tickets#mark_response_read'