Skip to content
Snippets Groups Projects
Verified Commit d8f6871c authored by Timm Fitschen's avatar Timm Fitschen
Browse files

STY: js-beautified caosdb.js

parent 7f02d11b
No related branches found
No related tags found
No related merge requests found
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2019 IndiScale GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2019 IndiScale GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
'use strict';
/**
......@@ -69,8 +69,7 @@ function getUserRealm() {
* @return Array containing the roles of the user.
*/
function getUserRoles() {
return Array.from(document.getElementsByClassName("caosdb-user-role")
).map(el => el.innerText);
return Array.from(document.getElementsByClassName("caosdb-user-role")).map(el => el.innerText);
}
/**
......@@ -189,9 +188,9 @@ function getPropertyDatatype(element) {
x => x.classList.contains("caosdb-property-datatype"),
x => x.classList.contains("caosdb-preview-container"));
if(dt_elem.length == 1){
if (dt_elem.length == 1) {
return $(dt_elem[0]).text();
} else if (dt_elem.length > 1){
} else if (dt_elem.length > 1) {
throw new Error("The datatype of this property could not uniquely be determined.");
}
......@@ -229,12 +228,12 @@ function getEntityPath(element) {
// if ($(element).find('[data-entity-path]').length == 1) {
// return $(element).find('[data-entity-path]')[0].dataset.entityPath;
// }
if (typeof $(element).find('.caosdb-f-entity-path').val() !== 'undefined') {
// This is needed for the edit mode to work properly:
return $(element).find('.caosdb-f-entity-path').val();
}
return getEntityHeadingAttribute(element, "path");
}
......@@ -249,12 +248,12 @@ function getEntityChecksum(element) {
// if ($(element).find('[data-entity-checksum]').length == 1) {
// return $(element).find('[data-entity-checksum]')[0].dataset.entityChecksum;
// }
if (typeof $(element).find('.caosdb-f-entity-checksum').val() !== 'undefined') {
// This is needed for the edit mode to work properly:
return $(element).find('.caosdb-f-entity-checksum').val();
}
return getEntityHeadingAttribute(element, "checksum");
}
......@@ -269,12 +268,12 @@ function getEntitySize(element) {
// if ($(element).find('[data-entity-size]').length == 1) {
// return $(element).find('[data-entity-size]')[0].dataset.entitySize;
// }
if (typeof $(element).find('.caosdb-f-entity-size').val() !== 'undefined') {
// This is needed for the edit mode to work properly:
return $(element).find('.caosdb-f-entity-size').val();
}
return getEntityHeadingAttribute(element, "size");
}
......@@ -347,7 +346,7 @@ function input2caosdbDate(date, time) {
var hasEntityPermission = function (entity, permission) {
if (userHasRole("administration")) {
// administration is a special role. It has * permissions.
return true;
return true;
}
const permissions = getAllEntityPermissions(entity);
return permissions.indexOf(permission.toUpperCase()) > -1;
......@@ -501,7 +500,7 @@ function getEntityXML(ent_element) {
function getPropertyName(element) {
var name_element = element.getElementsByClassName("caosdb-property-name");
if(name_element.length > 0) {
if (name_element.length > 0) {
return name_element[0].textContent;
} else if ($(element).is("[data-property-name]")) {
return $(element).attr("data-property-name");
......@@ -600,7 +599,7 @@ function getPropertyFromElement(propertyelement, names = undefined) {
var value_string = undefined;
if (valel && valel.textContent.length > 0) {
value_string = valel.textContent;
} else if (valel && valel.value && valel.value.length > 0 ) {
} else if (valel && valel.value && valel.value.length > 0) {
value_string = valel.value;
}
......@@ -617,7 +616,7 @@ function getPropertyFromElement(propertyelement, names = undefined) {
if (typeof value_string !== "undefined") {
// This is set to true, when there is a reference or a list of references:
if(typeof property.reference === "undefined") {
if (typeof property.reference === "undefined") {
property.reference = (valel.getElementsByClassName("caosdb-id").length > 0);
}
......@@ -741,8 +740,8 @@ function setPropertySafe(valueelement, property, propold) {
}
} else {
/* DEPRECATED css class .caosdb-property-text-value - Use
* .caosdb-f-property-single-raw-value or introduce new
* .caosdb-v-property-text-value */
* .caosdb-f-property-single-raw-value or introduce new
* .caosdb-v-property-text-value */
valueelement.innerHTML = "<span class='caosdb-property-text-value'>" + property.value + "</span>";
}
}
......@@ -789,7 +788,7 @@ function setProperty(element, property) {
* equivalent).
* @returns {string} The value of the the property with property_name or `undefined` when this property is not available for this entity.
*/
function getProperty(element, property_name, case_sensitive=true) {
function getProperty(element, property_name, case_sensitive = true) {
var props;
if (case_sensitive) {
props = getProperties(element).filter(el => el.name == property_name);
......@@ -886,7 +885,7 @@ function appendProperty(doc, element, property, append_datatype = false) {
*
* @param {string} root - the new root element.
* @returns {(Document|DocumentFragement)} the new document.
*/
*/
function _createDocument(root) {
var doc = undefined;
if (window.DocumentFragment) {
......@@ -916,9 +915,9 @@ function _createDocument(root) {
*
*/
function createEntityXML(role, name, id, properties, parents,
append_datatypes = false, datatype = undefined, description = undefined,
unit = undefined,
file_path = undefined, file_checksum = undefined, file_size = undefined) {
append_datatypes = false, datatype = undefined, description = undefined,
unit = undefined,
file_path = undefined, file_checksum = undefined, file_size = undefined) {
var doc = _createDocument(role);
var nelnode = doc.children[0];
......@@ -986,11 +985,11 @@ function createEntityXML(role, name, id, properties, parents,
*
*/
function createFileXML(name, id, parents,
file_path, file_checksum, file_size,
description = undefined) {
file_path, file_checksum, file_size,
description = undefined) {
return createEntityXML("File", name, id, {}, parents,
false, undefined, description, undefined,
file_path, file_checksum, file_size);
false, undefined, description, undefined,
file_path, file_checksum, file_size);
}
/**
......@@ -1006,7 +1005,7 @@ function wrapXML(root, xmls) {
caosdb_utils.assert_string(root, "param `root`");
var doc = _createDocument(root);
for (var i=0; i < xmls.length; i++) {
for (var i = 0; i < xmls.length; i++) {
doc.firstElementChild.appendChild(xmls[i].firstElementChild);
}
......@@ -1117,4 +1116,4 @@ async function update(xml) {
async function insert(xml) {
var wrapped = createInsert(xml);
return await transaction.insertEntitiesXml(wrapped);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment