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 Stage2 to Stage3 #2

Closed
wants to merge 7 commits into
base: stage2
from
Copy path View file
@@ -25,7 +25,7 @@ Testing.panel.Home = function(config) {
,border: false
,bodyCssClass: 'panel-desc'
}, {
xtype: 'modx-tree-menu'
xtype: 'testing-tree-categories'
,cls: 'main-wrapper'
,preventRender: true
}]
Copy path View file
@@ -1,57 +1,57 @@
/**
* Generates a Tree for managing the Top Menu
*
* @class MODx.tree.Menu
* @extends MODx.tree.Tree
* @param {Object} config An object of options.
* @xtype modx-tree-menu
* This is the part of the code the creates the actual tree by extending MODX.tree.Tree
*/
MODx.tree.Menu = function(config) {
Testing.tree.Categories = function(config) {
config = config || {};
Ext.applyIf(config,{
root_id: 'n_'
root_id: null
,root_name: _('menu_top')
,rootVisible: true
,rootVisible: false
,expandFirst: true
,enableDrag: true
,enableDrop: true
,url: MODx.config.connector_url
,action: 'system/menu/getNodes'
,sortAction: 'system/menu/sort'
,url: Testing.config.connectorUrl
,action: 'mgr/getNodes'
,sortAction: 'mgr/sort'
,primaryKey: 'text'
,useDefaultToolbar: true
,useDefaultToolbar: false
,ddGroup: 'modx-menu'
,tbar: [{
text: _('menu_create')
text: _('testing.category_create')
,cls:'primary-button'
,handler: this.createMenu
,handler: this.createCategory
,scope: this
}]
});
MODx.tree.Menu.superclass.constructor.call(this,config);
Testing.tree.Categories.superclass.constructor.call(this,config);
};
Ext.extend(MODx.tree.Menu, MODx.tree.Tree, {
Ext.extend(Testing.tree.Categories, MODx.tree.Tree, {
windows: {}
,createMenu: function(n,e) {
,createCategory: function(n,e) {
var r = {
parent: ''
};
if (this.cm && this.cm.activeNode && this.cm.activeNode.attributes && this.cm.activeNode.attributes.data) {
r['parent'] = this.cm.activeNode.attributes.data.text;
}
if (!this.windows.create_menu) {
this.windows.create_menu = MODx.load({
xtype: 'modx-window-menu-create'
if (!this.windows.create_category) {
this.windows.create_category = MODx.load({
xtype: 'testing-window-category-create'
,record: r
,listeners: {
'success': {fn:function(r) { this.refresh(); },scope:this}
'success': {
fn: function(r) {
this.refresh();
}
,scope:this
}
}
});
}
this.windows.create_menu.reset();
this.windows.create_menu.setValues(r);
this.windows.create_menu.show(e.target);
this.windows.create_category.reset();
this.windows.create_category.setValues(r);
this.windows.create_category.show(e.target);
}
,updateMenu: function(n,e) {
@@ -102,169 +102,44 @@ Ext.extend(MODx.tree.Menu, MODx.tree.Tree, {
break;
default:
m.push({
text: _('menu_create')
,handler: this.createMenu
text: _('testing.category_create')
,handler: this.createCategory
});
break;
}
return m;
}
});
Ext.reg('modx-tree-menu',MODx.tree.Menu);
Ext.reg('testing-tree-categories', Testing.tree.Categories);
/**
* Generates the Create Menu window
*
* @class MODx.window.CreateMenu
* @extends MODx.Window
* @param {Object} config An object of options.
* @xtype modx-window-menu-create
* This code creates the popup window that allows us to create new categories
*/
MODx.window.CreateMenu = function(config) {
Testing.window.CreateCategory = function(config) {
config = config || {};
this.ident = config.ident || 'modx-cmenu-'+Ext.id();
Ext.applyIf(config,{
title: _('menu_create')
,width: 600
// ,height: 400
Ext.applyIf(config, {
title: _('testing.category_create')
,url: MODx.config.connector_url
,action: 'system/menu/create'
,fields: [{
xtype: 'modx-combo-menu'
fieldLabel: _('testing.parent')
,name: 'parent'
,hiddenName: 'parent'
,xtype: 'modx-combo-menu'
,anchor: '100%'
,fieldLabel: _('parent')
},{
layout: 'column'
,border: false
,style: 'padding-top: 15px;'
,defaults: {
layout: 'form'
,labelAlign: 'top'
,anchor: '100%'
,border: false
}
,items: [{
columnWidth: .5
,items: [{
xtype: 'hidden'
,name: 'previous_text'
,value: config.record && config.record.text ? config.record.text : ''
},{
fieldLabel: _('lexicon_key')
,description: MODx.expandHelp ? '' : _('lexicon_key_desc')
,name: 'text'
,xtype: 'textfield'
,allowBlank: false
,anchor: '100%'
,id: this.ident+'-text'
//,readOnly: config.update ? true : false
},{
xtype: MODx.expandHelp ? 'label' : 'hidden'
,forId: this.ident+'-text'
,html: _('lexicon_key_desc')
,cls: 'desc-under'
},{
fieldLabel: _('description')
,description: MODx.expandHelp ? '' : _('description_desc')
,name: 'description'
,xtype: 'textfield'
,allowBlank: true
,anchor: '100%'
,id: this.ident+'-description'
},{
xtype: MODx.expandHelp ? 'label' : 'hidden'
,forId: this.ident+'-description'
,html: _('description_desc')
,cls: 'desc-under'
},{
fieldLabel: _('handler')
,description: MODx.expandHelp ? '' : _('handler_desc')
,name: 'handler'
,xtype: 'textarea'
,anchor: '100%'
,grow: false
,id: this.ident+'-handler'
},{
xtype: MODx.expandHelp ? 'label' : 'hidden'
,forId: this.ident+'-handler'
,html: _('handler_desc')
,cls: 'desc-under'
},{
fieldLabel: _('permissions')
,description: MODx.expandHelp ? '' : _('permissions_desc')
,name: 'permissions'
,xtype: 'textfield'
,anchor: '100%'
,id: this.ident+'-permissions'
},{
xtype: MODx.expandHelp ? 'label' : 'hidden'
,forId: this.ident+'-permissions'
,html: _('permissions_desc')
,cls: 'desc-under'
}]
},{
columnWidth: .5
,items: [{
fieldLabel: _('action')
,description: MODx.expandHelp ? '' : _('action_desc')
,name: 'action_id'
,hiddenName: 'action_id'
,xtype: 'textfield'
,anchor: '100%'
,id: this.ident+'-action-id'
//,allowBlank: false
},{
xtype: MODx.expandHelp ? 'label' : 'hidden'
,forId: this.ident+'-action-id'
,html: _('action_desc')
,cls: 'desc-under'
},{
fieldLabel: _('parameters')
,description: MODx.expandHelp ? '' : _('parameters_desc')
,name: 'params'
,xtype: 'textfield'
,anchor: '100%'
,id: this.ident+'-params'
},{
xtype: MODx.expandHelp ? 'label' : 'hidden'
,forId: this.ident+'-params'
,html: _('parameters_desc')
,cls: 'desc-under'
},{
fieldLabel: _('namespace')
,description: MODx.expandHelp ? '' : _('namespace_desc')
,name: 'namespace'
,xtype: 'textfield'
,anchor: '100%'
,value: 'core'
,id: this.ident+'-namespace'
},{
xtype: MODx.expandHelp ? 'label' : 'hidden'
,forId: this.ident+'-namespace'
,html: _('namespace_desc')
,cls: 'desc-under'
},{
fieldLabel: _('icon')
,description: MODx.expandHelp ? '' : _('icon_desc')
,name: 'icon'
,xtype: 'textfield'
,anchor: '100%'
,id: this.ident+'-icon'
},{
xtype: MODx.expandHelp ? 'label' : 'hidden'
,forId: this.ident+'-icon'
,html: _('icon_desc')
,cls: 'desc-under'
}]
}]
fieldLabel: _('testing.name')
,name: 'name'
,xtype: 'textfield'
,allowBlank: false
,anchor: '100%'
}]
});
MODx.window.CreateMenu.superclass.constructor.call(this,config);
Testing.window.CreateCategory.superclass.constructor.call(this,config);
};
Ext.extend(MODx.window.CreateMenu,MODx.Window);
Ext.reg('modx-window-menu-create',MODx.window.CreateMenu);
Ext.extend(Testing.window.CreateCategory, MODx.Window);
Ext.reg('testing-window-category-create', Testing.window.CreateCategory);
/**
* Generates the Update Menu window
@@ -283,7 +158,7 @@ MODx.window.UpdateMenu = function(config) {
});
MODx.window.UpdateMenu.superclass.constructor.call(this,config);
};
Ext.extend(MODx.window.UpdateMenu,MODx.window.CreateMenu);
Ext.extend(MODx.window.UpdateMenu,MODx.window.CreateCategory);
Ext.reg('modx-window-menu-update',MODx.window.UpdateMenu);
/**
Copy path View file
@@ -1,4 +1,7 @@
<?php
$_lang['testing'] = 'Testing';
$_lang['testing.name'] = 'Testing';
$_lang['testing.desc'] = 'Description';
$_lang['testing.desc'] = 'Description';
$_lang['testing.category_create'] = 'Create new category';
$_lang['testing.parent'] = 'Parent category';
$_lang['testing.name'] = 'Category name';
@@ -0,0 +1,51 @@
<?php
class TestingCategoryGetNodesProcessor extends modObjectGetListProcessor {
public $classKey = 'TestingCategory';
public $languageTopics = array('testing:default');
public $objectType = 'testing.category';
public $defaultSortField = 'menuindex';
public function prepareQueryBeforeCount(xPDOQuery $c) {
$parent = null;
if ($_POST['node'] != 'root') {
$parent = explode('_', $_POST['node'])[1];
}
$c->where([
'parent' => $parent
]);
return parent::prepareQueryBeforeCount($c);
}
public function prepareRow(xPDOObject $object) {
$c = $this->modx->newQuery('TestingCategory');
$c->where([
'parent' => $object->get('id')
]);
$childrenCount = $this->modx->getCount('TestingCategory', $c);
$objectArray = [
'text' => $object->get('name'),
'id' => 'n_' . $object->get('id'),
'cls' => 'icon-menu',
'iconCls' => 'icon icon-' . ( $object->get('parent') != null ? 'navicon' : 'folder' ),
'type' => 'menu',
'pk' => $object->get('id'),
'leaf' => ($object->get('parent') != null),
'data' => $object->toArray()
];
if ($childrenCount < 1) {
// Workaround for leaf record not to display "arrows"
$objectArray['loaded'] = true;
}
return $objectArray;
}
public function outputArray(array $array, $count = false) {
return $this->modx->toJSON($array);
}
}
return 'TestingCategoryGetNodesProcessor';
@@ -0,0 +1,43 @@
<?php
class TestingCategorySortProcessor extends modProcessor {
public function process() {
$data = $this->getProperty('data');
if (empty($data)) {
return $this->failure();
}
$data = urldecode($data);
$data = $this->modx->fromJSON($data);
$nodes = [];
foreach ($data as $k => $v) {
$children = [];
foreach ($v as $ik => $iv) {
$children[] = explode('_', $ik)[1];
}
$nodes[] = [
'parent' => explode('_', $k)[1],
'children' => $children
];
}
for ($i = 0; $i < count($nodes); $i++) {
$parent_obj = $this->modx->getObject('TestingCategory', $nodes[$i]['parent']);
$parent_obj->set('parent', null);
$parent_obj->set('menuindex', $i);
$parent_obj->save();
for ($j = 0; $j < count($nodes[$i]['children']); $j++) {
$child_obj = $this->modx->getObject('TestingCategory', $nodes[$i]['children'][$j]);
$child_obj->set('parent', $nodes[$i]['parent']);
$child_obj->set('menuindex', $j);
$child_obj->save();
}
}
return $this->success();
}
}
return 'TestingCategorySortProcessor';
ProTip! Use n and p to navigate between commits in a pull request.