Improve DataTable form widget, fixes vague error in RecordFinder

This commit is contained in:
Samuel Georges 2015-03-24 20:10:24 +11:00
parent 6820b12ec0
commit 3c2494aa83
3 changed files with 55 additions and 24 deletions

View File

@ -14,15 +14,29 @@ use ApplicationException;
*/
class DataTable extends FormWidgetBase
{
/**
* {@inheritDoc}
*/
protected $defaultAlias = 'datatable';
//
// Configurable properties
//
/**
* @var string Table size
*/
protected $size = 'large';
public $size = 'large';
/**
* @var bool Allow rows to be sorted
* @todo Not implemented...
*/
public $rowSorting = false;
//
// Object properties
//
/**
* {@inheritDoc}
*/
protected $defaultAlias = 'datatable';
/**
* @var Backend\Widgets\Table Table widget
@ -34,7 +48,11 @@ class DataTable extends FormWidgetBase
*/
public function init()
{
$this->size = $this->getConfig('size', $this->size);
$this->fillFromConfig([
'size',
'rowSorting',
]);
$this->table = $this->makeTableWidget();
$this->table->bindToController();
}
@ -64,6 +82,23 @@ class DataTable extends FormWidgetBase
$this->populateTableWidget();
$this->vars['table'] = $this->table;
$this->vars['size'] = $this->size;
$this->vars['rowSorting'] = $this->rowSorting;
}
/**
* {@inheritDoc}
*/
public function getLoadValue()
{
$value = (array) parent::getLoadValue();
// Sync the array keys as the ID to make the
// table widget happy!
foreach ($value as $key => $_value) {
$value[$key] = ['id' => $key] + (array) $_value;
}
return $value;
}
/**
@ -82,6 +117,12 @@ class DataTable extends FormWidgetBase
$result += $records;
}
// We should be dealing with a simple array, so
// strip out the id columns in the final array.
foreach ($result as $key => $_result) {
unset($result[$key]['id']);
}
return $result;
}

View File

@ -101,11 +101,11 @@ class RecordFinder extends FormWidgetBase
}
/**
* Returns the value as a relation object from the model,
* Returns the model of a relation type,
* supports nesting via HTML array.
* @return Relation
*/
protected function getRelationObject()
protected function getRelationModel()
{
list($model, $attribute) = $this->resolveModelAttribute($this->valueFrom);
@ -116,17 +116,6 @@ class RecordFinder extends FormWidgetBase
]));
}
return $model->{$attribute}();
}
/**
* Returns the model of a relation type,
* supports nesting via HTML array.
* @return Relation
*/
protected function getRelationModel()
{
list($model, $attribute) = $this->resolveModelAttribute($this->valueFrom);
return $model->makeRelation($attribute);
}

View File

@ -353,9 +353,9 @@
dataContainer.setAttribute('type', 'hidden')
dataContainer.setAttribute('data-container', 'data-container')
dataContainer.value = records[i][columnName] !== undefined ?
records[i][columnName] :
""
dataContainer.value = records[i][columnName] !== undefined
? records[i][columnName]
: ""
cellContentContainer.setAttribute('class', 'content-container')
@ -391,9 +391,10 @@
Table.prototype.fetchRecords = function(onSuccess) {
this.dataSource.getRecords(
this.navigation.getPageFirstRowOffset(),
this.navigation.getPageFirstRowOffset(),
this.options.recordsPerPage,
onSuccess)
onSuccess
)
}
Table.prototype.updateScrollbar = function() {