Added sort order of taskbar by using sortable.
This commit is contained in:
parent
dd4652b515
commit
37321055fd
4 changed files with 45 additions and 6 deletions
|
@ -44,6 +44,24 @@ class App.TaskWidget extends App.Controller
|
|||
taskBarActions: @_getTaskActions()
|
||||
)
|
||||
|
||||
dndOptions =
|
||||
tolerance: 'pointer'
|
||||
distance: 15
|
||||
opacity: 0.6
|
||||
forcePlaceholderSize: true
|
||||
items: '> a'
|
||||
update: =>
|
||||
items = @el.find('.taskbar > a')
|
||||
order = []
|
||||
for item in items
|
||||
key = $(item).data('key')
|
||||
if !key
|
||||
throw "No such key attributes found for task item"
|
||||
order.push key
|
||||
App.TaskManager.reorder( order )
|
||||
|
||||
@el.find( '.taskbar' ).sortable( dndOptions )
|
||||
|
||||
remove: (e) =>
|
||||
e.preventDefault()
|
||||
key = $(e.target).parent().data('key')
|
||||
|
|
|
@ -34,6 +34,11 @@ class App.TaskManager
|
|||
_instance ?= new _Singleton
|
||||
_instance.notify( key )
|
||||
|
||||
@reorder: ( order ) ->
|
||||
if _instance == undefined
|
||||
_instance ?= new _Singleton
|
||||
_instance.reorder( order )
|
||||
|
||||
@reset: ->
|
||||
if _instance == undefined
|
||||
_instance ?= new _Singleton
|
||||
|
@ -59,7 +64,11 @@ class _Singleton extends App.Controller
|
|||
@tasksInitial()
|
||||
|
||||
all: ->
|
||||
App.Taskbar.all()
|
||||
tasks = App.Taskbar.all()
|
||||
tasks = _(tasks).sortBy( (task) ->
|
||||
return task.prio;
|
||||
)
|
||||
return tasks
|
||||
|
||||
worker: ( key ) ->
|
||||
return @workers[ key ] if @workers[ key ]
|
||||
|
@ -83,6 +92,7 @@ class _Singleton extends App.Controller
|
|||
params: params
|
||||
callback: callback
|
||||
client_id: 123
|
||||
prio: App.Taskbar.count() + 1
|
||||
notify: false
|
||||
active: active
|
||||
)
|
||||
|
@ -213,6 +223,16 @@ class _Singleton extends App.Controller
|
|||
task.save()
|
||||
App.Event.trigger 'ui:rerender'
|
||||
|
||||
reorder: ( order ) =>
|
||||
prio = 0
|
||||
for key in order
|
||||
task = @get( key )
|
||||
if !task
|
||||
throw "No such task with '#{key}' of order"
|
||||
prio++
|
||||
task.prio = prio
|
||||
task.save()
|
||||
|
||||
reset: =>
|
||||
App.Taskbar.deleteAll()
|
||||
App.Event.trigger 'ui:rerender'
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class App.Taskbar extends App.Model
|
||||
@configure 'Taskbar', 'key', 'client_id', 'callback', 'state', 'params', 'notify', 'active'
|
||||
@configure 'Taskbar', 'key', 'client_id', 'callback', 'state', 'params', 'prio', 'notify', 'active'
|
||||
# @extend Spine.Model.Local
|
||||
@extend Spine.Model.Ajax
|
||||
@url: 'api/taskbar'
|
||||
|
|
|
@ -8,6 +8,7 @@ class Taskbar < ActiveRecord::Migration
|
|||
t.column :callback, :string, :limit => 100, :null => false
|
||||
t.column :state, :string, :limit => 8000, :null => true
|
||||
t.column :params, :string, :limit => 2000, :null => true
|
||||
t.column :prio, :integer, :null => false
|
||||
t.column :notify, :boolean, :null => false, :default => false
|
||||
t.column :active, :boolean, :null => false, :default => false
|
||||
t.timestamps
|
||||
|
|
Loading…
Reference in a new issue