|
@@ -2,13 +2,14 @@
|
|
|
|
|
|
namespace Dcat\Admin\Form;
|
|
|
|
|
|
+use Dcat\Admin\Widgets\Form as WidgetForm;
|
|
|
use Dcat\Admin\Form;
|
|
|
use Dcat\Admin\Layout\Column;
|
|
|
|
|
|
class Layout
|
|
|
{
|
|
|
/**
|
|
|
- * @var Form
|
|
|
+ * @var Form|WidgetForm
|
|
|
*/
|
|
|
protected $form;
|
|
|
|
|
@@ -17,32 +18,69 @@ class Layout
|
|
|
*/
|
|
|
protected $columns = [];
|
|
|
|
|
|
- public function __construct(Form $form)
|
|
|
+ /**
|
|
|
+ * @var array
|
|
|
+ */
|
|
|
+ protected $currentFields = [];
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var bool
|
|
|
+ */
|
|
|
+ protected $hasColumn = false;
|
|
|
+
|
|
|
+ public function __construct($form)
|
|
|
{
|
|
|
$this->form = $form;
|
|
|
}
|
|
|
|
|
|
+ public function addField(Field $field)
|
|
|
+ {
|
|
|
+ $this->currentFields[] = $field;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function hasColumns()
|
|
|
+ {
|
|
|
+ return $this->hasColumn;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param int $width 1~12
|
|
|
* @param mixed $content
|
|
|
*/
|
|
|
- public function column(int $width, $content)
|
|
|
+ public function onlyColumn($width, $content)
|
|
|
{
|
|
|
$width = $width < 1 ? round(12 * $width) : $width;
|
|
|
|
|
|
+ $this->hasColumn = true;
|
|
|
+
|
|
|
+ $this->currentFields = [];
|
|
|
+
|
|
|
$column = new Column($content, $width);
|
|
|
|
|
|
$this->columns[] = $column;
|
|
|
+
|
|
|
+ foreach ($this->currentFields as $field) {
|
|
|
+ $column->append($field);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param int $width
|
|
|
+ * @param int $width 1~12
|
|
|
* @param mixed $content
|
|
|
*/
|
|
|
- public function prepend(int $width, $content)
|
|
|
+ public function column($width, $content)
|
|
|
{
|
|
|
$width = $width < 1 ? round(12 * $width) : $width;
|
|
|
|
|
|
+ $this->columns[] = new Column($content, $width);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param int $width
|
|
|
+ * @param mixed $content
|
|
|
+ */
|
|
|
+ public function prepend(int $width, $content)
|
|
|
+ {
|
|
|
$column = new Column($content, $width);
|
|
|
|
|
|
array_unshift($this->columns, $column);
|