Commit 27a7020c authored by Sven Franck's avatar Sven Franck

refactor "no records found/no auth" handler, set in property_dict

parent f61fd7f4
...@@ -20,28 +20,20 @@ ...@@ -20,28 +20,20 @@
"text_i18n":"validation_dict.requires_auth", "text_i18n":"validation_dict.requires_auth",
"children": [ "children": [
{ {
"generate": "widget", "href": "#global-popup",
"type": "controlgroup", "class_list": "translate action",
"property_dict": {"direction": "horizontal"}, "action": "login",
"children": [{ "rel": "popup",
"type": "a", "text": "Login",
"direct":{"className":"translate action", "href":"#global-popup"}, "text_i18n": "global_dict.common_dict.login",
"attributes":{ "icon": "lock"
"data-i18n":"global_dict.common_dict.login",
"data-action":"login",
"data-icon":"lock",
"data-rel": "popup"
}, },
"logic": {"text":"Login"} {
}, { "href":"#person::new",
"type": "a", "class_list": "translate ui-btn-slapos-black",
"direct": {"className":"translate ui-btn-slapos-black", "href": "#person::new"}, "text":"Register",
"attributes": { "text_i18n": "global_dict.common_dict.register",
"data-i18n": "global_dict.common_dict.register", "icon": "edit"
"data-icon": "edit"
},
"logic": {"text":"Register"}
}]
} }
] ]
} }
......
...@@ -152,6 +152,12 @@ html table.ui-table thead th, html table.ui-table thead td { ...@@ -152,6 +152,12 @@ html table.ui-table thead th, html table.ui-table thead td {
padding: 0; padding: 0;
} }
/* no items */
.ui-table tr td.ui-no-result {
text-align: center;
font-weight: bold;
}
/* table caption (will be inside a controlbar but belongs here) */ /* table caption (will be inside a controlbar but belongs here) */
html .ui-table-caption { html .ui-table-caption {
padding: 0.25em 0; padding: 0.25em 0;
...@@ -230,13 +236,18 @@ html table.ui-table tr td .ui-controlgroup { ...@@ -230,13 +236,18 @@ html table.ui-table tr td .ui-controlgroup {
margin: 0; margin: 0;
text-align: center; text-align: center;
} }
html table.ui-table tr td.ui-no-result .ui-controlgroup {
margin: 1em 0;
}
html table.ui-table tr td .ui-controlgroup .ui-controlgroup-controls { html table.ui-table tr td .ui-controlgroup .ui-controlgroup-controls {
width: auto; width: auto;
} }
/* why? a button should be a button
html table.ui-table tr td a.ui-btn { html table.ui-table tr td a.ui-btn {
border: 0 none; border: 0 none;
background: transparent; background: transparent;
} }
*/
html table.ui-table tr td a.ui-btn:after { html table.ui-table tr td a.ui-btn:after {
margin-top: -10px; margin-top: -10px;
} }
...@@ -276,8 +287,10 @@ html table tbody th .ui-checkbox .ui-btn, ...@@ -276,8 +287,10 @@ html table tbody th .ui-checkbox .ui-btn,
html table tbody th .ui-checkbox .ui-btn:hover, html table tbody th .ui-checkbox .ui-btn:hover,
html table tbody th .ui-radio .ui-btn, html table tbody th .ui-radio .ui-btn,
html table tbody th .ui-radio .ui-btn:hover, html table tbody th .ui-radio .ui-btn:hover,
/* why? white is white and black is black...
html table tbody td .ui-controlgroup-controls .ui-btn, html table tbody td .ui-controlgroup-controls .ui-btn,
html table tbody td .ui-controlgroup-controls .ui-btn:hover { html table tbody td .ui-controlgroup-controls .ui-btn:hover */
{
background-color: transparent; background-color: transparent;
background-image: none; background-image: none;
} }
......
...@@ -731,8 +731,8 @@ html body div.ui-slider-track.ui-body-slapos-black .ui-btn-active, ...@@ -731,8 +731,8 @@ html body div.ui-slider-track.ui-body-slapos-black .ui-btn-active,
html .ui-page-theme-slapos-black .ui-table-wrapper .ui-btn:active, html .ui-page-theme-slapos-black .ui-table-wrapper .ui-btn:active,
html .ui-page-theme-slapos-black .ui-table-wrapper .ui.btn.ui-btn-active, html .ui-page-theme-slapos-black .ui-table-wrapper .ui.btn.ui-btn-active,
/* Table rows on hover */ /* Table rows on hover */
html table.ui-table tbody tr:hover td, html table.ui-table tbody tr:hover td:not(.ui-no-result),
html table.ui-table tbody tr:hover th, html table.ui-table tbody tr:hover th:not(.ui-no-result),
/* Controlbar */ /* Controlbar */
html .ui-page-theme-slapos-black .ui-controlbar .ui-btn:active, html .ui-page-theme-slapos-black .ui-controlbar .ui-btn:active,
html .ui-page-theme-slapos-black .ui-controlbar .ui-btn.ui-btn-active, html .ui-page-theme-slapos-black .ui-controlbar .ui-btn.ui-btn-active,
......
...@@ -77,37 +77,5 @@ ...@@ -77,37 +77,5 @@
} }
] ]
} }
], ]
"placeholder_dict": {
"no_items": {
"text":"No items found.",
"text_i18n":"validation_dict.no_items_found",
"children": [{
"generate": "widget",
"type": "controlgroup",
"property_dict": {"direction": "horizontal"},
"children": [
{
"type": "a",
"direct": {
"href":"#",
"className": "translate "
},
"attributes": {
"data-icon":"chevron-sign-left",
"data-i18n":"global_dict.pagination_dict.back"
},
"logic": {"Text": "Back"}
}, {
"type": "a",
"direct": {"className":"translate ui-btn-slapos-black", "href": "#person::new"},
"attributes": {
"data-i18n": "page_dict.person.create",
"data-icon": "edit"
},
"logic": {"text":"Create person"}
}]
}]
}
}
} }
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
"form": true, "form": true,
"id": "invoice_overview", "id": "invoice_overview",
"property_dict": { "property_dict": {
"no_items": {
"message":"No invoices found",
"message_i18n":"page_dict.invoices.nodata"
},
"dynamic_children": [3], "dynamic_children": [3],
"requires_authentication": true, "requires_authentication": true,
"wrap_gadget": 2, "wrap_gadget": 2,
......
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
"form": true, "form": true,
"id": "computer_overview", "id": "computer_overview",
"property_dict": { "property_dict": {
"no_items": {
"message":"No servers associated with this network.",
"message_i18n":"page_dict.networks.nodata"
},
"initial_query_url_identifier": "group", "initial_query_url_identifier": "group",
"dynamic_children": [0], "dynamic_children": [0],
"requires_authentication": true, "requires_authentication": true,
...@@ -45,13 +49,6 @@ ...@@ -45,13 +49,6 @@
"bottom_grid": 1 "bottom_grid": 1
}, },
"children": [] "children": []
}], }]
"placeholder_dict": {
"no_items": {
"text":"No servers associated with this network.",
"text_i18n":"page_dict.networks.no_servers",
"children": []
}
}
} }
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
"form": true, "form": true,
"id": "network_overview", "id": "network_overview",
"property_dict": { "property_dict": {
"no_items": {
"message": "No networks found.",
"message_i18n": "page_dict.networks.nonet"
},
"dynamic_children": [4], "dynamic_children": [4],
"requires_authentication": true, "requires_authentication": true,
"depends_on": "login_state", "depends_on": "login_state",
...@@ -83,38 +87,6 @@ ...@@ -83,38 +87,6 @@
"bottom_grid": 1 "bottom_grid": 1
}, },
"children": [] "children": []
}],
"placeholder_dict": {
"no_items": {
"text":"No items found.",
"text_i18n":"validation_dict.no_items_found",
"children": [{
"generate": "widget",
"type": "controlgroup",
"property_dict": {"direction": "horizontal"},
"children": [
{
"type": "a",
"direct": {
"href":"#",
"className": "translate "
},
"attributes": {
"data-icon":"chevron-sign-left",
"data-i18n":"global_dict.pagination_dict.back"
},
"logic": {"Text": "Back"}
}, {
"type": "a",
"direct": {"className":"translate ui-btn-slapos-black", "href": "#networks::new"},
"attributes": {
"data-i18n": "page_dict.network.add",
"data-icon": "edit"
},
"logic": {"text":"Add new network"}
}]
}] }]
}
}
} }
...@@ -6,6 +6,19 @@ ...@@ -6,6 +6,19 @@
"form": true, "form": true,
"id": "user_sample", "id": "user_sample",
"property_dict": { "property_dict": {
"no_items": {
"message": "No person found",
"message_i18n": "page_dict.person.nodata",
"children": [
{
"href": "#person::new",
"text": "Create person",
"text_i18n": "page_dict.person.create",
"class_list": "translate ui-btn-slapos-black",
"icon": "edit"
}
]
},
"dynamic_children": [0], "dynamic_children": [0],
"requires_authentication": true, "requires_authentication": true,
"depends_on": "login_state", "depends_on": "login_state",
...@@ -75,37 +88,5 @@ ...@@ -75,37 +88,5 @@
} }
] ]
} }
], ]
"placeholder_dict": {
"no_items": {
"text":"No items found.",
"text_i18n":"validation_dict.no_items_found",
"children": [{
"generate": "widget",
"type": "controlgroup",
"property_dict": {"direction": "horizontal"},
"children": [
{
"type": "a",
"direct": {
"href":"#",
"className": "translate "
},
"attributes": {
"data-icon":"chevron-sign-left",
"data-i18n":"global_dict.pagination_dict.back"
},
"logic": {"Text": "Back"}
}, {
"type": "a",
"direct": {"className":"translate ui-btn-slapos-black", "href": "#person::new"},
"attributes": {
"data-i18n": "page_dict.person.create",
"data-icon": "edit"
},
"logic": {"text":"Create person"}
}]
}]
}
}
} }
...@@ -6,6 +6,18 @@ ...@@ -6,6 +6,18 @@
"form": true, "form": true,
"id": "service_overview", "id": "service_overview",
"property_dict": { "property_dict": {
"no_items": {
"message":"No Software installed.",
"message_i18n":"page_dict.servers.no_software",
"children": [
{
"href": "#software::new",
"text": "Add Software",
"text_i18n": "page_dict.servers.add_software",
"class_list": "translate ui-btn-slapos-black"
}
]
},
"initial_query_url_identifier": "reference_computer", "initial_query_url_identifier": "reference_computer",
"dynamic_children": [0], "dynamic_children": [0],
"wrap_gadget": 2, "wrap_gadget": 2,
...@@ -53,27 +65,6 @@ ...@@ -53,27 +65,6 @@
{"type": "a", "direct": {"href": "#software::add", "className": "ui-btn-slapos-black"}, "attributes": {"data-i18n":"page_dict.servers.add_software"}, "logic": {"text":"Install Software"}} {"type": "a", "direct": {"href": "#software::add", "className": "ui-btn-slapos-black"}, "attributes": {"data-i18n":"page_dict.servers.add_software"}, "logic": {"text":"Install Software"}}
] ]
}] }]
}],
"placeholder_dict": {
"no_items": {
"text":"No Software installed.",
"text_i18n":"page_dict.servers.no_software",
"children": [
{
"generate": "widget",
"type": "controlgroup",
"property_dict": {"direction": "horizontal"},
"children": [{
"type": "a",
"direct": {"className":"translate ui-btn-slapos-black", "href": "#software::new"},
"attributes": {
"data-i18n": "page_dict.servers.add_software"
},
"logic": {"text":"Add Software"}
} }
] ]
}
]
}
}
} }
...@@ -1254,7 +1254,12 @@ ...@@ -1254,7 +1254,12 @@
* @return {object} fragment * @return {object} fragment
**/ **/
"listgrid": function (spec, answer, field_dict, update, url_pointer) { "listgrid": function (spec, answer, field_dict, update, url_pointer) {
var element, i, target; var element, i, target, no_content;
// generate placeholder
no_content = function (config) {
return app.noItemsFound(config, "li");
};
// set update of gadget flag // set update of gadget flag
if (spec.property_dict.depends_on) { if (spec.property_dict.depends_on) {
...@@ -1269,7 +1274,7 @@ ...@@ -1269,7 +1274,7 @@
// no auth // no auth
if (answer === null) { if (answer === null) {
target = factory.util.wrapInForm(spec); target = factory.util.wrapInForm(spec);
target.appendChild(app.noItemsFound(app.default_dict.state_dict.no_auth)); target.appendChild(no_content(app.default_dict.state_dict.no_auth));
return target; return target;
} }
...@@ -1314,8 +1319,7 @@ ...@@ -1314,8 +1319,7 @@
} }
} }
} else { } else {
// no items found target.appendChild(no_content(spec.property_dict.no_items));
target.appendChild(app.noItemsFound());
} }
return target; return target;
}, },
...@@ -1330,8 +1334,26 @@ ...@@ -1330,8 +1334,26 @@
* @param {object} url_pointer indicates layout used * @param {object} url_pointer indicates layout used
* @return {object} fragment * @return {object} fragment
**/ **/
// TODO: refactor!
"listbox": function (spec, answer, field_dict, update, url_pointer) { "listbox": function (spec, answer, field_dict, update, url_pointer) {
var element, i, target, container, pack, slot, pop, active; var element, i, j, k, target, container, pack, slot, pop, active,
countColumns, column, no_content, no_result, content;
// count columns
countColumns = function (body) {
k = 0;
for (column in body) {
if (body.hasOwnProperty(column) && column.merge === undefined) {
k += 1;
}
}
return k;
};
// generate placeholder
no_content = function (config) {
return app.noItemsFound(config, "td", countColumns(spec.property_dict.layout.body))
};
// set update of gadget flag // set update of gadget flag
if (spec.property_dict.depends_on) { if (spec.property_dict.depends_on) {
...@@ -1346,11 +1368,13 @@ ...@@ -1346,11 +1368,13 @@
// no auth // no auth
if (answer === null) { if (answer === null) {
target = factory.util.wrapInForm(spec); target = factory.util.wrapInForm(spec);
target.appendChild(app.noItemsFound(app.default_dict.state_dict.no_auth)); target.appendChild(no_content(app.default_dict.state_dict.no_auth));
return target; return target;
} }
// determine target element, that will be returned // no results
no_result = answer.data.total_rows === 0;
if (update) { if (update) {
target = document.createDocumentFragment(); target = document.createDocumentFragment();
} else { } else {
...@@ -1381,7 +1405,6 @@ ...@@ -1381,7 +1405,6 @@
} }
// loop over dynamic data and generate table // loop over dynamic data and generate table
if (answer.data.total_rows > 0) {
for (i = 0; i < spec.children.length; i += 1) { for (i = 0; i < spec.children.length; i += 1) {
element = spec.children[i]; element = spec.children[i];
...@@ -1411,11 +1434,16 @@ ...@@ -1411,11 +1434,16 @@
// add elements when not updating, if updating only add dynamic // add elements when not updating, if updating only add dynamic
if (update !== true || element.dynamic) { if (update !== true || element.dynamic) {
target.appendChild(app.setContent(element, {}, update)); content = app.setContent(element, {}, update);
if (no_result) {
if (update) {
content.appendChild(no_content(spec.property_dict.no_items));
} else {
content.querySelector("tbody").appendChild(no_content(spec.property_dict.no_items));
} }
} }
} else { target.appendChild(content);
target.appendChild(app.noItemsFound()); }
} }
// assemble and/or return // assemble and/or return
...@@ -1437,7 +1465,12 @@ ...@@ -1437,7 +1465,12 @@
* @return {object} fragment * @return {object} fragment
**/ **/
"fieldlist": function (spec, answer, field_dict) { "fieldlist": function (spec, answer, field_dict) {
var i, element, target, update_gadget, reset_state, data; var i, element, target, update_gadget, reset_state, data, no_content;
// generate placeholder
no_content = function (config) {
return app.noItemsFound(config);
};
// set update of gadget flag // set update of gadget flag
if (spec.property_dict.depends_on) { if (spec.property_dict.depends_on) {
...@@ -1454,7 +1487,7 @@ ...@@ -1454,7 +1487,7 @@
spec.reset = reset_state; spec.reset = reset_state;
spec.depend = update_gadget; spec.depend = update_gadget;
target = factory.util.wrapInForm(spec); target = factory.util.wrapInForm(spec);
target.appendChild(app.noItemsFound(app.default_dict.state_dict.no_auth)); target.appendChild(no_content(app.default_dict.state_dict.no_auth));
return target; return target;
// auth or allow // auth or allow
...@@ -1462,10 +1495,8 @@ ...@@ -1462,10 +1495,8 @@
target = document.createDocumentFragment(); target = document.createDocumentFragment();
if ( if ((answer.data === undefined && answer.request_new === undefined)) {
//(answer.data && answer.data.total_rows === 0) || target.appendChild(no_content(spec.property_dict.no_items));
(answer.data === undefined && answer.request_new === undefined)) {
target.appendChild(app.noItemsFound());
} else { } else {
// set data // set data
if (answer && (answer.data || answer.request_new)) { if (answer && (answer.data || answer.request_new)) {
...@@ -4614,54 +4645,79 @@ ...@@ -4614,54 +4645,79 @@
* return a placeholder with button in case no items were found * return a placeholder with button in case no items were found
* @method noItemsFound * @method noItemsFound
* @param {object} content_dict Type of placeholder to create * @param {object} content_dict Type of placeholder to create
* @param {objecŧ} element * @param {string} type of element to generate
* @param {integer} count number of columns (if applicable)
* @return {object} HTML fragment * @return {object} HTML fragment
*/ */
app.noItemsFound = function (content_dict) { app.noItemsFound = function (content_dict, type, count) {
var i, reply, content, message, message_i18n; var i, fragment, data, action_menu, message, message_i18n, button, back,
wrap, class_string;
// provided in gadget config data = content_dict || {};
if (content_dict) { switch (type) {
message = content_dict.text; case "td": class_string = "ui-no-result"; break;
message_i18n = content_dict.text_i18n; case "li": class_string = "ui-li ui-li-static ui-first-child ui-last-child " +
content = content_dict.children; "ui-no-result ui-body-inherit";
break;
default: class_string = "responsive ui-content-element"; break;
};
// fallback // container
} else { fragment = factory.element(
message = "No items found."; type || "p",
message_i18n = "validation_dict.no_items_found"; {"className": class_string},
content = [{ {"colspan": count || null}
);
// info
fragment.appendChild(factory.element(
"span",
{"className": "translate"},
{"data-i18n": data.message_i18n || "validation_dict.no_items_found"},
{"text": data.message || "No items found."}
));
// action menu
if (data.children && data.children.length > 0) {
action_menu = {
"generate": "widget",
"type": "controlgroup",
"property_dict": {"direction": "horizontal"},
"children": []
};
for (i = 0; i < data.children.length; i += 1) {
button = data.children[i];
back = button.back;
action_menu.children.push({
"type": "a", "type": "a",
"direct": { "direct": {
"href": "#", "href": back ? "#" : button.href,
"className": "ui-corner-all ui-btn ui-shadow ui-btn-inline " + "className": "ui-corner-all ui-btn ui-shadow ui-btn-inline " +
"ui-icon-chevron-sign-left ui-btn-icon-left translate " (back ? "ui-icon-chevron-sign-left ui-btn-icon-left " :
(button.icon ? "ui-icon-" + button.icon +
" ui-btn-icon-left " : " ")) + (button.class_list || "")
}, },
"attributes": { "attributes": {
"data-rel": "back", "data-action": button.action || null,
"data-i18n": "global_dict.pagination_dict.back" "data-rel": back ? "back" : (button.rel || null),
"data-i18n": back ?
"global_dict.pagination_dict.back" : button.text_i18n
}, },
"logic": {"Text": "Back"} "logic": {"text": back ? "Back" : button.text}
}]; });
}
fragment.appendChild(app.setContent(action_menu));
} }
// <p> is not flexible... // table cells need a wrapping row
reply = factory.element( if (type === "td") {
"p", wrap = factory.element("tr");
{"className": "responsive ui-content-element"} wrap.appendChild(fragment);
); return wrap;
reply.appendChild(factory.element(
"span",
{"className": "translate"},
{"data-i18n": message_i18n},
{"text": message}
));
for (i = 0; i < content.length; i += 1) {
reply.appendChild(app.setContent(content[i]));
} }
return reply; return fragment;
}; };
/** /**
......
...@@ -85,7 +85,8 @@ ...@@ -85,7 +85,8 @@
"title": "Account Info", "title": "Account Info",
"create": "Create Person", "create": "Create Person",
"register": "Register", "register": "Register",
"subtitle": "Registration/Invoicing Info" "subtitle": "Registration/Invoicing Info",
"nodata": "No Person found"
}, },
"invoices": { "invoices": {
"title": "Invoices", "title": "Invoices",
...@@ -93,7 +94,8 @@ ...@@ -93,7 +94,8 @@
"download": "Download", "download": "Download",
"add": "Create new invoice", "add": "Create new invoice",
"overview": "Invoice Overview", "overview": "Invoice Overview",
"search": "Search Invoices" "search": "Search Invoices",
"nodata": "No invoices found"
}, },
"servers": { "servers": {
"no_software": "No software installed.", "no_software": "No software installed.",
...@@ -132,7 +134,8 @@ ...@@ -132,7 +134,8 @@
"search": "Search available services" "search": "Search available services"
}, },
"networks": { "networks": {
"no_servers": "No servers associated with this network.", "nonet": "No networks found.",
"nodata": "No servers associated with this network.",
"title": "Networks", "title": "Networks",
"subtitle": "Network Administration", "subtitle": "Network Administration",
"networks": "Created Networks", "networks": "Created Networks",
......
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