From 4366fc42ccbdb23bae0c2dd1974db9fdcb859faa Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Wed, 29 Aug 2012 00:57:55 +0200 Subject: [PATCH] Added serialization/deserialization capabilities Two changes to Framesheet : * serialize : basic implementation using JSON.stringify * deserialize : added method --- js/frameSheetModel.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/js/frameSheetModel.js b/js/frameSheetModel.js index 5ea52a0d..2de4c2b9 100644 --- a/js/frameSheetModel.js +++ b/js/frameSheetModel.js @@ -19,10 +19,23 @@ var FrameSheetModel = (function() { return true; // I'm always right dude }, - // Could be use to pass around model using long GET param (good enough for simple models) and + // Could be used to pass around model using long GET param (good enough for simple models) and // do some temporary locastorage serialize: function() { - throw "FrameSheet.serialize Not implemented" + return JSON.stringify(frames); + }, + + /** + * Load a framesheet from a string that might have been persisted in db / localstorage + * Overrides existing frames. + * @param {String} serialized + */ + deserializeFramesheet : function (serialized) { + try { + frames = eval(serialized); + } catch (e) { + throw "Could not load serialized framesheet." + e.getMessage() + } }, addEmptyFrame: function() {