Skip to content

Commit

Permalink
Allow groups in xwd to be nested and display correctly in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
FayCross committed Jul 13, 2022
1 parent 66cb2e5 commit 74d8753
Show file tree
Hide file tree
Showing 7 changed files with 311 additions and 265 deletions.
8 changes: 6 additions & 2 deletions editor/css/complex.css
Expand Up @@ -727,6 +727,10 @@ td.wizardlabel {
min-width: 155px;
}

.wizardgroup .column_table td.wizardlabel {
min-width: auto;
}

td.wizardvalue {
}

Expand All @@ -740,12 +744,12 @@ fieldset.wizardgroup.collapsed {
border-top-color: #ccc;
}

fieldset.wizardgroup legend {
fieldset.wizardgroup legend.noindent {
padding-right: 10px;
cursor: pointer;
}

fieldset.wizardgroup.wizardoptional legend {
fieldset.wizardgroup.wizardoptional legend.noindent {
margin-left: -17px;
}

Expand Down
65 changes: 32 additions & 33 deletions editor/js/language.js
Expand Up @@ -122,32 +122,34 @@ var EDITOR = (function ($, parent) {
{
menu_data.menu[i].submenu.sort(compare);
}

$($(this).children()).each(function() {
//console.log(" sub node: " + $(this)[0].nodeName);
var node_params = {};
for (var j=0, a=$(this)[0].attributes; j<a.length; j++) {
node_params[a[j].name] = a[j].value;
}
all_options.push({name: $(this)[0].nodeName, value: node_params});

// include the children of property groups
if (node_params.type == "group" && $(this).children().length > 0) {
for (var k=0; k<$(this).children().length; k++) {
var child_node_params = {};
for (var j=0, a=$(this).children()[k].attributes; j<a.length; j++) {
child_node_params[a[j].name] = a[j].value;
}
child_node_params.group = $(this)[0].nodeName;

function setUpOptions (node, isGroup, groupName) {
$($(node).children()).each(function() {
//console.log(" sub node: " + $(this)[0].nodeName);
var node_params = {};
for (var j=0, a=$(this)[0].attributes; j<a.length; j++) {
node_params[a[j].name] = a[j].value;
}

if (isGroup == true) {
node_params.group = groupName;

if (node_params.optional == "true") {
child_node_params.optional = node_params.optional;
if (parent.optional == "true") {
node_params.optional = node_params.optional;
}

all_options.push({name: $(this).children()[k].nodeName, value: child_node_params});
}
}
});
all_options.push({name: $(this)[0].nodeName, value: node_params});

// include the children of property groups
if (node_params.type == "group" && $(this).children().length > 0) {
setUpOptions(this, true, $(this)[0].nodeName);
// setUpOptions(this, true, (groupName == undefined ? '' : groupName + '.') + $(this)[0].nodeName);
}
});

}

setUpOptions(this);

// search attribute name and put that as the first one
$(all_options).each(function(key, option) {
Expand Down Expand Up @@ -204,7 +206,7 @@ var EDITOR = (function ($, parent) {
});
//wizard_data.menus = String(wizard_xml[0].attributes["menus"].value).split(',');

// Now add whether apge should be visible according to simple_mode and templates_sub_pages
// Now add whether page should be visible according to simple_mode and templates_sub_pages
if (simple_mode) {
$(menu_data.menu).each(function (i, menu) {
var enabled = false;
Expand All @@ -231,8 +233,6 @@ var EDITOR = (function ($, parent) {


process_language_file = function (xml) {
console.log(languagecodevariable + " language file is loaded...");

// Parse the file
var x2js = new X2JS({
// XML attributes. Default is "_"
Expand All @@ -243,7 +243,6 @@ var EDITOR = (function ($, parent) {
},

process_language_fallback = function (xml) {
console.log("en_GB fall-back language file is loaded...");
// Parse the file
var x2js = new X2JS({
// XML attributes. Default is "_"
Expand All @@ -265,14 +264,14 @@ var EDITOR = (function ($, parent) {
// set language_def
language = selected_language;
}
console.log("language files are merged:");
console.log(language);

//console.log("language files are merged:");
//console.log(language);
waitonlanguage();
},

process_data_xwd = function (xml) {
console.log("data.xwd is loaded...");
//console.log("data.xwd is loaded...");

var wizard_xml = $($.parseXML(xml)).find("wizard");

Expand All @@ -282,7 +281,7 @@ var EDITOR = (function ($, parent) {
},

process_config_file = function (xml) {
console.log("config file is loaded...");
//console.log("config file is loaded...");

// Used by the language selection box, ref. EDITOR.displayDataType (toolbox.js)
installed_languages = [];
Expand Down Expand Up @@ -399,7 +398,7 @@ var EDITOR = (function ($, parent) {
type: "GET",
url: _this.u,
dataType: "text",
success: function (data) { //console.log("**** " + _this.u); console.log(data);
success: function (data) {
_this.loaded = true;
_this.c(data);
}
Expand Down
141 changes: 82 additions & 59 deletions editor/js/toolbox.js
Expand Up @@ -325,7 +325,7 @@ var EDITOR = (function ($, parent) {
}
},

// ** Recursive function to traverse the xml and build
// Recursive function to traverse the xml and build
build_lo_data = function (xmlData, parent_id) {

// First lets generate a unique key
Expand Down Expand Up @@ -650,15 +650,6 @@ var EDITOR = (function ($, parent) {
}

if (options.type.toLowerCase() === "info") {
/*
var tdlabel = $('<td colspan="2" class="wizardparameter explanation">')
.append('<p>' + label + '</p>');
if (options.tooltip) {
$('<i class="tooltipIcon iconEnabled fa fa-info-circle"></i>')
.attr('title', options.tooltip)
.appendTo(tdlabel);
}
*/
tdlabel.attr("colspan", "2");
tr.append(tdlabel)
}
Expand Down Expand Up @@ -700,14 +691,18 @@ var EDITOR = (function ($, parent) {
.attr('title', options.deprecated)
.addClass("deprecated"));

if (options.optional == 'true') {
legend.prepend($('<i>')
.attr('id', 'optbtn_' + name)
.addClass('fa')
.addClass('fa-trash')
.addClass("xerte-icon")
.height(14)
.addClass("optional"));
if (options.optional == 'true' && options.group == undefined) { // nested groups don't have delete btn
legend
.addClass('noindent')
.prepend($('<i>')
.attr('id', 'optbtn_' + name)
.addClass('fa')
.addClass('fa-trash')
.addClass("xerte-icon")
.height(14)
.addClass("optional"));
} else {
group.addClass("wizardnestedgroup");
}

legend.append('<span class="legend_label">' + options.label + '</span>');
Expand All @@ -717,16 +712,22 @@ var EDITOR = (function ($, parent) {
.addClass("wizarddeprecated")

} else if (options.optional == 'true') {

group.addClass("wizardoptional")

legend
.append($('<i>')
.attr('id', 'optbtn_' + name)
.addClass('fa')
.addClass('fa-trash')
.addClass("xerte-icon")
.height(14)
.addClass("optional"));

if (options.group == undefined) { // nested groups don't have delete btn
legend
.addClass('noindent')
.append($('<i>')
.attr('id', 'optbtn_' + name)
.addClass('fa')
.addClass('fa-trash')
.addClass("xerte-icon")
.height(14)
.addClass("optional"));
} else {
group.addClass("wizardnestedgroup");
}

group.find('legend').append('<span class="legend_label">' + options.label + '</span>');

Expand All @@ -748,31 +749,33 @@ var EDITOR = (function ($, parent) {
.appendTo(legend.find('.legend_label'));
}

$('<i class="minMaxIcon fa fa-caret-up"></i>').appendTo(legend.find('.legend_label'));

legend.find('.legend_label').click(function() {
var $icon = $(this).find('i.minMaxIcon');
var $fieldset = $(this).parents('fieldset');
if (options.group == undefined) { // nested groups aren't collapsible
$('<i class="minMaxIcon fa fa-caret-up"></i>').appendTo(legend.find('.legend_label'));

legend.find('.legend_label').click(function() {
var $icon = $(this).find('i.minMaxIcon');
var $fieldset = $(this).parents('fieldset');

if ($fieldset.find('.table_holder').is(':visible')) {
$fieldset.find('.table_holder').slideUp(400, function() {
$icon
.removeClass('fa-caret-up')
.addClass('fa-caret-down');
if ($fieldset.find('.table_holder').is(':visible')) {
$fieldset.find('.table_holder').slideUp(400, function() {
$icon
.removeClass('fa-caret-up')
.addClass('fa-caret-down');

$fieldset.addClass('collapsed');
});
$fieldset.addClass('collapsed');
});

} else {
$fieldset.find('.table_holder').slideDown(400);
} else {
$fieldset.find('.table_holder').slideDown(400);

$icon
.removeClass('fa-caret-down')
.addClass('fa-caret-up');
$icon
.removeClass('fa-caret-down')
.addClass('fa-caret-up');

$fieldset.removeClass('collapsed');
}
});
$fieldset.removeClass('collapsed');
}
});
}

var info = "";
if (options.info) info = '<div class="group_info">' + options.info + '</div>';
Expand All @@ -793,8 +796,12 @@ var EDITOR = (function ($, parent) {
.append(group_table)
);
}

$(id).append(tr);

if (options.group == undefined) {
$(id).append(tr);
} else {
$('#groupTable_' + options.group).append(tr);
}

if (options.optional == 'true') {
$("#optbtn_" + name).on("click", function () {
Expand Down Expand Up @@ -822,17 +829,34 @@ var EDITOR = (function ($, parent) {
},

removeOptionalProperty = function (name, children) {

if (!confirm('Are you sure?')) {
return;
}

var toDelete = [];

// if it's a group being deleted then remove all of its children
// including children of nested groups
if (children) {
for (var i=0; i<children.length; i++) {
toDelete.push(children[i].name);

function getChildren(groupChildren) {
for (var i=0; i<groupChildren.length; i++) {

if (groupChildren[i].value.type == "group") {

getChildren(groupChildren[i].value.children);

} else {

toDelete.push(groupChildren[i].name);

}
}
}

getChildren(children);

} else {
toDelete.push(name);
}
Expand Down Expand Up @@ -2124,9 +2148,9 @@ var EDITOR = (function ($, parent) {
if (actvalue.indexOf('FileLocation +') >=0)
{
// Make sure the &#39; is translated to a '
console.log("Convert " + actvalue);
//console.log("Convert " + actvalue);
actvalue = $('<textarea/>').html(actvalue).val();
console.log(" ..to " + actvalue);
//console.log(" ..to " + actvalue);
}
setAttributeValue(key, [name], [actvalue]);
},
Expand Down Expand Up @@ -2181,9 +2205,9 @@ var EDITOR = (function ($, parent) {
if (actvalue.indexOf('FileLocation +') >=0)
{
// Make sure the &#39; is translated to a '
console.log("Convert " + actvalue);
//console.log("Convert " + actvalue);
actvalue = $('<textarea/>').html(actvalue).val();
console.log(" ..to " + actvalue);
//console.log(" ..to " + actvalue);
}
setAttributeValue(key, [name], [actvalue]);
},
Expand Down Expand Up @@ -2289,11 +2313,11 @@ var EDITOR = (function ($, parent) {
},

editDrawing = function(id, key, name, value){
console.log('Edit drawing: ' + id + ': ' + key + ', ' + name);
//console.log('Edit drawing: ' + id + ': ' + key + ', ' + name);
window.XOT = {};
window.XOT.callBack = function(key, name, xmldata) {
// Actions with url parameter here
console.log('Save drawing file: ' + key + ', ' + name);
//console.log('Save drawing file: ' + key + ', ' + name);
setAttributeValue(key, [name], [xmldata]);
// Refresh form, otherwise the value passed by the Edit button to the drawingEditor when the button is paused again
parent.tree.showNodeData(key);
Expand Down Expand Up @@ -2425,11 +2449,10 @@ var EDITOR = (function ($, parent) {

$.each(lo_node.children, function(i, key){
var name = getAttributeValue(lo_data[key]['attributes'], 'name', [], key);
/*var pageID = getAttributeValue(lo_data[key]['attributes'], 'pageID', [], key);*/
var linkID = getAttributeValue(lo_data[key]['attributes'], 'linkID', [], key);
var hidden = lo_data[key]['attributes'].hidePage;

if (/*(pageID.found && pageID.value != "") || */(linkID.found && linkID.value != ""))
if (linkID.found && linkID.value != "")
{

var page = [];
Expand Down

0 comments on commit 74d8753

Please sign in to comment.