Skip to content
Snippets Groups Projects
Commit bc07cc19 authored by srosse's avatar srosse
Browse files

OO-3896: prevent adding / droping an element on itself

parent b9cee1f4
No related branches found
No related tags found
No related merge requests found
...@@ -154,6 +154,8 @@ ...@@ -154,6 +154,8 @@
<exclude>**/fullcalendar/*</exclude> <exclude>**/fullcalendar/*</exclude>
<exclude>**/paella/**/*</exclude> <exclude>**/paella/**/*</exclude>
<exclude>**/sliderpips/jquery-ui-slider-pips.js</exclude> <exclude>**/sliderpips/jquery-ui-slider-pips.js</exclude>
<exclude>**/openolat/jquery.contenteditor.v2.js</exclude>
<exclude>**/interactjs/*</exclude>
</excludes> </excludes>
</configuration> </configuration>
</execution> </execution>
...@@ -190,6 +192,8 @@ ...@@ -190,6 +192,8 @@
<exclude>**/mediaelementjs/**/*</exclude> <exclude>**/mediaelementjs/**/*</exclude>
<exclude>**/paella/**/*</exclude> <exclude>**/paella/**/*</exclude>
<exclude>**/sliderpips/jquery-ui-slider-pips.js</exclude> <exclude>**/sliderpips/jquery-ui-slider-pips.js</exclude>
<exclude>**/openolat/jquery.contenteditor.v2.js</exclude>
<exclude>**/interactjs/*</exclude>
</excludes> </excludes>
</configuration> </configuration>
</execution> </execution>
...@@ -315,6 +319,8 @@ ...@@ -315,6 +319,8 @@
<exclude>**/mediaelementjs/**/*</exclude> <exclude>**/mediaelementjs/**/*</exclude>
<exclude>**/paella/**/*</exclude> <exclude>**/paella/**/*</exclude>
<exclude>**/sliderpips/jquery-ui-slider-pips.js</exclude> <exclude>**/sliderpips/jquery-ui-slider-pips.js</exclude>
<exclude>**/openolat/jquery.contenteditor.v2.js</exclude>
<exclude>**/interactjs/*</exclude>
</excludes> </excludes>
</configuration> </configuration>
</execution> </execution>
...@@ -355,6 +361,8 @@ ...@@ -355,6 +361,8 @@
<exclude>**/mediaelementjs/**/*</exclude> <exclude>**/mediaelementjs/**/*</exclude>
<exclude>**/paella/**/*</exclude> <exclude>**/paella/**/*</exclude>
<exclude>**/sliderpips/jquery-ui-slider-pips.js</exclude> <exclude>**/sliderpips/jquery-ui-slider-pips.js</exclude>
<exclude>**/openolat/jquery.contenteditor.v2.js</exclude>
<exclude>**/interactjs/*</exclude>
</excludes> </excludes>
</configuration> </configuration>
</execution> </execution>
......
...@@ -85,13 +85,15 @@ public class ContentEditorComponent extends FormBaseComponentImpl implements Com ...@@ -85,13 +85,15 @@ public class ContentEditorComponent extends FormBaseComponentImpl implements Com
public void setRootComponents(List<ContentEditorFragment> components) { public void setRootComponents(List<ContentEditorFragment> components) {
rootComponents = new ArrayList<>(components); rootComponents = new ArrayList<>(components);
for(ContentEditorFragment component:components) { for(ContentEditorFragment component:components) {
component.setTranslator(getTranslator()); if(getTranslator() != null) {
component.setTranslator(getTranslator());
}
} }
setDirty(true); setDirty(true);
} }
public void addRootComponent(ContentEditorFragment component) { public void addRootComponent(ContentEditorFragment component) {
if(rootComponents.contains(component)) return; if(rootComponents.contains(component) || !checkAdd(component)) return;
rootComponents.add(component); rootComponents.add(component);
setDirty(true); setDirty(true);
...@@ -101,6 +103,8 @@ public class ContentEditorComponent extends FormBaseComponentImpl implements Com ...@@ -101,6 +103,8 @@ public class ContentEditorComponent extends FormBaseComponentImpl implements Com
} }
public void addRootComponent(int index, ContentEditorFragment component) { public void addRootComponent(int index, ContentEditorFragment component) {
if(!checkAdd(component)) return;
if(index >= 0 && index < rootComponents.size()) { if(index >= 0 && index < rootComponents.size()) {
rootComponents.add(index, component); rootComponents.add(index, component);
} else { } else {
...@@ -112,6 +116,14 @@ public class ContentEditorComponent extends FormBaseComponentImpl implements Com ...@@ -112,6 +116,14 @@ public class ContentEditorComponent extends FormBaseComponentImpl implements Com
} }
} }
private boolean checkAdd(ContentEditorFragment componentToAdd) {
if(componentToAdd == this) {
setDirty(true);// add to itself forbidden
return false;
}
return true;
}
public boolean removeRootComponent(ContentEditorFragment component) { public boolean removeRootComponent(ContentEditorFragment component) {
boolean removed = rootComponents.remove(component); boolean removed = rootComponents.remove(component);
if(removed) { if(removed) {
......
...@@ -177,6 +177,8 @@ public class ContentEditorContainerComponent extends FormBaseComponentImpl imple ...@@ -177,6 +177,8 @@ public class ContentEditorContainerComponent extends FormBaseComponentImpl imple
} }
public void setElementAt(ContentEditorFragment component, int column, String sibling) { public void setElementAt(ContentEditorFragment component, int column, String sibling) {
if(!checkAdd(component)) return;
editorPart.setElementAt(component.getElementId(), column, sibling); editorPart.setElementAt(component.getElementId(), column, sibling);
addComponent(component); addComponent(component);
setDirty(true); setDirty(true);
...@@ -199,11 +201,22 @@ public class ContentEditorContainerComponent extends FormBaseComponentImpl imple ...@@ -199,11 +201,22 @@ public class ContentEditorContainerComponent extends FormBaseComponentImpl imple
} }
public void addElement(ContentEditorFragment newComponent, ContentEditorFragment collocator, PageElementTarget target) { public void addElement(ContentEditorFragment newComponent, ContentEditorFragment collocator, PageElementTarget target) {
if(!checkAdd(newComponent)) return;
editorPart.addElement(newComponent.getElementId(), collocator.getElementId(), target); editorPart.addElement(newComponent.getElementId(), collocator.getElementId(), target);
addComponent(newComponent); addComponent(newComponent);
setDirty(true); setDirty(true);
} }
private boolean checkAdd(ContentEditorFragment componentToAdd) {
if(componentToAdd == this) {
log.warn("Add container to itself: {}", componentToAdd);
setDirty(true);
return false;
}
return true;
}
private void doDropFragment(UserRequest ureq) { private void doDropFragment(UserRequest ureq) {
String sourceId = ureq.getParameter("source"); String sourceId = ureq.getParameter("source");
String slotId = ureq.getParameter("slot"); String slotId = ureq.getParameter("slot");
...@@ -253,7 +266,8 @@ public class ContentEditorContainerComponent extends FormBaseComponentImpl imple ...@@ -253,7 +266,8 @@ public class ContentEditorContainerComponent extends FormBaseComponentImpl imple
} }
public void addComponent(ContentEditorFragment fragmentCmp) { public void addComponent(ContentEditorFragment fragmentCmp) {
if(fragmentCmp == null) return; if(fragmentCmp == null || components.contains(fragmentCmp)) return;
components.add(fragmentCmp); components.add(fragmentCmp);
if(getTranslator() != null) { if(getTranslator() != null) {
fragmentCmp.setTranslator(getTranslator()); fragmentCmp.setTranslator(getTranslator());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment