Commit e9480fd3 authored by Sven Franck's avatar Sven Franck

added simple search functionality

parent 137a1e46
......@@ -5,39 +5,15 @@
* wrapper...
* TODO: relocate once working
*/
.searchbar_wrap {
width: 74%;
margin: 0 auto;
margin: 1em auto;
}
.searchbar_wrap .ui-input-search input {
padding-left: 0.25em;
padding-right: 4.5em;
}
.searchbar_wrap .ui-input-search:after {
left: auto;
right: 0;
opacity: 1;
margin: -13px 0.3125em 0;
top: 50%;
border-radius: 1em 1em 1em 1em;
height: 18px;
padding: 0;
width: 18px;
webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
border-style: solid;
border-width: 4px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
border-color: white /*#D5D5D5*/;
-moz-user-select: none;
cursor: pointer;
border-style: solid;
border-width: 4px;
border-radius: 1em;
background-position: -611px -1px;
background-color: rgba(0, 0, 0, 0.4);
background-image: url("../../img/jquery-mobile/icons-18-white.png");
background-repeat: no-repeat;
}
.searchbar_wrap .ui-input-search .ui-input-clear {
right: 2em;
}
......
......@@ -5,7 +5,10 @@
<title>Searchbar Module</title>
</head>
<body>
<!-- filter widget -->
<div data-filter="true" class="searchbar_filter translate" data-selector="items_listview" data-filter-placeholder="fff"></div>
<div data-filter="true"
class="searchbar_filter"
data-selector="items_listview"
data-filter-placeholder="Search">
</div>
</body>
</html>
\ No newline at end of file
......@@ -8,8 +8,11 @@ define([
response.data = source;
response.callback = function (self) {
var filter = self.dom.find(".searchbar_filter"),
value;
filter.on("filterbarbeforefilter", function (e, data) {
value = data.input.value;
if ( value ) {
// now we can autocomplete...
......@@ -29,6 +32,21 @@ define([
// if we follow the DC scheme, we have some core metadata and the
// rest must be stored in an attachment.
}
})
.on( "filterbarcreate", function( e, ui ) {
var uuid = $(e.target).data("mobileFilterbar").uuid,
target = $("#ui-filter-"+uuid).find(".ui-input-action");
target.on("click", function(e) {
value = $("#ui-filter-"+uuid).find("input").val();
$.mobile.changePage( "search.html", {
"transition": "slide",
"data": {
"search": value
}
});
});
});
......
......@@ -58,6 +58,7 @@ define([
priv.populate_item_storage = function () {
priv.items.put({
"_id": "1",
"item_id": "1",
"brand": "VILA",
"brand_id": "123",
"seller_id": "",
......@@ -143,6 +144,7 @@ define([
priv.items.put({
"_id": "2",
"item_id": "2",
"brand": "Stella Forest",
"brand_id": "123",
"seller_id": "",
......@@ -227,6 +229,7 @@ define([
});
priv.items.put({
"_id": "3",
"item_id": "3",
"brand": "Eleven Paris",
"brand_id": "123",
"title": "Pull Octave ",
......@@ -308,6 +311,7 @@ define([
});
priv.items.put({
"_id": "4",
"item_id": "4",
"brand": "Eleven Paris",
"brand_id": "123",
"seller_id": "",
......@@ -516,6 +520,7 @@ define([
});
priv.items.put({
"_id": "5",
"item_id": "5",
"brand": "See U Soon",
"brand_id": "356",
"title": "Debardeur Eve",
......@@ -636,12 +641,18 @@ define([
// @param {method} callback > callback to run with results
// pointer, method, options, callback
that.switchboard = function (param) {
var query = {};
var spec = param || {};
var i,
j,
item,
cases = [],
query = {},
spec = param || {},
searchString = "";
// default object
spec.default_items = [
"_id",
"item_id",
"brand",
"total_sales",
"price",
......@@ -663,6 +674,27 @@ define([
spec.options.limit = param.options.limit;
spec.options.sort_on = param.options.sort_on;
spec.options.select_list = param.options.select_list || spec.default_items;
spec.options.wildcard_character = '%'
}
// queries can be run
// > with different cases (currently upper/lower case),
// > on full select_list (passed elements or default),
// > without a query object, if empty string is passed (nothing to parse, faster search)
if (spec.query) {
if (spec.query_string !== "") {
cases.push(spec.query_string.toUpperCase(), spec.query_string.toLowerCase());
for (j = 0; j < cases.length; j += 1) {
for (i = 0; i < spec.options.select_list.length; i += 1) {
item = spec.options.select_list[i];
searchString += item + ': = "' + query.wildcard_character + cases[j] + query.wildcard_character + '"';
if (i < spec.options.select_list.length-1) {
searchString += ' OR ';
}
}
}
spec.options.query = searchString;
}
}
switch (param.pointer) {
......
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