2022-01-23 01:56:17 +01:00
|
|
|
|
|
|
|
export function splitHashParts()
|
2021-01-25 00:24:31 +01:00
|
|
|
{
|
|
|
|
const currentHash = location.hash.substr(1);
|
2021-03-22 16:51:57 +01:00
|
|
|
const hashParts = currentHash.split('?');
|
2021-01-25 00:24:31 +01:00
|
|
|
for (let i = 0, len = hashParts.length; i != len; ++i) {
|
|
|
|
hashParts[i] = decodeURIComponent(hashParts[i]);
|
|
|
|
}
|
|
|
|
return hashParts;
|
|
|
|
}
|
|
|
|
|
2022-06-09 19:24:17 +02:00
|
|
|
export function hashAsObject(hash)
|
2021-01-25 00:24:31 +01:00
|
|
|
{
|
|
|
|
const hashObject = {};
|
2022-06-09 19:24:17 +02:00
|
|
|
(hash || location.hash.substr(1)).split('&').forEach(function(hashPart) {
|
2021-01-25 00:24:31 +01:00
|
|
|
const parts = hashPart.split('=', 2);
|
|
|
|
if (parts.length < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
hashObject[decodeURIComponent(parts[0])] = parts.length > 1 ? decodeURIComponent(parts[1]) : undefined;
|
|
|
|
});
|
|
|
|
return hashObject;
|
|
|
|
}
|
|
|
|
|
2022-01-23 01:56:17 +01:00
|
|
|
export function getAndEmptyElement(elementId, specialActionsById)
|
2021-01-25 00:24:31 +01:00
|
|
|
{
|
|
|
|
return emptyDomElement(document.getElementById(elementId), specialActionsById);
|
|
|
|
}
|
|
|
|
|
2022-01-23 01:56:17 +01:00
|
|
|
export function emptyDomElement(domElement, specialActionsById)
|
2021-01-25 00:24:31 +01:00
|
|
|
{
|
|
|
|
let child = domElement.firstChild;
|
|
|
|
while (child) {
|
|
|
|
let specialAction = specialActionsById ? specialActionsById[child.id] : undefined;
|
|
|
|
let nextSibling = child.nextSibling;
|
|
|
|
if (specialAction !== 'keep') {
|
|
|
|
domElement.removeChild(child);
|
|
|
|
}
|
|
|
|
child = nextSibling;
|
|
|
|
}
|
|
|
|
return domElement;
|
|
|
|
}
|
|
|
|
|
2022-01-23 01:56:17 +01:00
|
|
|
export function alterFormSelection(form, command)
|
2021-01-25 00:24:31 +01:00
|
|
|
{
|
|
|
|
// modify form elements
|
|
|
|
const elements = form.elements;
|
|
|
|
for (let i = 0, len = elements.length; i != len; ++i) {
|
|
|
|
const element = elements[i];
|
|
|
|
if (element.type !== 'checkbox') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (command) {
|
|
|
|
case 'uncheck-all':
|
|
|
|
element.checked = false;
|
|
|
|
break;
|
|
|
|
case 'check-all':
|
|
|
|
element.checked = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// modify the actual data
|
|
|
|
const tables = form.getElementsByTagName('table');
|
|
|
|
for (let i = 0, len = tables.length; i != len; ++i) {
|
|
|
|
const data = tables[i].data;
|
|
|
|
if (!Array.isArray(data)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
data.forEach(function (row) {
|
|
|
|
switch (command) {
|
|
|
|
case 'uncheck-all':
|
|
|
|
row.selected = false;
|
|
|
|
break;
|
|
|
|
case 'check-all':
|
|
|
|
row.selected = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2021-02-13 17:14:49 +01:00
|
|
|
}
|
2021-01-25 00:24:31 +01:00
|
|
|
}
|
|
|
|
|
2022-01-23 01:56:17 +01:00
|
|
|
export function getProperty(object, property, fallback)
|
2021-01-25 00:24:31 +01:00
|
|
|
{
|
|
|
|
if (typeof object !== 'object') {
|
|
|
|
return fallback;
|
|
|
|
}
|
|
|
|
const value = object[property];
|
|
|
|
return value !== undefined ? value : fallback;
|
|
|
|
}
|
|
|
|
|
2022-01-23 01:56:17 +01:00
|
|
|
export function makeRepoName(dbName, dbArch)
|
2021-01-25 00:24:31 +01:00
|
|
|
{
|
|
|
|
return dbArch && dbArch !== 'x86_64' ? dbName + '@' + dbArch : dbName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the table row data for the table within the element with the specified ID.
|
2022-01-23 01:56:17 +01:00
|
|
|
export function getFormTableData(formId)
|
2021-01-25 00:24:31 +01:00
|
|
|
{
|
|
|
|
const formElement = document.getElementById(formId);
|
|
|
|
const tableElement = formElement.getElementsByTagName('table')[0];
|
|
|
|
if (tableElement === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const data = tableElement.data;
|
|
|
|
return Array.isArray(data) ? data : undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the cell values of selected rows.
|
|
|
|
/// \remarks The row data needs to be passed. The cell is determined by the specified \a propertyName.
|
2022-01-23 01:56:17 +01:00
|
|
|
export function getSelectedRowProperties(data, propertyName)
|
2021-01-25 00:24:31 +01:00
|
|
|
{
|
|
|
|
const propertyValues = [];
|
|
|
|
data.forEach(function (row) {
|
|
|
|
if (row.selected) {
|
|
|
|
propertyValues.push(row[propertyName]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return propertyValues;
|
2021-02-13 17:14:49 +01:00
|
|
|
}
|