|
2 | 2 |
|
3 | 3 | namespace App\Crud; |
4 | 4 |
|
| 5 | +use App\Classes\CrudForm; |
| 6 | +use App\Classes\FormInput; |
5 | 7 | use App\Models\Unit; |
6 | 8 | use App\Models\UnitGroup; |
7 | 9 | use App\Services\CrudEntry; |
@@ -125,6 +127,67 @@ public function isEnabled( $feature ): bool |
125 | 127 | */ |
126 | 128 | public function getForm( $entry = null ) |
127 | 129 | { |
| 130 | + return CrudForm::form( |
| 131 | + main: FormInput::text( |
| 132 | + label: __( 'Name' ), |
| 133 | + name: 'name', |
| 134 | + value: $entry->name ?? '', |
| 135 | + description: __( 'Provide a name to the resource.' ), |
| 136 | + validation: 'required', |
| 137 | + ), |
| 138 | + tabs: CrudForm::tabs( |
| 139 | + CrudForm::tab( |
| 140 | + identifier: 'general', |
| 141 | + label: __( 'General' ), |
| 142 | + fields: CrudForm::fields( |
| 143 | + FormInput::text( |
| 144 | + label: __( 'Identifier' ), |
| 145 | + name: 'identifier', |
| 146 | + description: __( 'Provide a unique value for this unit. Might be composed from a name but shouldn\'t include space or special characters.' ), |
| 147 | + validation: 'required|unique:' . Hook::filter( 'ns-table-name', 'nexopos_units' ) . ',identifier' . ( $entry !== null ? ',' . $entry->id : '' ), |
| 148 | + value: $entry->identifier ?? '', |
| 149 | + ), |
| 150 | + FormInput::media( |
| 151 | + label: __( 'Preview URL' ), |
| 152 | + name: 'preview_url', |
| 153 | + description: __( 'Preview of the unit.' ), |
| 154 | + value: $entry->preview_url ?? '', |
| 155 | + ), |
| 156 | + FormInput::text( |
| 157 | + label: __( 'Value' ), |
| 158 | + name: 'value', |
| 159 | + description: __( 'Define the value of the unit.' ), |
| 160 | + validation: 'required|numeric', |
| 161 | + value: $entry->value ?? '', |
| 162 | + ), |
| 163 | + FormInput::searchSelect( |
| 164 | + component: 'nsCrudForm', |
| 165 | + props: UnitGroupCrud::getFormConfig(), |
| 166 | + name: 'group_id', |
| 167 | + validation: 'required', |
| 168 | + options: Helper::toJsOptions( UnitGroup::get(), [ 'id', 'name' ] ), |
| 169 | + label: __( 'Group' ), |
| 170 | + description: __( 'Define to which group the unit should be assigned.' ), |
| 171 | + value: $entry->group_id ?? '', |
| 172 | + ), |
| 173 | + FormInput::switch( |
| 174 | + name: 'base_unit', |
| 175 | + validation: 'required', |
| 176 | + options: Helper::kvToJsOptions( [ __( 'No' ), __( 'Yes' ) ] ), |
| 177 | + label: __( 'Base Unit' ), |
| 178 | + description: __( 'Determine if the unit is the base unit from the group.' ), |
| 179 | + value: $entry ? ( $entry->base_unit ? 1 : 0 ) : 0, |
| 180 | + ), |
| 181 | + FormInput::textarea( |
| 182 | + label: __( 'Description' ), |
| 183 | + name: 'description', |
| 184 | + description: __( 'Provide a short description about the unit.' ), |
| 185 | + value: $entry->description ?? '', |
| 186 | + ) |
| 187 | + ) |
| 188 | + ) |
| 189 | + ) |
| 190 | + ); |
128 | 191 | return [ |
129 | 192 | 'main' => [ |
130 | 193 | 'label' => __( 'Name' ), |
|
0 commit comments