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 @@
"text_i18n":"validation_dict.requires_auth",
"children": [
{
"generate": "widget",
"type": "controlgroup",
"property_dict": {"direction": "horizontal"},
"children": [{
"type": "a",
"direct":{"className":"translate action", "href":"#global-popup"},
"attributes":{
"data-i18n":"global_dict.common_dict.login",
"data-action":"login",
"data-icon":"lock",
"data-rel": "popup"
},
"logic": {"text":"Login"}
}, {
"type": "a",
"direct": {"className":"translate ui-btn-slapos-black", "href": "#person::new"},
"attributes": {
"data-i18n": "global_dict.common_dict.register",
"data-icon": "edit"
},
"logic": {"text":"Register"}
}]
"href": "#global-popup",
"class_list": "translate action",
"action": "login",
"rel": "popup",
"text": "Login",
"text_i18n": "global_dict.common_dict.login",
"icon": "lock"
},
{
"href":"#person::new",
"class_list": "translate ui-btn-slapos-black",
"text":"Register",
"text_i18n": "global_dict.common_dict.register",
"icon": "edit"
}
]
}
......
......@@ -152,6 +152,12 @@ html table.ui-table thead th, html table.ui-table thead td {
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) */
html .ui-table-caption {
padding: 0.25em 0;
......@@ -230,13 +236,18 @@ html table.ui-table tr td .ui-controlgroup {
margin: 0;
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 {
width: auto;
}
/* why? a button should be a button
html table.ui-table tr td a.ui-btn {
border: 0 none;
background: transparent;
}
*/
html table.ui-table tr td a.ui-btn:after {
margin-top: -10px;
}
......@@ -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-radio .ui-btn,
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:hover {
html table tbody td .ui-controlgroup-controls .ui-btn:hover */
{
background-color: transparent;
background-image: none;
}
......
......@@ -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.ui-btn-active,
/* Table rows on hover */
html table.ui-table tbody tr:hover td,
html table.ui-table tbody tr:hover th,
html table.ui-table tbody tr:hover td:not(.ui-no-result),
html table.ui-table tbody tr:hover th:not(.ui-no-result),
/* Controlbar */
html .ui-page-theme-slapos-black .ui-controlbar .ui-btn:active,
html .ui-page-theme-slapos-black .ui-controlbar .ui-btn.ui-btn-active,
......
......@@ -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 @@
"form": true,
"id": "invoice_overview",
"property_dict": {
"no_items": {
"message":"No invoices found",
"message_i18n":"page_dict.invoices.nodata"
},
"dynamic_children": [3],
"requires_authentication": true,
"wrap_gadget": 2,
......
......@@ -6,6 +6,10 @@
"form": true,
"id": "computer_overview",
"property_dict": {
"no_items": {
"message":"No servers associated with this network.",
"message_i18n":"page_dict.networks.nodata"
},
"initial_query_url_identifier": "group",
"dynamic_children": [0],
"requires_authentication": true,
......@@ -45,13 +49,6 @@
"bottom_grid": 1
},
"children": []
}],
"placeholder_dict": {
"no_items": {
"text":"No servers associated with this network.",
"text_i18n":"page_dict.networks.no_servers",
"children": []
}
}
}]
}
......@@ -6,6 +6,10 @@
"form": true,
"id": "network_overview",
"property_dict": {
"no_items": {
"message": "No networks found.",
"message_i18n": "page_dict.networks.nonet"
},
"dynamic_children": [4],
"requires_authentication": true,
"depends_on": "login_state",
......@@ -83,38 +87,6 @@
"bottom_grid": 1
},
"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 @@
"form": true,
"id": "user_sample",
"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],
"requires_authentication": true,
"depends_on": "login_state",
......@@ -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 @@
"form": true,
"id": "service_overview",
"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",
"dynamic_children": [0],
"wrap_gadget": 2,
......@@ -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"}}
]
}]
}],
"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 @@
* @return {object} fragment
**/
"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
if (spec.property_dict.depends_on) {
......@@ -1269,7 +1274,7 @@
// no auth
if (answer === null) {
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;
}
......@@ -1314,8 +1319,7 @@
}
}
} else {
// no items found
target.appendChild(app.noItemsFound());
target.appendChild(no_content(spec.property_dict.no_items));
}
return target;
},
......@@ -1330,8 +1334,26 @@
* @param {object} url_pointer indicates layout used
* @return {object} fragment
**/
// TODO: refactor!
"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
if (spec.property_dict.depends_on) {
......@@ -1346,11 +1368,13 @@
// no auth
if (answer === null) {
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;
}
// determine target element, that will be returned
// no results
no_result = answer.data.total_rows === 0;
if (update) {
target = document.createDocumentFragment();
} else {
......@@ -1381,41 +1405,45 @@
}
// loop over dynamic data and generate table
if (answer.data.total_rows > 0) {
for (i = 0; i < spec.children.length; i += 1) {
element = spec.children[i];
for (i = 0; i < spec.children.length; i += 1) {
element = spec.children[i];
// set flag for referencing gadget
element.reference = spec.id;
// set flag for referencing gadget
element.reference = spec.id;
// set flag to label elements that should contain dynamic data
if (spec.property_dict.dynamic_children) {
if (spec.property_dict.dynamic_children.indexOf(i) > -1) {
// pass relevant information to method generating the gadget
element.portal_type = spec.portal_type_title;
element.feature_dict = spec.property_dict.feature_dict;
element.dynamic = true;
}
// set flag to label elements that should contain dynamic data
if (spec.property_dict.dynamic_children) {
if (spec.property_dict.dynamic_children.indexOf(i) > -1) {
// pass relevant information to method generating the gadget
element.portal_type = spec.portal_type_title;
element.feature_dict = spec.property_dict.feature_dict;
element.dynamic = true;
}
}
// generate table rows with dynamic data
if (element.type === "table") {
element.children = map.utils.mapTableRows(
answer.data.rows,
spec,
field_dict,
url_pointer,
update
);
}
// generate table rows with dynamic data
if (element.type === "table") {
element.children = map.utils.mapTableRows(
answer.data.rows,
spec,
field_dict,
url_pointer,
update
);
}
// add elements when not updating, if updating only add dynamic
if (update !== true || element.dynamic) {
target.appendChild(app.setContent(element, {}, update));
// add elements when not updating, if updating only add dynamic
if (update !== true || element.dynamic) {
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));
}
}
target.appendChild(content);
}
} else {
target.appendChild(app.noItemsFound());
}
// assemble and/or return
......@@ -1437,7 +1465,12 @@
* @return {object} fragment
**/
"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
if (spec.property_dict.depends_on) {
......@@ -1454,7 +1487,7 @@
spec.reset = reset_state;
spec.depend = update_gadget;
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;
// auth or allow
......@@ -1462,10 +1495,8 @@
target = document.createDocumentFragment();
if (
//(answer.data && answer.data.total_rows === 0) ||
(answer.data === undefined && answer.request_new === undefined)) {
target.appendChild(app.noItemsFound());
if ((answer.data === undefined && answer.request_new === undefined)) {
target.appendChild(no_content(spec.property_dict.no_items));
} else {
// set data
if (answer && (answer.data || answer.request_new)) {
......@@ -4614,54 +4645,79 @@
* return a placeholder with button in case no items were found
* @method noItemsFound
* @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
*/
app.noItemsFound = function (content_dict) {
var i, reply, content, message, message_i18n;
// provided in gadget config
if (content_dict) {
message = content_dict.text;
message_i18n = content_dict.text_i18n;
content = content_dict.children;
// fallback
} else {
message = "No items found.";
message_i18n = "validation_dict.no_items_found";
content = [{
"type": "a",
"direct": {
"href": "#",
"className": "ui-corner-all ui-btn ui-shadow ui-btn-inline " +
"ui-icon-chevron-sign-left ui-btn-icon-left translate "
},
"attributes": {
"data-rel": "back",
"data-i18n": "global_dict.pagination_dict.back"
},
"logic": {"Text": "Back"}
}];
}
app.noItemsFound = function (content_dict, type, count) {
var i, fragment, data, action_menu, message, message_i18n, button, back,
wrap, class_string;
data = content_dict || {};
switch (type) {
case "td": class_string = "ui-no-result"; break;
case "li": class_string = "ui-li ui-li-static ui-first-child ui-last-child " +
"ui-no-result ui-body-inherit";
break;
default: class_string = "responsive ui-content-element"; break;
};
// <p> is not flexible...
reply = factory.element(
"p",
{"className": "responsive ui-content-element"}
// container
fragment = factory.element(
type || "p",
{"className": class_string},
{"colspan": count || null}
);
reply.appendChild(factory.element(
// info
fragment.appendChild(factory.element(
"span",
{"className": "translate"},
{"data-i18n": message_i18n},
{"text": message}
{"data-i18n": data.message_i18n || "validation_dict.no_items_found"},
{"text": data.message || "No items found."}
));
for (i = 0; i < content.length; i += 1) {
reply.appendChild(app.setContent(content[i]));
// 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",
"direct": {
"href": back ? "#" : button.href,
"className": "ui-corner-all ui-btn ui-shadow ui-btn-inline " +
(back ? "ui-icon-chevron-sign-left ui-btn-icon-left " :
(button.icon ? "ui-icon-" + button.icon +
" ui-btn-icon-left " : " ")) + (button.class_list || "")
},
"attributes": {
"data-action": button.action || null,
"data-rel": back ? "back" : (button.rel || null),
"data-i18n": back ?
"global_dict.pagination_dict.back" : button.text_i18n
},
"logic": {"text": back ? "Back" : button.text}
});
}
fragment.appendChild(app.setContent(action_menu));
}
return reply;
// table cells need a wrapping row
if (type === "td") {
wrap = factory.element("tr");
wrap.appendChild(fragment);
return wrap;
}
return fragment;
};
/**
......
......@@ -85,7 +85,8 @@
"title": "Account Info",
"create": "Create Person",
"register": "Register",
"subtitle": "Registration/Invoicing Info"
"subtitle": "Registration/Invoicing Info",
"nodata": "No Person found"
},
"invoices": {
"title": "Invoices",
......@@ -93,7 +94,8 @@
"download": "Download",
"add": "Create new invoice",
"overview": "Invoice Overview",
"search": "Search Invoices"
"search": "Search Invoices",
"nodata": "No invoices found"
},
"servers": {
"no_software": "No software installed.",
......@@ -132,7 +134,8 @@
"search": "Search available services"
},
"networks": {
"no_servers": "No servers associated with this network.",
"nonet": "No networks found.",
"nodata": "No servers associated with this network.",
"title": "Networks",
"subtitle": "Network Administration",
"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