dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20967
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9809: externalized adapters for js storage
------------------------------------------------------------
revno: 9809
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-02-14 21:38:04 +0700
message:
externalized adapters for js storage
added:
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.idb.js
modified:
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.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
=== added 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 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.js 2013-02-14 14:38:04 +0000
@@ -0,0 +1,121 @@
+// web storage support (localStorage)
+dhis2.storage.Store.adapter( 'dom', (function () {
+ var storage = window.localStorage;
+
+ var indexer = function ( name ) {
+ return {
+ key: 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.name );
+ if ( callback ) callback.call( this, this, options );
+ },
+
+ save: function ( key, obj, callback ) {
+ var key = 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;
+ },
+
+ remove: function ( key, callback ) {
+ var key = this.name + '.' + key;
+ this.indexer.remove( key );
+ storage.removeItem( key );
+ if ( callback ) callback.call( this, this );
+
+ return this;
+ },
+
+ exists: function ( key, callback ) {
+ key = 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.name + '.', '' )
+ } );
+
+ if ( callback ) callback.call( this, this, keys );
+
+ return this;
+ },
+
+ load: function ( key, callback ) {
+ key = this.name + '.' + key;
+ var obj = storage.getItem( key );
+
+ if ( obj ) {
+ obj = JSON.parse( obj );
+ if ( callback ) callback.call( this, this, obj );
+ }
+
+ return this;
+ },
+
+ all: function ( callback ) {
+ var idx = this.indexer.all();
+ var arr = [];
+
+ for ( var k = 0; k < idx.length; k++ ) {
+ arr.push( JSON.parse( storage.getItem( idx[k] ) ) );
+ }
+
+ if ( callback ) callback.call( this, this, arr );
+
+ return this;
+ }
+ };
+})() );
=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.idb.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.idb.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.idb.js 2013-02-14 14:38:04 +0000
@@ -0,0 +1,37 @@
+// web storage support (indexedDb)
+dhis2.storage.Store.adapter( 'indexed-db', (function () {
+ function getIDB() {
+ return window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.oIndexedDB || window.msIndexedDB;
+ }
+
+ return {
+ valid: function () {
+ return false;
+ // return !!getIDB();
+ },
+
+ init: function ( options, callback ) {
+ throw 'Init not implemented'
+ },
+
+ save: function ( key, obj, callback ) {
+ throw 'Save not implemented'
+ },
+
+ remove: function ( key, callback ) {
+ throw 'Remove not implemented'
+ },
+
+ exists: function ( key, callback ) {
+ throw 'Exists not implemented'
+ },
+
+ load: function ( key, callback ) {
+ throw 'Load not implemented'
+ },
+
+ all: function ( callback ) {
+ throw 'All not implemented'
+ }
+ };
+})() );
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.js 2013-02-14 14:20:13 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.js 2013-02-14 14:38:04 +0000
@@ -70,163 +70,3 @@
obj['id'] = id;
Store.adapters.splice( 0, 0, obj );
};
-
-// web storage support (localStorage)
-dhis2.storage.Store.adapter( 'dom', (function () {
- var storage = window.localStorage;
-
- var indexer = function ( name ) {
- return {
- key: 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.name );
- if ( callback ) callback.call( this, this, options );
- },
-
- save: function ( key, obj, callback ) {
- var key = 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;
- },
-
- remove: function ( key, callback ) {
- var key = this.name + '.' + key;
- this.indexer.remove( key );
- storage.removeItem( key );
- if ( callback ) callback.call( this, this );
-
- return this;
- },
-
- exists: function ( key, callback ) {
- key = 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.name + '.', '' )
- } );
-
- if ( callback ) callback.call( this, this, keys );
-
- return this;
- },
-
- load: function ( key, callback ) {
- key = this.name + '.' + key;
- var obj = storage.getItem( key );
-
- if ( obj ) {
- obj = JSON.parse( obj );
- if ( callback ) callback.call( this, this, obj );
- }
-
- return this;
- },
-
- all: function ( callback ) {
- var idx = this.indexer.all();
- var arr = [];
-
- for ( var k = 0; k < idx.length; k++ ) {
- arr.push( JSON.parse( storage.getItem( idx[k] ) ) );
- }
-
- if ( callback ) callback.call( this, this, arr );
-
- return this;
- }
- };
-})() );
-
-// web storage support (indexedDb)
-dhis2.storage.Store.adapter( 'indexed-db', (function () {
- function getIDB() {
- return window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.oIndexedDB || window.msIndexedDB;
- }
-
- return {
- valid: function () {
- return false;
- // return !!getIDB();
- },
-
- init: function ( options, callback ) {
- throw 'Init not implemented'
- },
-
- save: function ( key, obj, callback ) {
- throw 'Save not implemented'
- },
-
- remove: function ( key, callback ) {
- throw 'Remove not implemented'
- },
-
- exists: function ( key, callback ) {
- throw 'Exists not implemented'
- },
-
- load: function ( key, callback ) {
- throw 'Load not implemented'
- },
-
- all: function ( callback ) {
- throw 'All not implemented'
- }
- };
-})() );
=== 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-14 14:00:36 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm 2013-02-14 14:38:04 +0000
@@ -8,7 +8,7 @@
<link type="text/css" rel="stylesheet" media="print" href="../dhis-web-commons/css/print.css" />
#foreach ( $style in $stylesheets )
<link type="text/css" rel="stylesheet" href="$style">
- #end
+ #end
<link rel="shortcut icon" href="../favicon.ico" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
@@ -18,7 +18,7 @@
<script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.min.js"></script>
<script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.ext.js"></script>
- <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.metadata.js"></script>
+ <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.metadata.js"></script>
<script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.tablesorter.min.js"></script>
<script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.upload-1.0.2.min.js"></script>
<script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.dhisAjaxSelect.js"></script>
@@ -48,20 +48,22 @@
<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.sharing.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.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>
- <script type="text/javascript" src="../main.js"></script>
+ <script type="text/javascript" src="../main.js"></script>
<script type="text/javascript" src="../request.js"></script>
#foreach( $javascript in $javascripts )
<script type="text/javascript" src="$javascript"></script>
#end
</head>
-
- <body>
+
+ <body>
#parse( "macros.vm" )
<div id="header">
- <img id="headerBanner" src="../dhis-web-commons/css/${stylesheetDirectory}/logo_banner.png"
+ <img id="headerBanner" src="../dhis-web-commons/css/${stylesheetDirectory}/logo_banner.png"
onclick="window.location.href='../dhis-web-dashboard-integration/interpretation.action'" style="cursor:pointer" title="$i18n.getString( 'view_intepretations' )">
-
+
#if( $maintenanceModules.size() > 0 )
<img id="menuSeparator1" src="../dhis-web-commons/css/${stylesheetDirectory}/logo_separator.png">
#end
@@ -85,7 +87,7 @@
#foreach( $module in $maintenanceModules )
<li><a href="${module.defaultAction}">$i18n.getString( $module.name ) </a></li>
#end
- </ul>
+ </ul>
</div>
#end
@@ -95,20 +97,20 @@
#foreach( $module in $serviceModules )
<li><a href="${module.defaultAction}">$i18n.getString( $module.name ) </a></li>
#end
- </ul>
+ </ul>
</div>
#end
-
+
<div id="menuDropDown3" class="menuDropDownArea">
- <ul class="menuDropDownBox">
+ <ul class="menuDropDownBox">
<li><a href="../dhis-web-commons-about/help.action">$i18n.getString( "help_center" ) </a></li>
- <li><a href="../dhis-web-commons-about/software.action">$i18n.getString( "supportive_software" ) </a></li>
+ <li><a href="../dhis-web-commons-about/software.action">$i18n.getString( "supportive_software" ) </a></li>
<li><a href="../dhis-web-commons-about/modules.action">$i18n.getString( "system_overview" ) </a></li>
<li><a href="../api">$i18n.getString( "web_api" ) </a></li>
<li><a href="../dhis-web-commons-about/about.action">$i18n.getString( "about_dhis2" ) </a></li>
</ul>
</div>
-
+
<div id="menuDropDown4" class="menuDropDownArea">
<ul class="menuDropDownBox">
<li><a href="../dhis-web-commons-about/userSettings.action">$i18n.getString( "settings" ) </a></li>
@@ -133,22 +135,22 @@
#mainPage { margin-left: 20px; }
</style>
#else
- <div id="leftBar">
+ <div id="leftBar">
<div id="hideLeftBar">
<a href="index.action" title="$i18n.getString( 'show_main_menu' )" id="showMainMenuLink">
<img src="../images/home_small.png" width="16" height="16" title="$i18n.getString( 'show_main_menu' )"/></a>
<a href="javascript:leftBar.hideAnimated()" title="$i18n.getString( 'hide_menu' )" id="hideMainMenuLink">
<img src="../images/hide_menu.png" width="16" height="16" title="$i18n.getString( 'hide_menu' )"/></a>
</div>
-
+
<div id="leftBarContents">
#parse( $menu )
</div>
</div>
#end
-
+
<div id="headerMessage" class="bold"></div>
-
+
<div class="page" id="mainPage"> <!-- Do not set style attr -->
#if( !$page )
<p>$i18n.getString( "no_page_specified" )</p>
@@ -161,13 +163,13 @@
leftBar.hide();
</script>
#end
-
+
<div id="rightBar">
<span id="hideRightBar"><a href="javascript:hideHelpContent()" title="$i18n.getString( 'close' )">
<img id="hideRightBarImg" src="../images/hide.png" alt="$i18n.getString( 'close' )"/></a>
</span>
<div id="rightBarContents"/>
</div>
-
+
</body>
</html>