From 0edf8eb19b3259fdf88c0af1f783fc3d22fa7f7f Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Wed, 6 May 2009 02:54:59 +0000 Subject: [PATCH] BUGFIX Fixed case where "NoWidgets" was trying to be called on editablesegment MINOR Code formatting on WidgetAreaEditor.js to make it easier to read git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@76176 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- javascript/WidgetAreaEditor.js | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/javascript/WidgetAreaEditor.js b/javascript/WidgetAreaEditor.js index 9ef84f01..9d6a2fa7 100644 --- a/javascript/WidgetAreaEditor.js +++ b/javascript/WidgetAreaEditor.js @@ -14,9 +14,19 @@ WidgetAreaEditor.prototype = { } // Create dummy sortable to prevent javascript errors - Sortable.create('WidgetAreaEditor_availableWidgets', {tag: 'li', handle: 'handle', containment: []}); + Sortable.create('WidgetAreaEditor_availableWidgets', { + tag: 'li', + handle: 'handle', + containment: [] + }); + // Used widgets are sortable - Sortable.create('WidgetAreaEditor_usedWidgets', {tag: 'div', handle: 'handle', containment: ['WidgetAreaEditor_availableWidgets', 'WidgetAreaEditor_usedWidgets'], onUpdate: this.updateWidgets}); + Sortable.create('WidgetAreaEditor_usedWidgets', { + tag: 'div', + handle: 'handle', + containment: ['WidgetAreaEditor_availableWidgets', 'WidgetAreaEditor_usedWidgets'], + onUpdate: this.updateWidgets + }); // Figure out maxid, this is used when creating new widgets this.maxid = 0; @@ -60,8 +70,10 @@ WidgetAreaEditor.prototype = { var usedWidgets = $('WidgetAreaEditor_usedWidgets').childNodes; for(var i = 0; i < usedWidgets.length; i++) { var widget = usedWidgets[i]; - if(widget.id && (widget.id.indexOf("Widget[") != 0)) { - new Ajax.Request('Widget_Controller/EditableSegment/' + widget.id, {onSuccess : $('WidgetAreaEditor_usedWidgets').parentNode.parentNode.insertWidgetEditor.bind(this)}); + if(widget.id && (widget.id.indexOf("Widget[") != 0) && (widget.id != 'NoWidgets')) { + new Ajax.Request('Widget_Controller/EditableSegment/' + widget.id, { + onSuccess : $('WidgetAreaEditor_usedWidgets').parentNode.parentNode.insertWidgetEditor.bind(this) + }); } } }, @@ -92,7 +104,14 @@ WidgetAreaEditor.prototype = { // Reapply behaviour new Draggable(clone.id); - Sortable.create('WidgetAreaEditor_usedWidgets', {tag: 'div', handle: 'handle', containment: ['WidgetAreaEditor_availableWidgets', 'WidgetAreaEditor_usedWidgets'], onUpdate: $('WidgetAreaEditor_usedWidgets').parentNode.parentNode.updateWidgets}); + + Sortable.create('WidgetAreaEditor_usedWidgets', { + tag: 'div', + handle: 'handle', + containment: ['WidgetAreaEditor_availableWidgets', 'WidgetAreaEditor_usedWidgets'], + onUpdate: $('WidgetAreaEditor_usedWidgets').parentNode.parentNode.updateWidgets + }); + UsedWidget.applyToChildren($('WidgetAreaEditor_usedWidgets'), 'div.Widget'); return; }