Moved to App.Utils.replaceTags() and fixed quoting issues.

This commit is contained in:
Martin Edenhofer 2016-03-09 08:09:56 +01:00
parent 18e407693a
commit f6deecacd4
4 changed files with 46 additions and 54 deletions

View file

@ -2,6 +2,9 @@ class App.WidgetTextModule extends App.Controller
constructor: -> constructor: ->
super super
if !@data
@data = {}
# remember instances # remember instances
@bindElements = [] @bindElements = []
if @selector if @selector
@ -26,22 +29,10 @@ class App.WidgetTextModule extends App.Controller
update: => update: =>
allRaw = App.TextModule.all() allRaw = App.TextModule.all()
all = [] all = []
data = @data || @
for item in allRaw for item in allRaw
if item.active is true if item.active is true
attributes = item.attributes() attributes = item.attributes()
attributes.content = attributes.content.replace( /#\{{0,2}(.+?)\s{0,2}\}/g, ( index, key ) -> attributes.content = App.Utils.replaceTags(attributes.content, @data)
key = key.replace( /@/g, 'data.' )
varString = "#{key}" + ''
#console.log( "tag replacement env: ", data)
try
#console.log( "tag replacement: " + key, varString )
key = eval (varString)
catch error
#console.log( "tag replacement error: " + error )
key = ''
return key
)
all.push attributes all.push attributes
# set new data # set new data

View file

@ -83,7 +83,8 @@
if (e.keyCode == 38 && active.prev().size()) { if (e.keyCode == 38 && active.prev().size()) {
active = active.prev() active = active.prev()
} else if ( e.keyCode == 40 && active.next().size() ) { }
else if (e.keyCode == 40 && active.next().size()) {
active = active.next() active = active.next()
} }
@ -94,7 +95,8 @@
if (active.position().top < 0) { if (active.position().top < 0) {
// scroll up // scroll up
menu.scrollTop( menu.scrollTop() + active.position().top ) menu.scrollTop( menu.scrollTop() + active.position().top )
} else if ( active.position().top + active.height() > menu.height() ) { }
else if ( active.position().top + active.height() > menu.height() ) {
// scroll down // scroll down
var invisibleHeight = active.position().top + active.height() - menu.height() var invisibleHeight = active.position().top + active.height() - menu.height()
menu.scrollTop( menu.scrollTop() + invisibleHeight ) menu.scrollTop( menu.scrollTop() + invisibleHeight )
@ -204,7 +206,7 @@
// set position of widget // set position of widget
Plugin.prototype.updatePosition = function() { Plugin.prototype.updatePosition = function() {
this.$widget.find('.dropdown-menu').scrollTop( 300 ); this.$widget.find('.dropdown-menu').scrollTop(300)
if (!this.$element.is(':visible')) return if (!this.$element.is(':visible')) return
// get cursor position // get cursor position
@ -372,13 +374,13 @@
var item = result[i] var item = result[i]
var element = $('<li>') var element = $('<li>')
element.attr('data-id', item.id) element.attr('data-id', item.id)
element.text(App.Utils.htmlEscape(item.name)) element.text(item.name)
element.addClass('u-clickable u-textTruncate') element.addClass('u-clickable u-textTruncate')
if (i == result.length-1) { if (i == result.length-1) {
element.addClass('is-active') element.addClass('is-active')
} }
if (item.keywords) { if (item.keywords) {
element.append($('<kbd>').text(App.Utils.htmlEscape(item.keywords))) element.append($('<kbd>').text(item.keywords))
} }
elements = elements.add(element) elements = elements.add(element)
} }
@ -400,8 +402,7 @@
$.fn[pluginName] = function (options) { $.fn[pluginName] = function (options) {
return this.each(function () { return this.each(function () {
if (!$.data(this, 'plugin_' + pluginName)) { if (!$.data(this, 'plugin_' + pluginName)) {
$.data(this, 'plugin_' + pluginName, $.data(this, 'plugin_' + pluginName, new Plugin(this, options))
new Plugin( this, options ));
} }
}); });
} }

View file

@ -101,7 +101,7 @@ class AgentTicketActionLevel0Test < TestCase
data: { data: {
name: 'some name' + random, name: 'some name' + random,
keywords: random, keywords: random,
content: 'some content #{@ticket.customer.lastname}' + random, content: 'some content #{ticket.customer.lastname}' + random,
}, },
) )