Commit 137a1e46 authored by Sven Franck's avatar Sven Franck

replaced window.App with dependency on App module in all gadgets

parent 4632b319
......@@ -67,7 +67,6 @@
, shim: {
'jqm': { deps: ['jquery'], exports: 'mobile' }
, 'jio': { deps: ['md5'] }
, 'complex_queries': { exports: 'complex_queries' }
, 'localstorage': { deps: ['jio', 'complex_queries'] }
, 'indexstorage': { deps: ['jio'] }
, 'renderjs': { deps: ['jquery'], exports: 'RenderJs' }
......@@ -102,12 +101,10 @@
// expose App once everything is loaded
spec.setup.done(function(App, Config) {
window.App = App;
// expose configuration - settings
window.App.settings = Config.settings;
App.settings = Config.settings;
// expose configuration - storages
window.App.storage = Config.storage;
App.storage = Config.storage;
for (i = 0; i < window.fallbackLoader.deferreds.length; i += 1) {
window.fallbackLoader.deferreds[i]
......
define([
'text!address.html!strip'
'app'
, 'text!address.html!strip'
, 'validval'
, 'css!address'
],
function (source, validator) {
function (App, source, validator) {
var response = {};
response.data = source;
response.callback = function (self) {
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!basket.html!strip'
'app'
, 'text!basket.html!strip'
, 'css!basket'
],
function (source) {
function (App, source) {
var response = {};
response.data = source;
response.callback = function (self) {
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!browser.html!strip'
'app'
, 'text!browser.html!strip'
, 'css!browser'
],
function (source) {
function (App, source) {
var response = {};
response.data = source;
response.callback = function (self) {
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'storage'
'app'
, 'storage'
, 'async'
],
function (storage) {
function (App, storage) {
"use strict";
var priv = {};
......@@ -36,13 +37,10 @@ define([
spec.config.settings.language_default = "en-EN";
spec.config.settings.language_current = spec.config.settings.language_default;
spec.config.settings.language_selector = "translate";
spec.config.settings.language_set = false;
} else {
// create application settings
spec.config.settings.language_default = spec.response.default_language || "en-EN";
spec.config.settings.language_current = spec.response.language_current || spec.config.settings.language_default;
spec.config.settings.language_selector = spec.response.selector || "translate";
spec.config.settings.language_set = spec.response.language_set || false;
}
spec.config.settings.screen_format = priv.setScreenDimensions();
......@@ -75,7 +73,7 @@ define([
function(data) {
priv.config_call(data);
}
)
);
// require(
// ["async!http://www.franckreich.de/members/export/x/configuration.json"],
// config_call
......@@ -98,6 +96,7 @@ define([
}
storage.queryStorage(spec);
}
// return config
return that;
}
......
define([
'text!confirm.html!strip'
'app'
, 'text!confirm.html!strip'
, 'css!confirm'
],
function (source) {
function (App, source) {
var response = {};
response.data = source;
response.callback = function (self) {
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!description.html!strip'
'app'
, 'text!description.html!strip'
, 'css!description'
],
function (source) {
function (App, source) {
var response = {};
response.data = source;
response.callback = function (self) {
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!details.html!strip'
'app'
, 'text!details.html!strip'
, 'css!details'
],
function (source) {
function (App, source) {
var response = {};
response.data = source;
response.callback = function (self) {
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!footer.html!strip'
'app'
, 'text!footer.html!strip'
, 'css!footer'
],
function (source) {
function (App, source) {
var response = {};
response.data = source;
response.callback = function (self) {
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!gallery.html!strip'
'app'
, 'text!gallery.html!strip'
, 'css!gallery'
],
function (source) {
function (App, source) {
var response = {};
response.data = source;
response.callback = function (self) {
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!index.html!strip'
'app'
, 'text!index.html!strip'
, 'css!index'
],
function (source) {
function (App, source) {
var response = {}, def;
response.data = source;
response.callback = function (self) {
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!item.html!strip'
'app'
, 'text!item.html!strip'
, 'css!item'
],
function (source) {
function (App, source) {
var response = {};
response.data = source;
response.callback = function (self) {
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!items.html!strip'
'app'
, 'text!items.html!strip'
, 'css!items'
],
function (source) {
function (App, source) {
var response = {};
response.data = source;
// TODO: the method to query and display items should be set be
// either the searchbar or the storage?
response.mockup = function (source, callback_mockup) {
var markup, spec,
gadget = RenderJs.getSelfGadget(),
id = gadget.dom.attr('id').split("__").splice(-1)[0],
config = gadget.state[0][id]._config,
module = config.datasource.module,
screen = window.App.settings.screen_format,
// settable options
screen = App.settings.screen_format,
size = screen === "small" ? "small" : "medium",
shortcut = size.substring(0, 1);
shortcut = size.substring(0, 1),
identifier = App.settings.identifier || "item_id";
spec = {};
......@@ -27,9 +32,29 @@ define([
"select_list": config.datasource.fields || undefined
};
// if we have a search tag being passed, run a search
if (location.search !== "") {
spec.query = true;
spec.query_string = location.search.split("=")[1].replace("+", " ");
}
spec.callback = function(err, response) {
var item, i, str = "", price;
// cleanup
// no results
// TODO: show something for users like most-searched/sold...
// TODO: this is optionable
if (response.total_rows === 0) {
str += "<li data-icon='false' class='empty_results'>" +
"<h3 class='translate' data-i18n='items.results_zero'></h3>" +
"<p class='translate' data-i18n='items.results_modify'></p>" +
"</li>";
} else {
// generate results
for (i = 0; i < response.total_rows; i += 1) {
item = response.rows[i].value;
......@@ -41,7 +66,8 @@ define([
}
str += "<li data-icon='false'>" +
"<a href='details.html?product=" + item._id +
"<a href='details.html?"+ identifier + "=" +
encodeURI(item[identifier]) +
"' title='" + item.brand + ", " + item.title + "'>" +
"<span class='img_container_items'>" +
"<img alt='" + item.title + "' src='" +
......@@ -49,6 +75,7 @@ define([
size + "' /></span><span class='description_items'>" +
item.brand + " " + item.title + " " + price + "</span></a></li>";
}
}
// add to data
markup = source.replace(/<!-- items -->/g, str);
......@@ -57,23 +84,54 @@ define([
}
// query for items
window.App[module].switchboard(spec);
App[module].switchboard(spec);
};
response.callback = function (self) {
if (window.App === undefined) {
var closest = function (elem, selector) {
var matchesSelector = elem.matches ||
elem.webkitMatchesSelector ||
elem.mozMatchesSelector ||
elem.msMatchesSelector;
while (elem) {
if (matchesSelector.bind(elem)(selector)) {
return elem;
} else {
elem = elem.parentNode;
}
}
return false;
};
// set binding for opening a detailed view
// TODO: this should also be a link-method call
self.dom.find("ul").on("click", "a", function (e) {
var key;
e.preventDefault();
key = closest(e.target, "a").getAttribute("href").split("?")[1];
// show this item
$.mobile.changePage("details.html", {
"transition": "slide",
"data": {
"product": key
}
});
});
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!login.html!strip'
'app'
, 'text!login.html!strip'
, 'validval'
, 'css!login'
],
function (source) {
function (App, source, validator) {
var response = {};
response.data = source;
response.callback = function (self) {
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!media.html!strip'
'app'
, 'text!media.html!strip'
, 'css!media'
],
function (source) {
function (App, source) {
var response = {};
response.data = source;
response.callback = function (self) {
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!payment.html!strip'
'app'
, 'text!payment.html!strip'
, 'css!payment'
],
function (source) {
function (App, source) {
var response = {};
response.data = source;
response.callback = function (self) {
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!refine.html!strip'
'app'
, 'text!refine.html!strip'
, 'css!refine'
],
function (source) {
function (App, source) {
var response = {};
response.data = source;
response.callback = function (self) {
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!search.html!strip'
'app'
, 'text!search.html!strip'
, 'css!search'
],
function (source) {
function (App, source) {
var response = {};
response.data = source;
response.callback = function (self) {
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!searchbar.html!strip'
'app'
, 'text!searchbar.html!strip'
, 'css!searchbar'
],
function (source) {
function (App, source) {
var response = {};
response.data = source;
response.callback = function (self) {
var filter = self.dom.find(".searchbar_filter");
filter.on("filterbarbeforefilter", function (e, data) {
var value = data.input.value;
if ( value ) {
// now we can autocomplete...
......@@ -34,19 +31,21 @@ define([
}
});
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!seo.html!strip'
'app'
, 'text!seo.html!strip'
, 'css!seo'
],
function (source) {
function (App, source) {
var response = {};
response.data = source;
response.callback = function (self) {
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!shipment.html!strip'
'app'
, 'text!shipment.html!strip'
, 'css!shipment'
],
function (source) {
function (App, source) {
var response = {};
response.data = source;
response.callback = function (self) {
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!sorting.html!strip'
'app'
, 'text!sorting.html!strip'
, 'css!sorting'
],
function (source) {
function (App, source) {
var response = {};
response.data = source;
response.callback = function (self) {
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!summary.html!strip'
'app'
, 'text!summary.html!strip'
, 'css!summary'
],
function (source) {
function (App, source) {
var response = {};
response.data = source;
response.callback = function (self) {
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!teaser.html!strip'
'app'
, 'text!teaser.html!strip'
, 'css!teaser'
],
function (source) {
function (App, source) {
var response = {};
response.data = source;
response.callback = function (self) {
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!terms.html!strip'
'app'
, 'text!terms.html!strip'
, 'css!terms'
],
function (source) {
function (App, source) {
var response = {};
response.data = source;
response.callback = function (self) {
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(gadget) {
// prefix instance-ids, pass JSON
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
});
window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self);
} else {
// prefix instance-ids, pass JSON
window.App.renderGadgets(self);
App.renderGadgets(self);
}
};
......
define([
'text!translate.html!strip'
'app'
, 'text!translate.html!strip'
, 'css!translate'
],
function (source) {
function (App, source) {
var response = {};
response.data = source;
......@@ -59,7 +60,7 @@ define([
//
priv.translate = function (language, target) {
var collection = target || $('body');
collection.find("." + window.App.settings.language_selector).i18n();
collection.find("." + App.settings.language_selector).i18n();
};
//
......@@ -68,7 +69,7 @@ define([
// @param {string} language > default language to set
//
priv.setTranslations = function (language) {
if (window.App.settings.language_set === "false") {
if (App.settings.language_set === "false") {
$.i18n.init({
"lng": language,
"load": 'current',
......@@ -79,7 +80,7 @@ define([
}, function () {
priv.translate(language);
});
window.App.settings.language_set = "true";
App.settings.language_set = "true";
} else {
priv.translate(language);
}
......@@ -118,9 +119,9 @@ define([
$(".popup_all").popup( 'close' );
if (window.App.settings.language_current !== language) {
if (App.settings.language_current !== language) {
// update language
window.App.settings.language_current = language;
App.settings.language_current = language;
// update icon
priv.setIcon(language);
......@@ -138,18 +139,19 @@ define([
// PUBLISH METHODS
// ====================================================================
// TODO: remove once callable via link
window.App.translate = priv.translate;
// TODO: can I add methods to a module, when accessing the module from another module???
App.translate = priv.translate;
// prefix instance-ids, pass JSON, trigger("create")
window.App.renderGadgets(gadget);
App.renderGadgets(gadget);
// ====================================================================
// INITIALIZE
// ====================================================================
priv.initialize(window.App.settings.language_current);
priv.initialize(App.settings.language_current);
};
if (window.App === undefined) {
if (App === undefined) {
def = new $.Deferred;
def.done(function(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