Fixes #3636 - Replacing a mention with a new leads to mentioning both agents.
This commit is contained in:
parent
c8660b6d6f
commit
cfa3981ef6
2 changed files with 48 additions and 1 deletions
|
@ -43,6 +43,7 @@
|
||||||
|
|
||||||
Plugin.prototype.bindEvents = function () {
|
Plugin.prototype.bindEvents = function () {
|
||||||
this.$element.on('keydown', this.onKeydown.bind(this))
|
this.$element.on('keydown', this.onKeydown.bind(this))
|
||||||
|
this.$element.on('keyup', this.onKeyup.bind(this))
|
||||||
// using onInput event to trigger onKeyPress behavior
|
// using onInput event to trigger onKeyPress behavior
|
||||||
// since keyPress doesn't work on Mobile Chrome / Android
|
// since keyPress doesn't work on Mobile Chrome / Android
|
||||||
this.$element.on('input', this.onKeypress.bind(this))
|
this.$element.on('input', this.onKeypress.bind(this))
|
||||||
|
@ -150,6 +151,15 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Plugin.prototype.onKeyup = function (e) {
|
||||||
|
|
||||||
|
// in normal use we make sure that mentions
|
||||||
|
// which has no text anymore get deleted
|
||||||
|
if (e.keyCode == 8 && !this.buffer) {
|
||||||
|
this.removeInvalidMentions()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Plugin.prototype.onKeypress = function (e) {
|
Plugin.prototype.onKeypress = function (e) {
|
||||||
this.log('BUFF', this.buffer, e.keyCode, String.fromCharCode(e.which))
|
this.log('BUFF', this.buffer, e.keyCode, String.fromCharCode(e.which))
|
||||||
|
|
||||||
|
@ -203,6 +213,15 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove invalid mentions
|
||||||
|
Plugin.prototype.removeInvalidMentions = function() {
|
||||||
|
this.$element.find('a[data-mention-user-id]').each(function() {
|
||||||
|
if ($(this).text() != '') return true
|
||||||
|
|
||||||
|
$(this).remove()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// check if at least one trigger is available with the given prefix
|
// check if at least one trigger is available with the given prefix
|
||||||
Plugin.prototype.hasAvailableTriggers = function(prefix) {
|
Plugin.prototype.hasAvailableTriggers = function(prefix) {
|
||||||
var result = _.find(this.helpers, function(helper) {
|
var result = _.find(this.helpers, function(helper) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
RSpec.shared_examples 'text modules' do |path:|
|
RSpec.shared_examples 'text modules' do |path:|
|
||||||
|
let!(:agent_fixed_name) { create :agent, firstname: 'FFFF1', lastname: 'GGGG1', groups: [Group.find_by(name: 'Users')] }
|
||||||
let!(:group1) { create :group }
|
let!(:group1) { create :group }
|
||||||
let!(:group2) { create :group }
|
let!(:group2) { create :group }
|
||||||
let!(:text_module_without_group) { create :text_module }
|
let!(:text_module_without_group) { create :text_module }
|
||||||
|
@ -40,6 +40,34 @@ RSpec.shared_examples 'text modules' do |path:|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does delete empty mentions (issue #3636 / FF only)' do
|
||||||
|
visit path
|
||||||
|
within(:active_content) do
|
||||||
|
find('select[name="group_id"]').select('Users')
|
||||||
|
find(:richtext).send_keys('@@FFFF1')
|
||||||
|
find(:richtext).send_keys(:enter)
|
||||||
|
find(:richtext).send_keys(:enter)
|
||||||
|
(agent_fixed_name.firstname.length + agent_fixed_name.lastname.length + 2).times do
|
||||||
|
find(:richtext).send_keys(:backspace)
|
||||||
|
end
|
||||||
|
expect(find(:richtext).all('a[data-mention-user-id]', visible: :all).count).to eq(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does delete empty mentions (issue #3636 / simulation)' do
|
||||||
|
visit path
|
||||||
|
within(:active_content) do
|
||||||
|
find('select[name="group_id"]').select('Users')
|
||||||
|
find(:richtext).send_keys('@@FFFF1')
|
||||||
|
find(:richtext).send_keys(:enter)
|
||||||
|
find(:richtext).send_keys(:enter)
|
||||||
|
find(:richtext).send_keys('test')
|
||||||
|
page.execute_script("$('a[data-mention-user-id]').first().html('<br>')")
|
||||||
|
find(:richtext).send_keys(:backspace)
|
||||||
|
expect(find(:richtext).all('a[data-mention-user-id]', visible: :all).count).to eq(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'supports group-dependent text modules' do
|
it 'supports group-dependent text modules' do
|
||||||
|
|
||||||
# give user access to all groups including those created
|
# give user access to all groups including those created
|
||||||
|
|
Loading…
Reference in a new issue