Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jqhph committed Jan 11, 2021
1 parent 2921f80 commit 268f013
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 20 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"php": ">=7.1.0",
"symfony/dom-crawler": "~3.1|~4.0|~5.0",
"laravel/framework": "~5.5|~6.0|~7.0|~8.0",
"doctrine/dbal": "2.*",
"spatie/eloquent-sortable": "3.*"
},
"require-dev": {
Expand Down
71 changes: 58 additions & 13 deletions src/Form/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -876,11 +876,13 @@ protected function formatAttributes()
}

/**
* @param bool $value
*
* @return $this
*/
public function disableHorizontal()
public function horizontal(bool $value = true)
{
$this->horizontal = false;
$this->horizontal = $value;

return $this;
}
Expand Down Expand Up @@ -1093,25 +1095,40 @@ public function when($value, $callback)
return $this;
}

public function setFormGroupClass($labelClass, bool $append = true)
/**
* @param string|array $class
* @param bool $append
*
* @return $this
*/
public function setFormGroupClass($class, bool $append = true)
{
$this->formGroupClass = $append
? array_unique(array_merge($this->formGroupClass, (array) $labelClass))
: (array) $labelClass;
? array_unique(array_merge($this->formGroupClass, (array) $class))
: (array) $class;

return $this;
}

/**
* @return string
*/
public function getFormGroupClass()
{
return implode(' ', $this->formGroupClass);
}

public function setFieldClass($labelClass, bool $append = true)
/**
* @param string|array $class
* @param bool $append
*
* @return $this
*/
public function setFieldClass($class, bool $append = true)
{
$this->fieldClass = $append
? array_unique(array_merge($this->fieldClass, (array) $labelClass))
: (array) $labelClass;
? array_unique(array_merge($this->fieldClass, (array) $class))
: (array) $class;

return $this;
}
Expand Down Expand Up @@ -1212,7 +1229,15 @@ public function display(bool $display)
return $this;
}

protected function defaultAttribute($attribute, $value)
/**
* 设置默认属性.
*
* @param string $attribute
* @param mixed $value
*
* @return $this
*/
public function defaultAttribute(string $attribute, $value)
{
if (! array_key_exists($attribute, $this->attributes)) {
$this->attribute($attribute, $value);
Expand All @@ -1231,6 +1256,13 @@ protected function shouldRender()
return $this->display;
}

/**
* 保存数据为json格式.
*
* @param int $option
*
* @return $this
*/
public function saveAsJson($option = 0)
{
return $this->saving(function ($value) use ($option) {
Expand All @@ -1242,10 +1274,15 @@ public function saveAsJson($option = 0)
});
}

/**
* 保存数据为字符串格式.
*
* @return $this
*/
public function saveAsString()
{
return $this->saving(function ($value) {
if (is_object($value) || is_object($value)) {
if (is_object($value) || is_array($value)) {
return json_encode($value);
}

Expand All @@ -1262,6 +1299,16 @@ public static function requireAssets()
static::$css && Admin::css(static::$css);
}

/**
* 设置默认class.
*/
protected function setDefaultClass()
{
if (is_string($class = $this->getElementClassString())) {
$this->defaultAttribute('class', $class);
}
}

/**
* Render this filed.
*
Expand All @@ -1273,9 +1320,7 @@ public function render()
return '';
}

if (is_string($class = $this->getElementClassString())) {
$this->defaultAttribute('class', $class);
}
$this->setDefaultClass();

$this->callComposing();

Expand Down
25 changes: 23 additions & 2 deletions src/Form/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Row implements Renderable
/**
* Fields in this row.
*
* @var array
* @var Collection
*/
protected $fields;

Expand All @@ -91,6 +91,11 @@ class Row implements Renderable
*/
protected $defaultFieldWidth = 12;

/**
* @var bool
*/
protected $horizontal = false;

/**
* Row constructor.
*
Expand All @@ -117,6 +122,22 @@ public function fields()
return $this->fields;
}

/**
* If the form horizontal layout.
*
* @param bool $value
*
* @return $this
*/
public function horizontal(bool $value = true)
{
$this->horizontal = $value;

$this->fields->each->horizontal($value);

return $this;
}

public function setFields(Collection $collection)
{
$this->fields = $collection;
Expand Down Expand Up @@ -176,7 +197,7 @@ public function __call($method, $arguments)
{
$field = $this->form->__call($method, $arguments);

$field->disableHorizontal();
$field->horizontal($this->horizontal);

$this->fields->push([
'width' => $this->defaultFieldWidth,
Expand Down
2 changes: 1 addition & 1 deletion src/Grid/Actions/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function render()
'data-action' => 'delete',
]);

return parent::render(); // TODO: Change the autogenerated stub
return parent::render();
}

public function url()
Expand Down
7 changes: 4 additions & 3 deletions src/Show/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,17 +491,18 @@ public function explode(string $d = ',')
* Render this column with the given view.
*
* @param string $view
* @param array $data
*
* @return $this
*/
public function view($view)
public function view($view, array $data = [])
{
$name = $this->name;

return $this->unescape()->as(function ($value) use ($view, $name) {
return $this->unescape()->as(function ($value) use ($view, $name, $data) {
$model = $this;

return view($view, compact('model', 'value', 'name'))->render();
return view($view, array_merge(compact('model', 'value', 'name'), $data))->render();
});
}

Expand Down
12 changes: 12 additions & 0 deletions src/Widgets/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,18 @@ public function getElementSelector()
return '.'.$this->getElementClass();
}

/**
* @param string $elementClass
*
* @return $this
*/
public function setElementClass(string $elementClass)
{
$this->elementClass = $elementClass;

return $this;
}

/**
* @return mixed
*/
Expand Down

0 comments on commit 268f013

Please sign in to comment.