From 7115103b5ea7017f32ebd7b9ef783c2cdbdd4819 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 4 Nov 2015 12:42:57 +0100 Subject: [PATCH] Mark ticket as changed if only one attachment is uploaded. Delete uploaded attachments on form rest. --- .../app/controllers/ticket_zoom.coffee | 16 ++++++++++++++ .../ticket_zoom/article_new.coffee | 4 ++-- app/controllers/ticket_articles_controller.rb | 22 ++++++++++++++----- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.coffee index 79760213c..d66bd4b8c 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.coffee @@ -415,6 +415,14 @@ class App.TicketZoom extends App.Controller currentParams = ticket: @formParam( @el.find('.edit') ) article: @formParam( @el.find('.article-add') ) + + # add attachments if exist + attachmentCount = @$('.article-add .textBubble .attachments .attachment').length + if attachmentCount > 0 + currentParams.article.attachments = true + else + delete currentParams.article.attachments + #console.log('lll', currentStore) # remove not needed attributes delete currentParams.article.form_id @@ -650,6 +658,14 @@ class App.TicketZoom extends App.Controller # reset task @taskReset() + # reset/delete uploaded attachments + App.Ajax.request( + type: 'DELETE' + url: App.Config.get('api_path') + '/ticket_attachment_upload' + data: JSON.stringify( { form_id: @form_id } ) + processData: false + ) + # reset edit ticket / reset new article App.Event.trigger('ui::ticket::taskReset', { ticket_id: @ticket.id }) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee index 821f4dc4c..78c349d8b 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee @@ -371,7 +371,7 @@ class App.TicketZoomArticleNew extends App.Controller openTextarea: (event, withoutAnimation) => if @articleNewEdit.hasClass('is-open') return - + duration = 300 if withoutAnimation @@ -517,7 +517,7 @@ class App.TicketZoomArticleNew extends App.Controller App.Ajax.request( type: 'DELETE' url: App.Config.get('api_path') + '/ticket_attachment_upload' - data: JSON.stringify( { store_id: store_id } ), + data: JSON.stringify( { store_id: store_id } ) processData: false ) diff --git a/app/controllers/ticket_articles_controller.rb b/app/controllers/ticket_articles_controller.rb index 0901ff793..da537268c 100644 --- a/app/controllers/ticket_articles_controller.rb +++ b/app/controllers/ticket_articles_controller.rb @@ -66,12 +66,24 @@ class TicketArticlesController < ApplicationController # DELETE /ticket_attachment_upload def ticket_attachment_upload_delete - Store.remove_item( params[:store_id] ) + if params[:store_id] + Store.remove_item(params[:store_id]) + render json: { + success: true, + } + return + elsif params[:form_id] + Store.remove( + object: 'UploadCache', + o_id: params[:form_id], + ) + render json: { + success: true, + } + return + end - # return result - render json: { - success: true, - } + render json: { message: 'No such store_id or form_id!' }, status: :unprocessable_entity end # POST /ticket_attachment_upload