From 00abecbd98e79ed5dcdea1d5aad37002b0a2e3cc Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sat, 12 Mar 2016 01:49:51 +0100 Subject: [PATCH] Added table dnd support for sort prio in overviews. --- .../_application_controller_generic.coffee | 2 ++ .../_application_controller_table.coffee | 13 +++++++++++++ .../javascripts/app/controllers/overview.coffee | 15 ++++++++++++++- app/assets/javascripts/app/models/overview.coffee | 4 ++-- app/models/group.rb | 1 + app/models/macro.rb | 3 +++ app/models/overview.rb | 8 +++++--- app/models/role.rb | 1 + 8 files changed, 41 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_application_controller_generic.coffee b/app/assets/javascripts/app/controllers/_application_controller_generic.coffee index b2ce9cb68..a37767ae8 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_generic.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_generic.coffee @@ -174,6 +174,8 @@ class App.ControllerGenericIndex extends App.Controller 'click': @edit container: @container explanation: @pageData.explanation or 'none' + groupBy: @groupBy + dndCallback: @dndCallback }, @pageData.tableExtend ) diff --git a/app/assets/javascripts/app/controllers/_application_controller_table.coffee b/app/assets/javascripts/app/controllers/_application_controller_table.coffee index 72b42bfdb..2444c798b 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_table.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_table.coffee @@ -33,6 +33,16 @@ class App.ControllerTable extends App.Controller @html @tableGen() @readjustHeaderWidths() + if @dndCallback + dndOptions = + tolerance: 'pointer' + distance: 15 + opacity: 0.6 + forcePlaceholderSize: true + items: 'tr' + update: @dndCallback + @el.find('table > tbody').sortable(dndOptions) + ### # table based on model @@ -103,6 +113,9 @@ class App.ControllerTable extends App.Controller attributeName: [ callbackAttributes ] + dndCallback: => + items = @el.find('table > tbody > tr') + console.log('all effected items', items) ) new App.ControllerTable( diff --git a/app/assets/javascripts/app/controllers/overview.coffee b/app/assets/javascripts/app/controllers/overview.coffee index 62f68ec5c..37cd09cf9 100644 --- a/app/assets/javascripts/app/controllers/overview.coffee +++ b/app/assets/javascripts/app/controllers/overview.coffee @@ -9,6 +9,8 @@ class Index extends App.ControllerContent el: @el id: @id genericObject: 'Overview' + defaultSortBy: 'prio' + #groupBy: 'role' pageData: title: 'Overviews' home: 'overviews' @@ -22,7 +24,18 @@ class Index extends App.ControllerContent { name: 'New Overview', 'data-type': 'new', class: 'btn--success' } ] container: @el.closest('.content') - large: true, + large: true + dndCallback: => + items = @el.find('table > tbody > tr') + order = [] + prio = 0 + for item in items + prio += 1 + id = $(item).data('id') + overview = App.Overview.find(id) + if overview.prio isnt prio + overview.prio = prio + overview.save() ) App.Config.set( 'Overview', { prio: 2300, name: 'Overviews', parent: '#manage', target: '#manage/overviews', controller: Index, role: ['Admin'] }, 'NavBarAdmin' ) \ No newline at end of file diff --git a/app/assets/javascripts/app/models/overview.coffee b/app/assets/javascripts/app/models/overview.coffee index c8a425a1b..0dc62d997 100644 --- a/app/assets/javascripts/app/models/overview.coffee +++ b/app/assets/javascripts/app/models/overview.coffee @@ -4,12 +4,13 @@ class App.Overview extends App.Model @url: @apiPath + '/overviews' @configure_attributes = [ { name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, 'null': false }, + { name: 'link', display: 'Link', readonly: 1 }, { name: 'role_id', display: 'Available for Role', tag: 'select', multiple: false, nulloption: true, null: false, relation: 'Role', translate: true }, { name: 'user_id', display: 'Available for User', tag: 'select', multiple: true, nulloption: true, null: true, relation: 'User', sortBy: 'firstname' }, { name: 'organization_shared', display: 'Only available for Users with shared Organization', tag: 'select', options: { true: 'yes', false: 'no' }, default: false, null: true }, # { name: 'content', display: 'Content', tag: 'textarea', limit: 250, 'null': false }, { name: 'condition', display: 'Conditions for shown Tickets', tag: 'ticket_selector', null: false }, - { name: 'prio', display: 'Prio', tag: 'input', type: 'text', limit: 10, 'null': false }, + { name: 'prio', display: 'Prio', readonly: 1 }, { name: 'view::s' display: 'Attributes' @@ -146,7 +147,6 @@ class App.Overview extends App.Model 'name', 'link', 'role', - 'prio', ] @description = ''' diff --git a/app/models/group.rb b/app/models/group.rb index 3a5639be3..d35c29613 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -8,5 +8,6 @@ class Group < ApplicationModel activity_stream_support role: Z_ROLENAME_ADMIN history_support + notify_clients_support latest_change_support end diff --git a/app/models/macro.rb b/app/models/macro.rb index a308cf61c..23b9408ef 100644 --- a/app/models/macro.rb +++ b/app/models/macro.rb @@ -4,4 +4,7 @@ class Macro < ApplicationModel store :perform validates :name, presence: true + notify_clients_support + latest_change_support + end diff --git a/app/models/overview.rb b/app/models/overview.rb index 579703219..13b0bf27d 100644 --- a/app/models/overview.rb +++ b/app/models/overview.rb @@ -7,16 +7,18 @@ class Overview < ApplicationModel validates :name, presence: true validates :prio, presence: true - before_create :fill_link - before_update :fill_link + before_create :fill_link + before_update :fill_link + notify_clients_support latest_change_support private # fill link def fill_link - return true if link && !link.empty? + return true if link.empty? + return true if !changes['name'] self.link = name.downcase link.gsub!(/\s/, '_') link.gsub!(/[^0-9a-z]/i, '_') diff --git a/app/models/role.rb b/app/models/role.rb index 63c61451f..d081689ab 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -5,5 +5,6 @@ class Role < ApplicationModel has_and_belongs_to_many :users, after_add: :cache_update, after_remove: :cache_update validates :name, presence: true activity_stream_support role: Z_ROLENAME_ADMIN + notify_clients_support latest_change_support end