Differ between server side change and delete (trigger local remove -not change- of object was deleted on server side).
This commit is contained in:
parent
dfd2b1893b
commit
7bec04cfbd
4 changed files with 51 additions and 7 deletions
|
@ -1122,10 +1122,15 @@ class App.ObserverController extends App.Controller
|
|||
@maybeRender(object)
|
||||
)
|
||||
|
||||
subscribe: (object) =>
|
||||
@maybeRender(object)
|
||||
subscribe: (object, typeOfChange) =>
|
||||
@maybeRender(object, typeOfChange)
|
||||
|
||||
maybeRender: (object, typeOfChange) =>
|
||||
if typeOfChange is 'remove'
|
||||
@release()
|
||||
@el.remove()
|
||||
return
|
||||
|
||||
maybeRender: (object) =>
|
||||
@log 'debug', 'maybeRender', @object_id, object, @model
|
||||
|
||||
if !@subscribeId
|
||||
|
|
|
@ -7,6 +7,7 @@ class App.TicketZoomArticleActions extends App.Controller
|
|||
'click [data-type=twitterStatusReply]': 'twitterStatusReply'
|
||||
'click [data-type=twitterDirectMessageReply]': 'twitterDirectMessageReply'
|
||||
'click [data-type=facebookFeedReply]': 'facebookFeedReply'
|
||||
'click [data-type=delete]': 'delete'
|
||||
|
||||
constructor: ->
|
||||
super
|
||||
|
@ -150,6 +151,18 @@ class App.TicketZoomArticleActions extends App.Controller
|
|||
icon: 'split'
|
||||
href: '#ticket/create/' + article.ticket_id + '/' + article.id
|
||||
}
|
||||
|
||||
if article.type.name is 'note'
|
||||
user = undefined
|
||||
if App.Session.get('id') == article.created_by_id
|
||||
user = App.User.find(App.Session.get('id'))
|
||||
if user.permission('ticket.agent')
|
||||
actions.push {
|
||||
name: 'delete'
|
||||
type: 'delete'
|
||||
icon: 'trash'
|
||||
href: '#'
|
||||
}
|
||||
actions
|
||||
|
||||
facebookFeedReply: (e) =>
|
||||
|
@ -355,6 +368,19 @@ class App.TicketZoomArticleActions extends App.Controller
|
|||
|
||||
App.Event.trigger('ui::ticket::setArticleType', { ticket: @ticket, type: type, article: articleNew } )
|
||||
|
||||
delete: (e) =>
|
||||
e.preventDefault()
|
||||
|
||||
callback = ->
|
||||
article_id = $(e.target).parents('[data-id]').data('id')
|
||||
article = App.TicketArticle.find(article_id)
|
||||
article.destroy()
|
||||
|
||||
new App.ControllerConfirm(
|
||||
message: 'Sure?'
|
||||
callback: callback
|
||||
container: @el.closest('.content')
|
||||
)
|
||||
|
||||
scrollToCompose: =>
|
||||
@el.closest('.content').find('.article-add').ScrollTo()
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ class App.TicketZoomArticleView extends App.Controller
|
|||
all = []
|
||||
for ticket_article_id in @ticket_article_ids
|
||||
controllerKey = ticket_article_id.toString()
|
||||
if !@articleController[controllerKey]
|
||||
if !@articleController[controllerKey] && App.TicketArticle.exists(ticket_article_id)
|
||||
el = $('<div></div>')
|
||||
@articleController[controllerKey] = new ArticleViewItem(
|
||||
ticket: @ticket
|
||||
|
|
|
@ -440,7 +440,7 @@ class App.Model extends Spine.Model
|
|||
)
|
||||
|
||||
# subscribe and render data after server change
|
||||
events = "#{@className}:create #{@className}:update #{@className}:touch #{@className}:destroy"
|
||||
events = "#{@className}:create #{@className}:update #{@className}:touch"
|
||||
App.Event.bind(
|
||||
events
|
||||
(item) =>
|
||||
|
@ -454,10 +454,23 @@ class App.Model extends Spine.Model
|
|||
App.Log.debug('Model', "request #{@className}.find(#{item.id}) from server")
|
||||
@full(item.id, false, true)
|
||||
App.Delay.set(callback, 500, item.id, "full-#{@className}-#{item.id}")
|
||||
|
||||
"Item::Subscribe::#{@className}"
|
||||
)
|
||||
|
||||
events = "#{@className}:destroy"
|
||||
App.Event.bind(
|
||||
events
|
||||
(item) =>
|
||||
if @SUBSCRIPTION_ITEM && @SUBSCRIPTION_ITEM[ item.id ]
|
||||
return if !App[ @className ].exists(item.id)
|
||||
genericObject = App[ @className ].find(item.id)
|
||||
App.Log.debug('Model', "server delete on #{@className}.find(#{item.id}) #{item.updated_at}")
|
||||
callback = ->
|
||||
genericObject.trigger('remove', genericObject)
|
||||
App.Delay.set(callback, 500, item.id, "delete-#{@className}-#{item.id}")
|
||||
"Item::SubscribeDelete::#{@className}"
|
||||
)
|
||||
|
||||
# remember item callback
|
||||
if !@SUBSCRIPTION_ITEM
|
||||
@SUBSCRIPTION_ITEM = {}
|
||||
|
|
Loading…
Reference in a new issue