/**
* Load the datagrid
*/
private function loadDataGrid()
{
// init vars
$langWidth = 60 / count($this->filter['language']);
// if nothing is submitted
// we don't need to fetch all the locale
$this->hasSubmissions = '' !== $this->filter['application'] . $this->filter['module'] . $this->filter['name'] . $this->filter['value'];
if ($this->hasSubmissions) {
// get all the translations for the selected languages
$translations = BackendLocaleModel::getTranslations($this->filter['application'], $this->filter['module'], $this->filter['type'], $this->filter['language'], $this->filter['name'], $this->filter['value']);
}
// create datagrids
$this->dgLabels = new BackendDataGridArray(isset($translations['lbl']) ? $translations['lbl'] : array());
$this->dgMessages = new BackendDataGridArray(isset($translations['msg']) ? $translations['msg'] : array());
$this->dgErrors = new BackendDataGridArray(isset($translations['err']) ? $translations['err'] : array());
$this->dgActions = new BackendDataGridArray(isset($translations['act']) ? $translations['act'] : array());
// put the datagrids (references) in an array so we can loop them
$dataGrids = array('lbl' => &$this->dgLabels, 'msg' => &$this->dgMessages, 'err' => &$this->dgErrors, 'act' => &$this->dgActions);
// loop the datagrids (as references)
foreach ($dataGrids as $type => &$dataGrid) {
/** @var $dataGrid BackendDataGridArray */
$dataGrid->setSortingColumns(array('module', 'name', 'application'), 'name');
// disable paging
$dataGrid->setPaging(false);
// set header label for reference code
$dataGrid->setHeaderLabels(array('name' => \SpoonFilter::ucfirst(BL::lbl('ReferenceCode'))));
// hide the application when only one application is shown
if ($this->filter['application'] != '') {
$dataGrid->setColumnHidden('application');
}
// hide edite_on
$dataGrid->setColumnHidden('edited_on');
// set column attributes for each language
foreach ($this->filter['language'] as $lang) {
// add a class for the inline edit
$dataGrid->setColumnAttributes($lang, array('class' => 'translationValue'));
// add attributes, so the inline editing has all the needed data
$dataGrid->setColumnAttributes($lang, array('data-id' => '{language: \'' . $lang . '\',application: \'[application]\',module: \'[module]\',name: \'[name]\',type: \'' . $type . '\'}'));
// escape the double quotes
$dataGrid->setColumnFunction(array('SpoonFilter', 'htmlentities'), array('[' . $lang . ']', null, ENT_QUOTES), $lang, true);
if ($type == 'act') {
$dataGrid->setColumnFunction('urldecode', array('[' . $lang . ']'), $lang, true);
}
// set header labels
$dataGrid->setHeaderLabels(array($lang => \SpoonFilter::ucfirst(BL::lbl(mb_strtoupper($lang)))));
// only 1 language selected?
if (count($this->filter['language']) == 1) {
$dataGrid->setColumnAttributes($lang, array('style' => 'width: ' . $langWidth . '%'));
// add id of translation for the export
$dataGrid->setColumnAttributes($lang, array('data-numeric-id' => '[translation_id]'));
// Hide translation_id column (only if only one language is selected
// because the key doesn't exist if more than 1 language is selected)
$dataGrid->setColumnHidden('translation_id');
// check if this action is allowed
if (BackendAuthentication::isAllowedAction('Add')) {
// add copy button
$dataGrid->addColumnAction('copy', null, BL::lbl('Copy'), BackendModel::createURLForAction('Add') . '&id=[translation_id]' . $this->filterQuery);
}
// check if this action is allowed
if (BackendAuthentication::isAllowedAction('Edit')) {
// add edit button
$dataGrid->addColumn('edit', null, BL::lbl('Edit'), BackendModel::createURLForAction('Edit') . '&id=[translation_id]' . $this->filterQuery);
}
} else {
// add id of translation for the export
$dataGrid->setColumnAttributes($lang, array('data-numeric-id' => '[translation_id_' . $lang . ']'));
$dataGrid->setColumnHidden('translation_id_' . $lang);
//ugly fix but the browser does funny things with the percentage when showing lots of languages
$dataGrid->setColumnAttributes($lang, array('style' => 'width: ' . $langWidth . '%; max-width: ' . 600 / count($this->filter['language']) . 'px;'));
}
}
}
}