Commit 217d02ca authored by Thibaut Frain's avatar Thibaut Frain

integrate jquerysheet with save and load function

parent c1f9edc9
......@@ -264,6 +264,11 @@ a.confirm, a.action {
}
div.ui-content > iframe {
height: 1000px;
height: 500px;
min-width: 1300px;
}
div.ui-content2 > iframe {
height: 500px;
min-width: 1300px;
}
\ No newline at end of file
......@@ -21,7 +21,6 @@
<link rel="stylesheet" href="../css/themes.css">
<!-- generic CSS -->
<link rel="stylesheet" href="../css/css.css">
<!-- Jquery, JQM, JQM extensions -->
<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../lib/jquery.mobile.js" type="text/javascript"></script>
......@@ -35,7 +34,6 @@
<!-- custom script -->
<!--script src="../js/erp5_loader.js" type="text/javascript"></script-->
<script src="../js/gadget_index.js" type="text/javascript"></script>
</head>
<body>
......@@ -152,14 +150,28 @@
</div>
</div>
<div id="iogadget"></div>
<!-- content -->
<div class="ui-content">
<!--table class="erp5_table" data-type="Computer">
</table-->
</div>
<!-- IO manager -->
<div id="iogadget"></div>
<!-- <div id="io" class="wrap left buttongroup" data-type="horizontal" data-role="controlgroup"> -->
<!-- <div data-role="fieldcontain"> -->
<!-- <textarea name="Filename" id="io-doc" placeholder="Filename"></textarea> -->
<!-- </div> -->
<!-- <span href="" id="save-doc" data-role="button" href="#page1"> -->
<!-- Save -->
<!-- </span> -->
<!-- <span href="" id="load-doc" data-role="button" href="#page1"> -->
<!-- Load -->
<!-- </span> -->
<!-- <span href="" id="new-doc" data-role="button" href="#page1"> -->
<!-- New -->
<!-- </span> -->
<!-- </div> -->
<!-- Interactor -->
<div id="interactorgadget"></div>
......@@ -186,5 +198,9 @@
</div>
</div>
</div>
<script type="text/javascript">
// force reload iframe in development environment
$('#ui-content iframe').first().contentWindow.location.reload(true);
</script>
</body>
</html>
......@@ -22,5 +22,18 @@
href="http://www.renderjs.org/interface/io"/>
</head>
<body>
<input type="text" name="fileName" id="svg-edit_docid" value="" placeholder="File name here">
<button id="save-doc" type="submit" class="btn btn-primary">
<i class="icon-download-alt icon-white"></i>
Save
</button>
<button id="load-doc" type="submit" class="btn btn-primary">
<i class="icon-download-alt icon-white"></i>
Load
</button>
<button id="new-doc" type="submit" class="btn btn-primary">
<i class="icon-download-alt icon-white"></i>
New document
</button>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="-1"/>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
<meta content="utf-8" http-equiv="encoding"/>
......@@ -13,10 +10,15 @@
<link rel="stylesheet" type="text/css" href="../lib/jquery.sheet/jquery-ui/theme/jquery-ui.min.css">
<script type="text/javascript" src="../lib/jquery.sheet/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="../lib/jschannel.js"></script>
<script type="text/javascript" src="../lib/renderjs.js"></script>
<script type="text/javascript" src="../lib/jquery.sheet/plugins/globalize.js"></script>
<script type="text/javascript" src="../lib/jquery.sheet/parser/formula/formula.js"></script>
<script type="text/javascript" src="../lib/jquery.sheet/parser/tsv/tsv.js"></script>
<script type="text/javascript" src="../lib/jquery.sheet/jquery.sheet.min.js"></script>
<script type="text/javascript" src="../lib/jquery.sheet/plugins/jquery.sheet.dts.js"></script>
<script type="text/javascript" src="../js/gadget_jqs.js"></script>
<!--Page styles-->
<style>
......@@ -73,22 +75,9 @@
</style>
</head>
<body>
<h1 id="header" class="ui-state-default">
<a href="http://visop-dev.com/Project+jQuery.sheet">
<img src="images/logo.png" style="position: absolute;top: -20px; left: 20px; border: none;" />
jQuery.sheet - The Ajax Spreadsheet, Demo
</a>
<br />
<span id="themeSwitcher"></span>
</h1>
<div id="mainWrapper" class="ui-corner-all wrapper">
<div id="sheet" class="jQuerySheet" style="height: 450px;"></div>
<div class="jQuerySheet" style="height: 450px;"></div>
</div>
<script type="text/javascript">
$('#sheet').sheet().getSheet().newSheet();
</script>
</body>
</html>
......@@ -10,7 +10,17 @@
rJS(window).ready(function () {
var g = rJS(this),
body = g.context,
main_context = g.context.find('.ui-content').first();
main_context = g.context.find('.ui-content').first(),
ioGadgetConfig = {"type": "local",
"username": "officejs",
"application_name": "officejs"
},
jioGadget,
jqsGadget;
function log(x) {
console.log(x);
}
function setTitle(title) {
g.context.find("#headergadget").find("h1").text(title);
......@@ -23,6 +33,33 @@
.then(setTitle);
}
function registerSaveButton(gadget) {
window.jqs = gadget;
$("#save-doc").click(function () {
var fileName = $("#iogadget input").val();
jioGadget.configureIO(ioGadgetConfig, fileName)
.then(gadget.get)
.then(function (o) {jioGadget.setIO(o); });
});
return gadget;
}
function registerLoadButton(gadget) {
$("#load-doc").click(function () {
var fileName = $("#iogadget input").val();
jioGadget.configureIO(ioGadgetConfig, fileName)
.then(jioGadget.getIO)
.then(gadget.put);
});
return gadget;
}
function registerCleanButton(gadget) {
$("#new-doc").click(function () {
gadget.clean();
});
}
function initializeRoute() {
body
.route("add", "", 1)
......@@ -55,13 +92,16 @@
.route("add", "/spreadsheet/", 1)
.done(function () {
g.declareIframedGadget('./spreadsheet.html', main_context)
.then(enhanceGadgetRendering);
.then(registerSaveButton)
.then(registerLoadButton)
.then(registerCleanButton);
});
}
g.declareGadget('./io.html', g.context.find("iogadget"))
.done(function (io_gadget) {
g.declareGadget('./io.html', g.context.find("#iogadget"))
.done(function (ioGadget) {
window.jio = ioGadget;
jioGadget = ioGadget;
// Trigger route change
initializeRoute();
$.url.onhashchange(function () {
......@@ -73,7 +113,6 @@
});
});
});
});
}(window, jQuery, rJS));
......@@ -7,6 +7,8 @@
gk.declareMethod('configureIO', function (json_configuration, key) {
rJS(this).jio = jIO.newJio(json_configuration);
rJS(this).jio_key = key;
console.log(rJS(this).jio);
return key;
})
.declareMethod('getIO', function () {
......@@ -25,6 +27,7 @@
deferred.reject(err);
}
} else {
console.log("getIO:" + response);
deferred.resolve(response || default_value);
}
});
......@@ -33,11 +36,10 @@
})
.declareMethod('setIO', function (value) {
var deferred = $.Deferred(),
default_value = "",
gadget = rJS(this);
console.log(this);
gadget.jio.put({"_id": gadget.jio_key},
function (err, response) {
if (err) {
......@@ -47,11 +49,13 @@
"_id": gadget.jio_key,
"_attachment": "body.txt",
"_data": value,
"_mimetype": "text/plain"
}, function (err, response) {
if (err) {
deferred.reject(err);
} else {
console.log("putIO: " + value);
deferred.resolve();
}
});
......
/*global window, jQuery, rJS*/
"use strict";
(function (window, $, rJS) {
var gk = rJS(window);
gk.declareMethod('init', function () {
rJS(this).parent = rJS(this).context.find('.jQuerySheet');
rJS(this).parent.sheet();
rJS(this).updateInstance();
rJS(this).instance.newSheet();
})
.declareMethod('get', function (name) {
rJS(this).updateInstance();
var json = $.sheet.dts.fromTables.json(rJS(this).instance, true);
console.log("get: " + JSON.stringify(json));
return JSON.stringify(json);
})
.declareMethod('put', function (spreadsheetString) {
var json = JSON.parse(spreadsheetString),
html = $.sheet.dts.toTables.json(json, true);
console.log("put: " + JSON.stringify(json));
rJS(this).parent.html(html).sheet();
})
.declareMethod('clean', function () {
delete (rJS(this).instance);
rJS(this).parent.html("");
rJS(this).parent.sheet();
rJS(this).instance = rJS(this).parent.getSheet();
rJS(this).instance.newSheet();
})
.declareMethod('updateInstance', function () {
rJS(this).instance = rJS(this).parent.getSheet();
})
.ready(function () {
rJS(this).init();
});
}(window, jQuery, rJS));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment