dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20284
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9194: FRED-API: made it possible to activate/deactivate in the GUI + other minor changes
------------------------------------------------------------
revno: 9194
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-12-07 00:41:42 +0300
message:
FRED-API: made it possible to activate/deactivate in the GUI + other minor changes
modified:
dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java
dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facilities.vm
dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/layout.vm
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java 2012-12-06 20:06:23 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java 2012-12-06 21:41:42 +0000
@@ -27,6 +27,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
@@ -67,7 +68,8 @@
{
Facilities facilities = new Facilities();
- Collection<OrganisationUnit> allOrganisationUnits = organisationUnitService.getAllOrganisationUnits();
+ List<OrganisationUnit> allOrganisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getAllOrganisationUnits() );
+ Collections.sort( allOrganisationUnits, IdentifiableObjectNameComparator.INSTANCE );
for ( OrganisationUnit organisationUnit : allOrganisationUnits )
{
@@ -101,6 +103,7 @@
// POST JSON
//--------------------------------------------------------------------------
+ @RequestMapping( value = "/{id}", method = RequestMethod.POST )
public ResponseEntity<Void> createFacility()
{
return new ResponseEntity<Void>( HttpStatus.OK );
@@ -110,6 +113,7 @@
// PUT JSON
//--------------------------------------------------------------------------
+ @RequestMapping( value = "/{id}", method = RequestMethod.PUT )
public ResponseEntity<Void> updateFacility()
{
return new ResponseEntity<Void>( HttpStatus.OK );
@@ -119,12 +123,49 @@
// DELETE JSON
//--------------------------------------------------------------------------
+ @RequestMapping( value = "/{id}", method = RequestMethod.DELETE )
public ResponseEntity<Void> deleteFacility()
{
return new ResponseEntity<Void>( HttpStatus.OK );
}
//--------------------------------------------------------------------------
+ // EXTRA WEB METHODS
+ //--------------------------------------------------------------------------
+
+ @RequestMapping( value = "/activate/{id}", method = RequestMethod.POST )
+ public ResponseEntity<Void> activateFacility( @PathVariable String id )
+ {
+ OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( id );
+
+ if ( organisationUnit != null )
+ {
+ organisationUnit.setActive( true );
+ organisationUnitService.updateOrganisationUnit( organisationUnit );
+
+ return new ResponseEntity<Void>( HttpStatus.OK );
+ }
+
+ return new ResponseEntity<Void>( HttpStatus.NOT_FOUND );
+ }
+
+ @RequestMapping( value = "/deactivate/{id}", method = RequestMethod.POST )
+ public ResponseEntity<Void> deactivateFacility( @PathVariable String id )
+ {
+ OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( id );
+
+ if ( organisationUnit != null )
+ {
+ organisationUnit.setActive( false );
+ organisationUnitService.updateOrganisationUnit( organisationUnit );
+
+ return new ResponseEntity<Void>( HttpStatus.OK );
+ }
+
+ return new ResponseEntity<Void>( HttpStatus.NOT_FOUND );
+ }
+
+ //--------------------------------------------------------------------------
// HELPERS
//--------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facilities.vm'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facilities.vm 2012-12-06 20:06:23 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facilities.vm 2012-12-06 21:41:42 +0000
@@ -1,8 +1,51 @@
+<script>
+ $(function () {
+ $(".activateButton").click(function () {
+ if (confirm("Are you sure you want to activate this facility?")) {
+ var id = $(this).parent().parent().find('.facility-id').text();
+
+ $.ajax({
+ url: 'facilities/activate/' + id,
+ type: 'POST',
+ async: false
+ }).complete(function () {
+ window.location.reload();
+ });
+ }
+ });
+
+ $(".deactivateButton").click(function () {
+ if (confirm("Are you sure you want to de-activate this facility?")) {
+ var id = $(this).parent().parent().find('.facility-id').text();
+
+ $.ajax({
+ url: 'facilities/deactivate/' + id,
+ type: 'POST',
+ async: false
+ }).complete(function () {
+ window.location.reload();
+ });
+ }
+ });
+ });
+</script>
+
+<div class="btn-group pull-right">
+ <a href="facilities.json" class="btn btn-small btn-info" style="margin-bottom: 5px;">
+ <span class="icon-white icon-download-alt"> </span> JSON
+ </a>
+
+ <!-- future feature
+ <button id="mapFacilities" disabled="disabled" class="btn btn-small btn-info" style="margin-bottom: 5px;">
+ <span class="icon-white icon-map-marker"> </span> Show in map
+ </button>
+ -->
+</div>
<table class="table table-bordered table-striped">
<thead>
<tr>
- <th>#</th>
+ <th>ID</th>
<th>Name</th>
<th>Active</th>
<th>Actions</th>
@@ -12,10 +55,22 @@
<tbody>
#foreach( $facility in $entity.facilities )
<tr>
- <td>$facility.id</td>
- <td>$facility.name</td>
- <td>$facility.active</td>
- <td>[ ACTIONS ]</td>
+ <td class="facility-id" style="width: 1px;">$facility.id</td>
+ <td class="facility-name">$facility.name</td>
+ <td class="facility-active" style="width: 1px;">
+ #if( $facility.active )
+ <button style="width: 44px;" class="deactivateButton btn btn-mini btn-success"><span class="icon-white icon-ok-circle"> </span> </button>
+ #else
+ <button style="width: 44px;" class="activateButton btn btn-mini btn-inverse"><span class="icon-white icon-ban-circle"> </span> </button>
+ #end
+ </td>
+
+ <td class="facility-actions" style="width: 1px;">
+ <div class="btn-group">
+ <button disabled="disabled" style="width: 42px;" class="editButton btn btn-mini btn-info"><span class="icon-white icon-edit"> </span> </button>
+ <button disabled="disabled" style="width: 42px;" class="deleteButton btn btn-mini btn-danger"><span class="icon-white icon-trash"> </span> </button>
+ </div>
+ </td>
</tr>
#end
</tbody>
=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/layout.vm'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/layout.vm 2012-12-06 20:06:23 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/layout.vm 2012-12-06 21:41:42 +0000
@@ -37,13 +37,14 @@
<div class="nav-collapse collapse">
<ul class="nav">
- <li #if( $pageName == "home" )class="active"#end><a href="../"><span class="icon-home"></span>Home</a></li>
+ <li #if( $pageName == "home" )class="active"#end><a href="../"><span class="icon-home"> </span> Home</a></li>
</ul>
</div>
</div>
</div>
</div>
+
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">