Improved App.CollectionController controller.
This commit is contained in:
parent
15cfe935ea
commit
3d594e11b3
9 changed files with 74 additions and 29 deletions
|
@ -764,6 +764,7 @@ class App.CollectionController extends App.Controller
|
||||||
model: '_need_to_be_defined_'
|
model: '_need_to_be_defined_'
|
||||||
sortBy: 'name'
|
sortBy: 'name'
|
||||||
order: 'ASC',
|
order: 'ASC',
|
||||||
|
insertPosition: 'after'
|
||||||
|
|
||||||
constructor: ->
|
constructor: ->
|
||||||
@events = @constructor.events unless @events
|
@events = @constructor.events unless @events
|
||||||
|
@ -819,8 +820,14 @@ class App.CollectionController extends App.Controller
|
||||||
@domChange(param[1])
|
@domChange(param[1])
|
||||||
else if param[0] is 'domRemove'
|
else if param[0] is 'domRemove'
|
||||||
@domRemove(param[1])
|
@domRemove(param[1])
|
||||||
|
else if param[0] is 'change'
|
||||||
|
@collectionSync(param[1])
|
||||||
|
else if param[0] is 'remove'
|
||||||
|
@collectionSync(param[1], 'destroy')
|
||||||
else if param[0] is 'renderAll'
|
else if param[0] is 'renderAll'
|
||||||
@renderAll()
|
@renderAll()
|
||||||
|
else
|
||||||
|
@log 'error', "Unknown type #{param[0]}", param[1]
|
||||||
if !@queue[0]
|
if !@queue[0]
|
||||||
@onRenderEnd()
|
@onRenderEnd()
|
||||||
@queueRunning = false
|
@queueRunning = false
|
||||||
|
@ -845,7 +852,7 @@ class App.CollectionController extends App.Controller
|
||||||
if type is 'destroy'
|
if type is 'destroy'
|
||||||
ids = []
|
ids = []
|
||||||
for item in items
|
for item in items
|
||||||
ids.push item.id
|
ids.push item[@uniqKey]
|
||||||
@queue.push ['domRemove', ids]
|
@queue.push ['domRemove', ids]
|
||||||
@uIRunner()
|
@uIRunner()
|
||||||
return
|
return
|
||||||
|
@ -875,7 +882,9 @@ class App.CollectionController extends App.Controller
|
||||||
lastOrderNew.push id
|
lastOrderNew.push id
|
||||||
|
|
||||||
# try to find positions of new items
|
# try to find positions of new items
|
||||||
|
@log 'debug', 'collectionSync lastOrderNew', lastOrderNew
|
||||||
applyOrder = App.Utils.diffPositionAdd(lastOrderNew, newOrder)
|
applyOrder = App.Utils.diffPositionAdd(lastOrderNew, newOrder)
|
||||||
|
@log 'debug', 'collectionSync applyOrder', applyOrder
|
||||||
if !applyOrder
|
if !applyOrder
|
||||||
@queue.push ['renderAll']
|
@queue.push ['renderAll']
|
||||||
@uIRunner()
|
@uIRunner()
|
||||||
|
@ -888,7 +897,7 @@ class App.CollectionController extends App.Controller
|
||||||
|
|
||||||
newItems = []
|
newItems = []
|
||||||
for apply in applyOrder
|
for apply in applyOrder
|
||||||
item = App[@model].find(apply.id)
|
item = @itemGet(apply.id)
|
||||||
item.meta_position = apply.position
|
item.meta_position = apply.position
|
||||||
newItems.push item
|
newItems.push item
|
||||||
@queue.push ['domChange', newItems]
|
@queue.push ['domChange', newItems]
|
||||||
|
@ -943,7 +952,7 @@ class App.CollectionController extends App.Controller
|
||||||
for field of @observe
|
for field of @observe
|
||||||
@log 'debug', 'domChange|change|compare', field, currentItem[field], attributes[field]
|
@log 'debug', 'domChange|change|compare', field, currentItem[field], attributes[field]
|
||||||
diff = !_.isEqual(currentItem[field], attributes[field])
|
diff = !_.isEqual(currentItem[field], attributes[field])
|
||||||
@log 'debug', 'domChange|diff', diff, item
|
@log 'debug', 'domChange|diff', diff
|
||||||
if diff
|
if diff
|
||||||
changedItems.push item
|
changedItems.push item
|
||||||
@itemAttributesSet(item[@uniqKey], attributes)
|
@itemAttributesSet(item[@uniqKey], attributes)
|
||||||
|
@ -963,8 +972,10 @@ class App.CollectionController extends App.Controller
|
||||||
@collectionOrderSet()
|
@collectionOrderSet()
|
||||||
@onRenderEnd()
|
@onRenderEnd()
|
||||||
|
|
||||||
|
itemDestroy: (id) =>
|
||||||
|
App[@model].destroy(id)
|
||||||
|
|
||||||
itemsAll: =>
|
itemsAll: =>
|
||||||
#App[@model].all()
|
|
||||||
App[@model].search(sortBy: @sortBy, order: @order)
|
App[@model].search(sortBy: @sortBy, order: @order)
|
||||||
|
|
||||||
itemAttributesDiff: (item) =>
|
itemAttributesDiff: (item) =>
|
||||||
|
@ -993,6 +1004,9 @@ class App.CollectionController extends App.Controller
|
||||||
attributes[field] = item[field]
|
attributes[field] = item[field]
|
||||||
attributes
|
attributes
|
||||||
|
|
||||||
|
itemGet: (id) =>
|
||||||
|
App[@model].find(id)
|
||||||
|
|
||||||
renderParts: (items) =>
|
renderParts: (items) =>
|
||||||
@log 'debug', 'renderParts', items
|
@log 'debug', 'renderParts', items
|
||||||
for item in items
|
for item in items
|
||||||
|
@ -1009,14 +1023,20 @@ class App.CollectionController extends App.Controller
|
||||||
html = $(App.view(@template)(
|
html = $(App.view(@template)(
|
||||||
item: item
|
item: item
|
||||||
))
|
))
|
||||||
|
itemCount = Object.keys(@renderList).length
|
||||||
@renderList[item[@uniqKey]] = html
|
@renderList[item[@uniqKey]] = html
|
||||||
if el is false
|
if el is false
|
||||||
return html
|
return html
|
||||||
else if !el
|
else if !el
|
||||||
position = item.meta_position + 1
|
position = item.meta_position
|
||||||
console.log('!el', item, position, item.meta_position)
|
if itemCount > position
|
||||||
#if item.meta_position
|
position += 1
|
||||||
@el.find(".js-item:nth-child(#{position})").before(html)
|
console.log('!el', item, position, item.meta_position, @el.find(".js-item:nth-child(#{position})"))
|
||||||
|
element = @el.find(".js-item:nth-child(#{position})")
|
||||||
|
if @insertPosition is 'before'
|
||||||
|
element.before(html)
|
||||||
|
else
|
||||||
|
element.after(html)
|
||||||
else
|
else
|
||||||
el.replaceWith(html)
|
el.replaceWith(html)
|
||||||
|
|
||||||
|
@ -1029,7 +1049,6 @@ class App.CollectionController extends App.Controller
|
||||||
click: (e) =>
|
click: (e) =>
|
||||||
row = $(e.target).closest('.js-item')
|
row = $(e.target).closest('.js-item')
|
||||||
id = row.data('id')
|
id = row.data('id')
|
||||||
console.log('click id', id)
|
|
||||||
@onClick(id, e)
|
@onClick(id, e)
|
||||||
|
|
||||||
onClick: (id, e) ->
|
onClick: (id, e) ->
|
||||||
|
@ -1041,7 +1060,7 @@ class App.CollectionController extends App.Controller
|
||||||
row = $(e.target).closest('.js-item')
|
row = $(e.target).closest('.js-item')
|
||||||
id = row.data('id')
|
id = row.data('id')
|
||||||
@onRemove(id,e)
|
@onRemove(id,e)
|
||||||
App[@model].destroy(id)
|
@itemDestroy(id)
|
||||||
|
|
||||||
onRemove: (id, e) ->
|
onRemove: (id, e) ->
|
||||||
# nothing
|
# nothing
|
||||||
|
|
|
@ -19,12 +19,9 @@ class App.TicketCreate extends App.Controller
|
||||||
@default_type = 'phone-in'
|
@default_type = 'phone-in'
|
||||||
|
|
||||||
# remember split info if exists
|
# remember split info if exists
|
||||||
split = ''
|
@split = ''
|
||||||
if @ticket_id && @article_id
|
if @ticket_id && @article_id
|
||||||
split = "/#{@ticket_id}/#{@article_id}"
|
@split = "/#{@ticket_id}/#{@article_id}"
|
||||||
|
|
||||||
# update navbar highlighting
|
|
||||||
@navupdate "#ticket/create/id/#{@id}#{split}"
|
|
||||||
|
|
||||||
# lisen if view need to be rerendered
|
# lisen if view need to be rerendered
|
||||||
@bind 'ticket_create_rerender', (defaults) =>
|
@bind 'ticket_create_rerender', (defaults) =>
|
||||||
|
@ -119,7 +116,7 @@ class App.TicketCreate extends App.Controller
|
||||||
"#ticket/create/id/#{@id}"
|
"#ticket/create/id/#{@id}"
|
||||||
|
|
||||||
show: =>
|
show: =>
|
||||||
@navupdate(url: '#', type: 'menu')
|
@navupdate "#ticket/create/id/#{@id}#{@split}", type: 'menu'
|
||||||
|
|
||||||
changed: =>
|
changed: =>
|
||||||
formCurrent = @formParam( @$('.ticket-create') )
|
formCurrent = @formParam( @$('.ticket-create') )
|
||||||
|
|
|
@ -34,20 +34,26 @@ class App.TaskbarWidget extends App.CollectionController
|
||||||
|
|
||||||
# bind to changes
|
# bind to changes
|
||||||
@bind('taskInit', =>
|
@bind('taskInit', =>
|
||||||
console.log('renderAll aaa')
|
@queue.push ['renderAll']
|
||||||
@renderAll()
|
@uIRunner()
|
||||||
console.log('renderAll bbb')
|
|
||||||
#@queue.push ['renderAll']
|
|
||||||
#@uIRunner()
|
|
||||||
)
|
)
|
||||||
@bind('taskUpdate', (tasks) =>
|
@bind('taskUpdate', (tasks) =>
|
||||||
@queue.push ['domChange', tasks]
|
@queue.push ['change', tasks]
|
||||||
@uIRunner()
|
@uIRunner()
|
||||||
)
|
)
|
||||||
@bind('taskRemove', (task_ids) =>
|
@bind('taskRemove', (tasks) =>
|
||||||
@queue.push ['domRemove', task_ids]
|
@queue.push ['remove', tasks]
|
||||||
@uIRunner()
|
@uIRunner()
|
||||||
)
|
)
|
||||||
|
@bind('taskCollectionOrderSet', (task_keys) =>
|
||||||
|
@collectionOrderSet(task_keys)
|
||||||
|
)
|
||||||
|
|
||||||
|
itemGet: (key) ->
|
||||||
|
App.TaskManager.get(key)
|
||||||
|
|
||||||
|
itemDestroy: (key) ->
|
||||||
|
App.TaskManager.remove(key)
|
||||||
|
|
||||||
itemsAll: ->
|
itemsAll: ->
|
||||||
App.TaskManager.allWithMeta()
|
App.TaskManager.allWithMeta()
|
||||||
|
|
|
@ -386,7 +386,7 @@ class Table extends App.Controller
|
||||||
'click': callbackCheckbox
|
'click': callbackCheckbox
|
||||||
)
|
)
|
||||||
|
|
||||||
@setSelected( @selected )
|
@setSelected(@selected)
|
||||||
|
|
||||||
# start user popups
|
# start user popups
|
||||||
@userPopups()
|
@userPopups()
|
||||||
|
|
|
@ -136,6 +136,8 @@ class App.OnlineNotificationWidget extends App.Controller
|
||||||
url: "#{@apiPath}/online_notifications/mark_all_as_read"
|
url: "#{@apiPath}/online_notifications/mark_all_as_read"
|
||||||
data: JSON.stringify('')
|
data: JSON.stringify('')
|
||||||
processData: true
|
processData: true
|
||||||
|
success: (data, status, xhr) =>
|
||||||
|
@fetch()
|
||||||
)
|
)
|
||||||
|
|
||||||
updateHeight: ->
|
updateHeight: ->
|
||||||
|
@ -219,6 +221,7 @@ class App.OnlineNotificationContentWidget extends App.CollectionController
|
||||||
sortBy: 'created_at'
|
sortBy: 'created_at'
|
||||||
order: 'DESC'
|
order: 'DESC'
|
||||||
alreadyShown: {}
|
alreadyShown: {}
|
||||||
|
insertPosition: 'before'
|
||||||
|
|
||||||
onRenderEnd: ->
|
onRenderEnd: ->
|
||||||
@container.counterGen()
|
@container.counterGen()
|
||||||
|
|
|
@ -332,7 +332,7 @@ class _taskManagerSingleton extends App.Controller
|
||||||
delete @allTasksByKey[key]
|
delete @allTasksByKey[key]
|
||||||
|
|
||||||
# rerender taskbar
|
# rerender taskbar
|
||||||
App.Event.trigger('taskRemove', [task.key])
|
App.Event.trigger('taskRemove', [task])
|
||||||
|
|
||||||
# destroy in backend storage
|
# destroy in backend storage
|
||||||
@taskDestroy(task)
|
@taskDestroy(task)
|
||||||
|
@ -369,6 +369,7 @@ class _taskManagerSingleton extends App.Controller
|
||||||
if task.prio isnt prio
|
if task.prio isnt prio
|
||||||
task.prio = prio
|
task.prio = prio
|
||||||
@taskUpdate(task, true)
|
@taskUpdate(task, true)
|
||||||
|
App.Event.trigger('taskCollectionOrderSet', order)
|
||||||
|
|
||||||
# release one task
|
# release one task
|
||||||
release: (key) =>
|
release: (key) =>
|
||||||
|
|
|
@ -632,15 +632,22 @@ class App.Utils
|
||||||
newOrderMethod = (a, b, applyOrder) ->
|
newOrderMethod = (a, b, applyOrder) ->
|
||||||
for position of b
|
for position of b
|
||||||
if a[position] isnt b[position]
|
if a[position] isnt b[position]
|
||||||
|
positionInt = parseInt(position)
|
||||||
|
|
||||||
# changes to complex, whole rerender
|
# changes to complex, whole rerender
|
||||||
if _.contains(a, b[position])
|
if _.contains(a, b[position])
|
||||||
|
console.log('aaa too complex', a, b[position])
|
||||||
return false
|
return false
|
||||||
|
|
||||||
# insert new item and try next
|
# insert new item and try next
|
||||||
a.splice(position, 0, b[position])
|
a.splice(positionInt, 0, b[position])
|
||||||
|
positionNew = 0
|
||||||
|
for positionA of a
|
||||||
|
if b[positionA] is b[position]
|
||||||
|
positionNew = parseInt(positionA)
|
||||||
|
break
|
||||||
apply =
|
apply =
|
||||||
position: parseInt(position)
|
position: positionNew
|
||||||
id: b[position]
|
id: b[position]
|
||||||
applyOrder.push apply
|
applyOrder.push apply
|
||||||
newOrderMethod(a, b, applyOrder)
|
newOrderMethod(a, b, applyOrder)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<a href="<%- @item.meta.url %>" title="<%= @item.meta.title %>" class="nav-tab task js-locationVerify <%= @item.meta.class %><% if @item.active: %> is-active<% end %><% if @item.notify: %> is-modified<% end %>" data-key="<%- @item.key %>">
|
<a href="<%- @item.meta.url %>" title="<%= @item.meta.title %>" class="nav-tab task js-item js-locationVerify <%= @item.meta.class %><% if @item.active: %> is-active<% end %><% if @item.notify: %> is-modified<% end %>" data-key="<%- @item.key %>">
|
||||||
<div class="nav-tab-icon" title="<%- @Ti(@item.meta.iconTitle) %>">
|
<div class="nav-tab-icon" title="<%- @Ti(@item.meta.iconTitle) %>">
|
||||||
<% if @item.meta.type is 'task': %>
|
<% if @item.meta.type is 'task': %>
|
||||||
<% if @item.notify: %>
|
<% if @item.notify: %>
|
||||||
|
|
|
@ -1468,6 +1468,18 @@ test("check diffPosition format", function() {
|
||||||
result = false
|
result = false
|
||||||
verify = App.Utils.diffPositionAdd(a, b)
|
verify = App.Utils.diffPositionAdd(a, b)
|
||||||
deepEqual(verify, result)
|
deepEqual(verify, result)
|
||||||
|
|
||||||
|
a = ['Ticket-347', 'TicketCreateScreen-2217']
|
||||||
|
b = ['Ticket-347', 'TicketCreateScreen-2217', 'TicketCreateScreen-71517']
|
||||||
|
result = [
|
||||||
|
{
|
||||||
|
position: 2,
|
||||||
|
id: 'TicketCreateScreen-71517',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
verify = App.Utils.diffPositionAdd(a, b)
|
||||||
|
deepEqual(verify, result)
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue