Improved text module.
This commit is contained in:
parent
fd92085ed5
commit
737f24c161
3 changed files with 48 additions and 16 deletions
|
@ -207,6 +207,9 @@ class Index extends App.Controller
|
||||||
if !@isRole('Customer')
|
if !@isRole('Customer')
|
||||||
new App.TextModuleUI(
|
new App.TextModuleUI(
|
||||||
el: @el.find('#text_module'),
|
el: @el.find('#text_module'),
|
||||||
|
data: {
|
||||||
|
ticket: @ticket,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
show_toogle: (e) ->
|
show_toogle: (e) ->
|
||||||
|
|
|
@ -42,22 +42,27 @@ class App.TextModuleUI extends App.Controller
|
||||||
# remember active text element
|
# remember active text element
|
||||||
inputElement.bind('focusin', ->
|
inputElement.bind('focusin', ->
|
||||||
@uiWidget = ui
|
@uiWidget = ui
|
||||||
|
@uiWidget.el.find('.well').removeClass('hide')
|
||||||
ui.area = $(@)
|
ui.area = $(@)
|
||||||
update = =>
|
|
||||||
|
|
||||||
|
# set window to new possition
|
||||||
|
update = =>
|
||||||
left = @uiWidget.area.offset().left
|
left = @uiWidget.area.offset().left
|
||||||
top = @uiWidget.area.offset().top
|
top = @uiWidget.area.offset().top
|
||||||
width = @uiWidget.area.width()
|
width = @uiWidget.area.width()
|
||||||
console.log 'TEXTAREA', left, top, width
|
|
||||||
@uiWidget.el.offset( left: left + width + 20, top: top )
|
|
||||||
@uiWidget.el.find('.well').removeClass('hide')
|
|
||||||
|
|
||||||
topWindow = $(window).scrollTop() + 50
|
topWindow = $(window).scrollTop() + 50
|
||||||
if top < topWindow
|
if top < topWindow
|
||||||
@uiWidget.el.offset( top: topWindow )
|
@uiWidget.el.offset( top: topWindow )
|
||||||
|
else
|
||||||
|
@uiWidget.el.offset( left: left + width + 20, top: top )
|
||||||
|
|
||||||
|
# update window possition every x ms
|
||||||
ui.interval( update, 150, 'text_module_box' )
|
ui.interval( update, 150, 'text_module_box' )
|
||||||
)
|
)
|
||||||
inputElement.bind('focusout', ->
|
inputElement.bind('focusout', ->
|
||||||
|
|
||||||
|
# clear update window possition
|
||||||
ui.clearInterval( 'text_module_box' )
|
ui.clearInterval( 'text_module_box' )
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -71,10 +76,18 @@ class App.TextModuleUI extends App.Controller
|
||||||
|
|
||||||
# remove one char
|
# remove one char
|
||||||
if key is 'backspace'
|
if key is 'backspace'
|
||||||
|
|
||||||
|
# prevent default key action
|
||||||
|
e.preventDefault()
|
||||||
|
|
||||||
ui.CaptureList = ui.CaptureList.slice( 0, -1 )
|
ui.CaptureList = ui.CaptureList.slice( 0, -1 )
|
||||||
|
|
||||||
# take over
|
# take over
|
||||||
else if key is 'enter'
|
else if key is 'enter'
|
||||||
|
|
||||||
|
# prevent default key action
|
||||||
|
e.preventDefault()
|
||||||
|
|
||||||
objects = ui.objectSearch( ui.CaptureList )
|
objects = ui.objectSearch( ui.CaptureList )
|
||||||
if objects[0]
|
if objects[0]
|
||||||
ui._insert( objects[0].content, ui )
|
ui._insert( objects[0].content, ui )
|
||||||
|
@ -83,11 +96,16 @@ class App.TextModuleUI extends App.Controller
|
||||||
ui.CaptureList = ''
|
ui.CaptureList = ''
|
||||||
ui.renderTable()
|
ui.renderTable()
|
||||||
|
|
||||||
# add char to search selection
|
# add space to search selection
|
||||||
else if key is 'space' || key.length is 1
|
else if key is 'space'
|
||||||
if key is 'space'
|
|
||||||
|
# prevent default key action
|
||||||
|
e.preventDefault()
|
||||||
|
|
||||||
ui.CaptureList = ui.CaptureList + ' '
|
ui.CaptureList = ui.CaptureList + ' '
|
||||||
else
|
|
||||||
|
# add char to search selection
|
||||||
|
else if key.length is 1
|
||||||
ui.CaptureList = ui.CaptureList + key
|
ui.CaptureList = ui.CaptureList + key
|
||||||
|
|
||||||
# prevent default key action
|
# prevent default key action
|
||||||
|
@ -106,10 +124,10 @@ class App.TextModuleUI extends App.Controller
|
||||||
# do code to test other keys
|
# do code to test other keys
|
||||||
inputElement.bind('keyup', (e) ->
|
inputElement.bind('keyup', (e) ->
|
||||||
if e.keyCode == 17
|
if e.keyCode == 17
|
||||||
console.log 'CTRL UP - pressed ', ui.CaptureList
|
|
||||||
ui.el.find('#text-module-search').val( '' )
|
|
||||||
ui.CaptureList = ''
|
ui.CaptureList = ''
|
||||||
|
console.log 'CTRL UP - pressed ', ui.CaptureList
|
||||||
ui.Capture = false
|
ui.Capture = false
|
||||||
|
ui.el.find('#text-module-search').val( '' )
|
||||||
ui.renderTable()
|
ui.renderTable()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -237,6 +255,17 @@ class App.TextModuleUI extends App.Controller
|
||||||
start = content.substr( 0, position )
|
start = content.substr( 0, position )
|
||||||
end = content.substr( position, content.length )
|
end = content.substr( position, content.length )
|
||||||
|
|
||||||
|
contentNew = contentNew.replace( /<%=\s{0,2}(.+?)\s{0,2}%>/g, ( all, key ) ->
|
||||||
|
key = key.replace( /@/g, 'ui.data.' )
|
||||||
|
varString = "#{key}" + ''
|
||||||
|
try
|
||||||
|
key = eval (varString)
|
||||||
|
catch error
|
||||||
|
console.log( "tag replacement: " + error )
|
||||||
|
key = ''
|
||||||
|
return key
|
||||||
|
)
|
||||||
|
|
||||||
# check if \n is needed
|
# check if \n is needed
|
||||||
startEnd = start.substr( start.length-2, 2 )
|
startEnd = start.substr( start.length-2, 2 )
|
||||||
|
|
||||||
|
@ -248,7 +277,7 @@ class App.TextModuleUI extends App.Controller
|
||||||
ui.area.val(content)
|
ui.area.val(content)
|
||||||
|
|
||||||
# update cursor position
|
# update cursor position
|
||||||
currentPosition = (position + contentNew.length + startDiver.length )
|
currentPosition = ( position + contentNew.length + startDiver.length + 1 )
|
||||||
ui.area.prop('selectionStart', currentPosition )
|
ui.area.prop('selectionStart', currentPosition )
|
||||||
ui.area.prop('selectionEnd', currentPosition )
|
ui.area.prop('selectionEnd', currentPosition )
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue