diff --git a/app/assets/javascripts/app/controllers/agent_ticket_create.coffee b/app/assets/javascripts/app/controllers/agent_ticket_create.coffee index 938409c13..88f907e11 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_create.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_create.coffee @@ -181,7 +181,8 @@ class App.TicketCreate extends App.Controller show: => @navupdate("#ticket/create/id/#{@id}#{@split}", type: 'menu') @autosaveStart() - @controllerBind('ticket_create_rerender', (template) => @renderQueue(template)) + @controllerBind('ticket_create_rerender', (template) => @renderQueue(template)) + @controllerBind('ticket_create_shared_draft_saved', @sharedDraftSaved) @controllerBind('ticket_create_import_draft_attachments', @importDraftAttachments) # initially hide sidebar on mobile @@ -192,6 +193,7 @@ class App.TicketCreate extends App.Controller hide: => @autosaveStop() @controllerUnbind('ticket_create_rerender', (template) => @renderQueue(template)) + @controllerUnbind('ticket_create_shared_draft_saved') @controllerUnbind('ticket_create_import_draft_attachments') changed: => @@ -305,6 +307,11 @@ class App.TicketCreate extends App.Controller error: -> App.Event.trigger(options.callbackName, { success: false }) + sharedDraftSaved: (options) => + @el + .find('.ticket-create input[name=shared_draft_id]') + .val(options.shared_draft_id) + updateTaskManagerAttachments: (attribute, attachments) => taskData = App.TaskManager.get(@taskKey) return if _.isEmpty(taskData) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.coffee index db85fa10f..bd00db322 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.coffee @@ -1016,6 +1016,7 @@ class App.TicketZoom extends App.Controller data: JSON.stringify(params) success: (data, status, xhr) => App.Collection.loadAssets(data.assets) + App.Event.trigger 'ui::ticket::shared_draft_saved', { ticket_id: @ticket_id, shared_draft_id: data.shared_draft_id } @draftFetched() error: => @draftFetched() 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 032831eec..c87e8a76a 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee @@ -80,6 +80,7 @@ class App.TicketZoomArticleNew extends App.Controller ) @controllerBind('ui::ticket::import_draft_attachments', @importDraftAttachments) + @controllerBind('ui::ticket::shared_draft_saved', @sharedDraftSaved) # add article attachment @controllerBind('ui::ticket::addArticleAttachent', (data) => @@ -659,6 +660,13 @@ class App.TicketZoomArticleNew extends App.Controller error: -> App.Event.trigger(options.callbackName, { success: false }) + sharedDraftSaved: (options) => + return if @ticket.id != options.ticket_id + + @el + .find('input[name=shared_draft_id]') + .val(options.shared_draft_id) + actions: -> actionConfig = App.Config.get('TicketZoomArticleAction') keys = _.keys(actionConfig).sort() diff --git a/app/assets/javascripts/app/controllers/widget/shared_draft.coffee b/app/assets/javascripts/app/controllers/widget/shared_draft.coffee index 34ffdd254..ce6d08cc6 100644 --- a/app/assets/javascripts/app/controllers/widget/shared_draft.coffee +++ b/app/assets/javascripts/app/controllers/widget/shared_draft.coffee @@ -66,6 +66,7 @@ class App.WidgetSharedDraft extends App.Controller success: (data, status, xhr) => App.Collection.loadAssets(data.assets) + App.Event.trigger 'ticket_create_shared_draft_saved', { shared_draft_id: data.shared_draft_id } @render() highlightError: -> diff --git a/spec/system/ticket/shared_draft_start_spec.rb b/spec/system/ticket/shared_draft_start_spec.rb index cc4dec1b1..20d6389a6 100644 --- a/spec/system/ticket/shared_draft_start_spec.rb +++ b/spec/system/ticket/shared_draft_start_spec.rb @@ -31,6 +31,16 @@ RSpec.describe 'Ticket Shared Draft Start', type: :system, authenticated_as: :au click '.settings.add' end + shared_examples 'shared draft ID is present' do + it 'sets shared draft ID' do + within :active_content do + elem = find('.ticket-create input[name=shared_draft_id]', visible: :all) + + expect(Ticket::SharedDraftStart).to be_exist(elem.value) + end + end + end + context 'sidebar' do context 'given multiple groups' do let(:another_group) { create(:group, shared_drafts: false) } @@ -96,6 +106,18 @@ RSpec.describe 'Ticket Shared Draft Start', type: :system, authenticated_as: :au .by 1 end end + + context 'draft saved' do + before do + within :draft_sidebar do + find('.js-name').fill_in with: 'Draft Name' + + click '.js-create' + end + end + + include_examples 'shared draft ID is present' + end end context 'update' do @@ -207,6 +229,8 @@ RSpec.describe 'Ticket Shared Draft Start', type: :system, authenticated_as: :au end end + include_examples 'shared draft ID is present' + it 'applies body' do within :active_content do expect(page).to have_text draft_body diff --git a/spec/system/ticket/shared_draft_zoom_spec.rb b/spec/system/ticket/shared_draft_zoom_spec.rb index eb9f033c7..a63f3df60 100644 --- a/spec/system/ticket/shared_draft_zoom_spec.rb +++ b/spec/system/ticket/shared_draft_zoom_spec.rb @@ -32,6 +32,16 @@ RSpec.describe 'Ticket Shared Draft Zoom', type: :system, authenticated_as: :aut visit "ticket/zoom/#{ticket.id}" end + shared_examples 'shared draft ID is present' do + it 'sets shared draft ID' do + within :active_content do + elem = find('.article-add input[name=shared_draft_id]', visible: :all) + + expect(Ticket::SharedDraftZoom).to be_exist(elem.value) + end + end + end + context 'buttons' do context 'when drafts disabled for the group' do let(:group_shared_drafts) { false } @@ -169,6 +179,17 @@ RSpec.describe 'Ticket Shared Draft Zoom', type: :system, authenticated_as: :aut expect(draft.reload.new_article[:body]).to match %r{another reply} end + context 'draft saved' do + before do + find('.articleNewEdit-body').send_keys('Some reply') + + click '.js-openDropdownMacro' + click :draft_save_button + end + + include_examples 'shared draft ID is present' + end + context 'draft loaded' do before do visit "ticket/zoom/#{ticket_with_draft.id}" @@ -214,6 +235,8 @@ RSpec.describe 'Ticket Shared Draft Zoom', type: :system, authenticated_as: :aut end end + include_examples 'shared draft ID is present' + it 'applies new article body' do expect(page).to have_text draft_body end