Commit e4cd2b62 authored by Sven Franck's avatar Sven Franck

listbox can read localStorage data

parent 86e4c35b
......@@ -1941,6 +1941,9 @@
field_config = {};
if (field.show) {
console.log(fields)
console.log(settings[property])
field_config = fields[settings[property]];
if (field.merge === undefined) {
......@@ -2020,14 +2023,13 @@
{
"type":"input",
"direct": {
"id": item._id,
"name":item._id,
"id": item.id,
"name": item.id,
"className": "action",
"type":"checkbox"
},
"attributes": {
"type": "checkbox",
"value": "Select " + item.title,
"value": "Select " + item.title || item.id,
"data-iconpos":"notext",
"data-reference":"select_item"
},
......@@ -2146,35 +2148,31 @@
max,
table_body = factory.generateElement("tbody",{},{},{});
if (answer && answer.length > 0) {
max = settings.max_records || answer.length;
if (answer && answer.data.total_rows > 0) {
max = settings.max_records || answer.data.total_rows;
for (l = 0; l < max; l += 1) {
item = answer[l];
item = answer.data.rows[l].doc;
row = factory.generateTableRow(settings, item);
table_body.appendChild(row);
}
} else {
// error or 0 results
row = factory.generateElement("tr");
l = 0;
l = settings.layout.columns.length;;
if (answer === undefined) {
error = "Error retrieving Data";
} else if (answer.length === 0 ) {
} else if (answer.data.total_rows === 0 ) {
error = "No records found. Please modify your search!";
} else {
error = "Internal error generating gadget";
}
if (settings.configuration.checkbox.show) {
l += 1;
}
for (property in settings.view) {
if (settings.view.hasOwnProperty(property)) {
field = settings.view[property];
if (field.show) {
if (settings.configuration.table.checkbox_rows) {
l += 1;
}
}
}
row.appendChild(factory.generateElement("th",
{"style":"text-align: center; line-height: 2em;"},
{"colspan":l},
......@@ -2448,7 +2446,7 @@
{
"className":"ui-footer " +
(config.widget_class || " ") +
(config.fixed ? "ui-footer-fixed " : " ") + "slidedown ui-bar-" +
(config.fixed ? "ui-footer-fixed " : " ") + "slideup ui-bar-" +
(config.theme || "inherit"),
},
{
......@@ -2752,6 +2750,7 @@
// label position and class
input_type = config.attributes.type;
if (input_type) {
switch (input_type) {
case "radio":
......@@ -3281,40 +3280,30 @@
*/
init.setPageBindings = function (e) {
// need jQuery...
//$(document)
// enhance (too late???, content is already visible?
//.enhanceWithin();
// $(element.parentNode).empty().append( priv[method](element, data) ).enhanceWithin();
/*
$(document)
// form validation initializer
$("form")
.filter(function () { return this.getAttribute("data-bound") !== true; })
.each(function (i, element) {
element.setAttribute("data-bound", true);
// TODO: how to add custom validations here?
$(element).validVal({
validate: {
onKeyup: "valid",
onBlur: "valid"
},
form: {
onInvalid: function() { return;}
}
});
});
});
*/
.find("form")
// .filter(function () {
// return this.getAttribute("data-bound") !== true;
// })
// .each(function (i, element) {
// element.setAttribute("data-bound", true);
// // TODO: how to add custom validations here?
// // TODO: async?
// $(element).validVal({
// validate: {
// onKeyup: "valid",
// onBlur: "valid"
// },
// form: {
// onInvalid: function() { return;}
// }
// });
// })
// .end()
/* TABLE SORTING CHECKBOX BINDINGS: */
// //TODO: can't set bindings, because we don't have a parent?
// // or always set on document for local and global should be autoset?
......@@ -3452,53 +3441,9 @@
// });
//
// // global form submit and client validation
// // TODO: change as pleased
// .on("click", ".action_submit", function (e) {
// var valid,
// form = document.getElementById(e.target.getAttribute("data-form")),
// target = e.target.href,
// id = form.id,
// pointer = "response:" + id,
// proceed = function (data, target) {
// // changePage with fragment_cache pointer
// $.mobile.changePage(target, {"transition": "slide", "data": data});
// };
//
// // stop
// e.preventDefault();
//
// // validate
// // TODO testForClass not working
// if ($(form).hasClass("validate")) {
// valid = $( form ).triggerHandler( "submitForm" );
// } else {
// valid = $( form ).serialize();
// }
//
// // fetch and proceed
// if (valid !== false) {
// $.ajax({
// "type":"POST",
// "url": "foo.php",
// "data": valid
// }).done(function(data) {
// // overwrite cache
// // NOTE: FAKE data until working
// priv.fragment_cache[id] = priv.getFakeRecords["payment"];
// proceed(pointer, target);
// }).fail(function(jqXHR) {
// // fake it
// priv.fragment_cache[id] = priv.getFakeRecords["payment"];
// proceed(pointer, target);
// });
// }
// });
// }
// });
};
/* ====================================================================== */
/* METHODS */
......@@ -3536,7 +3481,7 @@
active,
method,
fetch,
query,
options,
query_string,
query_limit,
path,
......@@ -3607,20 +3552,21 @@
portal_type = gadget_config.portal_type_source;
// build query object for later
query_string = '(portal_type:"% ' + portal_type + '")';
query_string = '(portal_type:"%' + portal_type + '")';
query_limit = gadget_config.max_records;
if (item) {
query_string += 'AND (id:"% ' + item + '")';
query_string += 'AND (id:"%' + item + '")';
query_limit = 1;
}
query = {
options = {
query: query_string,
limit: [0, query_limit],
sort_on: [],
select_list:[],
wildcard_character: '%'
wildcard_character: '%',
include_docs: true
};
})
.then(function() {
......@@ -3632,12 +3578,11 @@
// ==================================================
// TODO: remove this and all FakeData methods once ERP5 access is ok
// ==================================================
.then(init.testForFakeDump("items", portal_type))
.then(function () {
return init.testForFakeDump("items", portal_type);
})
.then(function(item_check) {
// while JIO returns undefined
if (item_check === undefined) {
fetch = true;
} else if (item_check.data.total_rows === 0) {
if (item_check.data.total_rows === 0) {
fetch = true;
}
})
......@@ -3646,11 +3591,17 @@
})
.then(function(fake_items) {
if (fetch) {
return init.dumpFakeData(fake_items, gadget_id, "items");
return init.dumpFakeData(
fake_items,
gadget_config.portal_type_source,
"items"
);
}
})
// ===============================================
.then(init.fetchData("items", query))
.then(function () {
return init.fetchData("items", options)
})
.then(function (items) {
fragment = factory.gadget_handlers[method](
gadget_config,
......@@ -3738,16 +3689,12 @@
* file. Successfull fallback file fetches will be stored in JIO.
* @method fetchData
* @param {string} storage jIO instance to use
* @param {string} portal_type Portal type to fetch
* @param {object} query
* @returns {object} promise object
*/
// NOTE: until we have real data we load fake data on application init!
init.fetchData = function (storage, portal_type, query) {
var store = init.storages[storage];
console.log("calling allDocs, query");
console.log(query);
return store.allDocs(query)
init.fetchData = function (storage, options) {
return init.storages[storage].allDocs(options)
.then(
function (response) {
return response;
......@@ -3771,7 +3718,8 @@
limit: [0, 1],
sort_on: [],
select_list: ['portal_type'],
wildcard_character: '%'
wildcard_character: '%',
include_docs: true
});
};
......@@ -3913,15 +3861,14 @@
/**
* Set all application bindings
* @method setGlobalBindings
* @param {object} e Custom event object
*/
init.setGlobalBindings = function (e) {
init.setGlobalBindings = function () {
// need jQuery again...
$(document)
.enhanceWithin()
// set pointers for popup content
// global popup
.on("click", ".toggle_global_popup", function (e) {
var link = e.target,
reference = link.getAttribute("data-reference"),
......@@ -3939,6 +3886,72 @@
}
})
// global actions
.on("click", ".action", function (e) {
var test, target, href, element, reference, form, valid;
switch (e.target.getAttribute("data-reference")) {
// form submit
case "submit":
form = document.getElementById(e.target.getAttribute("data-form"));
target = e.target.href;
e.preventDefault();
if (util.testForClass(form.className), "validate") {
valid = $(form).triggerHandler( "submitForm" );
} else {
valid = $(form).serialize();
}
// // TODO: how to update status?
// if (valid !== false) {
// jIO.util.ajax({
// "url": "data/" + attachment + ".json", "dataType":"json"
// })
// }
//
// target = e.target.href,
// id = form.id,
// pointer = "response:" + id,
// proceed = function (data, target) {
// // changePage with fragment_cache pointer
// $.mobile.changePage(target, {"transition": "slide", "data": data});
// };
//
// // stop
//
//
//
//
// // fetch and proceed
// if (valid !== false) {
// $.ajax({
// "type":"POST",
// "url": "foo.php",
// "data": valid
// }).done(function(data) {
// // overwrite cache
// // NOTE: FAKE data until working
// priv.fragment_cache[id] = priv.getFakeRecords["payment"];
// proceed(pointer, target);
// }).fail(function(jqXHR) {
// // fake it
// priv.fragment_cache[id] = priv.getFakeRecords["payment"];
// proceed(pointer, target);
// });
// }
// });
// }
// });
//
//
break;
};
})
// generate, cache and show popup contents based on pointer
.find("#global_popup, .local_popup")
.on("popupbeforeposition", function(e, ui) {
......
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