Commit 1aa8b2a6 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

erp5_officejs: Introduce Global Setting Gadget

parent dfe25ac1
<!DOCTYPE html>
<html manifest="gadget_officejs_setting.appcache">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>OfficeJS Router Gadget</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="jiodev.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_officejs_setting.js" type="text/javascript"></script>
</head>
<body>
<div data-gadget-url="gadget_officejs_jio.html"
data-gadget-scope="jio_gadget"
data-gadget-sandbox="public"></div>
</body>
</html>
\ No newline at end of file
/*global window, rJS, jIO, FormData, UriTemplate */
/*jslint indent: 2, maxerr: 3 */
(function (window, rJS, jIO) {
"use strict";
rJS(window)
.ready(function (gadget) {
// Initialize the gadget local parameters
gadget.state_parameter_dict = {};
gadget.state_parameter_dict.jio_storage = jIO.createJIO({
type: "indexeddb",
database: "global-setting"
});
})
.declareMethod('getSetting', function (key, default_value) {
var gadget = this;
return gadget.state_parameter_dict.jio_storage.get("setting")
.push(function (doc) {
return doc[key] || default_value;
}, function (error) {
if (error.status_code === 404) {
return default_value;
}
throw error;
});
})
.declareMethod('setSetting', function (key, value) {
var gadget = this;
return gadget.state_parameter_dict.jio_storage.get("setting")
.push(undefined, function (error) {
if (error.status_code === 404) {
return {};
}
throw error;
})
.push(function (doc) {
doc[key] = value;
return gadget.state_parameter_dict.jio_storage.put('setting', doc);
});
});
}(window, rJS, jIO));
\ No newline at end of file
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