-
Notifications
You must be signed in to change notification settings - Fork 72
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
base: main
Are you sure you want to change the base?
Conversation
mhoesche
commented
Feb 22, 2018
- 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)
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)
There was a problem hiding this 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
src/abstract_xml_object.js
Outdated
// Set width of generated fields manually. | ||
if (this.objectType.attribute && startingValue) { | ||
var len = startingValue.length * 10; | ||
if (len < 80) { len = 80; } |
There was a problem hiding this comment.
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 {
}
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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)
src/xml_unspecified_element.js
Outdated
@@ -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)); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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', { |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
src/jquery.xmleditor.js
Outdated
@@ -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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
src/xml_element.js
Outdated
@@ -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(){ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
src/xml_templates.js
Outdated
@@ -3,6 +3,7 @@ | |||
* @param init_object | |||
* @constructor | |||
*/ | |||
|
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
I updated / changed most of your comments and committed them to my branch. As I am not so familiar with GIT/GITHUB yet... do I need to pull the updated forked branch again? |
Added textmode active first demo
Fixed some build issues, as rake doesn't work for me
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. |