public function __construct(array $cfg) { if (isset($cfg['primary'])) { $this->id = isset($cfg['id']) ? $cfg['id'] : \bbn\str\text::genpwd(); $this->primary = $cfg['primary']; if (!isset($cfg['builder'])) { $cfg['builder'] = new \bbn\html\builder(); } $this->builder = $cfg['builder']; $this->grid = new \Kendo\UI\Grid($this->id); $this->dataSource = new \Kendo\Data\DataSource(); if (isset($cfg['data'])) { $this->dataSource->data($cfg['data']); } $this->schema = new \Kendo\Data\DataSourceSchema(); $this->schema->data('data'); $this->schema->total('total'); $this->model = new \Kendo\Data\DataSourceSchemaModel(); $this->model->id($cfg['primary']); foreach ($cfg['elements'] as $e) { if (isset($e['attr']['name'])) { $field = new \Kendo\Data\DataSourceSchemaModelField($e['attr']['name']); if (isset($e['attr']['name']) && isset($e['editable']) && $e['editable']) { if (isset($e['type'])) { $field->type($e['type']); } if (isset($e['null']) && $e['null']) { $field->nullable(true); } if (isset($e['attr']['readonly']) && $e['attr']['readonly']) { $field->editable(false); } else { if (isset($e['validation'])) { $field->validation($e['validation']); } } $this->model->addField($field); } if (empty($e['editable'])) { $field->editable(false); } if (!empty($e['default'])) { $field->defaultValue($e['default']); } } $col = new \Kendo\UI\GridColumn(); if (!isset($e['field']) || $e['field'] !== 'hidden') { if (isset($e['editable']) && $e['editable']) { /* if ( !isset($e['editor']) ){ $input = $this->builder->input($e, 1); $sc = $input->ele_and_script(); $e['editor'] = new \Kendo\JavaScriptFunction('function(container, options) { '.$sc[0].'.appendTo(container)'.$sc[1].' }'); } $col->editor($e['editor']); * */ } if (isset($e['raw'])) { $col->encoded(false); } if (isset($e['data'])) { $col->values($e['data']); } if (isset($e['label'])) { $col->title($e['label']); } if (isset($e['attr']['name'])) { $col->field($e['attr']['name']); } if (isset($e['width'])) { $col->width((int) $e['width']); } if (isset($e['format'])) { $col->format('{0:' . $e['format'] . '}'); } if (isset($e['hidden'])) { $col->hidden(true); } if (isset($e['template'])) { $col->template($e['template']); } if (isset($e['editor'])) { $col->editor($e['editor']); } if (isset($e['encoded'])) { $col->encoded($e['encoded']); } if (isset($e['commands'])) { foreach ($e['commands'] as $c) { if (isset($c['click'])) { $c['click'] = new \Kendo\JavaScriptFunction($c['click']); } $col->addCommandItem($c); } } if (count(\bbn\tools::to_array($col)) > 0) { $this->grid->addColumn($col); } } } if (isset($cfg['url'])) { $this->transport = new \Kendo\Data\DataSourceTransport(); if (isset($cfg['all'])) { $this->set_all($cfg['url']); } else { if (isset($cfg['select'])) { $this->set_select($cfg['select'] === 1 || $cfg['select'] === 'on' ? 'json/select/' . $cfg['url'] : $cfg['select']); } if (isset($cfg['insert'])) { $this->set_insert($cfg['insert'] === 1 || $cfg['insert'] === 'on' ? 'json/insert/' . $cfg['url'] : $cfg['insert']); } if (isset($cfg['update'])) { $this->set_update($cfg['update'] === 1 || $cfg['update'] === 'on' ? 'json/update/' . $cfg['url'] : $cfg['update']); } if (isset($cfg['delete'])) { $this->set_delete($cfg['delete'] === 1 || $cfg['delete'] === 'on' ? 'json/delete/' . $cfg['url'] : $cfg['delete']); } } $this->dataSource->transport($this->transport); } if (isset($cfg['data'])) { $this->dataSource->data($cfg['data']); } $this->schema->model($this->model); $this->dataSource->schema($this->schema)->pageSize(50); $this->grid->attr("class", "appui-full-height")->datasource($this->dataSource)->editable(['mode' => 'popup'])->filterable(true)->resizable(true)->sortable(true)->groupable(true)->pageable(true)->columnMenu(true)->edit(new \Kendo\JavaScriptFunction('function(){ $(".k-edit-form-container").parent().css({ height:"auto", width:720, "max-height":appui.v.height-100 }).restyle().data("kendoWindow").title("' . \bbn\str\text::escape_dquotes($cfg['description']) . '").center(); }')); $this->cfg['args'] = [$this->id]; $this->cfg['datasource']['schema']['model']['id'] = $this->primary; } }