Commit 12d065cc authored by Ivan Tyagov's avatar Ivan Tyagov

Separate cache proeprties from Gadget instance ones (caching have a

wider scope outside Gadget itself).
Use concistent format for naming attributes.
parent c7b04104
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<head> <head>
<body> <body>
<div data-gadget="say-hello.html" <div data-gadget="say-hello.html"
data-gadget:property="{&quot;cacheable&quot;: &quot;1&quot;, &quot;cache_id&quot;: &quot;say_hello&quot;}"></div> data-gadget-cacheable="1"
data-gadget-cache-id="say_hello"></div>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -8,11 +8,13 @@ ...@@ -8,11 +8,13 @@
<div id="A" <div id="A"
data-gadget="A.html" data-gadget="A.html"
data-gadget:property="{&quot;cacheable&quot;: &quot;1&quot;, &quot;cache_id&quot;: &quot;A&quot;}"></div> data-gadget-cacheable="1"
data-gadget-cache-id="A"></div>
<div id="B" <div id="B"
data-gadget="B.html" data-gadget="B.html"
data-gadget:property="{&quot;cacheable&quot;: &quot;1&quot;, &quot;cache_id&quot;: &quot;B&quot;}"></div> data-gadget-cacheable="1"
data-gadget-cache-id="B"></div>
<div data-gadget="" <div data-gadget=""
id="main-interactor"> id="main-interactor">
......
...@@ -59,17 +59,17 @@ var RenderJs = (function () { ...@@ -59,17 +59,17 @@ var RenderJs = (function () {
gadget_js = new RenderJs.Gadget(gadget_id, gadget); gadget_js = new RenderJs.Gadget(gadget_id, gadget);
RenderJs.GadgetIndex.registerGadget(gadget_js); RenderJs.GadgetIndex.registerGadget(gadget_js);
// XXX: update Gadget's instance with contents of "data-gadget-property"
if (url!==undefined && url!==""){ if (url!==undefined && url!==""){
gadget_property = gadget.attr("data-gadget:property"); cacheable = gadget.attr("data-gadget-cacheable");
cacheable = false; cache_id = gadget.attr("data-gadget-cache-id");
if (gadget_property!==undefined) { if (cacheable!==undefined && cache_id!==undefined){
gadget_property = $.parseJSON(gadget_property); cacheable = Boolean(parseInt(cacheable));
cacheable = Boolean(gadget_property.cacheable);
} }
//cacheable = false ; // to develop faster //cacheable = false ; // to develop faster
if (cacheable) { if (cacheable) {
// get from cache if possible, use last part from URL as cache_key // get from cache if possible, use last part from URL as cache_key
cache_id = gadget_property.cache_id;
app_cache = RenderJs.Cache.get(cache_id, undefined); app_cache = RenderJs.Cache.get(cache_id, undefined);
if(app_cache===undefined || app_cache===null){ if(app_cache===undefined || app_cache===null){
// not in cache so we pull from network and cache // not in cache so we pull from network and cache
...@@ -157,8 +157,8 @@ var RenderJs = (function () { ...@@ -157,8 +157,8 @@ var RenderJs = (function () {
updateGadgetData: function(gadget) { updateGadgetData: function(gadget) {
/* Do real gagdet update here */ /* Do real gagdet update here */
var data_source, data_handler; var data_source, data_handler;
data_source = gadget.attr("data-gadget:data-source"); data_source = gadget.attr("data-gadget-source");
data_handler = gadget.attr("data-gadget:data-handler"); data_handler = gadget.attr("data-gadget-handler");
// acquire data and pass it to method handler // acquire data and pass it to method handler
if (data_source!==undefined && data_source!==""){ if (data_source!==undefined && data_source!==""){
$.ajax({url:data_source, $.ajax({url:data_source,
...@@ -176,8 +176,8 @@ var RenderJs = (function () { ...@@ -176,8 +176,8 @@ var RenderJs = (function () {
tab_container.empty(); tab_container.empty();
html_string =['<div class="gadget" ', html_string =['<div class="gadget" ',
'data-gadget="' + gadget + '"', 'data-gadget="' + gadget + '"',
'data-gadget:data-handler="' + gadget_data_handler + '" ', 'data-gadget-handler="' + gadget_data_handler + '" ',
'data-gadget:data-source="' + gadget_data_source +'"></div>'].join('\n'); 'data-gadget-source="' + gadget_data_source +'"></div>'].join('\n');
tab_container.append(html_string); tab_container.append(html_string);
tab_gadget = tab_container.find(".gadget"); tab_gadget = tab_container.find(".gadget");
......
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