Пример #1
0
 /**
  * Returns the javascript coming with the object
  * 
  * @return string javascript string
  */
 public function script($with_ele = 1)
 {
     $this->update();
     $r = '';
     if (isset($this->attr['id'])) {
         if (isset($this->cfg['events'])) {
             foreach ($this->cfg['events'] as $event => $fn) {
                 $r .= '.' . $event . '(' . (strpos($fn, 'function') === 0 ? $fn : 'function(e){' . $fn . '}') . ')';
             }
         }
         if (isset($this->cfg['widget'], $this->cfg['widget']['name'])) {
             $r .= '.' . $this->cfg['widget']['name'] . '(';
             if (isset($this->cfg['widget']['options'])) {
                 $r .= '{';
                 foreach ($this->cfg['widget']['options'] as $n => $o) {
                     $r .= '"' . $n . '":';
                     if (is_string($o)) {
                         $o = trim($o);
                         if (strpos($o, 'function(') === 0) {
                             $r .= $o;
                         } else {
                             $r .= '"' . \bbn\str\text::escape_dquotes($o) . '"';
                         }
                     } else {
                         if (is_bool($o)) {
                             $r .= $o ? 'true' : 'false';
                         } else {
                             $r .= json_encode($o);
                         }
                     }
                     $r .= ',';
                 }
                 $r .= '}';
             }
             $r .= ')';
         }
         if (!empty($this->help)) {
             // tooltip
         }
         if (!empty($r)) {
             if ($with_ele) {
                 $r = '$("#' . $this->attr['id'] . '")' . $r . ';' . PHP_EOL;
             } else {
                 $r = $r . ';' . PHP_EOL;
             }
         }
     }
     if (!empty($this->script)) {
         $r .= $this->script . PHP_EOL;
     }
     if (is_array($this->content)) {
         foreach ($this->content as $c) {
             if (is_array($c)) {
                 $c = new \bbn\html\element($c);
             }
             if (is_object($c) && method_exists($c, 'script')) {
                 $r .= $c->script();
             }
         }
     }
     return $r;
 }
Пример #2
0
 /**
  * Returns a value string ready to be put inside quotes, with quotes and percent escaped.
  * 
  * <code>
  * $this->db->escape_value("L'infanzia di \"maria\"");
  * </code>
  * 
  * @param string $value The string to escape.
  * 
  * @return string | false
  */
 public function escape_value($value, $esc = "'")
 {
     if (is_string($value)) {
         return str_replace('%', '\\%', $esc === '"' ? \bbn\str\text::escape_dquotes($value) : \bbn\str\text::escape_squotes($value));
     }
     return $value;
 }
Пример #3
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;
     }
 }