cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

XUI dynamic combobox via ACL and JavaScript

ptc-1958594
1-Newbie

XUI dynamic combobox via ACL and JavaScript

Adepters,

please help me with the following issue. I tried to develope adynamic combobox that allowes comfortable selection of "target-IDs" relating to cross references and jump marks. Unfortunately I stuck at 80% of the entire script.

So here is what happened until now:

ACL-Code that creates the $DialogWindow by calling doc_open($XMLDialogPath,1).
This script works fine as fare as I can see:


function my_dlgitem_callback(win, dlgitem, event, data, appdata){
# possible event/s: ITEM_CHANGED, ITEM_FOCUSED, and ITEM_UNFOCUSED
if(dlgitem == 'OKbutton' && event=='ITEM_CHANGED'){

$CombSelValue = dlgitem_get(win, 'tarbox', 'TEXT');
modify_tag Idref=$CombSelValue;

event_stop_process(1)
}
}

function CreateDialogAbsprungmarke(oid){

$XMLDialogPath = 'C:\Programme\Epic\custom\dialogs\absprungmarke.xml';
$DialogDoc = doc_open($XMLDialogPath,1);
$DialogWindow = window_create('xui',0x10,$DialogDoc);

# DialogWindow.dlgitem_set_value($DialogWindow, "tarbox", "test.123");

$currentOid = $oid;

# callbacks
dlgitem_add_callback($DialogWindow, 'OKbutton', 'my_dlgitem_callback');

# show dialog window
window_show($DialogWindow,1);

# Stop execution of ACL until OK-button was pressed
event_process();

response("And so on...");

}

The XUI-XML-File includes the JavaScript that offers the IDs: from the current document:


<window focus="tarbox" id="tarid" modal="false" orient="vertical" title="TargetID wählen:">

<combobox id="tarbox" type="dropdown" value="id...">

combobox>

<button label="OK" type="accept" id="OKbutton">

<script type="application/x-javascript" ev:event="domactivate">

<script type="application/x-javascript" ev:event="domactivate">

var doc = Application.activeDocument;

var tags = doc.getElementsByAttribute("ID-Ueberschrift",",0);

// var CurrentDialogDoc = Application.event.target.ownerDocument; ???

var CurrentDialogDoc = "C:\\Programme\\Epic\\custom\\dialogs\\absprungmarke.xml";

var xmlDoc = Application.openDocument(CurrentDialogDoc,(0,0001));

for (i=0; i<tags.length; i++)=" {<=" p=">

var CurrentNode = tags.item(i).firstChild;

if(CurrentNode.nodeType == CurrentNode.TEXT_NODE){

ComboNode = xmlDoc.getElementById("tarbox");

listNode = xmlDoc.createElement("listitem");

ComboNode.appendChild(listNode);

listNode.setAttribute("label", tags.item(i).getAttribute('ID-Ueberschrift'));

} else {

// print(CurrentNode.firstChild.NodeType);

}

}

script>

button>

window>


Is it possible to modify the XUI-dialog without opening the same xui-file a second time?

How canI point the current XUI-Document with JavaScript???

I think something is wrong because the script results in the following Error:

Java VM Version 1.5.0_07-b03 -- Sun Microsystems Inc.
org.mozilla.javascript.WrappedException: Wrapped org.w3c.dom.DOMException: [A30111] DOM-Ausnahme: Es wurde versucht, ein schreibgeschütztes Objekt zu ändern (<js_eval>#15)
at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1693)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:157)
at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:201)
at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:64)
at org.mozilla.javascript.gen.c4._c0(<js_eval>:15)
at org.mozilla.javascript.gen.c4.call(<js_eval>)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:337)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2755)
at org.mozilla.javascript.gen.c4.call(<js_eval>)
at org.mozilla.javascript.gen.c4.exec(<js_eval>)
at org.mozilla.javascript.Context.evaluateString(Context.java:1132)
at com.arbortext.epic.internal.js.JavaScript.eval(JavaScript.java:110)
at com.arbortext.epic.internal.js.JavaScript.eval(JavaScript.java:141)
Caused by: org.w3c.dom.DOMException: [A30111] DOM-Ausnahme: Es wurde versucht, ein schreibgeschütztes Objekt zu ändern
at com.arbortext.epic.internal.aom.NodeImpl.appendChild(Native Method)
at com.arbortext.epic.internal.aom.NodeImpl.appendChild(NodeImpl.java:306)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:142)
... 11 more


8 REPLIES 8

Is your XML XUI file readonly on the filesystem?

On Wed, Aug 26, 2009 at 11:04 AM, Johannes Wizenmann <
johannes.wizenmann@heller.biz> wrote:

> Adepters,
>
> please help me with the following issue. I tried to develope a dynamic
> combobox that allowes comfortable selection of "target-IDs" relating to
> cross references and jump marks. Unfortunately I stuck at 80% of the entire
> script.
>
> So here is what happened until now:
>
> * ACL-Code that creates the $DialogWindow by calling
> doc_open($XMLDialogPath,1).
> This script works fine as fare as I can see:*

Hi Johannes-



You definitely don't want to point to the XUI document in the file system-I'm not sure what that would do but probably nothing good. 🙂



The version of the code to get the dialog document you have commented out in your javascript code is what you want I think. Specifically,



var CurrentDialogDoc = Application.event.target.ownerDocument;



Then just use CurrentDialogDoc directly, remove the business with xmlDoc. Or, to minimize changing your code, assign it directly as above, i.e.



var xmlDoc = Application.event.target.ownerDocument;



Then you can leave the rest of the references to xmlDoc as they are.



If you still have problems, post your revised code and any error messages you get and we'll take another look.



--Clay


Actually, I think I see what you mean about reloading the dialog.
Would this work?

var xuiwin = Application.event.target;
var CurrentDialogDoc = xuiwin.dialogView.document;


Adeptors,

it works! I changed my XUI-Doc like this:


var doc = Application.activeDocument;var tags = doc.getElementsByAttribute("ID-Ueberschrift",",0);

var CurrentDialogDoc = Application.event.target.ownerDocument;

for (i=0; i<tags.length; i++)=" {<=" em=">

var CurrentNode = tags.item(i).firstChild;

if(CurrentNode.nodeType == CurrentNode.TEXT_NODE){

ComboNode = CurrentDialogDoc.getElementById("tarbox");

listNode = CurrentDialogDoc.createElement("listitem");

ComboNode.appendChild(listNode);

listNode.setAttribute("label", tags.item(i).getAttribute('ID-Ueberschrift'));

} else {

// print(CurrentNode.firstChild.NodeType);

}

}


And everything seems to work 🙂

BUT...

In practice I had to realize that the performance is very bad. It takes definitely to long to automatically insert the ID-Value for the current OID. We work with very large XML-Documents (relative...) so the following script:

var tags = doc.getElementsByAttribute("ID-Ueberschrift",",0);

takes about 70 ID values from the active document.

takes about values from the active document.

After I press the OK button the script works a view seconds and inserts the selected ID:

sample

<absprungmarke idref="&lt;strong">Immer.bi.kundendiens.uAnker1"/>

Does anybody have an Idee how to optimize the script?

1.)It should work much faster

2.)The dynamic ID values first appear after I press ok button. How can I make them available in themoment the dialog appears?

3.) How can I close the dialog after I press ok button? I suppose:CurrentDialogDoc.close()

Many thanks!

Hi Johannes-



One thing I noticed about your script is that you have the search for
the "tarbox" listbox inside the loop. That's going to slow things down
considerably. Move that outside the loop and that should help.



Another thing you can do to speed things up is build the list offline
and then insert the completed list all in one shot. Inserting a listitem
into an existing listbox in the dialog is expensive, because the dialog
then tries to repaint the list each time. Building the list offline and
then replacing the existing list with the new one is much quicker (and
you don't get the annoying flicker, either). Try something like this:



var doc = Application.activeDocument;

var tags = doc.getElementsByAttribute("ID-Ueberschrift",",0);

var CurrentDialogDoc = Application.event.target.ownerDocument;

// get ComboNode outside the loop

var ComboNode = CurrentDialogDoc.getElementById("tarbox");

// create a clone of the combobox that will replace it once we're done

var newCombo = ComboNode.cloneNode(false);

// add the listitems to the clone

for (i=0; i<tags.length; i++)=" {<br="/>
var CurrentNode = tags.item(i).firstChild;

if(CurrentNode.nodeType == CurrentNode.TEXT_NODE){

listNode = CurrentDialogDoc.createElement("listitem");

listNode.setAttribute("label",
tags.item(i).getAttribute('ID-Ueberschrift'));

newCombo.appendChild(listNode);

} else {

// print(CurrentNode.firstChild.NodeType);

}

// the list is built, now insert it in the dialog doc

ComboNode.parentNode.replaceChild(newCombo,ComboNode);

}



HTH.



--Clay


Hi Clay,

your script works well. It displays all IDs in a second. The only thing I had to adjust was the nesting at the end of the script. "ComboNode..." was inside the for-statement.

How can I generate the combolist in the moment the dialog appears? Until now I always have to click the OK button until the script starts to work. I couldn't find an appropriate event... 😞

I hope you can give me an advice for this final step.

Thanks

Johannes

Hi Johannes-



Sorry about leaving the replaceChild call inside the loop. I was trying
to code off the top of my head.



To have the script run when the dialog opens, you want to have it in a
script element as a direct child of the root window element, and have
its ev:event attribute set to "windowload". There's one caveat though:
since it's running at windowload, the event.target.ownerDocument trick
doesn't work, so you have to use a different way to get the dialog
document. This usually does the trick:



var CurrentDialogDoc = Application.event.target.dialogView.document;



--Clay


thank you! it all works fine now and I'm done for today!
Top Tags