From 5abc2eceefa1575582f54c77b82d97fa8bd9ce75 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Tue, 4 Mar 2014 00:26:42 +0000 Subject: [PATCH] Fix broken delete of link when to_id is not set (not saved entry) --- etemplate/js/et2_widget_link.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/etemplate/js/et2_widget_link.js b/etemplate/js/et2_widget_link.js index f9bd631b32..5e482f794d 100644 --- a/etemplate/js/et2_widget_link.js +++ b/etemplate/js/et2_widget_link.js @@ -1465,7 +1465,10 @@ var et2_link_list = et2_link_string.extend( .appendTo(delete_button) // We don't use ui-icon because it assigns a bg image .addClass("delete icon") - .bind( 'click', function() {self._delete_link(_link_data.link_id||_link_data, row);}); + .bind( 'click', function() {self._delete_link( + self.value && typeof self.value.to_id != 'object' && _link_data.link_id ? _link_data.link_id:_link_data, + row + );}); // Context menu row.bind("contextmenu", function(e) { @@ -1491,11 +1494,26 @@ var et2_link_list = et2_link_string.extend( // No link ID means a link on an unsaved entry. // Just remove the row, but need to adjust the link_to value also row.slideUp(row.remove); - var value = link_id.widget.getValue(); - if(value && value.to_id) + + // Look for a link-to with the same ID, refresh it + if(link_id.link_id) + { + var self = this; + var _widget = link_id.widget || null; + this.getRoot().iterateOver( + function(widget) { + if(widget.id == self.id) { + _widget = widget; + } + }, + this, et2_link_to + ); + var value = _widget != null ? _widget.getValue() : false; + if(_widget && value && value.to_id) { - delete value.to_id[link_id.value_index]; - link_id.widget.set_value(value); + delete value.to_id[link_id.link_id]; + _widget.set_value(value); + } } } }