Skip to content

Commit

Permalink
Merge pull request #11 from createit-ru/feature/msextrafield
Browse files Browse the repository at this point in the history
Feature/msextrafield
  • Loading branch information
biz87 authored Apr 23, 2024
2 parents fe1c021 + 74c2360 commit 247e699
Show file tree
Hide file tree
Showing 20 changed files with 1,702 additions and 3 deletions.
2 changes: 1 addition & 1 deletion _build/resolvers/resolver_02_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
}
}
foreach ($tableFields as $field) {
$manager->removeField($class, $field);
//$manager->removeField($class, $field);
}
// 2. Operate with indexes
$indexes = [];
Expand Down
3 changes: 2 additions & 1 deletion assets/components/minishop3/css/mgr/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ a.x-menu-item .x-menu-item-text .icon { line-height: 16px; top: auto; }
.ms3-btn-action {padding: 3px 20px 3px 6px!important;}
.ms3-btn-action i.icon {padding-right: 3px;width: 15px;}
/* Windows */
.ms3-window .x-form-label-top .x-form-item label.x-form-item-label { padding-top: 15px !important; }
/*.ms3-window .x-form-label-top .x-form-item label.x-form-item-label { padding-top: 15px !important; }*/
.ms3-window .x-panel-mc,
.ms3-window .x-tab-panel-bwrap > .x-tab-panel-body > .x-panel { margin-top: -14px; }
.ms3-window .x-window-body.tabs { padding: 5px 10px 0 10px; }
.ms3-window .desc { font-style: italic; padding-top: 5px; color: #555555; }
.ms3-window .text-success { color: green; }
/* Tree */
.ms3-panel .x-tree-root-ct,
.ms3-window .x-tree-root-ct { overflow: visible; }
Expand Down
204 changes: 204 additions & 0 deletions assets/components/minishop3/js/mgr/utilities/extrafield/grid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
ms3.grid.ExtraField = function (config) {
config = config || {};
if (!config.id) {
config.id = 'ms3-grid-extrafields';
}
config.disableContextMenuAction = true;
config.class_key = null;

Ext.applyIf(config, {
baseParams: {
action: 'MiniShop3\\Processors\\Utilities\\ExtraField\\GetList'
},
stateful: true,
stateId: config.id,
multi_select: true,
});
ms3.grid.ExtraField.superclass.constructor.call(this, config);
};

Ext.extend(ms3.grid.ExtraField, ms3.grid.Default, {

getFields: function () {
return ['id', 'class', 'key', 'label', 'dbtype', 'exists', 'active', 'actions'];
},

getTopBar: function () {
return [{
text: '<i class="icon icon-plus"></i> ' + _('ms3_btn_create'),
handler: this.createExtraField,
scope: this
}, '->', this.getSearchField()];
},

getColumns: function () {
return [
{
header: _('ms3_id'),
dataIndex: 'id',
width: 50,
sortable: true
}, {
header: _('ms3_extrafields_class'),
dataIndex: 'class',
width: 150,
sortable: true,
hidden: true
}, {
header: _('ms3_extrafields_key'),
dataIndex: 'key',
width: 100,
sortable: true
}, {
header: _('ms3_extrafields_label'),
dataIndex: 'label',
width: 100,
sortable: true
}, {
header: _('ms3_extrafields_dbtype'),
dataIndex: 'dbtype',
width: 100,
sortable: true
}, {
header: _('ms3_extrafields_exists'),
dataIndex: 'exists',
width: 80,
sortable: true,
renderer: ms3.utils.renderBoolean
}, {
header: _('ms3_active'),
dataIndex: 'active',
width: 80,
sortable: true,
renderer: ms3.utils.renderBoolean
}, {
header: _('ms3_actions'),
dataIndex: 'actions',
id: 'actions',
width: 70,
renderer: ms3.utils.renderActions
}
];
},

getListeners: function () {
return {
rowDblClick: function (grid, rowIndex, e) {
const row = grid.store.getAt(rowIndex);
this.updateExtraField(grid, e, row);
},
};
},

extraFieldAction: function (method) {
const ids = this._getSelectedIds();
if (!ids.length) {
return false;
}
MODx.Ajax.request({
url: ms3.config.connector_url,
params: {
action: 'MiniShop3\\Processors\\Utilities\\ExtraField\\Multiple',
method: method,
ids: Ext.util.JSON.encode(ids),
},
listeners: {
success: {
fn: function () {
//noinspection JSUnresolvedFunction
this.refresh();
}, scope: this
},
failure: {
fn: function (response) {
MODx.msg.alert(_('error'), response.message);
}, scope: this
},
}
})
},

createExtraField: function (btn, e) {
let w = Ext.getCmp('ms3-window-extra-field-create');
if (w) {
w.close();
}
w = MODx.load({
xtype: 'ms3-window-extra-field-create',
id: 'ms3-window-extra-field-create',
listeners: {
success: {
fn: function () {
this.refresh();
}, scope: this
}
}
});
w.setValues({
attributes: '',
default: '',
class: this.config.class_key
});
w.show(e.target);
},

updateExtraField: function (btn, e, row) {
if (typeof(row) != 'undefined') {
this.menu.record = row.data;
}
const id = this.menu.record.id;

MODx.Ajax.request({
url: this.config.url,
params: {
action: 'MiniShop3\\Processors\\Utilities\\ExtraField\\Get',
id: id
},
listeners: {
success: {
fn: function (r) {
let w = Ext.getCmp('ms3-window-extra-field-update');
if (w) {
w.close();
}

w = MODx.load({
xtype: 'ms3-window-extra-field-update',
id: 'ms3-window-extra-field-update',
record: r.object,
listeners: {
success: {
fn: function () {
this.refresh();
}, scope: this
}
}
});
w.fp.getForm().reset();
w.fp.getForm().setValues(r.object);
w.show(e.target);
}, scope: this
}
}
});
},

removeExtraField: function () {
const ids = this._getSelectedIds();

Ext.MessageBox.confirm(
_('ms3_menu_remove_title'),
ids.length > 1
? _('ms3_menu_remove_multiple_confirm')
: _('ms3_menu_remove_confirm'),
function (val) {
if (val == 'yes') {
this.extraFieldAction('Remove');
}
},
this
);
},

});
Ext.reg('ms3-grid-extrafields', ms3.grid.ExtraField);
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* Generates the Extra Fiels Classes Tree
*
* @class ms3.tree.ExtraFieldClass
* @extends MODx.tree.Tree
* @param {Object} config An object of options.
* @xtype ms3-tree-extrafieldclass
*/
MODx.tree.ExtraFieldClass = function (config) {
config = config || {};
Ext.applyIf(config, {
title: _('user_groups'),
id: 'ms3-tree-extrafieldclass',
url: MODx.config.connector_url,
action: 'MiniShop3\\Processors\\Utilities\\ExtraField\\GetClassNodes',
rootIconCls: 'icon-group',
//root_id: 'n_ug_0',
//root_name: _('user_groups'),
enableDD: false,
rootVisible: false,
//ddAppendOnly: true,
useDefaultToolbar: false,
tbar: [],

resize: {
fn: function(cmp) {
if (Ext.getCmp('ms3-grid-extrafields').hidden) {
cmp.layout.west.getSplitBar().el.hide();
}
},
scope: this
},
refresh: {
fn: function() {
this.setActiveClassKey();
},
scope: this
}
});
MODx.tree.ExtraFieldClass.superclass.constructor.call(this, config);
};

Ext.extend(MODx.tree.ExtraFieldClass, MODx.tree.Tree, {
windows: {

},

/**
* Handles tree clicks
* @param {Object} n The node clicked
* @param {Object} e The event object
*/
_handleClick: function (n, e) {
e.stopEvent();
e.preventDefault();

this.setActiveClassKey(n.attributes.type);

if (this.disableHref) { return true; }
if (e.ctrlKey) { return true; }
return true;
},
getMenu: function () {
return [];
},
setActiveClassKey: function(class_key) {
const grid = Ext.getCmp('ms3-grid-extrafields'),
westPanel = Ext.getCmp('ms3-tree-panel-extrafield').layout.west
;
if (class_key) {
grid.store.removeAll();
grid.show();
westPanel.getSplitBar().el.show();
grid.config.class_key = class_key;
grid.store.baseParams.class = class_key;
grid.store.load();
} else {
grid.hide();
westPanel.getSplitBar().el.hide();

}
}
});
Ext.reg('ms3-tree-extrafieldclass', MODx.tree.ExtraFieldClass);
Loading

0 comments on commit 247e699

Please sign in to comment.