Example #1
0
 private function get_default_grid_config($table, $params = [])
 {
     if ($this->db && ($cfg = $this->db->modelize($table)) && isset($cfg['keys']['PRIMARY']) && count($cfg['keys']['PRIMARY']['columns']) === 1 && ($table = $this->db->table_full_name($table))) {
         $id = \bbn\str\text::genpwd();
         $full_cfg = ['id' => $id, 'table' => $table, 'description' => null, 'url' => implode("/", $params), 'primary' => $cfg['keys']['PRIMARY']['columns'][0], 'select' => 'json/select/' . $table, 'insert' => 'json/insert/' . $table, 'update' => 'json/update/' . $table, 'delete' => 'json/delete/' . $table, 'elements' => []];
         $args = $params;
         array_shift($args);
         $where = [];
         for ($i = 0; $i < count($args) - 1; $i++) {
             if (isset($cfg['fields'][$args[$i]])) {
                 array_push($where, [$args[$i], '=', $args[$i + 1]]);
             }
             $i++;
         }
         $limit = 5;
         $i = 0;
         foreach ($cfg['fields'] as $name => $f) {
             $r = $this->get_default_col_config($table, $name, $where, $params);
             $full_cfg['elements'][$i] = $this->get_default_col_config($table, $name, $where, $params);
             $full_cfg['elements'][$i]['table'] = $table;
             if ($f['key'] === 'PRI' || $i >= $limit) {
                 $full_cfg['elements'][$i]['hidden'] = 1;
             }
             $i++;
         }
         array_push($full_cfg['elements'], ['attr' => ['name' => 'id'], 'commands' => [['name' => 'edit', 'text' => 'Mod.'], ['name' => 'destroy', 'text' => 'Suppr.']], 'label' => 'Actions', 'width' => 160]);
         //die(print_r($full_cfg));
         return $full_cfg;
     }
 }
Example #2
0
 /**
  * @return string
  */
 public static function make_fingerprint()
 {
     return \bbn\str\text::genpwd(32, 16);
 }
Example #3
0
 public function label($cfg)
 {
     if (isset($cfg['null']) && $cfg['null']) {
         $label = ['tag' => 'div', 'attr' => ['class' => self::$label_class], 'content' => []];
         $tmp = ['tag' => 'label', 'text' => isset($cfg['label']) ? $cfg['label'] : ' '];
         if (isset($cfg['attr']['id'])) {
             $tmp['attr'] = ['for' => $cfg['attr']['id']];
         }
         array_push($label['content'], $tmp);
         $label_content = ['tag' => 'div', 'css' => ['display' => 'block', 'position' => 'absolute', 'right' => '0px', 'top' => '3px'], 'content' => [['tag' => 'span', 'text' => 'Null?  '], ['tag' => 'input', 'attr' => ['id' => \bbn\str\text::genpwd(), 'type' => 'checkbox'], 'events' => ['click' => 'function(e){
                     $("#' . $cfg['attr']['id'] . '").prop("disabled", $(this).is(":checked"));' . (isset($cfg['widget']['name']) ? '
                     appui.f.log("' . $cfg['widget']['name'] . '");
                     try{
                       $("#' . $cfg['attr']['id'] . '").' . $cfg['widget']['name'] . '("enable", (!$(this).is(":checked")));
                     }
                     catch(err){
                       appui.f.log(err);
                     }' : '') . '
                   }']]]];
         if (empty($cfg['attr']['value'])) {
             $label_content['content'][1]['attr']['checked'] = true;
         }
         array_push($label['content'], $label_content);
     } else {
         $label = ['tag' => 'label', 'text' => isset($cfg['label']) ? $cfg['label'] : ' ', 'attr' => ['class' => self::$label_class]];
         if (isset($cfg['attr']['id'])) {
             $label['attr']['for'] = $cfg['attr']['id'];
         }
     }
     return new \bbn\html\element($label);
 }
Example #4
0
 /**
  * This will build a new HTML form element according to the given configuration.
  * Only name and tag are mandatory, then other values depending on the tag
  * 
  * @param array $cfg The configuration
  * @return self
  */
 public function __construct($cfg)
 {
     if (is_string($cfg)) {
         $cfg = ['field' => 'text', 'attr' => ['name' => $cfg]];
     }
     parent::__construct($cfg);
     if ($this->tag) {
         $mandatory_attr = array();
         if (!isset($this->attr['id'])) {
             $this->attr['id'] = \bbn\str\text::genpwd(20, 15);
         }
         $this->script = isset($cfg['script']) ? $cfg['script'] : '';
         $this->value = isset($cfg['value']) ? $cfg['value'] : '';
         switch ($this->tag) {
             case "input":
                 array_push($mandatory_attr, "type");
                 break;
             case "textarea":
                 array_push($mandatory_attr, "cols", "rows");
                 break;
             case "select":
                 array_push($mandatory_attr, "attr");
                 break;
         }
         foreach ($mandatory_attr as $m) {
             if (!isset($this->attr[$m])) {
                 die("Argument {$m} is missing in your config... Sorry!");
             }
         }
     }
     return $this;
 }
Example #5
0
 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;
     }
 }