Exemple #1
0
 function dashboard()
 {
     \LaraPage::html()->ngApp();
     $form = new LaraForm('test');
     $form->putEmailTwbs('email')->setLabel('E-mail');
     $form->putSubmitTwbs('Отправить')->addClass('btn-success');
     return $this->setLayout('lk-adminlte::admin')->response(['content' => $form]);
 }
 function getForm()
 {
     $form = new LaraForm($this->relation);
     $form->putTbHidden('relation')->setValue($this->relation);
     $options = $this->getOptions();
     if (!is_array($options)) {
         $options = [];
     }
     $form->putTbGroupCheckbox('has_many', $options, false);
     $ids = $this->ids();
     $form->initValues(['has_many' => array_combine($ids, $ids)]);
     return $form;
 }
 function getForm()
 {
     $form = new LaraForm($this->relation);
     $form->putTbHidden('relation')->setValue($this->relation);
     $method = \Str::camel('relation_' . $this->relation);
     $model = call_user_func([$this, $method]);
     $options = $model::orderBy($this->orderByModel())->listsExt();
     if (!is_array($options)) {
         $options = [];
     }
     $method = \Str::camel('empty_' . $this->relation);
     if (method_exists($this, $method)) {
         $empty = call_user_func([$this, $method]);
         $options = [0 => $empty] + $options;
     }
     $form->putTbGroupRadio('belongs_to', $options, false);
     $ids = $this->ids();
     $form->initValues(['belongs_to' => $ids]);
     return $form;
 }
Exemple #4
0
 function toArray()
 {
     $this->init();
     $box = $this->form->putAlteBox('Фильтры списка');
     $body = $box->putAlteBoxBody()->removeClass('box-primary');
     foreach ($this->filters as $filter) {
         /* @var $filter FilterSelfLike */
         $filter->element($body);
         $filter->query($this->model);
     }
     if ($this->form->isSubmitted()) {
         $box->addClass('box-solid box-success');
     } else {
         $box->addClass('box-default');
     }
     $footer = $box->putAlteBoxFooter();
     $footer->putSubmitTwbs('Применить')->addClass('btn-success btn-disabled col-lg-6');
     $footer->putButtonLinkTwbs($this->base_url, 'Сбросить')->addClass('btn-default col-lg-6');
     //        ->removeClass('box-primary');
     return ['form_filter' => $this->form, 'models' => $this->model->paginate($this->per_page)];
 }
 function buildForm()
 {
     $form = new LaraForm($this->relation);
     $form->putTbHidden('relation')->setValue($this->relation);
     $options = [];
     $model = $this->traitEntityBelongsToMany_getBelongsModel();
     if ($model) {
         $options = $model::orderBy($this->orderByModel())->listsExt();
         if (!is_array($options)) {
             $options = [];
         }
     }
     $form->putTbGroupCheckbox('belongs_to_many', $options, false);
     $ids = $this->ids();
     $form->initValues(['belongs_to_many' => array_combine($ids, $ids)]);
     if ($form->validate()) {
         $many = $form->getFieldValue('belongs_to_many');
         $filtered = array_filter($many, function ($value) {
             return $value;
         });
         $ids = array_keys($filtered);
         $this->model->{$this->relation}()->sync($ids);
     }
     $this->traitEntityBelongsToMany_form = $form;
 }
Exemple #6
0
 function toArray()
 {
     $this->init();
     if ($this->with_trash) {
         $this->model->withTrashed();
         $this->addFilterInCheckboxButton('with_trash', 'Режим поиска', [0 => 'Не удаленные', 1 => 'Удаленные'], [0 => Model::FILTER_SOFT_DELETE_NO, 1 => Model::FILTER_SOFT_DELETE_YES], [0 => 0], [0 => function ($query) {
             $query->whereNull('deleted_at');
         }, 1 => function ($query) {
             $query->whereNotNull('deleted_at');
         }]);
     }
     //        dd($this->getList()->toArray());
     return ['models' => $this->getList(), 'filter' => $this->getForm(), 'filters' => $this->form->getValue(), 'js_filters' => implode(' ', $this->getJsFilters()), 'vendor' => $this->getVendor(), 'entity' => $this->getEntity()];
 }
Exemple #7
0
 public function validate()
 {
     $res = $this->isSubmitted() && parent::validate();
     if ($res) {
         $rules = [];
         $names = [];
         if ($this->validator_rules) {
             foreach ($this->validator_rules as $f => $element_rules) {
                 $name = LaraForm::getNameFromDot($f);
                 $elements = $this->getElementsByName($name);
                 if (count($elements)) {
                     $rules[$f] = $element_rules;
                     $names[$f] = '"' . Arr::get($elements, 0)->getLabel() . '"';
                 }
             }
             $validator = \Validator::make($this->getValue(), $rules, $this->validator_messages, $names);
             if ($validator->fails()) {
                 $errors = [];
                 foreach ($validator->errors()->toArray() as $k => $v) {
                     Arr::set($errors, $k, Arr::get($v, 0));
                 }
                 //dd($validator->errors()->toArray(), $errors);
                 $this->setErrors($errors);
                 $res = false;
             }
         }
     }
     return $res;
 }
Exemple #8
0
 public function __construct($id, $method = 'post', $attributes = null, $trackSubmit = true)
 {
     parent::__construct($id, $method, $attributes, $trackSubmit);
     $this->build();
 }