From 0065028ee61a7a433cce58c9501bd40340fdd5a4 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 5 Jul 2017 07:18:19 +0200 Subject: [PATCH] Implemented issue#341 - optional subject for email, define if twitter initials are used and default internal state of new notes. --- .../app/controllers/ticket_zoom.coffee | 19 +- .../ticket_zoom/article_new.coffee | 218 ++++++++++-------- .../{higlighter.coffee => highlighter.coffee} | 0 .../controllers/ticket_zoom/setting.coffee | 35 +++ .../javascripts/app/views/ticket_zoom.jst.eco | 15 +- .../app/views/ticket_zoom/article_new.jst.eco | 10 +- .../app/views/ticket_zoom/setting.jst.eco | 3 + .../20170630000001_ticket_zoom_setting.rb | 99 ++++++++ db/seeds/settings.rb | 65 +++++- test/browser_test_helper.rb | 2 +- 10 files changed, 342 insertions(+), 124 deletions(-) rename app/assets/javascripts/app/controllers/ticket_zoom/{higlighter.coffee => highlighter.coffee} (100%) create mode 100644 app/assets/javascripts/app/controllers/ticket_zoom/setting.coffee create mode 100644 app/assets/javascripts/app/views/ticket_zoom/setting.jst.eco create mode 100644 db/migrate/20170630000001_ticket_zoom_setting.rb diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.coffee index d523501f2..067618d68 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.coffee @@ -404,7 +404,7 @@ class App.TicketZoom extends App.Controller ) new App.TicketZoomOverviewNavigator( - el: elLocal.find('.overview-navigator') + el: elLocal.find('.js-overviewNavigatorContainer') ticket_id: @ticket_id overview_id: @overview_id ) @@ -412,13 +412,13 @@ class App.TicketZoom extends App.Controller new App.TicketZoomTitle( object_id: @ticket_id overview_id: @overview_id - el: elLocal.find('.ticket-title') + el: elLocal.find('.js-ticketTitleContainer') task_key: @task_key ) new App.TicketZoomMeta( object_id: @ticket_id - el: elLocal.find('.ticket-meta') + el: elLocal.find('.js-ticketMetaContainer') ) @attributeBar = new App.TicketZoomAttributeBar( @@ -445,7 +445,12 @@ class App.TicketZoom extends App.Controller ) @highligher = new App.TicketZoomHighlighter( - el: elLocal.find('.highlighter') + el: elLocal.find('.js-highlighterContainer') + ticket_id: @ticket_id + ) + + new App.TicketZoomSetting( + el: elLocal.find('.js-settingContainer') ticket_id: @ticket_id ) @@ -557,14 +562,16 @@ class App.TicketZoom extends App.Controller return if !@ticket currentStoreTicket = @ticket.attributes() delete currentStoreTicket.article + internal = @Config.get('ui_ticket_zoom_article_note_new_internal') currentStore = ticket: currentStoreTicket article: to: '' cc: '' + subject: '' type: 'note' body: '' - internal: 'true' + internal: internal in_reply_to: '' if @permissionCheck('ticket.customer') @@ -575,7 +582,7 @@ class App.TicketZoom extends App.Controller formCurrent: => currentParams = ticket: @formParam(@el.find('.edit')) - article: @formParam(@el.find('.article-add')) + article: @articleNew.params() # add attachments if exist attachmentCount = @$('.article-add .textBubble .attachments .attachment').length 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 c42c5ba7a..60fd1b1bf 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee @@ -28,107 +28,9 @@ class App.TicketZoomArticleNew extends App.Controller constructor: -> super - # set possble article types - possibleArticleType = - note: true - phone: true - if @ticket && @ticket.create_article_type_id - articleTypeCreate = App.TicketArticleType.find(@ticket.create_article_type_id).name - if articleTypeCreate is 'twitter status' - possibleArticleType['twitter status'] = true - else if articleTypeCreate is 'twitter direct-message' - possibleArticleType['twitter direct-message'] = true - else if articleTypeCreate is 'email' - possibleArticleType['email'] = true - else if articleTypeCreate is 'facebook feed post' - possibleArticleType['facebook feed comment'] = true - else if articleTypeCreate is 'telegram personal-message' - possibleArticleType['telegram personal-message'] = true - if @ticket && @ticket.customer_id - customer = App.User.find(@ticket.customer_id) - if customer.email - possibleArticleType['email'] = true - - # gets referenced in @setArticleType @internalSelector = true @type = @defaults['type'] || 'note' - @articleTypes = [] - if possibleArticleType.note - internal = @Config.get('ui_ticket_zoom_article_new_internal') - - @articleTypes.push { - name: 'note' - icon: 'note' - attributes: [] - internal: internal, - features: ['attachment'] - } - if possibleArticleType.email - @articleTypes.push { - name: 'email' - icon: 'email' - attributes: ['to', 'cc'] - internal: false, - features: ['attachment'] - } - if possibleArticleType['facebook feed comment'] - @articleTypes.push { - name: 'facebook feed comment' - icon: 'facebook' - attributes: [] - internal: false, - features: [] - } - if possibleArticleType['twitter status'] - @articleTypes.push { - name: 'twitter status' - icon: 'twitter' - attributes: [] - internal: false, - features: ['body:limit', 'body:initials'] - maxTextLength: 140 - warningTextLength: 30 - } - if possibleArticleType['twitter direct-message'] - @articleTypes.push { - name: 'twitter direct-message' - icon: 'twitter' - attributes: ['to'] - internal: false, - features: ['body:limit', 'body:initials'] - maxTextLength: 10000 - warningTextLength: 500 - } - if possibleArticleType.phone - @articleTypes.push { - name: 'phone' - icon: 'phone' - attributes: [] - internal: false, - features: ['attachment'] - } - if possibleArticleType['telegram personal-message'] - @articleTypes.push { - name: 'telegram personal-message' - icon: 'telegram' - attributes: [] - internal: false, - features: ['attachment'] - maxTextLength: 10000 - warningTextLength: 5000 - } - - if @permissionCheck('ticket.customer') - @type = 'note' - @articleTypes = [ - { - name: 'note' - icon: 'note' - attributes: [] - internal: false, - features: ['attachment'] - }, - ] + @setPossibleArticleTypes() if @permissionCheck('ticket.customer') @internalSelector = false @@ -181,6 +83,114 @@ class App.TicketZoomArticleNew extends App.Controller @render() ) + setPossibleArticleTypes: => + possibleArticleType = + note: true + phone: true + if @ticket && @ticket.create_article_type_id + articleTypeCreate = App.TicketArticleType.find(@ticket.create_article_type_id).name + if articleTypeCreate is 'twitter status' + possibleArticleType['twitter status'] = true + else if articleTypeCreate is 'twitter direct-message' + possibleArticleType['twitter direct-message'] = true + else if articleTypeCreate is 'email' + possibleArticleType['email'] = true + else if articleTypeCreate is 'facebook feed post' + possibleArticleType['facebook feed comment'] = true + else if articleTypeCreate is 'telegram personal-message' + possibleArticleType['telegram personal-message'] = true + if @ticket && @ticket.customer_id + customer = App.User.find(@ticket.customer_id) + if customer.email + possibleArticleType['email'] = true + + # gets referenced in @setArticleType + @articleTypes = [] + if possibleArticleType.note + internal = @Config.get('ui_ticket_zoom_article_note_new_internal') + @articleTypes.push { + name: 'note' + icon: 'note' + attributes: [] + internal: internal, + features: ['attachment'] + } + if possibleArticleType.email + attributes = ['to', 'cc', 'subject'] + if !@Config.get('ui_ticket_zoom_article_email_subject') + attributes = ['to', 'cc'] + @articleTypes.push { + name: 'email' + icon: 'email' + attributes: attributes + internal: false, + features: ['attachment'] + } + if possibleArticleType['facebook feed comment'] + @articleTypes.push { + name: 'facebook feed comment' + icon: 'facebook' + attributes: [] + internal: false, + features: [] + } + if possibleArticleType['twitter status'] + attributes = ['body:limit', 'body:initials'] + if !@Config.get('ui_ticket_zoom_article_twitter_initials') + attributes = ['body:limit'] + @articleTypes.push { + name: 'twitter status' + icon: 'twitter' + attributes: [] + internal: false, + features: ['body:limit', 'body:initials'] + maxTextLength: 140 + warningTextLength: 30 + } + if possibleArticleType['twitter direct-message'] + attributes = ['body:limit', 'body:initials'] + if !@Config.get('ui_ticket_zoom_article_twitter_initials') + attributes = ['body:limit'] + @articleTypes.push { + name: 'twitter direct-message' + icon: 'twitter' + attributes: ['to'] + internal: false, + features: ['body:limit', 'body:initials'] + maxTextLength: 10000 + warningTextLength: 500 + } + if possibleArticleType.phone + @articleTypes.push { + name: 'phone' + icon: 'phone' + attributes: [] + internal: false, + features: ['attachment'] + } + if possibleArticleType['telegram personal-message'] + @articleTypes.push { + name: 'telegram personal-message' + icon: 'telegram' + attributes: [] + internal: false, + features: ['attachment'] + maxTextLength: 10000 + warningTextLength: 5000 + } + + if @permissionCheck('ticket.customer') + @type = 'note' + @articleTypes = [ + { + name: 'note' + icon: 'note' + attributes: [] + internal: false, + features: ['attachment'] + }, + ] + placeCaretAtEnd: (el) -> el.focus() if typeof window.getSelection isnt 'undefined' && typeof document.createRange isnt 'undefined' @@ -318,9 +328,6 @@ class App.TicketZoomArticleNew extends App.Controller params.form_id = @form_id params.content_type = 'text/html' - if !params['internal'] - params['internal'] = false - if @permissionCheck('ticket.customer') sender = App.TicketArticleSender.findByAttribute('name', 'Customer') type = App.TicketArticleType.findByAttribute('name', 'web') @@ -332,6 +339,11 @@ class App.TicketZoomArticleNew extends App.Controller params.sender_id = sender.id params.type_id = type.id + if params.internal + params.internal = true + else + params.internal = false + if params.type is 'twitter status' App.Utils.htmlRemoveRichtext(@$('[data-name=body]'), false) params.content_type = 'text/plain' @@ -478,6 +490,8 @@ class App.TicketZoomArticleNew extends App.Controller @articleNewEdit.attr('data-type', type) @$('.js-selectableTypes').addClass('hide').filter("[data-type='#{type}']").removeClass('hide') + @setPossibleArticleTypes() + # get config config = {} for articleTypeConfig in @articleTypes diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/higlighter.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/highlighter.coffee similarity index 100% rename from app/assets/javascripts/app/controllers/ticket_zoom/higlighter.coffee rename to app/assets/javascripts/app/controllers/ticket_zoom/highlighter.coffee diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/setting.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/setting.coffee new file mode 100644 index 000000000..1103f9e3c --- /dev/null +++ b/app/assets/javascripts/app/controllers/ticket_zoom/setting.coffee @@ -0,0 +1,35 @@ +class App.TicketZoomSetting extends App.Controller + events: + 'click .js-setting': 'show' + + constructor: -> + super + return if !@permissionCheck('admin') + @render() + + render: -> + @html(App.view('ticket_zoom/setting')()) + + show: -> + new Modal() + +class Modal extends App.ControllerModal + buttonClose: true + buttonCancel: true + buttonSubmit: false + head: 'Settings' + + constructor: -> + super + + render: => + super + + post: => + new App.SettingsArea( + area: 'UI::TicketZoom' + el: @el.find('.modal-body') + ) + + content: -> + App.view('generic/page_loading')() diff --git a/app/assets/javascripts/app/views/ticket_zoom.jst.eco b/app/assets/javascripts/app/views/ticket_zoom.jst.eco index 36ef86765..89d8733a8 100644 --- a/app/assets/javascripts/app/views/ticket_zoom.jst.eco +++ b/app/assets/javascripts/app/views/ticket_zoom.jst.eco @@ -1,21 +1,22 @@
<%- @C('ticket_hook') %> <%- @ticket.number %> -
-
-
+
+
+
-
-
+
+
+
-
-
+
+
diff --git a/app/assets/javascripts/app/views/ticket_zoom/article_new.jst.eco b/app/assets/javascripts/app/views/ticket_zoom/article_new.jst.eco index 4f160381a..7f7142818 100644 --- a/app/assets/javascripts/app/views/ticket_zoom/article_new.jst.eco +++ b/app/assets/javascripts/app/views/ticket_zoom/article_new.jst.eco @@ -41,13 +41,19 @@
-
+
-
+
+
+
+
+ +
+
diff --git a/app/assets/javascripts/app/views/ticket_zoom/setting.jst.eco b/app/assets/javascripts/app/views/ticket_zoom/setting.jst.eco new file mode 100644 index 000000000..491eab3c3 --- /dev/null +++ b/app/assets/javascripts/app/views/ticket_zoom/setting.jst.eco @@ -0,0 +1,3 @@ +
+ <%- @Icon('cog', 'dropdown-icon') %> +
\ No newline at end of file diff --git a/db/migrate/20170630000001_ticket_zoom_setting.rb b/db/migrate/20170630000001_ticket_zoom_setting.rb new file mode 100644 index 000000000..9966132fd --- /dev/null +++ b/db/migrate/20170630000001_ticket_zoom_setting.rb @@ -0,0 +1,99 @@ +class TicketZoomSetting < ActiveRecord::Migration + def up + + # return if it's a new setup + return if !Setting.find_by(name: 'system_init_done') + + setting = Setting.find_by(name: 'ui_ticket_zoom_article_new_internal') + if setting + setting.title = 'Note - default visibility' + setting.name = 'ui_ticket_zoom_article_note_new_internal' + setting.description = 'Default visibility for new articles.' + setting.preferences[:prio] = 100 + setting.options[:form][0][:name] = 'ui_ticket_zoom_article_note_new_internal' + setting.save! + end + Setting.create_if_not_exists( + title: 'Note - default visibility', + name: 'ui_ticket_zoom_article_note_new_internal', + area: 'UI::TicketZoom', + description: 'Default visibility for new articles.', + options: { + form: [ + { + display: '', + null: true, + name: 'ui_ticket_zoom_article_note_new_internal', + tag: 'boolean', + translate: true, + options: { + true => 'internal', + false => 'public', + }, + }, + ], + }, + state: true, + preferences: { + prio: 100, + permission: ['admin.ui'], + }, + frontend: true + ) + Setting.create_if_not_exists( + title: 'Email - subject field', + name: 'ui_ticket_zoom_article_email_subject', + area: 'UI::TicketZoom', + description: 'Use subject field for emails. If disabled, the ticket title will be used as subject.', + options: { + form: [ + { + display: '', + null: true, + name: 'ui_ticket_zoom_article_email_subject', + tag: 'boolean', + translate: true, + options: { + true => 'yes', + false => 'no', + }, + }, + ], + }, + state: false, + preferences: { + prio: 200, + permission: ['admin.ui'], + }, + frontend: true + ) + Setting.create_if_not_exists( + title: 'Twitter - tweet initials', + name: 'ui_ticket_zoom_article_twitter_initials', + area: 'UI::TicketZoom', + description: 'Add sender initials to end of a tweet.', + options: { + form: [ + { + display: '', + null: true, + name: 'ui_ticket_zoom_article_twitter_initials', + tag: 'boolean', + translate: true, + options: { + true => 'yes', + false => 'no', + }, + }, + ], + }, + state: true, + preferences: { + prio: 300, + permission: ['admin.ui'], + }, + frontend: true + ) + end + +end diff --git a/db/seeds/settings.rb b/db/seeds/settings.rb index 9734aa262..73b3b7797 100644 --- a/db/seeds/settings.rb +++ b/db/seeds/settings.rb @@ -546,18 +546,17 @@ Setting.create_if_not_exists( }, frontend: true ) - Setting.create_if_not_exists( - title: 'Define default visibility of new a new article', - name: 'ui_ticket_zoom_article_new_internal', + title: 'Note - default visibility', + name: 'ui_ticket_zoom_article_note_new_internal', area: 'UI::TicketZoom', - description: 'Set default visibility of new a new article.', + description: 'Default visibility for new note.', options: { form: [ { display: '', null: true, - name: 'ui_ticket_zoom_article_new_internal', + name: 'ui_ticket_zoom_article_note_new_internal', tag: 'boolean', translate: true, options: { @@ -569,7 +568,61 @@ Setting.create_if_not_exists( }, state: true, preferences: { - prio: 1, + prio: 100, + permission: ['admin.ui'], + }, + frontend: true +) +Setting.create_if_not_exists( + title: 'Email - subject field', + name: 'ui_ticket_zoom_article_email_subject', + area: 'UI::TicketZoom', + description: 'Use subject field for emails. If disabled, the ticket title will be used as subject.', + options: { + form: [ + { + display: '', + null: true, + name: 'ui_ticket_zoom_article_email_subject', + tag: 'boolean', + translate: true, + options: { + true => 'yes', + false => 'no', + }, + }, + ], + }, + state: false, + preferences: { + prio: 200, + permission: ['admin.ui'], + }, + frontend: true +) +Setting.create_if_not_exists( + title: 'Twitter - tweet initials', + name: 'ui_ticket_zoom_article_twitter_initials', + area: 'UI::TicketZoom', + description: 'Add sender initials to end of a tweet.', + options: { + form: [ + { + display: '', + null: true, + name: 'ui_ticket_zoom_article_twitter_initials', + tag: 'boolean', + translate: true, + options: { + true => 'yes', + false => 'no', + }, + }, + ], + }, + state: true, + preferences: { + prio: 300, permission: ['admin.ui'], }, frontend: true diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index 1e221f193..f0c42a8d1 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -2261,7 +2261,7 @@ wait untill text in selector disabppears 9.times { begin text = instance.find_elements(css: '.content.active .js-reset')[0].text - if !text || text.empty? + if text.blank? screenshot(browser: instance, comment: 'ticket_update_ok') sleep 1 return true