aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/coffee/dashboard/views/widgets-view.coffee
diff options
context:
space:
mode:
Diffstat (limited to 'server/sonar-web/src/main/coffee/dashboard/views/widgets-view.coffee')
-rw-r--r--server/sonar-web/src/main/coffee/dashboard/views/widgets-view.coffee49
1 files changed, 49 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/coffee/dashboard/views/widgets-view.coffee b/server/sonar-web/src/main/coffee/dashboard/views/widgets-view.coffee
index d004647a845..84191e4601b 100644
--- a/server/sonar-web/src/main/coffee/dashboard/views/widgets-view.coffee
+++ b/server/sonar-web/src/main/coffee/dashboard/views/widgets-view.coffee
@@ -8,6 +8,9 @@ define [
WidgetView
) ->
+ $ = jQuery
+
+
class extends Marionette.CompositeView
template: Templates['widgets']
itemView: WidgetView
@@ -34,6 +37,45 @@ define [
$container.eq(column).append itemView.el
+ onRender: ->
+ @initializeDragging() if @options.app.state.get 'configure'
+
+
+ initializeDragging: ->
+ blocks = @$('.block')
+ columnHandle = @$('.column-handle')
+ draggable = null
+
+ onDragLeave = (e) ->
+ $(e.currentTarget).removeClass 'block-hover'
+
+ onDrop = (e) =>
+ e.preventDefault()
+ draggable.detach().insertBefore $(e.currentTarget)
+ onDragLeave e
+ @options.app.saveDashboard()
+
+ blocks.on 'selectstart', ->
+ @dragDrop()
+ false
+ blocks.on 'dragstart', (e) ->
+ e.originalEvent.dataTransfer.setData 'Text', 'drag'
+ draggable = $(@)
+ columnHandle.show()
+ blocks.on 'dragover', (e) ->
+ if draggable.data('id') != $(@).data('id')
+ e.preventDefault()
+ $(e.currentTarget).addClass 'block-hover'
+ blocks.on 'drop', onDrop
+ blocks.on 'dragleave', onDragLeave
+
+ columnHandle.on 'dragover', (e) ->
+ e.preventDefault()
+ $(e.currentTarget).addClass 'block-hover'
+ columnHandle.on 'drop', onDrop
+ columnHandle.on 'dragleave', onDragLeave
+
+
configureWidgets: ->
@options.app.state.set configure: true
@@ -42,6 +84,13 @@ define [
@options.app.state.set configure: false
+ getLayout: ->
+ layout = $('.dashboard-column').map( ->
+ blocks = $(@).find '.block'
+ blocks.map( -> $(@).data('id')).get().join(',')
+ ).get().join(';')
+
+
serializeData: ->
_.extend super,
dashboard: @options.dashboard.toJSON()