Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progress between Stage6 to Stage7 #6

Closed
wants to merge 1 commit into from
Closed
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
71 changes: 51 additions & 20 deletions assets/components/testing/js/mgr/widgets/home.tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Ext.extend(MODx.tree.Menu, MODx.tree.Tree, {
parent: null
};
if (this.cm && this.cm.activeNode && this.cm.activeNode.attributes && this.cm.activeNode.attributes.data) {
r['parent'] = this.cm.activeNode.attributes.data.text;
r['parent'] = this.cm.activeNode.attributes.data.id;
}
if (!this.windows.create_category) {
this.windows.create_category = MODx.load({
Expand Down Expand Up @@ -95,29 +95,60 @@ Ext.extend(MODx.tree.Menu, MODx.tree.Tree, {
});
}

,getMenu: function(n,e) {
,getMenu: function(n, e) {
var m = [];
switch (n.attributes.type) {
case 'menu':
m.push({
text: _('testing.category_update')
,handler: this.updateCategory
});
m.push('-');
m.push({
text: _('testing.category_remove')
,handler: this.removeCategory
});
break;
default:
m.push({
text: _('testing.category_create')
,handler: this.createCategory
});
break;

// If the node we right click on has no parent, allow to create a category here
if (n.attributes.data.parent == null) {
m.push({
text: _('testing.category_create')
,handler: this.createCategory
});
}

// We're always going to allow updating a category
m.push({
text: _('testing.category_update')
,handler: this.updateCategory
});

// This is simply a separator in the menu
m.push('-');

// At the bottom we'll have the "dangerous" stuff
m.push({
text: _('testing.category_remove')
,handler: this.removeCategory
});

return m;
}

,_handleDrop: function(dropEvent) {
// Let's shortcut things
var drop_node = dropEvent.dropNode;
var traget_node = dropEvent.target;

// If the event is "append" we are just adding a new child in a list, not ON a parent, hence we can ignore it
if (dropEvent.point == 'append') {
return false;
}

// If our drop node has children AND the target node's parent is not the "root" we are attempting to drop at
// another node, which results in too many levels of categories. Simply returning false here will disable dropping
// in this position
if (traget_node.parentNode.id != 'root' && drop_node.childNodes.length > 0) {
return false;
}

// This is just the code from modx.tree.js to implement some basic functionality
if (!Ext.isEmpty(drop_node.attributes.treeHandler)) {
var h = Ext.getCmp(drop_node.attributes.treeHandler);
if (h) {
return h.handleDrop(this, dropEvent);
}
}
}
});
Ext.reg('modx-tree-menu',MODx.tree.Menu);

Expand Down