/custom/plugins/HzweiaKbaAddon/Resources/views/backend/hzweia_kba_addon/view/article/detail/hzweia_kba_tab.js
//{block name="Shopware.apps.HzweiaKbaAddon.view.article.detail.HzweiaKbaTab"}
Ext.define('Shopware.apps.HzweiaKbaAddon.view.article.detail.HzweiaKbaTab', {
extend: 'Ext.grid.Panel',
alias: 'widget.hzweia_kba_addon-detail-article_kba_list',
cls: 'viison-common--grid has--vertical-lines has--no-borders',
padding: 10,
title: 'HZWEIA',
initComponent: function() {
var me = this;
me.emptyText = "Fahrzeugliste nicht vorhanden";
me.columns = me.createColumns();
me.bbar = me.getPagingbar();
me.store = me.SoftwKbaManager;
me.selModel = me.getGridSelModel();
me.addEvents(
/**
* Fired when the user edited a product in the grid
*/
'saveProduct',
/**
* A search was triggered
*/
'search'
);
me.rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 2,
autoCancel: true,
listeners: {
scope: me,
edit: function (editor, context) {
me.fireEvent('saveProduct', editor, context)
}
}
});
me.plugins = me.rowEditing;
me.listeners = {
'afterrender': me.onAfterRender
};
this.callParent(arguments);
},
/**
* @return Ext.grid.column.Column[]
*/
createColumns: function () {
var me = this;
return [{
dataIndex: 'selected',
header: 'Ausgewählt',
flex: 1,
width: 60,
renderer: me.booleanColumnRenderer,
editor: {
xtype: 'checkbox',
inputValue: 1,
uncheckedValue: 0
}
}, {
dataIndex: 'ktype',
header: "KType",
flex: 1,
}, {
dataIndex: 'kba',
header: 'KBA-Nummer',
flex: 1,
}, {
dataIndex: 'hersteller',
header: 'Marke',
flex: 1,
}, {
dataIndex: 'modell',
header: 'Modell',
flex: 1,
}, {
dataIndex: 'typ',
header: 'Typ',
flex: 1,
}, {
dataIndex: 'plattform',
header: 'Plattform',
flex: 1,
}, {
dataIndex: 'baujahr',
header: 'Baujahr',
flex: 1,
}, {
dataIndex: 'motor',
header: 'Motor',
flex: 1,
}];
},
onAfterRender: function() {
var me = this;
Ext.each(me.columns, function(col) {
if (col.dataIndex === 'Detail_active') {
me.detailActiveColumn = col;
window.setTimeout(function() { col.setVisible(false); }, 0);
}
});
},
getGridSelModel: function () {
var me = this;
return Ext.create('Ext.selection.CheckboxModel', {
listeners: {
// Unlocks the delete button if the user has checked at least one checkbox
selectionchange: function (sm, selections) {
me.deleteButton.setDisabled(selections.length === 0);
me.splitViewModeBtn.setDisabled(selections.length === 0);
me.fireEvent('productchange', selections);
}
}
});
},
/**
* Creates rowEditor Plugin
*
* @return [Ext.grid.plugin.RowEditing]
*/
getRowEditorPlugin: function () {
return Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 2,
errorSummary: false,
pluginId: 'rowEditing'
});
},
/**
* Column renderer for boolean columns in order to
* @param value
*/
booleanColumnRenderer: function (value) {
var checked = 'sprite-ui-check-box-uncheck';
if (value == true) {
checked = 'sprite-ui-check-box';
}
return '';
},
/**
* Creates pagingbar
*
* @return Ext.toolbar.Paging
*/
getPagingbar: function () {
var me = this,
productSnippet = 'Einträge';
var pageSize = Ext.create('Ext.form.field.ComboBox', {
labelWidth: 120,
cls: Ext.baseCSSPrefix + 'page-size',
queryMode: 'local',
width: 180,
editable: false,
listeners: {
scope: me,
select: me.onPageSizeChange
},
store: Ext.create('Ext.data.Store', {
fields: ['value', 'name'],
data: [
{ value: '25', name: '25 ' + productSnippet },
{ value: '50', name: '50 ' + productSnippet },
{ value: '75', name: '75 ' + productSnippet },
{ value: '100', name: '100 ' + productSnippet },
{ value: '125', name: '125 ' + productSnippet },
{ value: '150', name: '150 ' + productSnippet }
]
}),
displayField: 'name',
valueField: 'value'
});
var pagingBar = Ext.create('Ext.toolbar.Paging', {
dock: 'bottom',
displayInfo: true
});
pagingBar.insert(pagingBar.items.length, [
{ xtype: 'tbspacer', width: 6 },
pageSize
]);
return pagingBar;
},
/**
* Event listener method which fires when the user selects
* a entry in the "number of orders"-combo box.
*
* @event select
* @param { object } combo - Ext.form.field.ComboBox
* @param { array } records - Array of selected entries
* @return void
*/
onPageSizeChange: function (combo, records) {
var record = records[0],
me = this;
me.store.pageSize = record.get('value');
if (!me.store.getProxy().extraParams.ast) {
return;
}
me.store.loadPage(1);
},
});
//{/block}
/custom/plugins/HzweiaKbaAddon/Resources/views/backend/hzweia_kba_addon/app.js
//{block name="backend/article/application"}
// {$smarty.block.parent}
// {include file="backend/hzweia_kba_addon/controller/hzweia_kba_addon.js"}
// {include file="backend/hzweia_kba_addon/view/article/detail/hzweia_kba_tab.js"}
//{/block}
Und mein bis jetzt noch sehr nichtssagender Backend-Controller:
Request()->getParam('limit', 30);
$offset = $this->Request()->getParam('start', 0);
$sort = $this->Request()->getParam('sort', null);
$builder = Shopware()->Models()->createQueryBuilder();
$builder->select('b')
->from('SoftwKbaManager\Models\Cars', 'b');
if (!empty($sort)) {
$sort[0]['property'] = 'b.' . $sort[0]['property'];
$builder->addOrderBy($sort);
}
$builder->setFirstResult($offset)
->setMaxResults($limit);
$query = $builder->getQuery();
$query->setHydrationMode(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);
$paginator = Shopware()->Container()->get('Models')->createPaginator($query);
$total = $paginator->count();
$data = $query->getArrayResult();
// sends the out put to the view
$this->View()->assign(array(
'success' => true,
'data' => $data,
'total' => $total
));
}
/**
* @throws Exception
*/
public function updateListAction()
{
try {
Shopware()->Models()->flush();
} catch (\Doctrine\ORM\OptimisticLockException $e) {
$this->View()->assign(
array(
'success' => false,
'message' => "Fehler " . print_r($e, true)
)
);
}
$this->View()->assign(array(
'success' => true
));
}
}