dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21054
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9867: added new storage adapter, dom-ss (sessionStorage). Must be explicitely set with adapter: 'dom-ss...
------------------------------------------------------------
revno: 9867
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-02-22 10:59:31 +0700
message:
added new storage adapter, dom-ss (sessionStorage). Must be explicitely set with adapter: 'dom-ss' on store creation (localStorage will still be default). Switch anonymous reporting to use dom-ss for meta-data.
added:
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.dom-ss.js
modified:
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/cacheManifest.vm
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/cacheManifest.vm
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.dom.js
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.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-caseentry/src/main/webapp/dhis-web-caseentry/cacheManifest.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/cacheManifest.vm 2013-02-21 07:08:28 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/cacheManifest.vm 2013-02-22 03:59:31 +0000
@@ -26,6 +26,7 @@
../dhis-web-commons/javascripts/dhis2/dhis2.comparator.js
../dhis-web-commons/javascripts/dhis2/dhis2.availability.js
../dhis-web-commons/javascripts/dhis2/dhis2.storage.js
+../dhis-web-commons/javascripts/dhis2/dhis2.storage.dom-ss.js
../dhis-web-commons/javascripts/dhis2/dhis2.storage.dom.js
../dhis-web-commons/javascripts/dhis2/dhis2.storage.idb.js
../dhis-web-commons/javascripts/jQuery/jquery.cookie.js
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js 2013-02-21 07:08:28 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js 2013-02-22 03:59:31 +0000
@@ -7,25 +7,25 @@
} );
// initialize the stores, and then try and add the data
- DAO.programs = new dhis2.storage.Store( {name: 'programs'}, function ( store ) {
- DAO.programAssociations = new dhis2.storage.Store( {name: 'programAssociations'}, function ( store ) {
- jQuery.getJSON( "getProgramMetaData.action", {}, function ( data ) {
- var keys = _.keys( data.metaData.programs );
- var objs = _.values( data.metaData.programs );
-
- DAO.programs.addAll( keys, objs, function ( store ) {
- var keys = _.keys( data.metaData.programAssociations );
- var objs = _.values( data.metaData.programAssociations );
-
- DAO.programAssociations.addAll( keys, objs, function ( store ) {
- selection.setListenerFunction( organisationUnitSelected );
- } );
+ DAO.programs = new dhis2.storage.Store( {name: 'programs', adapter: 'dom-ss' }, function ( store ) {
+ DAO.programAssociations = new dhis2.storage.Store( {name: 'programAssociations', adapter: 'dom-ss' }, function ( store ) {
+ jQuery.getJSON( "getProgramMetaData.action", {},function ( data ) {
+ var keys = _.keys( data.metaData.programs );
+ var objs = _.values( data.metaData.programs );
+
+ DAO.programs.addAll( keys, objs, function ( store ) {
+ var keys = _.keys( data.metaData.programAssociations );
+ var objs = _.values( data.metaData.programAssociations );
+
+ DAO.programAssociations.addAll( keys, objs, function ( store ) {
+ selection.setListenerFunction( organisationUnitSelected );
} );
- } ).fail(function() {
+ } );
+ } ).fail( function () {
selection.setListenerFunction( organisationUnitSelected );
- });
- });
- });
+ } );
+ } );
+ } );
} );
function organisationUnitSelected( orgUnits, orgUnitNames )
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/cacheManifest.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/cacheManifest.vm 2013-02-19 09:57:46 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/cacheManifest.vm 2013-02-22 03:59:31 +0000
@@ -27,6 +27,7 @@
javascripts/dhis2/dhis2.comparator.js
javascripts/dhis2/dhis2.availability.js
javascripts/dhis2/dhis2.storage.js
+javascripts/dhis2/dhis2.storage.dom-ss.js
javascripts/dhis2/dhis2.storage.dom.js
javascripts/dhis2/dhis2.storage.idb.js
javascripts/jQuery/jquery.cookie.js
=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.dom-ss.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.dom-ss.js 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.dom-ss.js 2013-02-22 03:59:31 +0000
@@ -0,0 +1,157 @@
+// dom storage support (sessionStorage)
+dhis2.storage.Store.adapter( 'dom-ss', (function () {
+ var storage = window.sessionStorage;
+
+ var indexer = function ( dbname, name ) {
+ return {
+ key: dbname + '.' + name + '.__index__',
+
+ all: function () {
+ var a = storage.getItem( this.key );
+
+ if ( a ) {
+ try {
+ a = JSON.parse( a );
+ } catch ( e ) {
+ a = null;
+ }
+ }
+
+ if ( a == null ) {
+ storage.setItem( this.key, JSON.stringify( [] ) );
+ }
+
+ return JSON.parse( storage.getItem( this.key ) );
+ },
+
+ add: function ( key ) {
+ var a = this.all();
+ a.push( key );
+ storage.setItem( this.key, JSON.stringify( a ) );
+ },
+
+ remove: function ( key ) {
+ var a = this.all();
+
+ if ( a.indexOf( key ) != -1 ) {
+ dhis2.array.remove( a, a.indexOf( key ), a.indexOf( key ) );
+ storage.setItem( this.key, JSON.stringify( a ) );
+ }
+ },
+
+ find: function ( key ) {
+ var a = this.all();
+ return a.indexOf( key );
+ }
+ }
+ }
+
+ return {
+ valid: function () {
+ return !!storage;
+ },
+
+ init: function ( options, callback ) {
+ this.indexer = indexer( this.dbname, this.name );
+ if ( callback ) callback.call( this, this, options );
+ },
+
+ add: function ( key, obj, callback ) {
+ var key = this.dbname + '.' + this.name + '.' + key;
+ if ( this.indexer.find( key ) == -1 ) this.indexer.add( key );
+ storage.setItem( key, JSON.stringify( obj ) );
+ if ( callback ) callback.call( this, this, obj );
+
+ return this;
+ },
+
+ addAll: function ( keys, objs, callback ) {
+ var that = this;
+
+ if ( keys.length == 0 || objs.length == 0 ) {
+ if ( callback ) callback.call( that, that );
+ return;
+ }
+
+ var key = keys.pop();
+ var obj = objs.pop();
+
+ this.add( key, obj, function ( store ) {
+ that.addAll( keys, objs, callback );
+ } );
+ },
+
+ remove: function ( key, callback ) {
+ var key = this.dbname + '.' + this.name + '.' + key;
+ this.indexer.remove( key );
+ storage.removeItem( key );
+ if ( callback ) callback.call( this, this );
+
+ return this;
+ },
+
+ exists: function ( key, callback ) {
+ var key = this.dbname + '.' + this.name + '.' + key;
+ var success = storage.getItem( key ) != null;
+ if ( callback ) callback.call( this, this, success );
+
+ return this;
+ },
+
+ keys: function ( callback ) {
+ var that = this;
+ var keys = this.indexer.all().map( function ( r ) {
+ return r.replace( that.dbname + '.' + that.name + '.', '' )
+ } );
+
+ if ( callback ) callback.call( this, this, keys );
+
+ return this;
+ },
+
+ fetch: function ( key, callback ) {
+ var arr = [];
+ var keys = $.isArray( key ) ? key : [ key ];
+
+ for ( var k = 0; k < keys.length; k++ ) {
+ var storage_key = this.dbname + '.' + this.name + '.' + keys[k];
+ var obj = storage.getItem( storage_key );
+
+ if ( obj ) {
+ obj = JSON.parse( obj );
+ obj.key = keys[k];
+ arr.push( obj );
+ }
+ }
+
+ if ( callback ) callback.call( this, this, arr );
+
+ return this;
+ },
+
+ fetchAll: function ( callback ) {
+ var arr = [];
+ var idx = this.indexer.all();
+
+ for ( var k = 0; k < idx.length; k++ ) {
+ var obj = JSON.parse( storage.getItem( idx[k] ) );
+ obj.key = idx[k].replace( that.dbname + '.' + that.name + '.', '' );
+ arr.push( obj );
+ }
+
+ if ( callback ) callback.call( this, this, arr );
+
+ return this;
+ },
+
+ destroy: function () {
+ this.keys( function ( store, keys ) {
+ for ( var key in keys ) {
+ this.remove( key );
+ }
+ } );
+
+ storage.removeItem( this.dbname + '.' + this.name + '.__index__' );
+ }
+ };
+})() );
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.dom.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.dom.js 2013-02-20 08:03:09 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.dom.js 2013-02-22 03:59:31 +0000
@@ -151,7 +151,7 @@
}
} );
- localStorage.removeItem( this.dbname + '.' + this.name + '.__index__' );
+ storage.removeItem( this.dbname + '.' + this.name + '.__index__' );
}
};
})() );
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm 2013-02-19 09:57:46 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm 2013-02-22 03:59:31 +0000
@@ -47,6 +47,7 @@
<script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.availability.js"></script>
<script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.trigger.js"></script>
<script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.js"></script>
+ <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.dom-ss.js"></script>
<script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.dom.js"></script>
<script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.idb.js"></script>
<script type="text/javascript" src="../dhis-web-commons/i18nJavaScript.action"></script>