Commit 56e3950e authored by Sven Franck's avatar Sven Franck

moved search and info fields form JSON API to automatic generation

parent bda756e0
......@@ -46,8 +46,11 @@
{"text":64, "text_i18n":"portal_type_dict.computer_dict.text_dict.64"}
]
},
"search": {"text": "Search available servers", "text_i18n": "portal_type_dict.computer_dict.text_dict.search", "id": "search_server_list", "records": true, "filter": true, "sorted": true}
"search": {
"text": "Search available servers",
"text_i18n": "portal_type_dict.computer_dict.text_dict.search",
"info_list": ["records", "filter", "sorted", "selected"]
}
},
"scheme": {
"header": [
......
......@@ -8,7 +8,7 @@
"id": "computer_overview",
"property_dict": {
"initial_query_url_identifier": "_id",
"dynamic_children": [2],
"dynamic_children": [1],
"requires_authentication": true,
"depends_on": "login_state",
"wrap_gadget": 2,
......@@ -29,6 +29,11 @@
{"value": "32", "text": "32", "text_i18n":"portal_type_dict.computer_dict.text_dict.32"},
{"value": "64", "text": "64", "text_i18n":"portal_type_dict.computer_dict.text_dict.64"}
]
},
"search": {
"text": "Search available servers",
"text_i18n": "portal_type_dict.computer_dict.text_dict.search",
"info_list": ["records", "filter", "sorted"]
}
},
"scheme": [
......@@ -51,18 +56,7 @@
]
}
],
"children": [
{
"generate": "widget",
"type": "controlbar",
"class_list": "responsive",
"children": [
{"type": "input", "direct": {"id":"search_server_list", "className": "translate"}, "attributes": {"data-action":"search", "data-enhanced":"true", "data-i18n": "[placeholder]portal_type_dict.computer_dict.text_dict.search","placeholder":"Search available servers", "data-icon":"search", "data-action-btn":"true", "data-type":"search", "type":"search"}, "logic":{"clear":"true", "action":"search"}},
{"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"records"}},
{"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"filter"}},
{"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"sorted"}}
]
}, {
"children": [{
"type": "a",
"direct": {"className":"translate ui-btn ui-icon-edit ui-btn-icon-left ui-corner-all ui-btn-inline ui-btn-slapos-black ui-link", "href": "#servers::new"},
"attributes": {
......@@ -75,8 +69,6 @@
"type": "table",
"class_list": "table-stroke ui-responsive",
"property_dict": {
"filter": "true",
"input": "#search_server_list",
"mode": "columntoggle",
"toggle_popup": false,
"wrap": "both",
......
......@@ -11,7 +11,7 @@
"message":"No invoices found",
"message_i18n":"portal_type_dict.invoice_dict.text_dict.nodata"
},
"dynamic_children": [1],
"dynamic_children": [0],
"requires_authentication": true,
"wrap_gadget": 2,
"sortable": true,
......@@ -30,6 +30,11 @@
{"value": "32", "text": "32", "text_i18n":"portal_type_dict.invoice_dict.text_dict.32"},
{"value": "64", "text": "64", "text_i18n":"portal_type_dict.invoice_dict.text_dict.64"}
]
},
"search": {
"text": "Search invoices",
"text_i18n": "portal_type_dict.invoice_dict.text_dict.search",
"info_list": ["records", "filter", "sorted"]
}
},
"scheme": [
......@@ -55,22 +60,10 @@
}
],
"children": [{
"generate": "widget",
"type": "controlbar",
"class_list": "responsive",
"children": [
{"type": "input", "direct": {"id":"search_invoice_list", "className": "translate"}, "attributes": {"data-action":"search", "data-enhanced":"true", "data-i18n": "[placeholder]portal_type_dict.invoice_dict.text_dict.search","placeholder":"Search invoices", "data-icon":"search", "data-action-btn":"true", "data-type":"search", "type":"search"}, "logic":{"clear":"true", "action":"search"}},
{"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"records"}},
{"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"filter"}},
{"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"sorted"}}
]
}, {
"generate": "widget",
"type": "table",
"class_list": "table-stroke ui-responsive",
"property_dict": {
"filter": "true",
"input": "#search_invoice_list",
"mode": "columntoggle",
"toggle_popup": false,
"wrap": "both",
......
......@@ -12,7 +12,7 @@
"message_i18n":"portal_type_dict.network_dict.text_dict.nodata"
},
"initial_query_url_identifier": "group",
"dynamic_children": [1],
"dynamic_children": [0],
"requires_authentication": true,
"depends_on": "login_state",
"wrap_gadget": 2,
......
......@@ -7,7 +7,7 @@
"view": "FOO",
"id": "network_overview",
"property_dict": {
"dynamic_children": [2],
"dynamic_children": [1],
"requires_authentication": true,
"depends_on": "login_state",
"wrap_gadget": 2,
......@@ -30,6 +30,11 @@
"no_items": {
"message": "No networks found.",
"message_i18n": "portal_type_dict.network_dict.text_dict.nonet"
},
"search": {
"text": "Search available networks",
"text_i18n": "portal_type_dict.network_dict.text_dict.search",
"info_list": ["records", "filter", "sorted"]
}
},
"scheme": [
......@@ -55,23 +60,11 @@
"data-icon": "edit"
},
"logic": {"text":"Add network"}
}, {
"generate": "widget",
"type": "controlbar",
"class_list": "responsive",
"children": [
{"type": "input", "direct": {"id":"search_network_list", "className": "translate"}, "attributes": {"data-action":"search", "data-enhanced":"true", "data-i18n": "[placeholder]portal_type_dict.network_dict.text_dict.search","placeholder":"Search available networks", "data-icon":"search", "data-action-btn":"true", "data-type":"search", "type":"search"}, "logic":{"clear":"true", "action":"search"}},
{"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"records"}},
{"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"filter"}},
{"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"sorted"}}
]
}, {
"generate": "widget",
"type": "table",
"class_list": "table-stroke ui-responsive",
"property_dict": {
"filter": "true",
"input": "#search_network_list",
"mode": "columntoggle",
"toggle_popup": false,
"wrap": "both",
......
......@@ -8,7 +8,7 @@
"id": "release_overview",
"property_dict": {
"initial_query_url_identifier": "reference_id",
"dynamic_children": [1],
"dynamic_children": [0],
"wrap_gadget": 2,
"link": true,
"link_identifier": "_id",
......@@ -25,6 +25,11 @@
{"value": "32", "text": "32", "text_i18n":"portal_type_dict.release_dict.text_dict.32"},
{"value": "64", "text": "64", "text_i18n":"portal_type_dict.release_dict.text_dict.64"}
]
},
"search": {
"text": "Search available networks",
"text_i18n": "portal_type_dict.release_dict.text_dict.search",
"info_list": ["records", "filter", "sorted"]
}
},
"scheme": [
......@@ -46,22 +51,10 @@
}
],
"children": [{
"generate": "widget",
"type": "controlbar",
"class_list": "responsive",
"children": [
{"type": "input", "direct": {"id":"search_release_list", "className": "translate"}, "attributes": {"data-action":"search", "data-enhanced":"true", "data-i18n": "[placeholder]portal_type_dict.release_dict.text_dict.search","placeholder":"Search available networks", "data-icon":"search", "data-action-btn":"true", "data-type":"search", "type":"search"}, "logic":{"clear":"true", "action":"search"}},
{"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"records"}},
{"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"filter"}},
{"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"sorted"}}
]
}, {
"generate": "widget",
"type": "table",
"class_list": "table-stroke ui-responsive",
"property_dict": {
"filter": "true",
"input": "#search_release_list",
"mode": "columntoggle",
"toggle_popup": false,
"wrap": "both",
......
......@@ -8,7 +8,7 @@
"id": "service_overview",
"property_dict": {
"initial_query_url_identifier": "reference_computer",
"dynamic_children": [2],
"dynamic_children": [1],
"wrap_gadget": 2,
"link": true,
"link_identifier": "_id",
......@@ -25,6 +25,11 @@
{"value": "32", "text": "32", "text_i18n":"portal_type_dict.service_dict.text_dict.32"},
{"value": "64", "text": "64", "text_i18n":"portal_type_dict.service_dict.text_dict.64"}
]
},
"search": {
"text": "Search available services",
"text_i18n": "portal_type_dict.service_dict.text_dict.search",
"info_list": ["records", "filter", "sorted"]
}
},
"scheme": [
......@@ -55,23 +60,11 @@
"data-icon": "edit"
},
"logic": {"text":"Install new service"}
}, {
"generate": "widget",
"type": "controlbar",
"class_list": "responsive",
"children": [
{"type": "input", "direct": {"id":"search_services_list", "className": "translate"}, "attributes": {"data-action":"search", "data-enhanced":"true", "data-i18n": "[placeholder]portal_type_dict.service_dict.text_dict.search","placeholder":"Search available services", "data-icon":"search", "data-action-btn":"true", "data-type":"search", "type":"search"}, "logic":{"clear":"true", "action":"search"}},
{"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"records"}},
{"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"filter"}},
{"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"sorted"}}
]
}, {
"generate": "widget",
"type": "table",
"class_list": "table-stroke ui-responsive",
"property_dict": {
"filter": "true",
"input": "#search_services_list",
"mode": "columntoggle",
"toggle_popup": false,
"wrap": "both",
......
......@@ -10,7 +10,7 @@
"link": true,
"link_identifier": "id",
"link_to_view": "install",
"dynamic_children": [1],
"dynamic_children": [0],
"pagination": {
"class_list": "responsive",
"option_list": [
......@@ -19,6 +19,11 @@
{"value": "32", "text": "32", "text_i18n":"portal_type_dict.software_dict.text_dict.32"},
{"value": "64", "text": "64", "text_i18n":"portal_type_dict.software_dict.text_dict.64"}
]
},
"search": {
"text": "Search available software",
"text_i18n": "portal_type_dict.software_dict.text_dict.search",
"info_list": ["records", "filter", "sorted", "selected"]
}
},
"scheme": [
......@@ -38,25 +43,12 @@
}
],
"children": [{
"generate": "widget",
"type": "controlbar",
"class_list": "responsive",
"children": [
{"type": "input", "direct": {"id":"search_software_list", "className": "translate"}, "attributes": {"data-action":"search", "data-enhanced":"true", "data-i18n": "[placeholder]portal_type_dict.software_dict.text_dict.search","placeholder":"Search available software", "data-icon":"search", "data-action-btn":"true", "data-type":"search", "type":"search"}, "logic":{"clear":"true", "action":"search"}},
{"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"records"}},
{"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"selected"}},
{"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"filter"}},
{"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"sorted"}}
]
}, {
"generate":"widget",
"type": "listview",
"class_list": "",
"theme": "slapos-white",
"property_dict": {
"inset":"true",
"filter": "true",
"input": "#search_software_list"
"inset":"true"
},
"children": []
}]
......
......@@ -9,7 +9,7 @@
"property_dict": {
"link": true,
"link_identifier": "id",
"dynamic_children": [1],
"dynamic_children": [0],
"pagination": {
"class_list": "responsive",
"option_list": [
......@@ -18,6 +18,11 @@
{"value": "32", "text": "32", "text_i18n":"portal_type_dict.software_dict.text_dict.32"},
{"value": "64", "text": "64", "text_i18n":"portal_type_dict.software_dict.text_dict.64"}
]
},
"search": {
"text": "Search available software",
"text_i18n": "portal_type_dict.software_dict.text_dict.search",
"info_list": ["records"]
}
},
"scheme": [
......@@ -38,22 +43,12 @@
}
],
"children": [{
"generate": "widget",
"type": "controlbar",
"class_list": "responsive",
"children": [
{"type": "input", "direct": {"id":"search_software_list", "className": "translate"}, "attributes": {"data-action":"search", "data-enhanced":"true", "data-i18n": "[placeholder]portal_type_dict.software_dict.text_dict.search","placeholder":"Search available software", "data-icon":"search", "data-action-btn":"true", "data-type":"search", "type":"search"}, "logic":{"clear":"true", "action":"search"}},
{"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"records"}}
]
}, {
"generate":"widget",
"type": "listview",
"class_list": "",
"theme": "slapos-white",
"property_dict": {
"inset":"true",
"filter": "true",
"input": "#search_software_list"
"inset":"true"
},
"children": []
}]
......
......@@ -1248,7 +1248,7 @@
* @return {object} fragment
**/
"listgrid": function (spec, answer, field_dict, update, url_pointer) {
var element, i, target, no_content, props;
var element, i, target, no_content, props, search, n, search_id;
props = spec.property_dict;
......@@ -1286,7 +1286,20 @@
// add pagination
if (props.pagination) {
spec.children.push(factory.util.paginate(props.pagination));
spec.children.push(factory.util.paginationBar(props.pagination));
}
// add search bar
if (props.search) {
search = factory.util.searchBar(props.search);
search_id = search.id;
spec.children.unshift(search.config);
// update dynamic children
// TODO: remove dynamic children! make sure all gadgets can handle data
for (n = 0; n < props.dynamic_children.length; n += 1) {
props.dynamic_children[n] = props.dynamic_children[n] + 1;
}
}
// loop children (elements to generate)
......@@ -1305,6 +1318,11 @@
// map data for listview and set as element.children
if (element.type === "listview") {
// add filter criteria
if (props.search && search_id) {
element.property_dict.filter = true;
element.property_dict.input = "#" + search_id;
}
element.children = map.utils.mapListItems(
answer.data.rows,
spec,
......@@ -1339,7 +1357,7 @@
"listbox": function (spec, answer, field_dict, update, url_pointer) {
var element, i, j, k, l, m, target, container, pack, slot, pop, active,
countColumns, column, no_content, no_result, content, segment, field,
props;
props, n, search, search_id;
// count columns
countColumns = function (scheme) {
......@@ -1429,9 +1447,22 @@
});
}
// add pagination
// add search bar
if (props.search) {
search = factory.util.searchBar(props.search);
search_id = search.id;
spec.children.unshift(search.config);
// update dynamic children
// TODO: remove dynamic children! make sure all gadgets can handle data
for (n = 0; n < props.dynamic_children.length; n += 1) {
props.dynamic_children[n] = props.dynamic_children[n] + 1;
}
}
// add pagination bar
if (props.pagination) {
spec.children.push(factory.util.paginate(props.pagination));
spec.children.push(factory.util.paginationBar(props.pagination));
}
// loop over dynamic data and generate table
......@@ -1452,6 +1483,11 @@
// generate table rows with dynamic data
if (element.type === "table") {
// set search configuration
if (props.search && search_id) {
element.property_dict.filter = true;
element.property_dict.input = "#" + search_id;
}
element.children = map.utils.mapTableRows(
answer.data.rows,
spec,
......@@ -1581,12 +1617,59 @@
/* ********************************************************************** */
factory.util = {};
/** Generate a pagination toolbar
/** Generate a seach bar (controlbar)
* @method searchBar
* @param {object} spec Pagination configuration
* @return {object} finished config object
**/
factory.util.searchBar = function (spec) {
var i, element_list, search_id, props, class_list;
search_id = "search_" + util.uuid();
class_list = spec.class_list || "";
props = spec.slot ? {"slot": spec.slot} : {};
element_list = [{
"type": "input",
"direct": {"id": search_id, "className": "translate"},
"attributes": {
"data-action": "search",
"data-enhanced": "true",
"data-i18n": "[placeholder]" + spec.text_i18n,
"placeholder": spec.text,
"data-icon": "search",
"data-action-btn": "true",
"data-type": "search",
"type": "search"
},
"logic":{"clear":"true", "action":"search"}
}];
for (i = 0; i < spec.info_list.length; i += 1) {
element_list.push({
"type": "div",
"direct": {"className":"info"},
"attributes": {"data-info": spec.info_list[i]}
});
}
return {
"config": {
"generate": "widget",
"type": "controlbar",
"class_list": class_list,
"property_dict": props,
"children": element_list
},
"id": search_id
};
};
/** Generate a pagination toolbar (controlbar)
* @method paginate
* @param {object} spec Pagination configuration
* @return {object} finished config object
**/
factory.util.paginate = function (spec) {
factory.util.paginationBar = function (spec) {
var n, option, props, option_list, class_list;
option_list = [{"value": "", "text": "", "text_i18n": ""}];
......
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