Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added options to translate the UI (German+English included) and control the UI a bit more #97

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

mhoesche
Copy link

  • Added translations to the UI - included English "en" and German "de"
  • Added readonly mode for the XML and Text editor
  • Added switches to hide UI elements when not needed
  • Added parameter to choose the initial display (XML or Text)

mhoesche and others added 3 commits February 22, 2018 13:41
Added readonly mode for the editor
Added switches to hide UI elements when not needed
Added parameter to choose the initial display (XML or Text)
Copy link
Member

@bbpennel bbpennel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for your interested in the XML editor! This PR introduces some valuable changes. I have added a number of comments and change requests

// Set width of generated fields manually.
if (this.objectType.attribute && startingValue) {
var len = startingValue.length * 10;
if (len < 80) { len = 80; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please expand the code blocks to

if () {
  // code
} else {

}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review.
Yes, sure - I will update. Tried to copy the used style, but here and there I oversaw something...

showExport: true,

// Switch to readonly mode
enableEdit: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good idea, but needs to be expanded. There are keyboard commands for editing the document that still work in readOnly mode. For instance, pressing enter/return will add a new element to the document in the "Design" mode ("XML" mode on master).

I would suggest checking for this flag in the add methods in jquery.xmleditor.js (addNode, addAttribute, addChildElement, etc)

@@ -88,7 +88,7 @@ XMLUnspecifiedElement.prototype.addContentContainers = function (recursive) {
var placeholder = document.createElement('div');
placeholder.className = 'placeholder';

placeholder.appendChild(document.createTextNode('Use the menu to add contents.'));
placeholder.appendChild(document.createTextNode(this.editor.options.i18n[this.options.userLang].useMenuToAddContents));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is causing an exception in /demo/mods.html, TypeError: this.options is undefined, it should be this.editor.options

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, wrong reference... will fix.

@@ -42,32 +42,32 @@ AddNodeMenu.prototype.populate = function(xmlElement) {
}

if (xmlElement.allowChildren) {
$("<li>Add Element</li>").data('xml', {
$("<li>" + this.editor.options.i18n[this.editor.options.userLang].addElement + "</li>").data('xml', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you feel about shortening this into either a function like
this.editor.i18n("addElement") or a constant that gets set at startup like this.editor.i18n.addElement? Its pretty... substantial to see everywhere :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good, but I am not so much into JavaScript (actually as a Java developer, I was happy to get this far...).
Probably something to work on for the next major rework.

@@ -1196,22 +1504,31 @@ $.widget( "xml.xmlEditor", {
// Menu Update functions
refreshMenuUndo: function(self) {
if (self.undoHistory.headIndex > 0) {
$("#" + xmlMenuHeaderPrefix + "Undo").removeClass("disabled").data("menuItemData").enabled = true;
$("#" + xmlMenuHeaderPrefix + self.options.i18n[self.options.userLang].undoMenuitem.replaceAll(' ','_')).removeClass("disabled").data("menuItemData").enabled = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if it is necessary to translate the id's of these elements? It seems like it might make styling of event binding more challenging.

Copy link
Author

@mhoesche mhoesche Mar 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, as long as menu_data.js has only the property "label", which is shown and translated, yes. But I consider changing this and have an additional "id" property for the menu-items that can be set here...

xsd/xsd2json.js Outdated
@@ -1,5 +1,5 @@
;var Xsd2Json = function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the compiled file, to edit you should update xsd/src/xsd2json.js instead. Run rake xsd2json.js in order to build this file, and commit the updated version. Sorry for the confusion.

@@ -223,6 +224,14 @@ XMLElement.prototype.populateChildren = function() {
}
}
});
// Patch to add "required" attributes. Does require a secondary change to know the "use" attribute also. See xsd2json-use.js : SchemaProcessor.prototype.createDefinition
$.each(this.objectType.attributes, function(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a fairly significant change that wasn't mentioned in the commits. I'm not opposed to auto-populating required attributes, which a number of people have requested. But I can't seem to get this to work, do you have any example schema where this is adding in attributes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was accidentially placed here - was a special use case I didn't plan to bring in here. But I will add a example with an XSD in the demo block.
Will add a switch, to turn this off (which I set to off/false)

deleteButton.appendChild(document.createTextNode('X'));
topActionSpan.appendChild(deleteButton);

if (this.editor.options.enableEdit) { // Only show menu entries in edit mode, not readonly mode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are also keyboard shortcuts that perform these actions which will still be active. I'd suggest updating the action methods to prevent them from making changes. See GUIEditor.prototype.deleteSelected and similar methods.

@@ -3,6 +3,7 @@
* @param init_object
* @constructor
*/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove line

@@ -46,17 +47,30 @@ AbstractXMLObject.prototype.createElementInput = function (inputID, startingValu
|| this.objectType.attribute || this.objectType.cdata || this.objectType.comment){
input = document.createElement('textarea');
input.id = inputID;
input.rows = 1; // added start size of 1 row
input.style.height = '18px'; // Predefined height for 1 row. Will be expanded using jQuery.autosize
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it work for you to override the height setting in the .attribute_container > textarea rule instead? Just a bit iffy on hardcoding a height in here unless necessary

@mhoesche
Copy link
Author

mhoesche commented Mar 1, 2018

I updated / changed most of your comments and committed them to my branch.
Some things have not changed: e.g. the ones where I did not place a comment above.

As I am not so familiar with GIT/GITHUB yet... do I need to pull the updated forked branch again?

@bbpennel
Copy link
Member

Sorry for the long delay, I tried reviewing this again, but it is difficult to do because this branch how so many changes on it. Would you be willing to break this PR up? A good first PR would be one that just adds the internationalization and german translation feature. After that, we could look at the read only mode, disabling the various views, etc in separate PRs.

@lfarrell lfarrell changed the base branch from master to main March 10, 2021 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants