Добавление select с данными из другой таблицы в modExtra
Всем привет. Кто-нибудь на заготовке modExtra делал CоmboBox с данными из других таблиц? У меня есть файл вызывающий модальное окно с полями для заполнения:
assets/components/extras/js/mgr/widgets/categories.window.js
тоесть нужно select сделать из
assets/components/extras/js/mgr/widgets/categories.window.js
Extras.window.CreateCategory = function (config) {
config = config || {};
if (!config.id) {
config.id = 'extras-category-window-create';
}
Ext.applyIf(config, {
title: _('extras_category_create'),
width: 550,
autoHeight: true,
url: Extras.config.connector_url,
action: 'mgr/category/create',
fields: this.getFields(config),
keys: [{
key: Ext.EventObject.ENTER, shift: true, fn: function () {
this.submit()
}, scope: this
}]
});
Extras.window.CreateCategory.superclass.constructor.call(this, config);
};
Ext.extend(Extras.window.CreateCategory, MODx.Window, {
getFields: function (config) {
return [{
xtype: 'textfield',
fieldLabel: _('extras_category_name'),
name: 'name',
id: config.id + '-name',
anchor: '99%',
allowBlank: false,
}, {
xtype: 'textfield',
fieldLabel: _('extras_category_repository'),
name: 'repository_id',
id: config.id + '-repository_id',
anchor: '99%',
allowBlank: true,
}, {
xtype: 'xcheckbox',
boxLabel: _('extras_category_active'),
name: 'active',
id: config.id + '-active',
checked: true,
}];
},
loadDropZones: function () {
}
});
Ext.reg('extras-category-window-create', Extras.window.CreateCategory);
Extras.window.UpdateCategory = function (config) {
config = config || {};
if (!config.id) {
config.id = 'extras-category-window-update';
}
Ext.applyIf(config, {
title: _('extras_category_update'),
width: 550,
autoHeight: true,
url: Extras.config.connector_url,
action: 'mgr/category/update',
fields: this.getFields(config),
keys: [{
key: Ext.EventObject.ENTER, shift: true, fn: function () {
this.submit()
}, scope: this
}]
});
Extras.window.UpdateCategory.superclass.constructor.call(this, config);
};
Ext.extend(Extras.window.UpdateCategory, MODx.Window, {
getFields: function (config) {
return [{
xtype: 'hidden',
name: 'id',
id: config.id + '-id',
}, {
xtype: 'textfield',
fieldLabel: _('extras_category_name'),
name: 'name',
id: config.id + '-name',
anchor: '99%',
allowBlank: false,
}, {
xtype: 'textfield',
fieldLabel: _('extras_category_repository'),
name: 'repository_id',
id: config.id + '-repository_id',
anchor: '99%',
allowBlank: true,
}, {
xtype: 'xcheckbox',
boxLabel: _('extras_category_active'),
name: 'active',
id: config.id + '-active',
}];
},
loadDropZones: function () {
}
});
Ext.reg('extras-category-window-update', Extras.window.UpdateCategory);тоесть нужно select сделать из
{
xtype: 'textfield',
fieldLabel: _('extras_category_repository'),
name: 'repository_id',
id: config.id + '-repository_id',
anchor: '99%',
allowBlank: true,
},В процессоре core/components/extras/processors/mgr/category/getlist.class.php<?php
class ExtrasCategoriesGetListProcessor extends modObjectGetListProcessor
{
public $objectType = 'ExtrasCategories';
public $classKey = 'ExtrasCategories';
public $defaultSortField = 'id';
public $defaultSortDirection = 'DESC';
//public $permission = 'list';
/**
* We do a special check of permissions
* because our objects is not an instances of modAccessibleObject
*
* @return boolean|string
*/
public function beforeQuery()
{
if (!$this->checkPermissions()) {
return $this->modx->lexicon('access_denied');
}
return true;
}
/**
* @param xPDOQuery $c
*
* @return xPDOQuery
*/
public function prepareQueryBeforeCount(xPDOQuery $c)
{
$query = trim($this->getProperty('query'));
if ($query) {
$c->where([
'name:LIKE' => "%{$query}%",
'OR:repository_id:LIKE' => "%{$query}%",
]);
}
return $c;
}
/**
* @param xPDOObject $object
*
* @return array
*/
public function prepareRow(xPDOObject $object)
{
if ($this->getProperty('combo')) {
$data = array(
'id' => $object->get('id'),
'name' => $object->get('name'),
);
} else {
$array = $object->toArray();
if (!$array['resource']) {
$array['resource'] = null;
}
$array['actions'] = [];
// Edit
$array['actions'][] = [
'cls' => '',
'icon' => 'icon icon-edit',
'title' => $this->modx->lexicon('extras_category_update'),
//'multiple' => $this->modx->lexicon('extras_categories_update'),
'action' => 'updateCategory',
'button' => true,
'menu' => true,
];
if (!$array['active']) {
$array['actions'][] = [
'cls' => '',
'icon' => 'icon icon-power-off action-green',
'title' => $this->modx->lexicon('extras_category_enable'),
'multiple' => $this->modx->lexicon('extras_categories_enable'),
'action' => 'enableCategory',
'button' => true,
'menu' => true,
];
} else {
$array['actions'][] = [
'cls' => '',
'icon' => 'icon icon-power-off action-gray',
'title' => $this->modx->lexicon('extras_category_disable'),
'multiple' => $this->modx->lexicon('extras_categories_disable'),
'action' => 'disableCategory',
'button' => true,
'menu' => true,
];
}
// Remove
$array['actions'][] = [
'cls' => '',
'icon' => 'icon icon-trash-o action-red',
'title' => $this->modx->lexicon('extras_category_remove'),
'multiple' => $this->modx->lexicon('extras_categories_remove'),
'action' => 'removeCategory',
'button' => true,
'menu' => true,
];
}
return $array;
}
}
return 'ExtrasCategoriesGetListProcessor';Может кто-нибудь помочь с этим? Комментарии: 15
Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
Потом просто используешь свой xtype где тебе нужно
Процессор примерно такой
Получилось сделать так, добавил в combo.js
а xtype в categories.window.js вышел такой:
Да, процессоры вообще не трогал, ну кроме изменения классов и лексиконов под себя, всё из дефольтной версии modExtras выводится. Теперь встала задача вывести в grid вместо id название)))
Если не ошибаюсь примерно как-то так
getlist.class.php
docs.modx.com/xpdo/2.x/class-reference/xpdoquery/xpdoquery.leftjoin
и
Синтаксис lefJoin правильный? Указываем класс модели и его алиас?!
ну и в самом файле categories.grid.js вставил поле:
И само поле
Поле стало пустым полностью)
Попробуй вынеси выше
position_name — это alias присоединенного поля. Поиск не ищет по данному полю. В чем могут быть нюансы.
modx.pro/development/19942
github.com/SequelONE/modExtra