Skip to content
Snippets Groups Projects
Commit cec3be01 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

js doc added

parent 997c281b
No related branches found
No related tags found
1 merge request!369Resolve "Functionality to update Terms of Service"
"use strict"; "use strict";
/* exported Promise*/ /* exported Promise*/
var AbstractAdminPanel = require('./AbstractAdminPanel'); var AbstractAdminPanel = require('./AbstractAdminPanel');
var PrivilegeType = require('../../map/data/PrivilegeType'); var PrivilegeType = require('../../map/data/PrivilegeType');
var Functions = require('../../Functions'); var Functions = require('../../Functions');
var GuiConnector = require('../../GuiConnector'); var GuiConnector = require('../../GuiConnector');
/* exported logger */ /* exported logger */
// noinspection JSUnusedLocalSymbols // noinspection JSUnusedLocalSymbols
var logger = require('../../logger'); var logger = require('../../logger');
// noinspection JSUnusedLocalSymbols // noinspection JSUnusedLocalSymbols
var Promise = require("bluebird"); var Promise = require("bluebird");
var xss = require("xss"); var xss = require("xss");
function ConfigurationAdminPanel(params) { /**
AbstractAdminPanel.call(this, params); *
* @param {Configuration} [params.configuration]
var self = this; * @param {HTMLElement} params.element
$(self.getElement()).addClass("minerva-configuration-tab"); * @param {Project} params.project
* @param {string} params.panelName
self._createGui(); * @param params.parent
} *
* @constructor
ConfigurationAdminPanel.prototype = Object.create(AbstractAdminPanel.prototype); * @extends AbstractAdminPanel
ConfigurationAdminPanel.prototype.constructor = ConfigurationAdminPanel; */
function ConfigurationAdminPanel(params) {
ConfigurationAdminPanel.prototype._createGui = function () { AbstractAdminPanel.call(this, params);
var self = this;
var configurationDiv = Functions.createElement({ var self = this;
type: "div" $(self.getElement()).addClass("minerva-configuration-tab");
});
self.getElement().appendChild(configurationDiv); self._createGui();
}
configurationDiv.appendChild(Functions.createElement({
type: "h3", ConfigurationAdminPanel.prototype = Object.create(AbstractAdminPanel.prototype);
content: 'Configuration category: <select name="categorySelect"></select>', ConfigurationAdminPanel.prototype.constructor = ConfigurationAdminPanel;
xss: false
})); /**
*
configurationDiv.appendChild(Functions.createElement({ * @private
type: "br" */
})); ConfigurationAdminPanel.prototype._createGui = function () {
var self = this;
var configurationTable = Functions.createElement({ var configurationDiv = Functions.createElement({
type: "table", type: "div"
name: "configurationTable", });
className: "display", self.getElement().appendChild(configurationDiv);
style: "width:100%"
}); configurationDiv.appendChild(Functions.createElement({
configurationDiv.appendChild(configurationTable); type: "h3",
content: 'Configuration category: <select name="categorySelect"></select>',
// noinspection JSUnusedGlobalSymbols xss: false
$(configurationTable).DataTable({ }));
columns: [{
title: 'Category' configurationDiv.appendChild(Functions.createElement({
}, { type: "br"
title: 'Name' }));
}, {
title: 'Value' var configurationTable = Functions.createElement({
}, { type: "table",
title: 'Save', name: "configurationTable",
orderable: false className: "display",
}], style: "width:100%"
order: [[1, "asc"]] });
}); configurationDiv.appendChild(configurationTable);
self.bindUserGuiPreference({
jQueryObject: $(configurationTable), // noinspection JSUnusedGlobalSymbols
event: 'length.dt', $(configurationTable).DataTable({
preferenceName: 'admin-configuration-datatable-length', columns: [{
defaultValue: '10', title: 'Category'
getter: function () { }, {
return $(configurationTable).DataTable().page.len() + ''; title: 'Name'
}, }, {
setter: function (value) { title: 'Value'
return $(configurationTable).DataTable().page.len(value).draw(); }, {
} title: 'Save',
}); orderable: false
}],
$(configurationTable).on("click", "[name='saveOption']", function () { order: [[1, "asc"]]
var button = this; });
return self.saveOption($(button).attr("data")).then(null, GuiConnector.alert); self.bindUserGuiPreference({
}); jQueryObject: $(configurationTable),
$(configurationTable).on("input", ".minerva-color-input", function () { event: 'length.dt',
var input = this; preferenceName: 'admin-configuration-datatable-length',
var value = $(input).val(); defaultValue: '10',
var type = $(input).attr("data"); getter: function () {
if (value.length !== 6) { return $(configurationTable).DataTable().page.len() + '';
value = "FFFFFF"; },
} setter: function (value) {
$("[name='edit-color-" + type + "']", configurationTable).css("background-color", "#" + value); return $(configurationTable).DataTable().page.len(value).draw();
}); }
$(configurationTable).on("click", ".minerva-color-button", function () { });
var button = this;
var value = $(button).css("background-color"); $(configurationTable).on("click", "[name='saveOption']", function () {
var type = $(button).attr("data"); var button = this;
var colorPicker = $(button).parent().spectrum({ return self.saveOption($(button).attr("data")).then(null, GuiConnector.alert);
color: value, });
move: function (color) { $(configurationTable).on("input", ".minerva-color-input", function () {
var value = color.toHexString().replace("#", ''); var input = this;
$("[name='edit-" + type + "']", configurationTable).val(value); var value = $(input).val();
$("[name='edit-color-" + type + "']", configurationTable).css("background-color", "#" + value); var type = $(input).attr("data");
}, if (value.length !== 6) {
hide: function () { value = "FFFFFF";
colorPicker.spectrum("destroy"); }
} $("[name='edit-color-" + type + "']", configurationTable).css("background-color", "#" + value);
}); });
return new Promise.delay(1).then(function () { $(configurationTable).on("click", ".minerva-color-button", function () {
colorPicker.show(); var button = this;
colorPicker.spectrum("show"); var value = $(button).css("background-color");
}); var type = $(button).attr("data");
}); // noinspection JSUnusedGlobalSymbols
}; var colorPicker = $(button).parent().spectrum({
color: value,
/** move: function (color) {
* var value = color.toHexString().replace("#", '');
* @returns {Promise} $("[name='edit-" + type + "']", configurationTable).val(value);
*/ $("[name='edit-color-" + type + "']", configurationTable).css("background-color", "#" + value);
ConfigurationAdminPanel.prototype.init = function () { },
var self = this; hide: function () {
return self.getServerConnector().getLoggedUser().then(function (user) { colorPicker.spectrum("destroy");
var configuration = self.getConfiguration(); }
var privilege = configuration.getPrivilegeType(PrivilegeType.CONFIGURATION_MANAGE); });
if (user.hasPrivilege(privilege)) { return new Promise.delay(1).then(function () {
self.setOptions(configuration.getOptions(), true); colorPicker.show();
} else { colorPicker.spectrum("show");
self.disablePanel("You have no privilege to manage configuration"); });
} });
}); };
};
/**
/** *
* * @returns {Promise}
* @param {ConfigurationOption[]} options */
* @param {boolean} editable ConfigurationAdminPanel.prototype.init = function () {
*/ var self = this;
ConfigurationAdminPanel.prototype.setOptions = function (options, editable) { return self.getServerConnector().getLoggedUser().then(function (user) {
var self = this; var configuration = self.getConfiguration();
var dataTable = $("[name='configurationTable']", self.getElement()).DataTable(); var privilege = configuration.getPrivilegeType(PrivilegeType.CONFIGURATION_MANAGE);
var data = []; if (user.hasPrivilege(privilege)) {
self.setOptions(configuration.getOptions(), true);
var categoryDropDown = $("[name='categorySelect']", self.getElement()); } else {
categoryDropDown.empty(); self.disablePanel("You have no privilege to manage configuration");
}
var categories = {"": true}; });
categoryDropDown.append('<option value=""></option>'); };
for (var i = 0; i < options.length; i++) {
var option = options[i]; /**
var rowData = self.optionToTableRow(option, editable); *
data.push(rowData); * @param {ConfigurationOption[]} options
* @param {boolean} editable
var group = option.getGroup(); */
if (categories[group] === undefined && group !== undefined) { ConfigurationAdminPanel.prototype.setOptions = function (options, editable) {
categories[group] = true; var self = this;
categoryDropDown.append('<option value="' + group + '">' + group + '</option>') var dataTable = $("[name='configurationTable']", self.getElement()).DataTable();
} var data = [];
}
categoryDropDown.change(function () { var categoryDropDown = $("[name='categorySelect']", self.getElement());
logger.warn($(this).val()); categoryDropDown.empty();
dataTable.column(0).search($(this).val()).draw();
}); var categories = {"": true};
categoryDropDown.append('<option value=""></option>');
dataTable.clear().rows.add(data).draw(); for (var i = 0; i < options.length; i++) {
}; var option = options[i];
var rowData = self.optionToTableRow(option, editable);
/** data.push(rowData);
*
* @param {ConfigurationOption} option var group = option.getGroup();
* @param {boolean} editable if (categories[group] === undefined && group !== undefined) {
* @returns {Array} categories[group] = true;
*/ categoryDropDown.append('<option value="' + group + '">' + group + '</option>')
ConfigurationAdminPanel.prototype.optionToTableRow = function (option, editable) { }
var value = option.getValue(); }
var row = []; categoryDropDown.change(function () {
var editOption; logger.warn($(this).val());
var disabled = ''; dataTable.column(0).search($(this).val()).draw();
if (!editable) { });
disabled = " disabled ";
} dataTable.clear().rows.add(data).draw();
};
if (option.getValueType() === "STRING" ||
option.getValueType() === "INTEGER" || /**
option.getValueType() === "DOUBLE" || *
option.getValueType() === "EMAIL" || * @param {ConfigurationOption} option
option.getValueType() === "PASSWORD" || * @param {boolean} editable
option.getValueType() === "URL") { * @returns {Array}
editOption = "<input name='edit-" + option.getType() + "' value='" + value + "'/>"; */
} else if (option.getValueType() === "TEXT") { ConfigurationAdminPanel.prototype.optionToTableRow = function (option, editable) {
editOption = "<textarea name='edit-" + option.getType() + "'>" + xss(value) + "</textarea>"; var value = option.getValue();
} else if (option.getValueType() === "BOOLEAN") { var row = [];
var checked = ""; var editOption;
if (value.toLowerCase() === "true") { var disabled = '';
checked = " checked "; if (!editable) {
} disabled = " disabled ";
editOption = "<input type='checkbox' name='edit-" + option.getType() + "' " + checked + " />"; }
} else if (option.getValueType() === "COLOR") {
editOption = "<div>" + if (option.getValueType() === "STRING" ||
"<input class='minerva-color-input' name='edit-" + option.getType() + "' data='" + option.getType() + "' value='" + value + "'/>" + option.getValueType() === "INTEGER" ||
"<button class='minerva-color-button' name='edit-color-" + option.getType() + "' data='" + option.getType() + "' style='background-color: #" + value + "'>&nbsp</button>" + option.getValueType() === "DOUBLE" ||
"</div>"; option.getValueType() === "EMAIL" ||
} else { option.getValueType() === "PASSWORD" ||
logger.warn("Don't know how to handle: " + option.getValueType()); option.getValueType() === "URL") {
editOption = "<input name='edit-" + option.getType() + "' value='" + value + "' readonly/>"; editOption = "<input name='edit-" + option.getType() + "' value='" + value + "'/>";
} } else if (option.getValueType() === "TEXT") {
var group = option.getGroup(); editOption = "<textarea name='edit-" + option.getType() + "'>" + xss(value) + "</textarea>";
if (group === undefined) { } else if (option.getValueType() === "BOOLEAN") {
group = ""; var checked = "";
} if (value.toLowerCase() === "true") {
row[0] = group; checked = " checked ";
row[1] = option.getCommonName(); }
row[2] = editOption; editOption = "<input type='checkbox' name='edit-" + option.getType() + "' " + checked + " />";
row[3] = "<button name='saveOption' data='" + option.getType() + "' " + disabled + "><i class='fa fa-save' style='font-size:17px'></i></button>"; } else if (option.getValueType() === "COLOR") {
return row; editOption = "<div>" +
}; "<input class='minerva-color-input' name='edit-" + option.getType() + "' data='" + option.getType() + "' value='" + value + "'/>" +
"<button class='minerva-color-button' name='edit-color-" + option.getType() + "' data='" + option.getType() + "' style='background-color: #" + value + "'>&nbsp</button>" +
ConfigurationAdminPanel.prototype.saveOption = function (type) { "</div>";
var self = this; } else {
return self.getServerConnector().getConfiguration().then(function (configuration) { logger.warn("Don't know how to handle: " + option.getValueType());
var option = configuration.getOption(type); editOption = "<input name='edit-" + option.getType() + "' value='" + value + "' readonly/>";
var element = $("[name='edit-" + type + "']", self.getElement()); }
var value; var group = option.getGroup();
if (element.is(':checkbox')) { if (group === undefined) {
if (element.is(':checked')) { group = "";
value = "true"; }
} else { row[0] = group;
value = "false"; row[1] = option.getCommonName();
} row[2] = editOption;
} else { row[3] = "<button name='saveOption' data='" + option.getType() + "' " + disabled + "><i class='fa fa-save' style='font-size:17px'></i></button>";
value = element.val(); return row;
} };
option.setValue(value);
return self.getServerConnector().updateConfigurationOption(option); /**
}); *
}; * @param {string} type
ConfigurationAdminPanel.prototype.destroy = function () { * @returns {Promise}
var self = this; */
var table = $("[name='configurationTable']", self.getElement())[0]; ConfigurationAdminPanel.prototype.saveOption = function (type) {
if ($.fn.DataTable.isDataTable(table)) { var self = this;
$(table).DataTable().destroy(); return self.getServerConnector().getConfiguration().then(function (configuration) {
} var option = configuration.getOption(type);
var element = $("[name='edit-" + type + "']", self.getElement());
}; var value;
if (element.is(':checkbox')) {
module.exports = ConfigurationAdminPanel; if (element.is(':checked')) {
value = "true";
} else {
value = "false";
}
} else {
value = element.val();
}
option.setValue(value);
return self.getServerConnector().updateConfigurationOption(option);
});
};
/**
*
*/
ConfigurationAdminPanel.prototype.destroy = function () {
var self = this;
var table = $("[name='configurationTable']", self.getElement())[0];
if ($.fn.DataTable.isDataTable(table)) {
$(table).DataTable().destroy();
}
};
module.exports = ConfigurationAdminPanel;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment