123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- namespace App\Http\Admin;
- use AdminColumn;
- use AdminColumnEditable;
- use AdminDisplay;
- use AdminForm;
- use AdminFormElement;
- use AdminSection;
- use App\Location;
- use App\User;
- use App\Watcher;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Log;
- use SleepingOwl\Admin\Contracts\Display\DisplayInterface;
- use SleepingOwl\Admin\Contracts\Form\FormInterface;
- use SleepingOwl\Admin\Contracts\Initializable;
- use SleepingOwl\Admin\Form\Buttons\Cancel;
- use SleepingOwl\Admin\Form\Buttons\Save;
- use SleepingOwl\Admin\Form\FormElements;
- use SleepingOwl\Admin\Section;
- /**
- * Class Users
- *
- * @property \App\User $model
- *
- * @see http://sleepingowladmin.ru/docs/model_configuration_section
- */
- class Users extends Section implements Initializable
- {
- /**
- * @see http://sleepingowladmin.ru/docs/model_configuration#ограничение-прав-доступа
- *
- * @var bool
- */
- protected $checkAccess = false;
- protected $redirect = ['edit' => 'display', 'create' => 'display'];
- //protected $model = User::class;
- /**
- * @var string
- */
- protected $title;
- public function initialize()
- {
- $this->creating(function ($config, Model $model) {
- });
- }
- /**
- * @var string
- */
- protected $alias;
- /**
- * @return DisplayInterface
- */
- public function onDisplay()
- {
- $form = AdminDisplay::datatablesAsync()->setDisplaySearch(true)
- ->setOrder([[0, 'desc']])
- ->setHtmlAttribute('class', 'table-primary')
- ->setColumns(
- AdminColumn::link('id', '#')->setWidth('30px'),
- AdminColumnEditable::text('name', 'Name')->setWidth('100px'),
- AdminColumn::link('email', 'Email')->setWidth('100px')
- )->paginate(20);
- return $form;
- }
- /**
- * @param int $id
- *
- * @return FormInterface
- */
- public function onEdit($id)
- {
- function product($id) {
- $formElement = [];
- if($id != null){
- $category = User::find($id)->id;
- $formElement[] = AdminSection::getModel(Location::class)->fireDisplay(['user_id' => $category]);
- }
- return $formElement;
- };
- $formElements = [
- AdminFormElement::text('name', 'Name')->required(),
- AdminFormElement::text('email', 'Name')->required(),
- ];
- $tabs = AdminDisplay::tabbed([
- 'General' => new FormElements($formElements),
- 'Locations' => new FormElements(product($id)),
- ]);
- $context = empty($id) ? $formElements : $tabs;
- $form = AdminForm::panel();
- $form->addBody($context);
- $form->getButtons()->setButtons([
- 'save' => new Save(),
- 'cancel' => new Cancel(),
- ]);
- return $form;
- }
- /**
- * @return FormInterface
- */
- public function onCreate()
- {
- return $this->onEdit(null);
- }
- /**
- * @return void
- */
- public function onDelete($id)
- {
- // remove if unused
- }
- /**
- * @return void
- */
- public function onRestore($id)
- {
- // remove if unused
- }
- }
|