Added table dnd support for sort prio in overviews.

This commit is contained in:
Martin Edenhofer 2016-03-12 01:49:51 +01:00
parent 34473a6d87
commit 00abecbd98
8 changed files with 41 additions and 6 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -8,5 +8,6 @@ class Group < ApplicationModel
activity_stream_support role: Z_ROLENAME_ADMIN
history_support
notify_clients_support
latest_change_support
end

View file

@ -4,4 +4,7 @@ class Macro < ApplicationModel
store :perform
validates :name, presence: true
notify_clients_support
latest_change_support
end

View file

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

View file

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