diff --git a/src/cockpit/389-console/src/lib/schema/schemaModals.jsx b/src/cockpit/389-console/src/lib/schema/schemaModals.jsx
new file mode 100644
index 0000000000..6b6049a988
--- /dev/null
+++ b/src/cockpit/389-console/src/lib/schema/schemaModals.jsx
@@ -0,0 +1,660 @@
+import React from "react";
+import {
+ Row,
+ Spinner,
+ Modal,
+ Icon,
+ Button,
+ Checkbox,
+ noop,
+ Form,
+ FormControl,
+ FormGroup,
+ ControlLabel,
+ Col
+} from "patternfly-react";
+import { Typeahead } from "react-bootstrap-typeahead";
+import PropTypes from "prop-types";
+import "../../css/ds.css";
+
+class ObjectClassModal extends React.Component {
+ render() {
+ const {
+ newOcEntry,
+ ocModalViewOnly,
+ addHandler,
+ editHandler,
+ handleTypeaheadChange,
+ handleFieldChange,
+ objectclasses,
+ attributes,
+ ocName,
+ ocDesc,
+ ocOID,
+ ocParent,
+ ocKind,
+ ocMust,
+ ocMay,
+ objectclassModalShow,
+ closeModal,
+ loading
+ } = this.props;
+ let spinner = "";
+ if (loading) {
+ spinner = (
+
+
+
+ Saving objectClass...
+
+
+ );
+ }
+
+ return (
+
+
+
+
+
+
+ {ocModalViewOnly ? (
+ `View ObjectClass - ${ocName}`
+ ) : (
+
+ {newOcEntry ? "Add" : "Edit"} ObjectClass
+ {ocName != "" ? ` - ${ocName}` : ""}{" "}
+
+ )}
+
+
+
+
+ {spinner}
+
+
+ {ocModalViewOnly ? (
+
+ ) : (
+
+
+
+
+ )}
+
+
+
+
+ );
+ }
+}
+
+ObjectClassModal.propTypes = {
+ addHandler: PropTypes.func,
+ editHandler: PropTypes.func,
+ newOcEntry: PropTypes.bool,
+ ocModalViewOnly: PropTypes.bool,
+ handleTypeaheadChange: PropTypes.func,
+ handleFieldChange: PropTypes.func,
+ objectclasses: PropTypes.array,
+ attributes: PropTypes.array,
+ ocName: PropTypes.string,
+ ocDesc: PropTypes.string,
+ ocOID: PropTypes.string,
+ ocParent: PropTypes.array,
+ ocKind: PropTypes.string,
+ ocMust: PropTypes.array,
+ ocMay: PropTypes.array,
+ objectclassModalShow: PropTypes.bool,
+ closeModal: PropTypes.func,
+ loading: PropTypes.bool
+};
+
+ObjectClassModal.defaultProps = {
+ addHandler: noop,
+ editHandler: noop,
+ newOcEntry: true,
+ ocModalViewOnly: false,
+ handleTypeaheadChange: noop,
+ handleFieldChange: noop,
+ objectclasses: [],
+ attributes: [],
+ ocName: "",
+ ocDesc: "",
+ ocOID: "",
+ ocParent: [],
+ ocKind: "",
+ ocMust: [],
+ ocMay: [],
+ objectclassModalShow: false,
+ closeModal: noop,
+ loading: false
+};
+
+class AttributeTypeModal extends React.Component {
+ render() {
+ const {
+ atName,
+ atDesc,
+ atOID,
+ atParent,
+ atSyntax,
+ atUsage,
+ atMultivalued,
+ atNoUserMod,
+ atAlias,
+ atEqMr,
+ atOrder,
+ atSubMr,
+ atModalViewOnly,
+ attributeModalShow,
+ newAtEntry,
+ addHandler,
+ editHandler,
+ handleTypeaheadChange,
+ handleFieldChange,
+ attributes,
+ syntaxes,
+ matchingrules,
+ closeModal,
+ loading
+ } = this.props;
+ let spinner = "";
+ if (loading) {
+ spinner = (
+
+
+
+ Saving attribute...
+
+
+ );
+ }
+
+ return (
+
+
+
+
+
+
+ {atModalViewOnly ? (
+ `View Attribute - ${atName}`
+ ) : (
+
+ {newAtEntry ? "Add" : "Edit"} Attribute
+ {atName != "" ? ` - ${atName}` : ""}{" "}
+
+ )}
+
+
+
+
+ {spinner}
+
+
+ {atModalViewOnly ? (
+
+ ) : (
+
+
+
+
+ )}
+
+
+
+
+ );
+ }
+}
+
+AttributeTypeModal.propTypes = {
+ addHandler: PropTypes.func,
+ editHandler: PropTypes.func,
+ handleTypeaheadChange: PropTypes.func,
+ handleFieldChange: PropTypes.func,
+ attributes: PropTypes.array,
+ matchingrules: PropTypes.array,
+ syntaxes: PropTypes.array,
+ atName: PropTypes.string,
+ atDesc: PropTypes.string,
+ atOID: PropTypes.string,
+ atParent: PropTypes.array,
+ atSyntax: PropTypes.array,
+ atUsage: PropTypes.string,
+ atMultivalued: PropTypes.bool,
+ atNoUserMod: PropTypes.bool,
+ atAlias: PropTypes.array,
+ atEqMr: PropTypes.array,
+ atOrder: PropTypes.array,
+ atSubMr: PropTypes.array,
+ atModalViewOnly: PropTypes.bool,
+ attributeModalShow: PropTypes.bool,
+ newAtEntry: PropTypes.bool,
+ closeModal: PropTypes.func,
+ loading: PropTypes.bool
+};
+
+AttributeTypeModal.defaultProps = {
+ addHandler: noop,
+ editHandler: noop,
+ handleTypeaheadChange: noop,
+ handleFieldChange: noop,
+ attributes: [],
+ matchingrules: [],
+ syntaxes: [],
+ atName: "",
+ atDesc: "",
+ atOID: "",
+ atParent: [],
+ atSyntax: [],
+ atUsage: "userApplications",
+ atMultivalued: false,
+ atNoUserMod: false,
+ atAlias: [],
+ atEqMr: [],
+ atOrder: [],
+ atSubMr: [],
+ atModalViewOnly: false,
+ attributeModalShow: false,
+ newAtEntry: true,
+ closeModal: noop,
+ loading: false
+};
+
+export { ObjectClassModal, AttributeTypeModal };
diff --git a/src/cockpit/389-console/src/lib/schema/schemaTables.jsx b/src/cockpit/389-console/src/lib/schema/schemaTables.jsx
new file mode 100644
index 0000000000..296845ce2e
--- /dev/null
+++ b/src/cockpit/389-console/src/lib/schema/schemaTables.jsx
@@ -0,0 +1,558 @@
+import React from "react";
+import {
+ Button,
+ DropdownButton,
+ MenuItem,
+ actionHeaderCellFormatter,
+ sortableHeaderCellFormatter,
+ tableCellFormatter,
+ noop
+} from "patternfly-react";
+import { DSTable } from "../dsTable.jsx";
+import PropTypes from "prop-types";
+import "../../css/ds.css";
+
+class ObjectClassesTable extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ searchFilterValue: "",
+ fieldsToSearch: ["name", "oid"],
+ columns: [
+ {
+ property: "name",
+ header: {
+ label: "ObjectClass Name",
+ props: {
+ index: 0,
+ rowSpan: 1,
+ colSpan: 1,
+ sort: true
+ },
+ transforms: [],
+ formatters: [],
+ customFormatters: [sortableHeaderCellFormatter]
+ },
+ cell: {
+ props: {
+ index: 0
+ },
+ formatters: [tableCellFormatter]
+ }
+ },
+ {
+ property: "oid",
+ header: {
+ label: "OID",
+ props: {
+ index: 1,
+ rowSpan: 1,
+ colSpan: 1,
+ sort: true
+ },
+ transforms: [],
+ formatters: [],
+ customFormatters: [sortableHeaderCellFormatter]
+ },
+ cell: {
+ props: {
+ index: 1
+ },
+ formatters: [tableCellFormatter]
+ }
+ },
+ {
+ property: "must",
+ header: {
+ label: "Required Attributes",
+ props: {
+ index: 2,
+ rowSpan: 1,
+ colSpan: 1,
+ sort: true
+ },
+ transforms: [],
+ formatters: [],
+ customFormatters: [sortableHeaderCellFormatter]
+ },
+ cell: {
+ props: {
+ index: 2
+ },
+ formatters: [
+ (value, { rowData }) => {
+ return [
{value.join(" ")} | ];
+ }
+ ]
+ }
+ },
+ {
+ property: "may",
+ header: {
+ label: "Allowed Attributes",
+ props: {
+ index: 3,
+ rowSpan: 1,
+ colSpan: 1,
+ sort: true
+ },
+ transforms: [],
+ formatters: [],
+ customFormatters: [sortableHeaderCellFormatter]
+ },
+ cell: {
+ props: {
+ index: 3
+ },
+ formatters: [
+ (value, { rowData }) => {
+ return [
{value.join(" ")} | ];
+ }
+ ]
+ }
+ },
+ {
+ property: "actions",
+ header: {
+ label: "Actions",
+ props: {
+ index: 4,
+ rowSpan: 1,
+ colSpan: 1
+ },
+ formatters: [actionHeaderCellFormatter]
+ },
+ cell: {
+ props: {
+ index: 4
+ },
+ formatters: [
+ (value, { rowData }) => {
+ return [
+
+ {rowData.x_origin === null ||
+ rowData.x_origin === undefined ||
+ rowData.x_origin[0].toLowerCase() != "user defined" ? (
+
+ ) : (
+
+
+
+
+
+ )}
+ |
+ ];
+ }
+ ]
+ }
+ }
+ ]
+ };
+ this.getColumns = this.getColumns.bind(this);
+ }
+
+ getColumns() {
+ return this.state.columns;
+ }
+
+ render() {
+ return (
+
+
+
+ );
+ }
+}
+
+ObjectClassesTable.propTypes = {
+ rows: PropTypes.array,
+ editModalHandler: PropTypes.func,
+ deleteHandler: PropTypes.func,
+ viewModalHandler: PropTypes.func,
+ loading: PropTypes.bool
+};
+
+ObjectClassesTable.defaultProps = {
+ rows: [],
+ editModalHandler: noop,
+ deleteHandler: noop,
+ viewModalHandler: noop,
+ loading: false
+};
+
+class AttributesTable extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ searchFilterValue: "",
+ fieldsToSearch: ["name", "oid"],
+ columns: [
+ {
+ property: "name",
+ header: {
+ label: "Attribute Name",
+ props: {
+ index: 0,
+ rowSpan: 1,
+ colSpan: 1,
+ sort: true
+ },
+ transforms: [],
+ formatters: [],
+ customFormatters: [sortableHeaderCellFormatter]
+ },
+ cell: {
+ props: {
+ index: 0
+ },
+ formatters: [tableCellFormatter]
+ }
+ },
+ {
+ property: "oid",
+ header: {
+ label: "OID",
+ props: {
+ index: 1,
+ rowSpan: 1,
+ colSpan: 1,
+ sort: true
+ },
+ transforms: [],
+ formatters: [],
+ customFormatters: [sortableHeaderCellFormatter]
+ },
+ cell: {
+ props: {
+ index: 1
+ },
+ formatters: [tableCellFormatter]
+ }
+ },
+ {
+ property: "syntax",
+ header: {
+ label: "Syntax",
+ props: {
+ index: 2,
+ rowSpan: 1,
+ colSpan: 1,
+ sort: true
+ },
+ transforms: [],
+ formatters: [],
+ customFormatters: [sortableHeaderCellFormatter]
+ },
+ cell: {
+ props: {
+ index: 2
+ },
+ formatters: [
+ (value, { rowData }) => {
+ return [
+
+ {
+ this.props.syntaxes.filter(
+ attr => attr.id === value[0]
+ )[0]["label"]
+ }
+ |
+ ];
+ }
+ ]
+ }
+ },
+ {
+ property: "multivalued",
+ header: {
+ label: "Multivalued",
+ props: {
+ index: 3,
+ rowSpan: 1,
+ colSpan: 1,
+ sort: true
+ },
+ transforms: [],
+ formatters: [],
+ customFormatters: [sortableHeaderCellFormatter]
+ },
+ cell: {
+ props: {
+ index: 3
+ },
+ formatters: [
+ (value, { rowData }) => {
+ return [
{value ? "yes" : "no"} | ];
+ }
+ ]
+ }
+ },
+ {
+ property: "actions",
+ header: {
+ label: "Actions",
+ props: {
+ index: 4,
+ rowSpan: 1,
+ colSpan: 1
+ },
+ formatters: [actionHeaderCellFormatter]
+ },
+ cell: {
+ props: {
+ index: 4
+ },
+ formatters: [
+ (value, { rowData }) => {
+ return [
+
+ {rowData.x_origin === null ||
+ rowData.x_origin === undefined ||
+ rowData.x_origin[0].toLowerCase() != "user defined" ? (
+
+ ) : (
+
+
+
+
+
+ )}
+ |
+ ];
+ }
+ ]
+ }
+ }
+ ]
+ };
+ this.getColumns = this.getColumns.bind(this);
+ }
+
+ getColumns() {
+ return this.state.columns;
+ }
+
+ render() {
+ return (
+
+
+
+ );
+ }
+}
+
+AttributesTable.propTypes = {
+ rows: PropTypes.array,
+ editModalHandler: PropTypes.func,
+ deleteHandler: PropTypes.func,
+ viewModalHandler: PropTypes.func,
+ syntaxes: PropTypes.array,
+ loading: PropTypes.bool
+};
+
+AttributesTable.defaultProps = {
+ rows: [],
+ editModalHandler: noop,
+ deleteHandler: noop,
+ viewModalHandler: noop,
+ syntaxes: [],
+ loading: false
+};
+
+class MatchingRulesTable extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ searchFilterValue: "",
+ fieldsToSearch: ["name", "oid"],
+ columns: [
+ {
+ property: "name",
+ header: {
+ label: "Matching Rule Name",
+ props: {
+ index: 0,
+ rowSpan: 1,
+ colSpan: 1,
+ sort: true
+ },
+ transforms: [],
+ formatters: [],
+ customFormatters: [sortableHeaderCellFormatter]
+ },
+ cell: {
+ props: {
+ index: 0
+ },
+ formatters: [tableCellFormatter]
+ }
+ },
+ {
+ property: "oid",
+ header: {
+ label: "OID",
+ props: {
+ index: 1,
+ rowSpan: 1,
+ colSpan: 1,
+ sort: true
+ },
+ transforms: [],
+ formatters: [],
+ customFormatters: [sortableHeaderCellFormatter]
+ },
+ cell: {
+ props: {
+ index: 1
+ },
+ formatters: [tableCellFormatter]
+ }
+ },
+ {
+ property: "syntax",
+ header: {
+ label: "Syntax",
+ props: {
+ index: 2,
+ rowSpan: 1,
+ colSpan: 1,
+ sort: true
+ },
+ transforms: [],
+ formatters: [],
+ customFormatters: [sortableHeaderCellFormatter]
+ },
+ cell: {
+ props: {
+ index: 2
+ },
+ formatters: [tableCellFormatter]
+ }
+ },
+ {
+ property: "desc",
+ header: {
+ label: "Description",
+ props: {
+ index: 3,
+ rowSpan: 1,
+ colSpan: 1,
+ sort: true
+ },
+ transforms: [],
+ formatters: [],
+ customFormatters: [sortableHeaderCellFormatter]
+ },
+ cell: {
+ props: {
+ index: 3
+ },
+ formatters: [tableCellFormatter]
+ }
+ }
+ ]
+ };
+ this.getColumns = this.getColumns.bind(this);
+ }
+
+ getColumns() {
+ return this.state.columns;
+ }
+
+ render() {
+ return (
+
+
+
+ );
+ }
+}
+
+MatchingRulesTable.propTypes = {
+ rows: PropTypes.array
+};
+
+MatchingRulesTable.defaultProps = {
+ rows: []
+};
+
+export { ObjectClassesTable, AttributesTable, MatchingRulesTable };
diff --git a/src/cockpit/389-console/src/lib/tools.jsx b/src/cockpit/389-console/src/lib/tools.jsx
index 631135e838..7617a78cdf 100644
--- a/src/cockpit/389-console/src/lib/tools.jsx
+++ b/src/cockpit/389-console/src/lib/tools.jsx
@@ -6,7 +6,9 @@ export function searchFilter(searchFilterValue, columnsToSearch, rows) {
if (columnsToSearch && columnsToSearch.length) {
columnsToSearch.forEach(column => {
if (column in row) {
- rowToSearch.push(row[column]);
+ if (row[column] != null) {
+ rowToSearch.push(row[column]);
+ }
}
});
} else {
@@ -53,22 +55,26 @@ export function log_cmd(js_func, desc, cmd_array) {
cmd_list.push(cmd);
}
}
- console.log(
- "CMD: " + js_func + ": " + desc + " ==> " + cmd_list.join(" ")
- );
+ console.log("CMD: " + js_func + ": " + desc + " ==> " + cmd_list.join(" "));
}
}
// Convert DS timestamp to a friendly string: 20180921142257Z -> 10/21/2018, 2:22:57 PM
-export function get_date_string (timestamp) {
+export function get_date_string(timestamp) {
let year = timestamp.substr(0, 4);
let month = timestamp.substr(4, 2);
let day = timestamp.substr(6, 2);
let hour = timestamp.substr(8, 2);
let minute = timestamp.substr(10, 2);
let sec = timestamp.substr(12, 2);
- let date = new Date(parseInt(year), (parseInt(month) - 1), parseInt(day),
- parseInt(hour), parseInt(minute), parseInt(sec));
+ let date = new Date(
+ parseInt(year),
+ parseInt(month) - 1,
+ parseInt(day),
+ parseInt(hour),
+ parseInt(minute),
+ parseInt(sec)
+ );
return date.toLocaleString();
}
@@ -81,8 +87,14 @@ export function get_date_diff(start, end) {
let hour = start.substr(8, 2);
let minute = start.substr(10, 2);
let sec = start.substr(12, 2);
- let startDate = new Date(parseInt(year), parseInt(month), parseInt(day),
- parseInt(hour), parseInt(minute), parseInt(sec));
+ let startDate = new Date(
+ parseInt(year),
+ parseInt(month),
+ parseInt(day),
+ parseInt(hour),
+ parseInt(minute),
+ parseInt(sec)
+ );
// Get the servers current date
year = end.substr(0, 4);
@@ -91,17 +103,23 @@ export function get_date_diff(start, end) {
hour = end.substr(8, 2);
minute = end.substr(10, 2);
sec = end.substr(12, 2);
- let currDate = new Date(parseInt(year), parseInt(month), parseInt(day),
- parseInt(hour), parseInt(minute), parseInt(sec));
+ let currDate = new Date(
+ parseInt(year),
+ parseInt(month),
+ parseInt(day),
+ parseInt(hour),
+ parseInt(minute),
+ parseInt(sec)
+ );
// Generate pretty elapsed time string
- let seconds = Math.floor((currDate - (startDate)) / 1000);
+ let seconds = Math.floor((currDate - startDate) / 1000);
let minutes = Math.floor(seconds / 60);
let hours = Math.floor(minutes / 60);
let days = Math.floor(hours / 24);
- hours = hours - (days * 24);
- minutes = minutes - (days * 24 * 60) - (hours * 60);
- seconds = seconds - (days * 24 * 60 * 60) - (hours * 60 * 60) - (minutes * 60);
+ hours = hours - days * 24;
+ minutes = minutes - days * 24 * 60 - hours * 60;
+ seconds = seconds - days * 24 * 60 * 60 - hours * 60 * 60 - minutes * 60;
return `${days} days, ${hours} hours, ${minutes} minutes, and ${seconds} seconds`;
}
@@ -114,7 +132,7 @@ export function bad_file_name(file_name) {
return false;
}
-export function valid_port (val) {
+export function valid_port(val) {
// Validate value is a number and between 1 and 65535
let result = !isNaN(val);
if (result) {
@@ -125,9 +143,9 @@ export function valid_port (val) {
return result;
}
-export function valid_dn (dn) {
+export function valid_dn(dn) {
// Validate value is a valid DN (sanity validation)
- if (dn.endsWith(',')) {
+ if (dn.endsWith(",")) {
return false;
}
let dn_regex = new RegExp("^([A-Za-z]+=.*)");
diff --git a/src/cockpit/389-console/src/schema.html b/src/cockpit/389-console/src/schema.html
deleted file mode 100644
index cb6baf9fb5..0000000000
--- a/src/cockpit/389-console/src/schema.html
+++ /dev/null
@@ -1,377 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/cockpit/389-console/src/schema.js b/src/cockpit/389-console/src/schema.js
deleted file mode 100644
index ea6159b99d..0000000000
--- a/src/cockpit/389-console/src/schema.js
+++ /dev/null
@@ -1,925 +0,0 @@
-var attr_btn_html =
- '
' +
- '' +
- '' +
- '
';
-
-var attr_btn_html_only_view =
- '
';
-
-var oc_btn_html =
- '
' +
- '' +
- '' +
- '
';
-
-var oc_btn_html_only_view =
- '
';
-
-var schema_oc_table;
-var schema_at_table;
-var schema_mr_table;
-
-var attr_usage_opts = ['userApplications', 'directoryOperation', 'distributedOperation', 'dSAOperation'];
-var oc_kind_opts = ['STRUCTURAL', 'ABSTRACT', 'AUXILIARY'];
-
-function is_x_origin_user_defined(x_origin) {
- if (typeof x_origin === 'string' && x_origin.toLowerCase() !== 'user defined' || x_origin == null) {
- return false;
- } else {
- return true;
- }
-}
-
-// Leave only user defined attributes if the checkbox is crossed
-$.fn.dataTable.ext.search.push(
- function(settings, searchData, index, rowData, counter) {
- var x_origin;
- if ( settings.sTableId == "attr-table" ) {
- if ( $("#attr-user-defined").is(":checked") ) {
- x_origin = rowData[7];
- if (!is_x_origin_user_defined(x_origin)) {
- return false;
- }
- }
- } else {
- if ( $("#oc-user-defined").is(":checked") ) {
- x_origin = rowData[5];
- if (!is_x_origin_user_defined(x_origin)) {
- return false;
- }
- }
- }
- return true;
- }
-);
-
-function clear_oc_form() {
- // Clear input fields and reset dropboxes
- $("#add-edit-oc-header").html('Add Objectclass');
- $(".ds-modal-error").hide();
- $("#oc-name").attr('disabled', false);
- $("#oc-name").val("");
- $("#oc-oid").val("");
- $("#oc-kind").prop('selectedIndex',0);
- $("#oc-desc").val("");
- $("#oc-parent").prop('selectedIndex',0);
- $("#schema-list").prop('selectedIndex',-1);
- $('#oc-required-list').find('option').remove();
- $('#oc-allowed-list').find('option').remove();
- $("#save-oc-button").attr('disabled', false);
-}
-
-function clear_attr_form() {
- // Clear input fields and reset dropboxes
- $("#add-edit-attr-header").html('Add Attribute');
- $(".ds-modal-error").hide();
- $("#attr-name").attr('disabled', false);
- $("#attr-name").val("");
- $("#attr-syntax").val("");
- $("#attr-desc").val("");
- $("#attr-parent").prop('selectedIndex',0);
- $("#attr-usage").prop('selectedIndex',0);
- $("#attr-oid").val("");
- $("#attr-alias").val("");
- $('#attr-multivalued').prop('checked', false);
- $('#attr-no-user-mod').prop('checked', false);
- $("#attr-eq-mr-select").prop('selectedIndex',0);
- $("#attr-order-mr-select").prop('selectedIndex',0);
- $("#attr-sub-mr-select").prop('selectedIndex',0);
- $("#save-attr-button").attr('disabled', false);
-}
-
-function load_schema_objects_to_select(object, select_id, schema_json_select) {
- var data = [];
- for (var i = 0; i < schema_json_select[object].items.length; i++) {
- item = schema_json_select[object].items[i];
- if (item.name) {
- data.push.apply(data, [item.name]);
- } else {
- data.push.apply(data, [item.oid]);
- }
- }
- // Update html select
- $.each(data, function (i, item) {
- $("#" + select_id).append($('
').attr("value", oc_name).text(oc_name);
- $("#oc-parent").append(option);
- }
- $("#save-oc-spinner").hide();
- popup_success("The objectClass was saved in DS");
- $("#add-edit-oc-form").modal('toggle');
- }).
- fail(function(data) {
- $("#save-oc-spinner").hide();
- popup_err("Error", "Failed to save the objectClass\n" + data.message);
- $("#add-edit-oc-form").modal('toggle');
- });
- });
-
- // Required Attributes
- $("#oc-must-add-button").on("click", function () {
- var add_attrs = $("#schema-list").val();
- if (add_attrs && add_attrs != '' && add_attrs.length > 0) {
- for (var i = 0; i < add_attrs.length; i++) {
- if ( $('#oc-required-list option[value="' + add_attrs[i] + '"]').val() === undefined) {
- $('#oc-required-list').append($("
").val(add_attrs[i]).text(add_attrs[i]));
- }
- }
- $("#schema-list").find('option:selected').remove();
- }
- });
- $("#oc-must-remove-button").on("click", function () {
- var add_attrs = $("#oc-required-list").find('option:selected');
- if (add_attrs && add_attrs != '' && add_attrs.length > 0) {
- for (var i = 0; i < add_attrs.length; i++) {
- if ( $('#schema-list option[value="' + add_attrs[i].text + '"]').val() === undefined) {
- $('#schema-list').append($("
").val(add_attrs[i].text).text(add_attrs[i].text));
- }
- }
- }
- $("#oc-required-list").find('option:selected').remove();
- sort_list( $("#schema-list") );
- });
-
- // Allowed Attributes
- $("#oc-may-add-button").on("click", function () {
- var add_attrs = $("#schema-list").val();
- if (add_attrs && add_attrs != '' && add_attrs.length > 0) {
- for (var i = 0; i < add_attrs.length; i++) {
- if ( $('#oc-allowed-list option[value="' + add_attrs[i] + '"]').val() === undefined) {
- $('#oc-allowed-list').append($("
").val(add_attrs[i]).text(add_attrs[i]));
- }
- }
- $("#schema-list").find('option:selected').remove();
- }
- });
- $("#oc-may-remove-button").on("click", function () {
- var add_attrs = $("#oc-allowed-list").find('option:selected');
- if (add_attrs && add_attrs != '' && add_attrs.length > 0) {
- for (var i = 0; i < add_attrs.length; i++) {
- if ( $('#schema-list option[value="' + add_attrs[i].text + '"]').val() === undefined) {
- $('#schema-list').append($("
").val(add_attrs[i].text).text(add_attrs[i].text));
- }
- }
- }
- $("#oc-allowed-list").find('option:selected').remove();
- sort_list( $("#schema-list") );
- });
-
- /*
- *
- * Add Attribute Form
- *
- */
- $("#create-attr-button").on("click", function() {
- clear_attr_form();
- });
-
- $("#save-attr-button").on("click", function() {
- var attr_name = $("#attr-name").val();
- var attr_oid = $("#attr-oid").val();
- var attr_syntax = $("#attr-syntax").val();
- var attr_syntax_text = $("#attr-syntax :selected").text();
- var attr_usage = $('#attr-usage').val();
- var attr_desc = $('#attr-desc').val();
- var attr_x_origin = "user defined";
- var attr_parent = $('#attr-parent').val();
- var attr_aliases = $('#attr-alias').val().split(" ");
- var eq_mr= $('#attr-eq-mr-select').val();
- var order_mr = $('#attr-order-mr-select').val();
- var sub_mr = $('#attr-sub-mr-select').val();
- var multiple = 'no';
- if ( $("#attr-multivalued").is(":checked") ) {
- multiple = 'yes';
- }
- var no_user_mod = false;
- if ( $("#attr-no-user-mod").is(":checked") ) {
- no_user_mod = true;
- }
- var action = 'add';
- var edit = false;
- if ( $("#add-edit-attr-header").text().indexOf("Edit Attribute") != -1){
- edit = true;
- action = 'replace';
- }
-
- if (attr_name == '') {
- report_err($("#attr-name"), 'You must provide an attribute name');
- return;
- }
- if (attr_syntax == '') {
- report_err($("#attr-syntax"), 'You must provide an attribute syntax');
- return;
- }
-
- var cmd = [DSCONF, server_inst, 'schema', 'attributetypes', action, attr_name];
- // Process and validate parameters
- if (attr_aliases) {
- cmd.push.apply(cmd, ["--aliases"]);
- cmd.push.apply(cmd, attr_aliases);
- }
- if (attr_syntax) {
- cmd.push.apply(cmd, ["--syntax", attr_syntax]);
- }
- if (multiple == 'no') {
- cmd.push.apply(cmd, ["--single-value"]);
- } else {
- cmd.push.apply(cmd, ["--multi-value"]);
- }
- if (no_user_mod) {
- cmd.push.apply(cmd, ["--no-user-mod"]);
- } else {
- cmd.push.apply(cmd, ["--user-mod"]);
- }
- cmd.push.apply(cmd, ["--oid", attr_oid]);
- cmd.push.apply(cmd, ["--usage", attr_usage]);
- cmd.push.apply(cmd, ["--sup", attr_parent]);
- cmd.push.apply(cmd, ["--desc", attr_desc]);
- cmd.push.apply(cmd, ["--x-origin", attr_x_origin]);
- cmd.push.apply(cmd, ["--equality"]);
- if (eq_mr) {
- cmd.push.apply(cmd, [eq_mr]);
- } else {
- cmd.push.apply(cmd, [""]);
- }
- cmd.push.apply(cmd, ["--substr"]);
- if (sub_mr) {
- cmd.push.apply(cmd, [sub_mr]);
- } else {
- cmd.push.apply(cmd, [""]);
- }
- cmd.push.apply(cmd, ["--ordering"]);
- if (order_mr) {
- cmd.push.apply(cmd, [order_mr]);
- } else {
- cmd.push.apply(cmd, [""]);
- }
- $("#save-attr-spinner").show();
- log_cmd('#save-attr-button (click)', 'Save attribute', cmd);
- cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV]}).
- done(function(data) {
- var attr_syntax_name = '
' +
- attr_syntax_text.substr(0, attr_syntax_text.indexOf(" (")) + '
';
- $("#attr-name").attr('disabled', false);
- // Update html table (if edit: delete old then add new)
- if ( edit ) {
- var selector = $('tr:contains(' + attr_name + ')');
- schema_at_table.row(selector).remove().draw(false);
- }
- var cmd = [DSCONF, '-j', 'ldapi://%2fvar%2frun%2f' + server_id + '.socket', 'schema', 'attributetypes', 'query', attr_name];
- log_cmd('#save-oc-button (click)', 'Get attribute', cmd);
- cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV]}).
- done(function(at_data) {
- var obj = JSON.parse(at_data);
- var item = obj.at;
- schema_at_table.row.add( [
- item.name,
- item.oid,
- attr_syntax_name,
- multiple,
- attr_btn_html,
- item.desc,
- item.aliases,
- item.x_origin,
- attr_usage_opts[item.usage],
- item.no_user_mod,
- item.sup,
- item.equality,
- item.ordering,
- item.substr,
-
- ] ).draw( false );
- $("#attr-name").attr('disabled', false);
- }).
- fail(function(at_data) {
- popup_err("err", at_data.message);
- console.log("Query attributes failed: " + at_data.message);
- check_inst_alive(1);
- });
- if (!edit) {
- var option = $('
').attr("value", attr_name).text(attr_name);
- $("#schema-list").append(option);
- }
- $("#save-attr-spinner").hide();
- popup_success("The attribute was saved in DS");
- $("#add-edit-attr-form").modal('toggle');
- }).
- fail(function(data) {
- $("#save-attr-spinner").hide();
- popup_err("Error", "Failed to save the attribute: " + data.message);
- $("#add-edit-attr-form").modal('toggle');
- });
- });
-
- function load_attr_form(element) {
- clear_attr_form();
- var data = schema_at_table.row(element.parents('tr') ).data();
- var edit_attr_name = data[0];
- var edit_attr_oid = data[1];
- var edit_attr_syntax = $.parseHTML(data[2])[0].title;
- var edit_attr_multivalued = data[3];
- var edit_attr_desc = data[5];
- var edit_attr_aliases = data[6];
- var edit_attr_x_origin = data[7];
- var edit_attr_usage = data[8];
- var edit_attr_no_user_mod = data[9];
- var edit_attr_parent = data[10];
- var edit_attr_eq_mr = data[11];
- var edit_attr_order_mr = data[12];
- var edit_attr_sub_mr = data[13];
-
- $("#add-edit-attr-header").html('Edit Attribute: ' + edit_attr_name);
- $("#attr-name").val(edit_attr_name);
- $("#attr-name").attr('disabled', true);
- $("#attr-oid").val(edit_attr_oid);
- $("#attr-usage")[0].value = edit_attr_usage;
- $("#attr-parent")[0].value = edit_attr_parent;
- $("#attr-desc").val(edit_attr_desc);
- if (edit_attr_aliases) {
- $("#attr-alias").val(edit_attr_aliases.join(" "));
- }
- $("#attr-syntax").val(edit_attr_syntax);
- $("#attr-multivalued").prop('checked', false);
- if (edit_attr_multivalued == "yes") {
- $("#attr-multivalued").prop('checked', true);
- }
- $("#attr-no-user-mod").prop('checked', false);
- if (edit_attr_no_user_mod) {
- $("#attr-no-user-mod").prop('checked', true);
- }
- $("#save-attr-spinner").show();
- $("#attr-eq-mr-select")[0].value = edit_attr_eq_mr;
- $("#attr-order-mr-select")[0].value = edit_attr_order_mr;
- $("#attr-sub-mr-select")[0].value = edit_attr_sub_mr;
- $("#save-attr-spinner").hide();
-
- $("#add-edit-attr-form").modal('toggle');
- }
-
- function load_view_attr_form(element) {
- clear_attr_form();
- var data = schema_at_table.row(element.parents('tr') ).data();
- var edit_attr_name = data[0];
- var edit_attr_oid = data[1];
- var edit_attr_syntax = $.parseHTML(data[2])[0].title;
- var edit_attr_multivalued = data[3];
- var edit_attr_desc = data[5];
- var edit_attr_aliases = data[6];
- var edit_attr_x_origin = data[7];
- var edit_attr_usage = data[8];
- var edit_attr_no_user_mod = data[9];
- var edit_attr_parent = data[10];
- var edit_attr_eq_mr = data[11];
- var edit_attr_order_mr = data[12];
- var edit_attr_sub_mr = data[13];
-
- $("#attr-name-view").val(edit_attr_name);
- $("#attr-oid-view").val(edit_attr_oid);
- $("#attr-usage-view")[0].value = edit_attr_usage;
- $("#attr-parent-view")[0].value = edit_attr_parent;
- $("#attr-desc-view").val(edit_attr_desc);
- if (edit_attr_aliases) {
- $("#attr-alias-view").val(edit_attr_aliases.join(" "));
- }
- $("#attr-syntax-view").val(edit_attr_syntax);
- $("#attr-multivalued-view").prop('checked', false);
- if (edit_attr_multivalued == "yes") {
- $("#attr-multivalued-view").prop('checked', true);
- }
- $("#attr-no-user-mod-view").prop('checked', false);
- if (edit_attr_no_user_mod) {
- $("#attr-no-user-mod-view").prop('checked', true);
- }
- $("#attr-eq-mr-select-view").val(edit_attr_eq_mr);
- $("#attr-order-mr-select-view").val(edit_attr_order_mr);
- $("#attr-sub-mr-select-view").val(edit_attr_sub_mr);
-
- $("#view-attr-form").modal('toggle');
- }
-
- $(document).on('click', '.attr-view-btn', function(e) {
- e.preventDefault();
- load_view_attr_form($(this));
- });
-
- $(document).on('click', '.attr-edit-btn', function(e) {
- e.preventDefault();
- load_attr_form($(this));
- });
-
- $(document).on('click', '.attr-del-btn', function(e) {
- e.preventDefault();
- var data = schema_at_table.row( $(this).parents('tr') ).data();
- var del_attr_name = data[0];
- var at_row = $(this);
- popup_confirm("Are you sure you want to delete attribute:
" + del_attr_name + "", "Confirmation", function (yes) {
- if (yes) {
- var cmd = [DSCONF, '-j', 'ldapi://%2fvar%2frun%2f' + server_id + '.socket', 'schema', 'attributetypes', 'remove', del_attr_name];
- log_cmd('.attr-del-btn (click)', 'Remove attribute', cmd);
- cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV]}).done(function(data) {
- popup_success("Attribute was successfully removed!");
- schema_at_table.row( at_row.parents('tr') ).remove().draw( false );
- $("#schema-list option[value='" + del_attr_name + "']").remove();
- }).fail(function(data) {
- popup_err("Attribute removal error", del_attr_name + " removal has failed: " + data.message);
- });
- }
- });
- });
-
- function load_view_oc_form(element) {
- clear_oc_form();
- var data = schema_oc_table.row(element.parents('tr') ).data();
- var edit_oc_name = data[0];
- var edit_oc_oid = data[1];
- var edit_oc_required = data[2].split(" ");
- var edit_oc_allowed = data[3].split(" ");
- var edit_oc_x_origin = data[5];
- var edit_oc_kind = data[6];
- var edit_oc_desc = data[7];
- var edit_oc_parent = data[8];
-
- $("#oc-name-view").val(edit_oc_name);
- $("#oc-oid-view").val(edit_oc_oid);
- $("#oc-kind-view")[0].value = edit_oc_kind;
- $("#oc-desc-view").val(edit_oc_desc);
- $("#oc-parent-view")[0].value = edit_oc_parent;
- $.each(edit_oc_required, function (i, item) {
- if (item) {
- $("#oc-required-list-view").append($('