From ee7319ab1ff1461bf117b55cca9aec7e379ebca7 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 19 Mar 2018 11:33:47 +0100 Subject: [PATCH] Follow up for issue #338 behaviour reply behaviour. --- .../ticket_zoom/article_action/email_reply.coffee | 1 + .../app/controllers/ticket_zoom/article_new.coffee | 12 ++++++++---- app/controllers/users_controller.rb | 10 +++++++--- test/controllers/user_controller_test.rb | 10 ++++++++++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/article_action/email_reply.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/article_action/email_reply.coffee index 4845d1e98..3228ba3bc 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/article_action/email_reply.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/article_action/email_reply.coffee @@ -195,6 +195,7 @@ class EmailReply extends App.Controller type: type article: articleNew signaturePosition: signaturePosition + focus: 'to' }) # add attachments to form 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 0a183c008..bc76912be 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee @@ -54,19 +54,23 @@ class App.TicketZoomArticleNew extends App.Controller @openTextarea(null, true) for key, value of data.article if key is 'body' - @$('[data-name="' + key + '"]').html(value) + @$("[data-name=\"#{key}\"]").html(value) else - @$('[name="' + key + '"]').val(value).trigger('change') + @$("[name=\"#{key}\"]").val(value).trigger('change') # preselect article type @setArticleType(data.type.name, data.signaturePosition) + # set focus into field + if data.focus + @$("[name=\"#{data.focus}\"], [data-name=\"#{data.focus}\"]").focus().parent().find('.token-input').focus() + return + # set focus at end of field if data.position is 'end' @placeCaretAtEnd(@textarea.get(0)) return - # set focus into field @textarea.focus() ) @@ -89,7 +93,6 @@ class App.TicketZoomArticleNew extends App.Controller # set expand of text area only once @bind('ui::ticket::shown', (data) => return if data.ticket_id.toString() isnt @ticket.id.toString() - console.log('SHOW, ui::ticket::shown', data.ticket_id) @tokanice() ) @@ -111,6 +114,7 @@ class App.TicketZoomArticleNew extends App.Controller if !e.attrs.value.match(/@/) || e.attrs.value.match(/\s/) e.preventDefault() return false + e.attrs.label = e.attrs.value true ) App.Delay.set(a, 500, undefined, 'tags') diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 639d06873..b94587ce4 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -428,11 +428,15 @@ class UsersController < ApplicationController if params[:label] || params[:term] users = [] user_all.each do |user| - realname = user.firstname.to_s + ' ' + user.lastname.to_s - if user.email && user.email.to_s != '' + realname = user.fullname + if user.email.present? && realname != user.email realname = "#{realname} <#{user.email}>" end - a = { id: user.id, label: realname, value: user.email } + a = if params[:term] + { id: user.id, label: realname, value: user.email } + else + { id: user.id, label: realname, value: realname } + end users.push a end diff --git a/test/controllers/user_controller_test.rb b/test/controllers/user_controller_test.rb index d6a365bb7..1b810356f 100644 --- a/test/controllers/user_controller_test.rb +++ b/test/controllers/user_controller_test.rb @@ -527,6 +527,16 @@ class UserControllerTest < ActionDispatch::IntegrationTest assert_not(result[0]['role_ids']) assert_not(result[0]['roles']) + get "/api/v1/users/search?term=#{CGI.escape("Customer#{firstname}")}", params: {}, headers: @headers.merge('Authorization' => credentials) + assert_response(200) + result = JSON.parse(@response.body) + assert_equal(Array, result.class) + assert_equal(result_user1['id'], result[0]['id']) + assert_equal("Customer#{firstname} Customer Last ", result[0]['label']) + assert_equal('new_customer_by_agent@example.com', result[0]['value']) + assert_not(result[0]['role_ids']) + assert_not(result[0]['roles']) + role = Role.find_by(name: 'Agent') get "/api/v1/users/search?query=#{CGI.escape("Customer#{firstname}")}&role_ids=#{role.id}&label=true", params: {}, headers: @headers.merge('Authorization' => credentials) assert_response(200)