Ability to Set Loading Option Depending on Presence of Attribute in DITA
Are you missing a feature? Request its implementation here.
-
- Posts: 171
- Joined: Thu Aug 30, 2018 10:06 pm
Ability to Set Loading Option Depending on Presence of Attribute in DITA
Post by dreifsnider »
Hi Oxygen Support,
This question is related to my post about using xml:lang CSS selector: common-problems-f34/topic27291.html
We have DITA topics whose contents have been translated. To indicate this, we've added a new attribute to our custom DITA schema called "translated" that supports a single value of "yes". We typically set this attribute on the root <topic> element.
We would now like our SMEs to review the translated content in Web Author; however, since the translated content is not the actual source content, we want to prevent SMEs from editing the topic's contents.
To achieve this, I've attempted to use a plugin to control the loading options and set the editing mode to "review" and to set trackedChanges to "forced" if any element has the attribute "translated".
For example, here's my plugin JS code:
I noticed that the "translated" attribute is converted into "data-attr-translated" when Web Author is rendered, hence my use of "data-attr-translated".
Do you have any suggestions for how we can set the editing mode to "review" and trackChanges to "forced" if any element in the topic has the translated attribute?
Thanks!
Daniel
This question is related to my post about using xml:lang CSS selector: common-problems-f34/topic27291.html
We have DITA topics whose contents have been translated. To indicate this, we've added a new attribute to our custom DITA schema called "translated" that supports a single value of "yes". We typically set this attribute on the root <topic> element.
We would now like our SMEs to review the translated content in Web Author; however, since the translated content is not the actual source content, we want to prevent SMEs from editing the topic's contents.
To achieve this, I've attempted to use a plugin to control the loading options and set the editing mode to "review" and to set trackedChanges to "forced" if any element has the attribute "translated".
For example, here's my plugin JS code:
Code: Select all
function checkIfAttributeExists(attributeName) {
const elements = document.querySelectorAll(`[${attributeName}]`);
return elements.length > 0;
}
const attributeToCheck = "data-attr-translated";
const hasAttribute = checkIfAttributeExists(attributeToCheck);
goog.events.listen(workspace, sync.api.Workspace.EventType.BEFORE_EDITOR_LOADED, function(e) {
if (e.options.url.includes('.dita')) {
e.options['showDitaMapView'] = 'true';
if (hasAttribute) {
e.options.trackChanges = 'forced'
e.options.modes = 'review'
} else {
e.options.trackChanges = 'enabled'
}
}
});
Do you have any suggestions for how we can set the editing mode to "review" and trackChanges to "forced" if any element in the topic has the translated attribute?
Thanks!
Daniel
-
- Posts: 515
- Joined: Wed May 20, 2009 2:40 pm
Re: Ability to Set Loading Option Depending on Presence of Attribute in DITA
Hi,
The event that you are listening is BEFORE_EDITOR_LOADED and at this moment the document is not loaded.
Ty to change it to EDITOR_LOADED and set the trackChanges to 'forced' (setting the reiew mode at this point will not have an effect).
Is this solution ok for your use case or is absolutly necessary to impose also the reiew mode?
Best Regards,
Mihaela
The event that you are listening is BEFORE_EDITOR_LOADED and at this moment the document is not loaded.
Ty to change it to EDITOR_LOADED and set the trackChanges to 'forced' (setting the reiew mode at this point will not have an effect).
Is this solution ok for your use case or is absolutly necessary to impose also the reiew mode?
Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
http://www.oxygenxml.com
-
- Posts: 171
- Joined: Thu Aug 30, 2018 10:06 pm
Re: Ability to Set Loading Option Depending on Presence of Attribute in DITA
Post by dreifsnider »
Hi Mihaela,
Thank you very much for your reply.
I tried changing the listener to EDITOR_LOADED, but unfortunately, this also doesn't seem to work. The console throws the error "Cannot set properties of undefined (setting 'trackChanges')":
Here is my updated JS:
As you can see, I'm also using the BEFORE_EDITOR_LOADED listener to set a couple of other loading options. Could this be causing the issue?
Thanks!
Daniel
Thank you very much for your reply.
I tried changing the listener to EDITOR_LOADED, but unfortunately, this also doesn't seem to work. The console throws the error "Cannot set properties of undefined (setting 'trackChanges')":
image.png
which leads me to believe that loading options is not supported in the EDITOR_LOADED listener.Here is my updated JS:
Code: Select all
goog.events.listen(workspace, sync.api.Workspace.EventType.BEFORE_EDITOR_LOADED, function(e) {
let editTopicContents = new URLSearchParams(window.location.search).has('editReferencesInPlace');
if (e.options.url.includes('.dita')) {
// Open DITA Map View automatically
e.options['showDitaMapView'] = 'true';
}
if (e.options.url.endsWith('.ditamap')) {
// Open DITA Map View automatically and set view mode to show topic titles
e.options['showDitaMapView'] = 'true';
e.options['showTopicTitles'] = 'true';
if (editTopicContents) {
e.options.trackChanges = 'enabled';
} else {
e.options.trackChanges = 'default';
}
}
});
workspace.listen(sync.api.Workspace.EventType.EDITOR_LOADED, function(e) {
function checkIfAttributeExists(attributeName) {
const elements = document.querySelectorAll(`[${attributeName}]`);
return elements.length > 0;
}
const attributeToCheck = "data-attr-translated";
const hasAttribute = checkIfAttributeExists(attributeToCheck);
if (hasAttribute) {
e.options.trackChanges = 'forced';
} else {
e.options.trackChanges = 'default';
}
});
Thanks!
Daniel
You do not have the required permissions to view the files attached to this post.
-
- Posts: 515
- Joined: Wed May 20, 2009 2:40 pm
Re: Ability to Set Loading Option Depending on Presence of Attribute in DITA
Hello,
To impose the track changes state on editor loaded you have to do this:
Best Regards,
Mihaela
To impose the track changes state on editor loaded you have to do this:
Code: Select all
e.editor.options.trackChanges = "forced";
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
http://www.oxygenxml.com
-
- Posts: 171
- Joined: Thu Aug 30, 2018 10:06 pm
Re: Ability to Set Loading Option Depending on Presence of Attribute in DITA
Post by dreifsnider »
Hi Mihaela,
Thank you very much for your reply.
This worked perfectly and I'm now able to set the trackChanges option according to the presence of the attribute.
Thank you again!
Daniel
Thank you very much for your reply.
This worked perfectly and I'm now able to set the trackChanges option according to the presence of the attribute.
Thank you again!
Daniel
-
- Posts: 515
- Joined: Wed May 20, 2009 2:40 pm
Re: Ability to Set Loading Option Depending on Presence of Attribute in DITA
Hi Daniel,
I am glad that the solution worked.
Please let us know when you have any other question.
Best Regards,
Mihaela
I am glad that the solution worked.
Please let us know when you have any other question.
Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service