Commit ff33d12e authored by Sven Franck's avatar Sven Franck

bugfix: default item search, timing of renaming gadget ids

parent 14cebc93
...@@ -148,10 +148,11 @@ define([ ...@@ -148,10 +148,11 @@ define([
priv.doc.on('pagebeforeshow', 'div.ui-page', function () { priv.doc.on('pagebeforeshow', 'div.ui-page', function () {
var page = $(this); var page = $(this);
// need to call this every time a page is shown... // need to call this every time a page is shown...
RenderJs.init(); RenderJs.init(page);
RenderJs.bindReady(function () { RenderJs.bindReady(function () {
var gadget = RenderJs.GadgetIndex.getGadgetById(page.attr('id')); var gadget = RenderJs.GadgetIndex.getGadgetById(page.attr('id'));
if (gadget.isEnhanced() === false) { if (gadget.isEnhanced() === false) {
page.trigger("create"); page.trigger("create");
gadget.setEnhanced(true); gadget.setEnhanced(true);
...@@ -227,11 +228,18 @@ define([ ...@@ -227,11 +228,18 @@ define([
that.renderGadgets = function (gadget) { that.renderGadgets = function (gadget) {
var gadget_id = gadget.dom.attr('id'), var gadget_id = gadget.dom.attr('id'),
gadget_parent = gadget.dom.parents("div[data-gadget]"), gadget_parent = gadget.dom.parents("div[data-gadget]"),
gadget_props = gadget["state"], gadget_props,
gadget_cleaned_id = gadget_id.split("__").slice(-1)[0], gadget_cleaned_id,
propsToSet, propsToSet,
fwd = [], new_id,
i; fwd = [], i;
if (!gadget_parent.is(".ui-page-active")) {
return;
}
gadget_props = gadget["state"];
gadget_cleaned_id = gadget_id.split("__").slice(-1)[0];
// JSON property API // JSON property API
// "state": [ // "state": [
...@@ -283,9 +291,16 @@ define([ ...@@ -283,9 +291,16 @@ define([
} }
}); });
// update this gadgets id with the parent gadget id // update this gadgets id with the parent gadget id. Make sure to also
// add the new id inside the renderJs GadgetIndex. Previsouly the id
// was set only on child gadgets, which worked because gadgets had not
// been loaded at the time when the id was modified. Since this only
// seems to work in FF with multiple nested gadget levels, we set the
// id here, but must also update the id of the gadget in the gadgetIndex
if (gadget_parent.length > 0) { if (gadget_parent.length > 0) {
gadget.dom.attr('id', gadget_parent.attr('id') + "__" + gadget_id); new_id = gadget_parent.attr('id') + "__" + gadget_id;
RenderJs.GadgetIndex.getGadgetById(gadget_id).id = new_id;
gadget.dom.attr('id', new_id);
} }
}; };
......
...@@ -37,12 +37,12 @@ var RenderJs = (function () { ...@@ -37,12 +37,12 @@ var RenderJs = (function () {
return { return {
init: function (callback) { init: function (selector) {
/* /*
* Do all initialization * Do all initialization
*/ */
if (RENDERJS_ENABLE_IMPLICIT_GADGET_RENDERING) { if (RENDERJS_ENABLE_IMPLICIT_GADGET_RENDERING) {
RenderJs.bootstrap( $('body') ); RenderJs.bootstrap( selector || $('body') );
} }
var root_gadget = RenderJs.GadgetIndex.getRootGadget(); var root_gadget = RenderJs.GadgetIndex.getRootGadget();
if (RENDERJS_ENABLE_IMPLICIT_INTERACTION_BIND||RENDERJS_ENABLE_IMPLICIT_ROUTE_CREATE) { if (RENDERJS_ENABLE_IMPLICIT_INTERACTION_BIND||RENDERJS_ENABLE_IMPLICIT_ROUTE_CREATE) {
...@@ -89,7 +89,6 @@ var RenderJs = (function () { ...@@ -89,7 +89,6 @@ var RenderJs = (function () {
*/ */
var gadget_list, gadget, gadget_id, gadget_js; var gadget_list, gadget, gadget_id, gadget_js;
gadget_list = root.find("[data-gadget]"); gadget_list = root.find("[data-gadget]");
// register all gadget in advance so checkAndTriggerReady // register all gadget in advance so checkAndTriggerReady
// can have accurate information for list of all gadgets // can have accurate information for list of all gadgets
gadget_list.each(function (i, el) { gadget_list.each(function (i, el) {
......
...@@ -19,9 +19,9 @@ define([ ...@@ -19,9 +19,9 @@ define([
if (window.App === undefined) { if (window.App === undefined) {
def = new $.Deferred; def = new $.Deferred;
def.done(function(zzz) { def.done(function(gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
window.App.renderGadgets(zzz); window.App.renderGadgets(gadget);
}); });
window.fallbackLoader.deferreds.push(def); window.fallbackLoader.deferreds.push(def);
......
...@@ -20,6 +20,7 @@ define([ ...@@ -20,6 +20,7 @@ define([
spec.pointer = config.datasource.pointer; spec.pointer = config.datasource.pointer;
spec.method = spec.pointer ? undefined : config.datasource.method || "allDocs"; spec.method = spec.pointer ? undefined : config.datasource.method || "allDocs";
spec.storage = spec.pointer ? undefined : config.datasource.storage || "items";
spec.options = spec.pointer ? undefined : { spec.options = spec.pointer ? undefined : {
"limit": config.datasource.limit || [0, 24], "limit": config.datasource.limit || [0, 24],
"sort_on": config.datasource.sort || [["_id", "descending"]], "sort_on": config.datasource.sort || [["_id", "descending"]],
......
...@@ -23,14 +23,15 @@ ...@@ -23,14 +23,15 @@
} }
} }
] ]
}' }'>
></div> </div>
<!-- panel --> <!-- panel -->
<div data-role="panel" <div data-role="panel"
id="search_panel" id="search_panel"
data-gadget="modules/refine/refine.html" data-gadget="modules/refine/refine.html"
data-gadget-module="refine"></div> data-gadget-module="refine">
</div>
<!-- content --> <!-- content -->
<div data-role="content" class="ui-content search_content"> <div data-role="content" class="ui-content search_content">
...@@ -42,7 +43,8 @@ ...@@ -42,7 +43,8 @@
data-rel="panel" data-rel="panel"
data-role="button" data-role="button"
data-iconpos="notext" data-iconpos="notext"
data-icon="grid"></a> data-icon="grid">
</a>
<!-- global search --> <!-- global search -->
<div id="searchbar" <div id="searchbar"
...@@ -55,7 +57,8 @@ ...@@ -55,7 +57,8 @@
<div id="sorting" <div id="sorting"
class="search_element" class="search_element"
data-gadget="modules/sorting/sorting.html" data-gadget="modules/sorting/sorting.html"
data-gadget-module="sorting"></div> data-gadget-module="sorting">
</div>
<!-- results --> <!-- results -->
<div id="results" <div id="results"
...@@ -75,14 +78,18 @@ ...@@ -75,14 +78,18 @@
} }
} }
] ]
}' }'>
></div> </div>
</div> </div>
<!-- footer --> <!-- footer -->
<div id="footer" <div id="footer"
data-role="footer" data-role="footer"
data-position="fixed" data-position="fixed"
data-gadget="modules/footer/footer.html" data-gadget="modules/footer/footer.html"
data-gadget-module="footer"></div> data-gadget-module="footer">
</div>
</body> </body>
</html> </html>
...@@ -6,72 +6,7 @@ define([ ...@@ -6,72 +6,7 @@ define([
var response = {}; var response = {};
response.data = source; response.data = source;
response.mockup = function (source, callback_mockup) {
var gadget = RenderJs.getSelfGadget();
// renderGadget
window.App.renderGadgets(gadget);
/*
id = gadget.dom.attr('id').split("__").splice(-1)[0],
config = gadget.state[0][id]._config,
module = config.datasource.module,
// TODO: no fan of pointers (yet)
// pointers keep jio query parameter in storage.js,
// => so they don't need to be with JSON
pointer = config.datasource.pointer,
// regardless of a pointer, we declare defaults
method = pointer ? undefined : config.datasource.method || "allDocs",
options = pointer ? undefined : {
"limit": config.datasource.limit || [0, 24],
"sort_on": config.datasource.sort || [["_id", "descending"]],
"select_list": config.datasource.fields || undefined
},
data,
markup,
screen = window.App.settings.screen_format,
// this defines the size of the images to be displayed
// TODO: this should be customizable
size = screen === "small" ? "small" : "medium",
shortcut = size.substring(0, 1);
data = window.App[module].switchboard(
pointer,
method,
options,
function(response) {
var item, i, str = "", price;
for (i = 0; i < response.length; i += 1) {
item = response[i];
if (item.price === item.original_price) {
price = item.price + "€";
} else {
price = "<span class='rebate'>" + item.price + "€</span> (" +
item.original_price + "€)";
}
str += "<li data-icon='false'>" +
"<a href='details.html?product=" + item._id +
"' title='" + item.brand + ", " + item.title + "'>" +
"<span class='img_container_items'>" +
"<img alt='" + item.title + "' src='" +
item.media + item.dimensions[0].vars[0].media.img[0][shortcut] +
size + "' /></span><span class='description_items'>" +
item.brand + " " + item.title + " " + price + "</span></a></li>";
}
// add to data
markup = source.replace(/<!-- items -->/g, str);
// this is not response.callback(!!)*/
callback_mockup(source);
//}
//);
};
response.callback = function (self) { response.callback = function (self) {
var filter = self.dom.find(".searchbar_filter"); var filter = self.dom.find(".searchbar_filter");
......
...@@ -637,7 +637,7 @@ define([ ...@@ -637,7 +637,7 @@ define([
// pointer, method, options, callback // pointer, method, options, callback
that.switchboard = function (param) { that.switchboard = function (param) {
var query = {}; var query = {};
var spec = {}; var spec = param || {};
// default object // default object
spec.default_items = [ spec.default_items = [
...@@ -656,11 +656,13 @@ define([ ...@@ -656,11 +656,13 @@ define([
query.select_list = []; query.select_list = [];
query.wildcard_character = '%' query.wildcard_character = '%'
// if we have a pointer, we can disregard method & options // if we have a pointer, we can disregard method & options,
// but we must set on spec directly, because query will only be
// assigned in a defined case
if (param.pointer === undefined) { if (param.pointer === undefined) {
query.limit = param.options.limit; spec.options.limit = param.options.limit;
query.sort_on = param.options.sort_on; spec.options.sort_on = param.options.sort_on;
query.select_list = param.options.select_list || spec.default_items; spec.options.select_list = param.options.select_list || spec.default_items;
} }
switch (param.pointer) { switch (param.pointer) {
...@@ -681,9 +683,9 @@ define([ ...@@ -681,9 +683,9 @@ define([
break; break;
// default search with parameters passed! // default
default: default:
that.queryStorage(spec);
break; break;
} }
}; };
......
...@@ -8,6 +8,13 @@ ...@@ -8,6 +8,13 @@
<script data-main="js/main.js" src="js/libs/require/require.js"></script> <script data-main="js/main.js" src="js/libs/require/require.js"></script>
</head> </head>
<body> <body>
<div data-role="page" id="search" data-gadget="modules/search/search.html" data-gadget-module="search"></div>
<div
data-role="page"
id="search"
data-gadget="modules/search/search.html"
data-gadget-module="search">
</div>
</body> </body>
</html> </html>
\ 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