dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #26284
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13027: update ouwt tree if either username or version has been changed
------------------------------------------------------------
revno: 13027
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-11-26 13:30:24 +0100
message:
update ouwt tree if either username or version has been changed
modified:
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTreePartial.vm
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java
--
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-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm 2012-10-31 09:36:23 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm 2013-11-26 12:30:24 +0000
@@ -1,5 +1,6 @@
{
"version":"$!encoder.jsonEncode( $version )"
+,"username":"$!encoder.jsonEncode( $username )"
,"realRoot":$realRoot
,"roots": [ #foreach( $root in $rootOrganisationUnits )$root.id#if( $velocityCount < $rootOrganisationUnits.size() ),#end#end ]
#if( ! $versionOnly )
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTreePartial.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTreePartial.vm 2012-06-29 15:11:05 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTreePartial.vm 2013-11-26 12:30:24 +0000
@@ -1,4 +1,7 @@
-{"organisationUnits": {
+{
+"version":"$!encoder.jsonEncode( $version )"
+,"username":"$!encoder.jsonEncode( $username )"
+,"organisationUnits": {
#foreach( $unit in $organisationUnits )
"${unit.id}":{"id":${unit.id},"n":"$!encoder.jsonEncode( ${unit.name} )",#if( $unit.parent )"pid":${unit.parent.id},#end"c":[#foreach( $child in $unit.sortedChildren )${child.id}#if( $velocityCount < $unit.children.size() ),#end#end]}
#if( $velocityCount < $organisationUnits.size() ),#end#end
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js 2013-09-09 11:23:06 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js 2013-11-26 12:30:24 +0000
@@ -29,6 +29,7 @@
var OU_PARTIAL_KEY = "ouPartial";
var OU_ROOTS_KEY = "ouRoots";
var OU_VERSION_KEY = "ouVersion";
+var OU_USERNAME_KEY = "ouUsername";
var OU_SELECTED_KEY = "ouSelected";
dhis2.ou.store = new dhis2.storage.Store( {
@@ -135,6 +136,18 @@
localStorage.removeItem( OU_VERSION_KEY );
};
+ this.getUsername = function() {
+ return localStorage[ OU_USERNAME_KEY ] ? localStorage[ OU_USERNAME_KEY ] : "";
+ };
+
+ this.setUsername = function( username ) {
+ localStorage[ OU_USERNAME_KEY ] = username;
+ };
+
+ this.clearUsername = function() {
+ localStorage.removeItem( OU_USERNAME_KEY );
+ };
+
this.getAllOrganisationUnits = function() {
var def = $.Deferred();
@@ -149,7 +162,18 @@
this.setOrganisationUnits = function( ous ) {
$.extend( organisationUnits, ous );
ous = ous ? _.values( ous ) : [];
- return dhis2.ou.store.setAll( OU_KEY, ous );
+
+ var def = $.Deferred();
+
+ // clear out old tree
+ dhis2.ou.store.clear(OU_KEY).always(function() {
+ // set new tree
+ dhis2.ou.store.setAll(OU_KEY, ous).always(function() {
+ def.resolve();
+ });
+ });
+
+ return def.promise();
};
this.getOrganisationUnit = function( id ) {
@@ -239,14 +263,19 @@
} );
}
- function update_required( remoteVersion, remoteRoots ) {
+ function update_required( remoteVersion, remoteRoots, remoteUsername ) {
var localVersion = selection.getVersion();
+ var localUsername = selection.getUsername();
var localRoots = selection.getRoots();
if ( localVersion != remoteVersion ) {
return true;
}
+ if( localUsername != remoteUsername ) {
+ return true;
+ }
+
if ( localRoots == null || localRoots.length == 0 ) {
return true;
}
@@ -271,13 +300,14 @@
if ( data.indexOf( "<!DOCTYPE" ) != 0 ) {
data = JSON.parse( data );
realRoot = data.realRoot;
- should_update = update_required( data.version, data.roots );
+ should_update = update_required( data.version, data.roots, data.username );
}
} ).always( function() {
if( should_update ) {
selection.ajaxOrganisationUnits( false ).done(function( data ) {
selection.setRoots( data.roots );
selection.setVersion( data.version );
+ selection.setUsername( data.username );
selection.setOrganisationUnits( data.organisationUnits ).done(function() {
sync_and_reload();
$( "#orgUnitTree" ).trigger( "ouwtLoaded" );
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java 2013-11-19 11:41:34 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java 2013-11-26 12:30:24 +0000
@@ -110,6 +110,13 @@
return version;
}
+ private String username;
+
+ public String getUsername()
+ {
+ return username;
+ }
+
private boolean versionOnly;
public void setVersionOnly( Boolean versionOnly )
@@ -262,6 +269,8 @@
version = getVersionString();
+ username = currentUserService.getCurrentUsername();
+
return SUCCESS;
}