[xwiki-users] XWiki Class and Javascript
Hello, I've a problem to integrate and use Javascript in XWiki when I use Class and Sheet, in 'inline' mode. I've a second class, called IGCountriesClass, with 2 properties: a static list called countryzone (contains "EU|AP|LA|NA|WW" for Europe, Asian Pacific, North America, Latina America and WorldWide) and a string property called countryname for the country name. This Class is used to create some documents with format EU/France, EU/Espagne, EU/Italie, LA/Brasil, etc... to add more countries if needed. I've also another Class with 2 lists properties (called intergeozone and intergeocountry), first is static with "EU|AP|LA|NA|WW" like countryzone from first Class. The second list is a database list property which is filled with hibernate query "select doc.name, doc.title from com.xpn.xwiki.doc.XWikiDocument as doc where doc.web = 'EtudeIGCountries' and doc.name != 'WebHome' order by doc.name" Well, my problem, I need to control the filling of the second list with countries belonging to the selected zone in the first list. It's really so easy to do this with using javascript in normal web use, easy to with xwiki in 'view' mode but I've a problem to do it with javascript when I go to 'inline' mode. I use this code in the second Class Sheet, all is ok in 'view' mode but problem come when I go in 'inline' mode. I get problem with result from $obj.get(objectname) apparently. Could someone help me, please? :) [code] {{html}} <!--script type="text/javascript"//--> function initZone() { var selObj = document.getElementById('countriesSelect'); selObj.options[0] = new Option('---',''); selObj.selectedIndex = 0; } function changeListe() { choix = document.getElementById("zonesList").value populateCountries(choix) } function populateCountries(newzone) { var countObj = 0; var selObj = document.getElementById('countriesSelect'); for (var i = 0; i < selObj.options.length; i++) { selObj.options[i] = null; } selObj.options.length=null; selObj.options[countObj++] = new Option('---',''); selObj.selectedIndex = 0; #set ($filespace = "EtudeIGCountries") #set ($recherche = $xwiki.searchDocuments("where doc.name != 'WebHome' and doc.space = ? order by doc.name asc",[${filespace}])) #foreach($entry in $sorttool.sort($recherche)) #set ($tempdoc = "${entry}") #set ($doctemp = $xwiki.getDocument($tempdoc)) #set ($obj = $doctemp.getObject('EtudeCode.EtudeIGCountriesClass')) #set ($entryDoc = $xwiki.getDocument($entry)) #if($entryDoc.getObject('EtudeCode.EtudeIGCountriesClass')) if ((newzone == "${obj.get('countryzone')}") || (newzone == "WW")) { selObj.options[countObj++] = new Option("${obj.get('countryname')}", "${obj.get('countryname')}"); } #end #end } </script> <!--SELECT id="zonesList" onchange="changeListe()" name="zonesList"//--> #foreach($listitem in $list) ## * value: $listitem displayed value: $map.get($listitem).getValue() #if ($map.get($listitem).getValue() == "NA") <OPTION value="$map.get($listitem).getValue()" SELECTED>$map.get($listitem).getValue()</OPTION> #else <OPTION value="$map.get($listitem).getValue()">$map.get($listitem).getValue()</OPTION> #end #end </SELECT> <SELECT id="countriesSelect" name="countriesList"></SELECT> <!--script type="text/javascript">initZone();</script//--> {{/html}} [/code] -- View this message in context: http://xwiki.475771.n2.nabble.com/XWiki-Class-and-Javascript-tp5770427p57704... Sent from the XWiki- Users mailing list archive at Nabble.com.
On 11/24/2010 02:59 PM, Pidoux75 wrote:
I use this code in the second Class Sheet, all is ok in 'view' mode but problem come when I go in 'inline' mode. I get problem with result from $obj.get(objectname) apparently.
$obj.get('propname') is equivalent to $doc.display('propname', $obj) which changes the display mode according to the current mode: view, edit. Use $obj.getProperty('propname').getValue() instead. -- Sergiu Dumitriu http://purl.org/net/sergiu/
Thanks a lot :) In the same way, is there a means of get a javascript value and put in velocity value ? like <!--script type="text/javascript"//--> function changeList() { choix = document.getElementById("zonesList").value; #set ($newname = newZone) $obj.set('intergeozone', choix); populateCountries(choix); } </script> Cause, if I write this, I got an error "Failed to execute macro: velocity". Is there a way to do it or not? -- View this message in context: http://xwiki.475771.n2.nabble.com/XWiki-Class-and-Javascript-tp5770427p57735... Sent from the XWiki- Users mailing list archive at Nabble.com.
On 11/25/2010 10:55 AM, Pidoux75 wrote:
Thanks a lot :)
In the same way, is there a means of get a javascript value and put in velocity value ?
like
<!--script type="text/javascript"//--> function changeList() {
choix = document.getElementById("zonesList").value; #set ($newname = newZone) $obj.set('intergeozone', choix); populateCountries(choix);
} </script>
Cause, if I write this, I got an error "Failed to execute macro: velocity".
Is there a way to do it or not?
Velocity is executed on the server, JavaScript is executed on the client. You can't use JS variables inside Velocity, only the other way around. To send JS variables to Velocity, you have to send a request to the server. Take a look at http://www.prototypejs.org/api/ajax/updater -- Sergiu Dumitriu http://purl.org/net/sergiu/
Hmmm ok I'll go to look for Ajax.request but is it possible to use this inside a class? To explains exactly that I need, when I'm on my previous class, now I can use my 2 lists with javascript to intercept change from first list, but I need now to save if I made changes (with clicking "save and view" at bottom of the page) else I keep the old values from the page. So, if I use this ajax method, I can do this? -- View this message in context: http://xwiki.475771.n2.nabble.com/XWiki-Class-and-Javascript-tp5770427p57741... Sent from the XWiki- Users mailing list archive at Nabble.com.
Hi Sergiu I looked http://www.prototypejs.org/api/ajax/updater but really I don't really understand how it works and how to use in my case. Can you give me some real example from my own request to get how it works please? Thanks by advance, Pierre -- View this message in context: http://xwiki.475771.n2.nabble.com/XWiki-Class-and-Javascript-tp5770427p57763... Sent from the XWiki- Users mailing list archive at Nabble.com.
participants (2)
-
Pidoux75 -
Sergiu Dumitriu