diff --git a/app/assets/javascripts/app/controllers/_ui_element/select.coffee b/app/assets/javascripts/app/controllers/_ui_element/select.coffee index 01b0692a3..13a830dd4 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/select.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/select.coffee @@ -35,8 +35,43 @@ class App.UiElement.select extends App.UiElement.ApplicationUiElement # filter attributes @filterOption(attribute, params) + item = $( App.view('generic/select')(attribute: attribute) ) + + # bind event listeners + @bindEventListeners(item, attribute, params) + # return item - $( App.view('generic/select')(attribute: attribute) ) + item + + @bindEventListeners: (item, attribute, params) -> + if attribute.display_warn + item.bind('change', (e) => + @bindWarnDisplayListener(e.target.value, attribute, params, item) + ) + + # initialization for default selection + @bindWarnDisplayListener(attribute.value, attribute, params, item) + + @bindWarnDisplayListener: (selectedVal, attribute, params, item) -> + warn_visible = @shouldDisplayWarn(selectedVal, attribute, params) + @toggleDisplayWarn(warn_visible, attribute, item) + + @shouldDisplayWarn: (selectedVal, attribute, params) -> + return if !selectedVal + return if !params + + params[attribute.name + '_is_display_warning'](selectedVal) + + @toggleDisplayWarn: (warn_visible, attribute, item) -> + if !warn_visible + item.removeClass('display-warn') + item.find('.alert--warning').remove() + return + + item.addClass('display-warn') + warn_elem = $('
') + warn_elem.html(attribute.warn) + item.append(warn_elem) # 1. If attribute.value is not among the current options, then search within historical options # 2. If attribute.value is not among current and historical options, then add the value itself as an option diff --git a/app/assets/javascripts/app/controllers/agent_ticket_create/form_handler_signature.coffee b/app/assets/javascripts/app/controllers/agent_ticket_create/form_handler_signature.coffee index 3bf7d56cc..8b1c8f6f7 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_create/form_handler_signature.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_create/form_handler_signature.coffee @@ -11,7 +11,7 @@ class TicketCreateFormHandlerSignature # check if signature needs to be added type = ui.el.closest('.content').find('[name="formSenderType"]').val() - if signature && signature.body && type is 'email-out' + if signature && signature.active && signature.body && type is 'email-out' signatureFinished = App.Utils.replaceTags(signature.body, { user: App.Session.get(), config: App.Config.all() }) currentBody = ui.el.closest('.content').find('[data-name=body]') 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 f77657f0b..3140ef3a7 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 @@ -339,7 +339,7 @@ class EmailReply extends App.Controller signature = App.Signature.find(group.signature_id) # add/replace signature - if signature && signature.body + if signature && signature.active && signature.body # if signature has changed, remove it signature_id = ui.$('[data-signature=true]').data('signature-id') diff --git a/app/assets/javascripts/app/models/group.coffee b/app/assets/javascripts/app/models/group.coffee index 43f6448ef..43d50af87 100644 --- a/app/assets/javascripts/app/models/group.coffee +++ b/app/assets/javascripts/app/models/group.coffee @@ -9,7 +9,7 @@ class App.Group extends App.Model { name: 'follow_up_possible', display: __('Follow-up possible'),tag: 'select', default: 'yes', options: { yes: 'yes', 'new_ticket': 'do not reopen Ticket but create new Ticket' }, null: false, note: __('Follow-up for closed ticket possible or not.'), translate: true }, { name: 'follow_up_assignment', display: __('Assign follow-ups'), tag: 'select', default: 'yes', options: { true: 'yes', false: 'no' }, null: false, note: __('Assign follow-up to latest agent again.'), translate: true }, { name: 'email_address_id', display: __('Email'), tag: 'select', multiple: false, null: true, relation: 'EmailAddress', nulloption: true, do_not_log: true }, - { name: 'signature_id', display: __('Signature'), tag: 'select', multiple: false, null: true, relation: 'Signature', nulloption: true, do_not_log: true }, + { name: 'signature_id', display: __('Signature'), tag: 'select', multiple: false, null: true, relation: 'Signature', nulloption: true, do_not_log: true, display_warn: true, warn: __('This signature is inactive, it won\'t be included in the reply. Change state here') }, { name: 'note', display: __('Note'), tag: 'textarea', note: __('Notes are visible to agents only, never to customers.'), limit: 250, null: true }, { name: 'updated_at', display: __('Updated'), tag: 'datetime', readonly: 1 }, { name: 'active', display: __('Active'), tag: 'active', default: true }, @@ -43,3 +43,6 @@ class App.Group extends App.Model change: 'Change' overview: 'Overview' full: 'Full' + + signature_id_is_display_warning: (signature_id) -> + !App.Signature.find(signature_id).active diff --git a/app/assets/javascripts/app/views/generic/select.jst.eco b/app/assets/javascripts/app/views/generic/select.jst.eco index d60ebcc05..bc0420544 100644 --- a/app/assets/javascripts/app/views/generic/select.jst.eco +++ b/app/assets/javascripts/app/views/generic/select.jst.eco @@ -1,12 +1,14 @@