=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.java 2013-07-25 18:52:33 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.java 2013-07-26 08:38:57 +0000 @@ -154,7 +154,7 @@ ContextUtils.okResponse( response, "Dashboard item added" ); } - @RequestMapping( value = "/{dashboardUid}/items/{itemUid}/position/{position}", method = RequestMethod.PUT, consumes = "application/json" ) + @RequestMapping( value = "/{dashboardUid}/items/{itemUid}/position/{position}", method = RequestMethod.POST ) public void moveItem( HttpServletResponse response, HttpServletRequest request, @PathVariable String dashboardUid, @PathVariable String itemUid, @PathVariable int position ) throws Exception { @@ -167,7 +167,7 @@ } if ( dashboard.moveItem( itemUid, position ) ) - { + { dashboardService.updateDashboard( dashboard ); ContextUtils.okResponse( response, "Dashboard item moved" ); === modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.js' --- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.js 2013-07-26 06:59:52 +0000 +++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.js 2013-07-26 08:38:57 +0000 @@ -6,6 +6,10 @@ dhis2.db.currentShareType; dhis2.db.currentShareId; +//------------------------------------------------------------------------------ +// Document ready +//------------------------------------------------------------------------------ + $( document ).ready( function() { $( "#interpretationArea" ).autogrow(); @@ -43,12 +47,14 @@ hitItem: "
  • ${name}" + "Add
  • ", - chartItem: "
  • Remove" + + chartItem: "
  • " + + "
  • " + "
  • ", - mapItem: "
  • Remove" + + mapItem: "
  • " + + "
  • " + "
  • " @@ -56,6 +62,59 @@ dhis2.db.dashboardReady = function( id ) { + $( ".item" ).draggable( { + containment: "#contentDiv", + stack: ".item", + revert: true, + start: dhis2.db.dragStart, + stop: dhis2.db.dragStop + } ); + + $( ".item" ).droppable( { + over: dhis2.db.dropOver, + out: dhis2.db.dropOut + } ); + + $( ".dropItem" ).droppable( { + accept: ".item", + drop: dhis2.db.dropItem + } ); +} + +dhis2.db.dragStart = function( event, ui ) { + $( this ).css( "opacity", "0.6" ); + dhis2.db.currentItem = $( this ).attr( "id" ); +} + +dhis2.db.dragStop = function( event, ui ) { + $( this ).css( "opacity", "1.0" ); + $( ".dropItem" ).hide(); + dhis2.db.currentItem = undefined; +} + +dhis2.db.dropOver = function( event, ui ) { + var itemId = $( this ).attr( "id" ); + var dropItemId = "drop" + itemId; + $( "#" + dropItemId ).show(); +} + +dhis2.db.dropOut = function( event, ui ) { + var itemId = $( this ).attr( "id" ); + var dropItemId = "drop" + itemId; + $( "#" + dropItemId ).hide(); +} + +dhis2.db.dropItem = function( event, ui ) { + var position = $( this ).data( "position" ); + dhis2.db.moveItem( dhis2.db.currentItem, position ); +} + +dhis2.db.moveItem = function( id, position ) { + var url = "../api/dashboards/" + dhis2.db.current + "/items/" + id + "/position/" + position; + + $.post( url, function() { + dhis2.db.renderDashboard( dhis2.db.current ); + } ); } dhis2.db.openAddDashboardForm = function() @@ -207,11 +266,11 @@ { if ( "chart" == item.type ) { - $d.append( $.tmpl( dhis2.db.tmpl.chartItem, { "itemId": item.id, "id": item.chart.id, "name": item.chart.name } ) ) + $d.append( $.tmpl( dhis2.db.tmpl.chartItem, { "itemId": item.id, "id": item.chart.id, "name": item.chart.name, "position": index } ) ) } else if ( "map" == item.type ) { - $d.append( $.tmpl( dhis2.db.tmpl.mapItem, { "itemId": item.id, "id": item.map.id, "name": item.map.name } ) ) + $d.append( $.tmpl( dhis2.db.tmpl.mapItem, { "itemId": item.id, "id": item.map.id, "name": item.map.name, "position": index } ) ) } else if ( "users" == item.type ) { === modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/style/dashboard.css' --- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/style/dashboard.css 2013-07-26 06:59:52 +0000 +++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/style/dashboard.css 2013-07-26 08:38:57 +0000 @@ -78,6 +78,7 @@ border-radius: 3px; cursor: pointer; box-shadow: #ddd 0px 1px 1px 0px; + background-color: #fff; } .item:hover @@ -88,11 +89,12 @@ .dropItem { - width: 405px; - margin-right: 19px; - height: 340px; - border: 1px solid #b0d2e8; - background-color: #e5f3f9; + width: 205px; + height: 328px; + padding: 6px; + margin: 0 19px 19px 0; + border: 1px dashed #9ec5df; + background-color: #e9f5fb; border-radius: 3px; display: none; }