From cc4b107209682dad69df3ca26404de8ebb994b63 Mon Sep 17 00:00:00 2001 From: Kazuhiko Shiozaki <kazuhiko@nexedi.com> Date: Mon, 25 Nov 2013 11:37:20 +0100 Subject: [PATCH] store spreadsheet data in the same JSON as graph one. --- dream/platform/static/src/dream.js | 3 +- dream/platform/static/src/dream_launcher.js | 76 ++++++++------------- dream/platform/static/src/jsonPlumb.js | 6 +- 3 files changed, 35 insertions(+), 50 deletions(-) diff --git a/dream/platform/static/src/dream.js b/dream/platform/static/src/dream.js index b0794864..cbf57055 100644 --- a/dream/platform/static/src/dream.js +++ b/dream/platform/static/src/dream.js @@ -271,8 +271,7 @@ $.ajax( '/runSimulation', { data: JSON.stringify({ - json: model, - spreadsheet: $.sheet.instance[0].exportSheet.json() + json: model }), contentType: 'application/json', type: 'POST', diff --git a/dream/platform/static/src/dream_launcher.js b/dream/platform/static/src/dream_launcher.js index f7a2c03b..5d954540 100644 --- a/dream/platform/static/src/dream_launcher.js +++ b/dream/platform/static/src/dream_launcher.js @@ -294,8 +294,37 @@ } else { dream_instance.redraw(); } + + var spreadsheet = data.spreadsheet; + if (spreadsheet !== undefined) { + $.sheet.makeTable.json(JSON.parse(response.data)); + } }; + // spreadsheet + var default_config = { + id: "jquerysheet-div", + style: '', + jquerySheet: true, + jquerySheetCss: true, + parser: true, + jqueryUiCss: true, + scrollTo: false, + jQueryUI: false, + raphaelJs: false, + gRaphaelJs: false, + colorPicker: false, + colorPickerCss: false, + elastic: false, + advancedMath: false, + finance: false, + editable: true, + autoFiller: true, + urlGet: 'lib/jquery.sheet-2.0.0/new_spreadsheet.html' + }; + + var sheet = $('.jQuerySheet').sheet(default_config); + // Check if there is already data when we first load the page, if yes, then build graph from it jio.get({ _id: "dream_demo" @@ -310,12 +339,6 @@ _id: "dream_demo", data: data }, function (err, response) {}); - - jio.put({ - _id: "dream_demo.spreadsheet", - data: JSON.stringify($.sheet.instance[0].exportSheet.json(), undefined, " ") - }, function (err, response) {}); - }); }); @@ -486,46 +509,5 @@ $("#graph_zone").hide(); -// spreadsheet - var default_config = { - id: "jquerysheet-div", - style: '', - jquerySheet: true, - jquerySheetCss: true, - parser: true, - jqueryUiCss: true, - scrollTo: false, - jQueryUI: false, - raphaelJs: false, - gRaphaelJs: false, - colorPicker: false, - colorPickerCss: false, - elastic: false, - advancedMath: false, - finance: false, - editable: true, - autoFiller: true, - urlGet: 'lib/jquery.sheet-2.0.0/new_spreadsheet.html' - }; - - - var sheet = $('.jQuerySheet').sheet(default_config); - - // reread spreadsheet from jio - jio.get({ - _id: "dream_demo.spreadsheet" - }, function (err, response) { - if (response !== undefined && response.data !== undefined) { - var config = $.extend({ - buildSheet: $.sheet.makeTable.json(JSON.parse(response.data)) - }); - sheet.sheet(config); - } - }); - - sheet.bind('sheetCellEdited', function() { - // TODO - }); - }); })(jQuery); diff --git a/dream/platform/static/src/jsonPlumb.js b/dream/platform/static/src/jsonPlumb.js index ad5d17c6..6ae60f5b 100644 --- a/dream/platform/static/src/jsonPlumb.js +++ b/dream/platform/static/src/jsonPlumb.js @@ -257,12 +257,16 @@ }; priv.getData = function () { - return { + var data = { "nodes": priv.node_container, "edges": priv.edge_container, "preference": priv.preference_container, "general": priv.general_container }; + if ($.sheet.instance !== undefined) { + data['spreadsheet'] = $.sheet.instance[0].exportSheet.json(); + } + return data; }; priv.removeElement = function (element_id) { -- 2.30.9