Skip to content
This repository was archived by the owner on Mar 14, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/js/adm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,9 @@ ADM.copySubtree = function (node) {
ADM.paste = function () {
var node, parent, target;
target = ADM._selection ? ADM._selection : ADM._activePage;
if (ADM._clipboard && ADM._clipboard.getType() === 'Page') {
target = ADM.getDesignRoot();
}
if (!ADM._clipboard || !target) {
return;
}
Expand Down Expand Up @@ -1859,7 +1862,7 @@ ADMNode.prototype.removeChild = function (child, dryrun) {
* @return {ADMNode} The removed child, or null if not found.
*/
ADMNode.prototype.removeChildFromZone = function (zoneName, index, dryrun) {
var zone, removed, child, parentNode;
var zone, removed, child, parentNode, parent;
zone = this._zones[zoneName];
if (!zone) {
console.error("Error: no such zone found while removing child: " +
Expand All @@ -1883,7 +1886,21 @@ ADMNode.prototype.removeChildFromZone = function (zoneName, index, dryrun) {
child._root = null;

if (child.isSelected()) {
ADM.setSelected(null);
parent = this;
// Select sibling of removed node, or parent node
// if removed node is the last node of parent. The
// order is next sibling, prev sibling and parent
if (zone.length === 0) {
//find the first selectable ancestor
while (!parent.isSelectable()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also check "parent !== null" in case there's no selectable ancestor

parent = parent.getParent();
}
ADM.setSelected(parent);
} else if (index < zone.length) {
ADM.setSelected(zone[index])
} else {
ADM.setSelected(zone[zone.length - 1]);
}
}

this.fireModelEvent("modelUpdated",
Expand Down
68 changes: 16 additions & 52 deletions src/js/views/property.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,8 @@
},

refresh: function(event, widget) {
var node;
widget = widget || this;
if (event) {
if (event.node && !(event.name === "modelUpdated" &&
event.type === "nodeRemoved")) {
if (event.type === "propertyChanged" && event.node.getType() === 'Design') {
return;
}
widget._showProperties(event.node);
} else {
node = ADM.getActivePage();
widget._showProperties(node);
}
}
widget._showProperties(ADM.getSelectedNode());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you use event.node?

},

// Private functions
Expand All @@ -92,14 +80,15 @@
widget.refresh(event,widget);
},

_activePageChangedHandler: function(event, widget) {
widget = widget || this;
widget.refresh(event,widget);
},

_modelUpdatedHandler: function(event, widget) {
widget = widget || this;
widget.refresh(event,widget);
if (event && (event.type === "propertyChanged" &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember another patch has done similar thing, why do it again?

event.node.getType() === 'Design')) {
return;
} else {

widget.refresh(event,widget);
}
},

_showProperties: function(node) {
Expand Down Expand Up @@ -498,43 +487,18 @@
.appendTo(content);
content.find('#deleteElement')
.bind('click', function (e) {
var parent, zone, index, msg;
var doDelete = function () {
try {
index = node.getZoneIndex();
parent = node.getParent();
zone = parent.getZoneArray(node.getZone());
if (type === "Page") {
$.rib.pageUtils.deletePage(node.getUid(), false);
} else {
ADM.removeChild(node.getUid(), false);
}
// Select sibling of removed node, or parent node
// if removed node is the last node of parent. The
// order is next sibling, prev sibling and parent
if (zone.length === 0) {
//find the first selectable ancestor
while (!parent.isSelectable()) {
parent = parent.getParent();
}
ADM.setSelected(parent);
} else if (index < zone.length) {
ADM.setSelected(zone[index])
} else {
ADM.setSelected(zone[zone.length - 1]);
}
}
catch (err) {
console.error(err.message);
}
}
if (type === "Page") {
var msg, node;
node = ADM.getSelectedNode();
if (!node) return false;
if (node.getType() === "Page") {
// TODO: i18n
msg = "Are you sure you want to delete the page '%1'?";
msg = msg.replace("%1", node.getProperty("id"));
$.rib.confirm(msg, doDelete);
$.rib.confirm(msg, function () {
$.rib.pageUtils.deletePage(node.getUid());
});
} else {
doDelete();
ADM.removeChild(node.getUid(), false);
}
e.stopPropagation();
return false;
Expand Down