Commit 8869d0c2 by Sven Marnach

Fix zone deletion.

When deleting a zone, the old version only removed it from the DOM, but not from
the underlying data structure that is sent to the server when the save button is
pressed.  This resulted in zones not actually being deleted.  This commit fixes
this issue.  Also fix a typo in a variable name while we are here.
parent 0b8af86c
...@@ -145,7 +145,7 @@ function DragAndDropEditBlock(runtime, element) { ...@@ -145,7 +145,7 @@ function DragAndDropEditBlock(runtime, element) {
name = 'zone-', name = 'zone-',
$elements = _fn.build.$el, $elements = _fn.build.$el,
num, num,
obj; zoneObj;
if (!oldZone) oldZone = {}; if (!oldZone) oldZone = {};
...@@ -168,7 +168,9 @@ function DragAndDropEditBlock(runtime, element) { ...@@ -168,7 +168,9 @@ function DragAndDropEditBlock(runtime, element) {
_fn.build.form.zone.obj.push(zoneObj); _fn.build.form.zone.obj.push(zoneObj);
// Add fields to zone position form // Add fields to zone position form
$elements.zones.form.append(inputTemplate(zoneObj)); $zoneNode = $(inputTemplate(zoneObj));
$zoneNode.data('index', num);
$elements.zones.form.append($zoneNode);
_fn.build.form.zone.enableDelete(); _fn.build.form.zone.enableDelete();
// Add zone div to target // Add zone div to target
...@@ -183,12 +185,21 @@ function DragAndDropEditBlock(runtime, element) { ...@@ -183,12 +185,21 @@ function DragAndDropEditBlock(runtime, element) {
remove: function(e) { remove: function(e) {
var $el = $(e.currentTarget).closest('.zone-row'), var $el = $(e.currentTarget).closest('.zone-row'),
classes = $el.attr('class'), classes = $el.attr('class'),
id = classes.slice(classes.indexOf('zone-row') + 9); id = classes.slice(classes.indexOf('zone-row') + 9),
index = $el.data('index'),
array_index;
e.preventDefault(); e.preventDefault();
$el.detach(); $el.detach();
$('#' + id, element).detach(); $('#' + id, element).detach();
// Find the index of the zone in the array and remove it.
for (array_index = 0; array_index < _fn.build.form.zone.obj.length;
array_index++) {
if (_fn.build.form.zone.obj[array_index].index == index) break;
}
_fn.build.form.zone.obj.splice(array_index, 1);
_fn.build.form.zone.formCount--; _fn.build.form.zone.formCount--;
_fn.build.form.zone.disableDelete(); _fn.build.form.zone.disableDelete();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment