schema = $schema;
}
/**
* Returns the Admin Form to edit the schema
*
* This data is processed by the SchemaBuilder class
*
* @return string the HTML for the editor form
* @see SchemaBuilder
*/
public function getEditor() {
$form = new Form(array('method' => 'POST', 'id'=>'plugin__struct'));
$form->setHiddenField('do', 'admin');
$form->setHiddenField('page', 'struct');
$form->setHiddenField('table', $this->schema->getTable());
$form->setHiddenField('schema[id]', $this->schema->getId());
$form->addHTML('
');
$form->addHTML('
Sort
Label
Multi-Input?
Configuration
Type
'); // FIXME localize
foreach($this->schema->getColumns() as $key => $obj) {
$form->addHTML($this->adminColumn($key, $obj));
}
// FIXME new one needs to be added dynamically, this is just for testing
$form->addHTML($this->adminColumn('new1', new Column($this->schema->getMaxsort()+10, new Text()), 'new'));
$form->addHTML('
');
$form->addButton('save', 'Save')->attr('type','submit');
return $form->toHTML() . $this->initJSONEditor();
}
/**
* Gives the code to attach the JSON editor to the config field
*
* We do not use the "normal" way, because this is rarely used code and there's no need to always load it.
*
* @todo decide if that is really the way we want to go
* @return string
*/
protected function initJSONEditor() {
$html = '';
$html .= '';
$html .= '';
$html .= '';
$html .= '';
return $html;
}
/**
* Returns the HTML to edit a single column definition of the schema
*
* @param string $column_id
* @param Column $col
* @param string $key The key to use in the form
* @return string
* @todo this should probably be reused for adding new columns via AJAX later?
*/
protected function adminColumn($column_id, Column $col, $key='cols') {
$base = 'schema['.$key.'][' . $column_id . ']'; // base name for all fields
$html = '