Improved tag and link widget.

This commit is contained in:
Martin Edenhofer 2016-06-09 12:46:53 +02:00
parent e9bb0aafc0
commit 9169b6fb88
4 changed files with 42 additions and 32 deletions

View file

@ -198,7 +198,6 @@ class App.TicketZoom extends App.Controller
"#ticket/zoom/#{@ticket_id}"
show: (params) =>
@navupdate(url: '#', type: 'menu')
# set all notifications to seen
@ -413,8 +412,8 @@ class App.TicketZoom extends App.Controller
@initDone = true
# if shown was before init rendering, start actions again
if @shown
@positionPageHeaderStart()
return if !@shown
@positionPageHeaderStart()
App.Event.trigger('ui::ticket::shown', { ticket_id: @ticket_id })
scrollToBottom: =>

View file

@ -9,9 +9,11 @@ class App.WidgetLink extends App.Controller
# if links are given, do not init fetch
if @links
@localLinks = _.clone(@links)
@render()
else
@fetch()
return
@fetch()
fetch: =>
# fetch item on demand
@ -25,20 +27,20 @@ class App.WidgetLink extends App.Controller
link_object_value: @object.id
processData: true
success: (data, status, xhr) =>
@links = data.links
@localLinks = data.links
App.Collection.loadAssets(data.assets)
@render()
)
reload: (links) ->
@links = links
reload: (links) =>
@localLinks = _.clone(links)
@render()
render: =>
return if @lastLinks && _.isEqual(@lastLinks, @links)
@lastLinks = @links
return if @lastLocalLinks && _.isEqual(@lastLocalLinks, @localLinks)
@lastLocalLinks = _.clone(@localLinks)
list = {}
for item in @links
for item in @localLinks
if !list[ item['link_type'] ]
list[ item['link_type'] ] = []

View file

@ -1,4 +1,6 @@
class App.WidgetTag extends App.Controller
editMode: false
pendingRefresh: false
possibleTags: {}
elements:
'.js-newTagLabel': 'newTagLabel'
@ -18,12 +20,14 @@ class App.WidgetTag extends App.Controller
@key = "tags::#{@object_type}::#{@object.id}"
if @tags
@localTags = _.clone(@tags)
@render()
return
@fetch()
fetch: =>
@pendingRefresh = false
@ajax(
id: @key
type: 'GET'
@ -33,19 +37,22 @@ class App.WidgetTag extends App.Controller
o_id: @object.id
processData: true
success: (data, status, xhr) =>
@tags = data.tags
@localTags = data.tags
@render()
)
reload: (tags) ->
@tags = tags
reload: (tags) =>
if @editMode
@pendingRefresh = true
return
@localTags = _.clone(tags)
@render()
render: ->
return if @lastTags && _.isEqual(@lastTags, @tags)
@lastTags = @tags
render: =>
return if @lastLocalTags && _.isEqual(@lastLocalTags, @localTags)
@lastLocalTags = _.clone(@localTags)
@html App.view('widget/tag')(
tags: @tags || [],
tags: @localTags || [],
)
source = "#{App.Config.get('api_path')}/tag_search"
@ -59,21 +66,26 @@ class App.WidgetTag extends App.Controller
@possibleTags[item.value] = true
)
showInput: (e) ->
showInput: (e) =>
e.preventDefault()
@newTagLabel.addClass('hide')
@newTagInput.removeClass('hide').focus()
@editMode = true
hideOrAddInput: (e) ->
hideOrAddInput: (e) =>
e.preventDefault()
@newTagLabel.removeClass('hide')
@newTagInput.addClass('hide')
@onAddTag(e)
@editMode = false
onAddTag: (e) =>
e.preventDefault()
item = @$('[name="new_tag"]').val().trim()
return if !item
if !item
if @pendingRefresh
@fetch()
return
@add(item)
add: (items) =>
@ -82,11 +94,11 @@ class App.WidgetTag extends App.Controller
@addItem(item)
addItem: (item) =>
if _.contains(@tags, item)
if _.contains(@localTags, item)
@render()
return
return if App.Config.get('tag_new') is false && !@possibleTags[item]
@tags.push item
@localTags.push item
@render()
@ajax(
@ -97,8 +109,6 @@ class App.WidgetTag extends App.Controller
o_id: @object.id
item: item
processData: true,
success: (data, status, xhr) =>
@fetch()
)
onRemoveTag: (e) =>
@ -109,7 +119,7 @@ class App.WidgetTag extends App.Controller
remove: (item) =>
@tags = _.filter(@tags, (tagItem) -> return tagItem if tagItem isnt item)
@localTags = _.filter(@localTags, (tagItem) -> return tagItem if tagItem isnt item)
@render()
@ajax(
@ -120,8 +130,6 @@ class App.WidgetTag extends App.Controller
o_id: @object.id
item: item
processData: true
success: (data, status, xhr) =>
@fetch()
)
searchTag: (e) ->

View file

@ -114,10 +114,11 @@ class AgentTicketActionLevel8Test < TestCase
css: '.content.active .js-newTagInput',
value: 'tag1',
)
sleep 2
sendkey(
value: :enter,
)
sleep 0.5
sleep 2
# set tag #2
click(
@ -130,7 +131,7 @@ class AgentTicketActionLevel8Test < TestCase
sendkey(
value: :enter,
)
sleep 0.5
sleep 2
# set tag #3 + #4
click(
@ -143,7 +144,7 @@ class AgentTicketActionLevel8Test < TestCase
sendkey(
value: :enter,
)
sleep 0.5
sleep 2
# set tag #5
click(
@ -156,7 +157,7 @@ class AgentTicketActionLevel8Test < TestCase
click(
css: '#global-search',
)
sleep 0.5
sleep 2
# verify tags
tags_verify(