Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move js to separate file to prevent escaped entities in Plone 5
- Loading branch information
Showing
3 changed files
with
141 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
function moveItems(from, to) | ||
{ | ||
// shortcuts for selection fields | ||
var src = document.getElementById(from); | ||
var tgt = document.getElementById(to); | ||
|
||
if (src.selectedIndex == -1) selectionError(); | ||
else | ||
{ | ||
// iterate over all selected items | ||
// --> attribute "selectedIndex" doesn't support multiple selection. | ||
// Anyway, it works here, as a moved item isn't selected anymore, | ||
// thus "selectedIndex" indicating the "next" selected item :) | ||
while (src.selectedIndex > -1) | ||
if (src.options[src.selectedIndex].selected) | ||
{ | ||
// create a new virtal object with values of item to copy | ||
temp = new Option(src.options[src.selectedIndex].text, | ||
src.options[src.selectedIndex].value); | ||
// append virtual object to targe | ||
tgt.options[tgt.length] = temp; | ||
// want to select newly created item | ||
temp.selected = true; | ||
// delete moved item in source | ||
src.options[src.selectedIndex] = null; | ||
} | ||
} | ||
} | ||
|
||
// move item from "from" selection to "to" selection | ||
function from2to(name) | ||
{ | ||
moveItems(name+"-from", name+"-to"); | ||
copyDataForSubmit(name); | ||
} | ||
|
||
// move item from "to" selection back to "from" selection | ||
function to2from(name) | ||
{ | ||
moveItems(name+"-to", name+"-from"); | ||
copyDataForSubmit(name); | ||
} | ||
|
||
function swapFields(a, b) | ||
{ | ||
// swap text | ||
var temp = a.text; | ||
a.text = b.text; | ||
b.text = temp; | ||
// swap value | ||
temp = a.value; | ||
a.value = b.value; | ||
b.value = temp; | ||
// swap selection | ||
temp = a.selected; | ||
a.selected = b.selected; | ||
b.selected = temp; | ||
} | ||
|
||
// move selected item in "to" selection one up | ||
function moveUp(name) | ||
{ | ||
// shortcuts for selection field | ||
var toSel = document.getElementById(name+"-to"); | ||
|
||
if (toSel.selectedIndex == -1) | ||
selectionError(); | ||
else if (toSel.options[0].selected) | ||
alert("Cannot move further up!"); | ||
else for (var i = 0; i < toSel.length; i++) | ||
if (toSel.options[i].selected) | ||
{ | ||
swapFields(toSel.options[i-1], toSel.options[i]); | ||
copyDataForSubmit(name); | ||
} | ||
} | ||
|
||
// move selected item in "to" selection one down | ||
function moveDown(name) | ||
{ | ||
// shortcuts for selection field | ||
var toSel = document.getElementById(name+"-to"); | ||
|
||
if (toSel.selectedIndex == -1) { | ||
selectionError(); | ||
} else if (toSel.options[toSel.length-1].selected) { | ||
alert("Cannot move further down!"); | ||
} else { | ||
for (var i = toSel.length-1; i >= 0; i--) { | ||
if (toSel.options[i].selected) { | ||
swapFields(toSel.options[i+1], toSel.options[i]); | ||
} | ||
} | ||
copyDataForSubmit(name); | ||
} | ||
} | ||
|
||
// copy each item of "toSel" into one hidden input field | ||
function copyDataForSubmit(name) | ||
{ | ||
// shortcuts for selection field and hidden data field | ||
var toSel = document.getElementById(name+"-to"); | ||
var toDataContainer = document.getElementById(name+"-toDataContainer"); | ||
|
||
// delete all child nodes (--> complete content) of "toDataContainer" span | ||
while (toDataContainer.hasChildNodes()) | ||
toDataContainer.removeChild(toDataContainer.firstChild); | ||
|
||
// create new hidden input fields - one for each selection item of | ||
// "to" selection | ||
for (var i = 0; i < toSel.options.length; i++) | ||
{ | ||
// create virtual node with suitable attributes | ||
var newNode = document.createElement("input"); | ||
var newAttr = document.createAttribute("name"); | ||
newAttr.nodeValue = name.replace(/-/g, '.')+':list'; | ||
newNode.setAttributeNode(newAttr); | ||
|
||
newAttr = document.createAttribute("type"); | ||
newAttr.nodeValue = "hidden"; | ||
newNode.setAttributeNode(newAttr); | ||
|
||
newAttr = document.createAttribute("value"); | ||
newAttr.nodeValue = toSel.options[i].value; | ||
newNode.setAttributeNode(newAttr); | ||
|
||
// actually append virtual node to DOM tree | ||
toDataContainer.appendChild(newNode); | ||
} | ||
} | ||
|
||
// error message for missing selection | ||
function selectionError() | ||
{alert("Must select something!")} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6aade69
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 commit breaks tests: src/z3c/form/browser/orderedselect.txt expects
and instead gets
Should be easy to fix. Can you do it?
6aade69
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.
The other test failure, in README.txt, is also attributable to this change:
6aade69
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.
fixed.
6aade69
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.
Thank you! 🍰
6aade69
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 has also broken some Plone 4.3 tests; for example http://jenkins.plone.org/job/plone-4.3-python-2.7/2805/testReport/src.collective.z3cform/datetimewidget/converter_txt/
6aade69
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 info, I missed that too.
fixed in collective/collective.z3cform.datetimewidget@957a55e (the commit did not trigger the 4.3-build)
6aade69
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 think this commit might be causing this issue: plone/Products.CMFPlone#530
6aade69
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 commit also seems to break MultiSelectWidget in overlays. I get
ReferenceError: to2from is not defined
andReferenceError: from2to is not defined
javascript errors6aade69
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.
(Filing bugs is better than commenting on old commits. I apologize for starting this trend here.)