diff --git a/app/assets/javascripts/app/controllers/task_widget.js.coffee b/app/assets/javascripts/app/controllers/task_widget.js.coffee index 73ef89084..24b9cb600 100644 --- a/app/assets/javascripts/app/controllers/task_widget.js.coffee +++ b/app/assets/javascripts/app/controllers/task_widget.js.coffee @@ -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') diff --git a/app/assets/javascripts/app/lib/app_post/task_manager.js.coffee b/app/assets/javascripts/app/lib/app_post/task_manager.js.coffee index 20d88fa00..f284598f0 100644 --- a/app/assets/javascripts/app/lib/app_post/task_manager.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/task_manager.js.coffee @@ -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' diff --git a/app/assets/javascripts/app/models/taskbar.js.coffee b/app/assets/javascripts/app/models/taskbar.js.coffee index 137a0429c..736a2e2ab 100644 --- a/app/assets/javascripts/app/models/taskbar.js.coffee +++ b/app/assets/javascripts/app/models/taskbar.js.coffee @@ -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' diff --git a/db/migrate/20130529124443_taskbar.rb b/db/migrate/20130529124443_taskbar.rb index e86dae02d..43ccd6c00 100644 --- a/db/migrate/20130529124443_taskbar.rb +++ b/db/migrate/20130529124443_taskbar.rb @@ -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