Skip to content

Instantly share code, notes, and snippets.

@pavel-one
Created July 11, 2018 11:43
Show Gist options
  • Save pavel-one/675bba81243900fda23352189094d660 to your computer and use it in GitHub Desktop.
Save pavel-one/675bba81243900fda23352189094d660 to your computer and use it in GitHub Desktop.
example grid tab for modx-resource
/**
* init
* @param config
*/
var recipeComponents = function(config) {
config = config || {};
recipeComponents.superclass.constructor.call(this,config);
};
Ext.extend(recipeComponents,Ext.Component,{
window:{},
grid:{},
tree:{},
panel:{},
combo:{},
config: {},
view: {},
extra: {},
connector_url: '/assets/components/pavel/connector.php'
});
Ext.reg('recipeComponents',recipeComponents);
recipeComponents = new recipeComponents();
/*
* Added modx tab
*/
Ext.override(MODx.panel.Resource, {
getParentFields: MODx.panel.Resource.prototype.getFields,
getFields: function (config) {
//console.log(config);
var parentFields = this.getParentFields.call(this,config);
for (var i in parentFields) {
var item = parentFields[i];
if (item.id == 'modx-resource-tabs') {
//console.log(item);
item.items.push({
id: 'constructor-recipe'
,autoHeight: true
,title: 'Конструктор'
,layout: 'form'
,anchor: '100%'
,items: [{
html: '<p>Все пользовательские компоненты, которые добавляет автор рецепта</p>'
,xtype: 'modx-description'
},{
xtype: 'modx-tabs'
,defaults: { border: false ,autoHeight: true }
,border: true
,items: [{
title: 'Компоненты'
,defaults: { autoHeight: true }
,items: [{
html: '<p>Компоненты добавленные пользователем</p>'
,xtype: 'modx-description'
}, {
xtype: 'recipecomponents-grid-components',
record: config.record
}]
},{
title: 'Инструменты'
,defaults: { autoHeight: true }
,items: [{
html: '<p>Инструменты добавленные пользователем</p>'
,xtype: 'modx-description'
}, {
xtype: 'recipecomponents-grid-instrument',
record: config.record
}]
},{
title: 'Упакова'
,defaults: { autoHeight: true }
,items: [{
html: '<p>Упаковка добавленная пользователем</p>'
,xtype: 'modx-description'
}, {
xtype: 'recipecomponents-grid-packing',
record: config.record
}]
}]
}]
});
}
}
return parentFields;
}
});
recipeComponents.grid.Components = function(config) {
config = config || {};
//console.log(recipeComponents.connector_url);
Ext.applyIf(config,{
id: 'recipecomponents-grid-components'
,url: recipeComponents.connector_url
,baseParams: { action: 'mgr/phase/getlist', id: config.record.id}
,fields: ['id','title','order','resource_id']
,paging: true
,remoteSort: true
,anchor: '97%'
,autoExpandColumn: 'name'
,save_action: 'mgr/subscribers/updateFromGrid'
,autosave: true
,columns: [{
header: 'id'
,dataIndex: 'id'
,sortable: true
,hidden: false
},{
header: 'Название'
,dataIndex: 'title'
,sortable: true
},{
header: 'Номер сортировки'
,dataIndex: 'order'
,sortable: true
,hidden: true
},{
header: 'resource_id'
,dataIndex: 'resource_id'
,sortable: true
,hidden: true
}]
});
recipeComponents.grid.Components.superclass.constructor.call(this,config)
};
Ext.extend(recipeComponents.grid.Components,MODx.grid.Grid);
Ext.reg('recipecomponents-grid-components',recipeComponents.grid.Components);
recipeComponents.grid.Packing = function(config) {
config = config || {};
Ext.applyIf(config,{
id: 'recipecomponents-grid-packing'
,url: recipeComponents.connector_url
,baseParams: { action: 'mgr/packing/getlist', id: config.record.id}
,fields: ['id','title','order','recipe_id', 'product_id']
,paging: true
,remoteSort: true
,anchor: '97%'
,autoExpandColumn: 'name'
,save_action: 'mgr/subscribers/updateFromGrid'
,autosave: true
,columns: [{
header: 'id'
,dataIndex: 'id'
,sortable: true
,hidden: false
},{
header: 'Название'
,dataIndex: 'title'
,sortable: true
},{
header: 'Номер сортировки'
,dataIndex: 'order'
,sortable: true
,hidden: true
},{
header: 'ID рецепта'
,dataIndex: 'recipe_id'
,sortable: true
,hidden: true
},{
header: 'product_id'
,dataIndex: 'product_id'
,sortable: true
,hidden: false
,renderer: function (value) {
if (!value) return;
return '<a target="_blank" href="/index.php?a=resource/update&id='+value+'">Редактировать</a>';
}
},{
header: 'Название продукта'
,dataIndex: 'pagetitle'
,sortable: true
,hidden: false
}]
});
recipeComponents.grid.Packing.superclass.constructor.call(this,config)
};
Ext.extend(recipeComponents.grid.Packing,MODx.grid.Grid);
Ext.reg('recipecomponents-grid-packing',recipeComponents.grid.Packing);
recipeComponents.grid.Instrument = function(config) {
config = config || {};
Ext.applyIf(config,{
id: 'recipecomponents-grid-instrument'
,url: recipeComponents.connector_url
,baseParams: { action: 'mgr/instrument/getlist', id: config.record.id}
,fields: ['id','title','order','recipe_id', 'product_id', 'pagetitle']
,paging: true
,remoteSort: true
,anchor: '97%'
,autoExpandColumn: 'name'
,save_action: 'mgr/subscribers/updateFromGrid'
,autosave: true
,columns: [{
header: 'id'
,dataIndex: 'id'
,sortable: true
,hidden: false
},{
header: 'Название'
,dataIndex: 'title'
,sortable: true
},{
header: 'Номер сортировки'
,dataIndex: 'order'
,sortable: true
,hidden: true
},{
header: 'ID рецепта'
,dataIndex: 'recipe_id'
,sortable: true
,hidden: true
},{
header: 'Перейти к товару'
,dataIndex: 'product_id'
,sortable: true
,hidden: false
,renderer: function (value) {
//http://mashe.flat12.ru/manager/index.php?a=resource/update&id=31
if (!value) return;
return '<a target="_blank" href="/index.php?a=resource/update&id='+value+'">Редактировать</a>'
}
},{
header: 'Название товара'
,dataIndex: 'pagetitle'
,sortable: true
,hidden: false
}]
});
recipeComponents.grid.Instrument.superclass.constructor.call(this,config)
};
Ext.extend(recipeComponents.grid.Instrument,MODx.grid.Grid);
Ext.reg('recipecomponents-grid-instrument',recipeComponents.grid.Instrument);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment