Implement LocalStorage manager ...

This commit is contained in:
Paulo Veiga 2011-11-28 22:17:55 -03:00
parent 410d3553b1
commit a33daf4563
4 changed files with 41 additions and 28 deletions

View File

@ -108,7 +108,7 @@
files="XMLMindmapSerializerFactory.js"/> files="XMLMindmapSerializerFactory.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="PersistenceManager.js"/> <filelist dir="${basedir}/src/main/javascript/" files="PersistenceManager.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="DwrPersistenceManager.js"/> <filelist dir="${basedir}/src/main/javascript/" files="DwrPersistenceManager.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="FilePersistenceManager.js"/> <filelist dir="${basedir}/src/main/javascript/" files="LocalStorageManager.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="EditorProperties.js"/> <filelist dir="${basedir}/src/main/javascript/" files="EditorProperties.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="IconGroup.js"/> <filelist dir="${basedir}/src/main/javascript/" files="IconGroup.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="BubbleTip.js"/> <filelist dir="${basedir}/src/main/javascript/" files="BubbleTip.js"/>
@ -151,22 +151,22 @@
files="commands/AddRelationshipCommand.js"/> files="commands/AddRelationshipCommand.js"/>
<filelist dir="${basedir}/src/main/javascript/" <filelist dir="${basedir}/src/main/javascript/"
files="commands/MoveControlPointCommand.js"/> files="commands/MoveControlPointCommand.js"/>
<filelist dir="${basedir}/src/main/javascript/" <!--<filelist dir="${basedir}/src/main/javascript/"-->
files="commands/freeMind/DragTopicCommand.js"/> <!--files="commands/freeMind/DragTopicCommand.js"/>-->
<filelist dir="${basedir}/src/main/javascript/" <!--<filelist dir="${basedir}/src/main/javascript/"-->
files="commands/freeMind/ReconnectTopicCommand.js"/> <!--files="commands/freeMind/ReconnectTopicCommand.js"/>-->
<filelist dir="${basedir}/src/main/javascript/" <filelist dir="${basedir}/src/main/javascript/"
files="layout/boards/Board.js"/> files="layout/boards/Board.js"/>
<filelist dir="${basedir}/src/main/javascript/" <!--<filelist dir="${basedir}/src/main/javascript/"-->
files="layout/boards/freemind/Board.js"/> <!--files="layout/boards/freemind/Board.js"/>-->
<filelist dir="${basedir}/src/main/javascript/" <!--<filelist dir="${basedir}/src/main/javascript/"-->
files="layout/boards/freemind/Entry.js"/> <!--files="layout/boards/freemind/Entry.js"/>-->
<filelist dir="${basedir}/src/main/javascript/" <!--<filelist dir="${basedir}/src/main/javascript/"-->
files="layout/boards/freemind/CentralTopicBoard.js"/> <!--files="layout/boards/freemind/CentralTopicBoard.js"/>-->
<filelist dir="${basedir}/src/main/javascript/" <!--<filelist dir="${basedir}/src/main/javascript/"-->
files="layout/boards/freemind/MainTopicBoard.js"/> <!--files="layout/boards/freemind/MainTopicBoard.js"/>-->
<filelist dir="${basedir}/src/main/javascript/" <filelist dir="${basedir}/src/main/javascript/"
files="layout/BaseLayoutManager.js"/> files="layout/BaseLayoutManager.js"/>
<filelist dir="${basedir}/src/main/javascript/" <filelist dir="${basedir}/src/main/javascript/"

View File

@ -41,7 +41,7 @@ mindplot.DwrPersitenceManager = new Class({
) )
}, },
load : function(mapId) { loadMapDom : function(mapId) {
$assert(mapId, "mapId can not be null"); $assert(mapId, "mapId can not be null");
throw "This must be implemented"; throw "This must be implemented";

View File

@ -16,31 +16,38 @@
* limitations under the License. * limitations under the License.
*/ */
mindplot.FilePersitenceManager = new Class({ mindplot.LocalStorageManager = new Class({
Extends:mindplot.PersitenceManager, Extends:mindplot.PersitenceManager,
initialize: function() { initialize: function() {
this.parent(); this.parent();
}, },
saveMapXml : function(mapId, mapXml, pref, saveHistory, events) { saveMapXml : function(mapId, mapXml, pref, saveHistory, events) {
console.log(mapXml); localStorage.setItem(mapId + "-xml", mapXml);
events.onSuccess(); events.onSuccess();
}, },
load : function(mapId) { loadMapDom : function(mapId) {
$assert(mapId, "mapId can not be null"); var xml = localStorage.getItem(mapId + "-xml");
if (xml == null) {
var domDocument; // Let's try to open one from the local directory ...
var xmlRequest = new Request({ var xmlRequest = new Request({
url: '../maps/' + mapId + '.xml', url: '../maps/' + mapId + '.xml',
method: 'get', method: 'get',
async: false, async: false,
onSuccess: function(responseText, responseXML) { onSuccess: function(responseText) {
domDocument = responseXML; xml = responseText;
} }
}); });
xmlRequest.send(); xmlRequest.send();
return this.loadFromDom(mapId, domDocument);
// If I could not load it from a file, hard code one.
if (xml == null) {
xml = '<map name="6" version="pela"><topic central="true" text="General Status" id="1"/></map>';
}
}
return core.Utils.createDocumentFromText(xml);
} }
} }
); );

View File

@ -42,6 +42,12 @@ mindplot.PersitenceManager = new Class({
}, },
load: function(mapId) { load: function(mapId) {
$assert(mapId, "mapId can not be null");
var domDocument = this.loadMapDom(mapId);
return this.loadFromDom(mapId, domDocument);
},
loadMapDom: function(mapId) {
throw "Method must be implemented"; throw "Method must be implemented";
}, },