Skip to content

Commit

Permalink
Add latest files
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayMurha committed Aug 14, 2022
1 parent ac8910c commit bc95090
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 30 deletions.
14 changes: 7 additions & 7 deletions resources/views/form/belongsto.blade.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
<div id="{{$containerId}}" class="{{$viewClass['form-group']}} {!! !$errors->has($errorKey) ? '' : 'has-error' !!}">
<div id="{{ $containerId }}" class="{{$viewClass['form-group']}} {!! !$errors->has($errorKey) ? '' : 'has-error' !!}">

<label for="{{$id}}" class="{{$viewClass['label']}} control-label">{{$label}}</label>
<label for="{{ $id }}" class="{{$viewClass['label']}} control-label">{{$label}}</label>

<div class="{{$viewClass['field']}}">
<div class="{{ $viewClass['field'] }}">

@include('admin::form.error')

<input type="hidden" name="{{$name}}"/>
<input type="hidden" name="{{ $name }}"/>

<select class="form-control {{$class}} hide" style="width: 100%"
name="{{$name}}@if(!empty($multiple))[]@endif" {!! $attributes !!} >
@empty($multiple)
<option value=""></option>
@endempty
@foreach($options as $select => $option)
<option
value="{{$select}}" {{ in_array($select, (array)old($column, $value)) ?'selected':'' }}>{{$option}}</option>
<option value="{{$select}}" {{ in_array($select, (array)old($column, $value)) ?'selected':'' }}>
{{ $option }}
</option>
@endforeach
</select>

Expand All @@ -27,6 +28,5 @@
</div>

@include('admin::form.help-block')

</div>
</div>
2 changes: 1 addition & 1 deletion resources/views/form/belongstomany.blade.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@include('admin::form.belongsto',['multiple' => true])
@include('admin::form.belongsto',['multiple'=>true])
2 changes: 2 additions & 0 deletions resources/views/form/morphto.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@include('admin::form.belongsto')
<input type="hidden" name="{{ $typeColumn }}" value="{{ $morphClass }}">
4 changes: 2 additions & 2 deletions src/Form/Field/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ protected function addScript()
$.get(url, function (data) {
modal.find('.modal-body').html(data);
modal.find('.select').iCheck({
radioClass:'iradio_minimal-blue',
checkboxClass:'icheckbox_minimal-blue'
radioClass: 'iradio_minimal-blue',
checkboxClass: 'icheckbox_minimal-blue'
});
modal.find('.box-header:first').hide();
Expand Down
6 changes: 2 additions & 4 deletions src/Form/Field/CanCascadeFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,17 @@ protected function addCascadeScript()
'oneNotIn': function(a, b) { return a.filter(v => b.includes(v)).length == 0; },
};
var cascade_groups = {$cascadeGroups};
cascade_groups.forEach(function (event) {
var default_value = '{$this->getValueByJs()}' + '';
var class_name = event.class;
if(default_value == event.value) {
$('.'+class_name+'').removeClass('hide');
}
});
$('{$this->getElementClassSelector()}').on('{$this->cascadeEvent}', function (e) {
$('{$this->getElementClassSelector()}').on('{$this->cascadeEvent}', function (e) {
{$this->getFormFrontValue()}
cascade_groups.forEach(function (event) {
var group = $('div.cascade-group.'+event.class);
if( operator_table[event.operator](checked, event.value) ) {
Expand Down
42 changes: 26 additions & 16 deletions src/Form/Field/MorphTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,40 @@

namespace Encore\Admin\Form\Field;

use Illuminate\Support\Str;

class MorphTo extends BelongsTo
{
protected $typeColumn;

protected $morphClass;

protected $view = 'admin::form.belongsTo';
public function __construct($morphName, $arguments = [])
{
$this->typeColumn = $morphName . '_type';
$column = $morphName . '_id';
parent::__construct($column, $arguments);

if (empty($arguments[1])) {
$this->label = Str::title($morphName);
}

public function __construct($column, $arguments = [])
$this->addVariables([
'typeColumn' => $this->typeColumn,
'morphClass' => $this->morphClass()
]);
}

/**
* @return mixed
*/
public function morphClass()
{
$this->typeColumn = $column . '_type';
parent::__construct($column . '_id', $arguments);
if (!$this->morphClass) {
$modelClass = (new $this->selectable)->model;
$this->morphClass = (new $modelClass)->getMorphClass();
}
return $this->morphClass;
}

public function value($value = null)
Expand All @@ -35,16 +57,4 @@ public function currenMorphClass()
{
return $this->form->model()->{$this->typeColumn};
}

/**
* @return mixed
*/
public function morphClass()
{
if (!$this->morphClass) {
$modelClass = (new $this->selectable)->model;
$this->morphClass = (new $modelClass)->getMorphClass();
}
return $this->morphClass;
}
}

0 comments on commit bc95090

Please sign in to comment.