Remove matching form block when custom field is deleted
This commit is contained in:
@@ -618,16 +618,27 @@ var WysijaForm = {
|
|||||||
return encodeURI(str).replace(/[!'()*]/g, escape);
|
return encodeURI(str).replace(/[!'()*]/g, escape);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateBlock: function(data) {
|
updateBlock: function(field) {
|
||||||
var hasUpdated = false;
|
var hasUpdated = false;
|
||||||
WysijaForm.getBlocks().each(function(b) {
|
WysijaForm.getBlocks().each(function(b) {
|
||||||
if(b.block.getData().id == data.id) {
|
if(b.block.getData().id === field.id) {
|
||||||
hasUpdated = true;
|
hasUpdated = true;
|
||||||
b.block.redraw(data);
|
b.block.redraw(field);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return hasUpdated;
|
return hasUpdated;
|
||||||
|
},
|
||||||
|
removeBlock: function(field, callback) {
|
||||||
|
var hasRemoved = false;
|
||||||
|
WysijaForm.getBlocks().each(function(b) {
|
||||||
|
if(b.block.getData().id === field.id) {
|
||||||
|
hasRemoved = true;
|
||||||
|
b.block.removeBlock(callback);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return hasRemoved;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -836,10 +847,6 @@ WysijaForm.Block = Class.create({
|
|||||||
Effect.Fade(this.element.identify(), {
|
Effect.Fade(this.element.identify(), {
|
||||||
duration: 0.2,
|
duration: 0.2,
|
||||||
afterFinish: function(effect) {
|
afterFinish: function(effect) {
|
||||||
if(effect.element.next('.mailpoet_form_block') !== undefined && callback !== false) {
|
|
||||||
// show controls of next block to allow mass delete
|
|
||||||
WysijaForm.get(effect.element.next('.mailpoet_form_block')).block.showControls();
|
|
||||||
}
|
|
||||||
// remove placeholder
|
// remove placeholder
|
||||||
if(effect.element.previous('.block_placeholder') !== undefined) {
|
if(effect.element.previous('.block_placeholder') !== undefined) {
|
||||||
effect.element.previous('.block_placeholder').remove();
|
effect.element.previous('.block_placeholder').remove();
|
||||||
|
@@ -18,15 +18,19 @@ class CustomFields {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function delete($id) {
|
function delete($id) {
|
||||||
$result = false;
|
|
||||||
|
|
||||||
$custom_field = CustomField::findOne($id);
|
$custom_field = CustomField::findOne($id);
|
||||||
if($custom_field !== false) {
|
if($custom_field === false or !$custom_field->id()) {
|
||||||
|
wp_send_json(array(
|
||||||
|
'result' => false
|
||||||
|
));
|
||||||
|
} else {
|
||||||
$custom_field->delete();
|
$custom_field->delete();
|
||||||
$result = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
wp_send_json($result);
|
wp_send_json(array(
|
||||||
|
'result' => true,
|
||||||
|
'field' => $custom_field->asArray()
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function save($data = array()) {
|
function save($data = array()) {
|
||||||
|
@@ -547,9 +547,16 @@
|
|||||||
endpoint: 'customFields',
|
endpoint: 'customFields',
|
||||||
action: 'delete',
|
action: 'delete',
|
||||||
data: id
|
data: id
|
||||||
}).done(function(result) {
|
}).done(function(response) {
|
||||||
if(result === true) {
|
if(response.result === true) {
|
||||||
item.remove();
|
item.remove();
|
||||||
|
|
||||||
|
if(response.field !== undefined) {
|
||||||
|
WysijaForm.removeBlock(response.field, function() {
|
||||||
|
mailpoet_form_save(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
mailpoet_form_fields();
|
mailpoet_form_fields();
|
||||||
MailPoet.Notice.success(
|
MailPoet.Notice.success(
|
||||||
"<%= __('Removed custom field “"+name+"“') %>"
|
"<%= __('Removed custom field “"+name+"“') %>"
|
||||||
|
Reference in New Issue
Block a user