Added sort order of taskbar by using sortable.

This commit is contained in:
Martin Edenhofer 2013-06-01 16:49:02 +02:00
parent dd4652b515
commit 37321055fd
4 changed files with 45 additions and 6 deletions

View file

@ -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')

View file

@ -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'

View file

@ -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'

View file

@ -2,12 +2,13 @@ class Taskbar < ActiveRecord::Migration
def up
create_table :taskbars do |t|
t.column :user_id, :integer, :null => false
t.column :last_contact, :datetime, :null => false
t.column :client_id, :string, :null => false
t.column :last_contact, :datetime, :null => false
t.column :client_id, :string, :null => false
t.column :key, :string, :limit => 100, :null => false
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 :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