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

View file

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

View file

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

View file

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