-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from mariusconstantin2503/v2
V2
- Loading branch information
Showing
29 changed files
with
375 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/resources/views/fields/assets/js/checklist_dependency.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<!-- include checklist_dependency js--> | ||
<script> | ||
jQuery(document).ready(function($) { | ||
$('.checklist_dependency').each(function(index, item){ | ||
var unique_name = $(this).data('entity'); | ||
var dependencyJson = window[unique_name]; | ||
var thisField = $(this); | ||
thisField.find('.primary_list').change(function(){ | ||
var idCurrent = $(this).data('id'); | ||
if($(this).is(':checked')){ | ||
//add hidden field with this value | ||
var nameInput = thisField.find('.hidden_fields_primary').data('name'); | ||
var inputToAdd = $('<input type="hidden" class="primary_hidden" name="'+nameInput+'[]" value="'+idCurrent+'">'); | ||
thisField.find('.hidden_fields_primary').append(inputToAdd); | ||
$.each(dependencyJson[idCurrent], function(key, value){ | ||
//check and disable secondies checkbox | ||
thisField.find('input.secondary_list[value="'+value+'"]').prop( "checked", true ); | ||
thisField.find('input.secondary_list[value="'+value+'"]').prop( "disabled", true ); | ||
//remove hidden fields with secondary dependency if was setted | ||
var hidden = thisField.find('input.secondary_hidden[value="'+value+'"]'); | ||
if(hidden) | ||
hidden.remove(); | ||
}); | ||
}else{ | ||
//remove hidden field with this value | ||
thisField.find('input.primary_hidden[value="'+idCurrent+'"]').remove(); | ||
// uncheck and active secondary checkboxs if are not in other selected primary. | ||
var secondary = dependencyJson[idCurrent]; | ||
var selected = []; | ||
thisField.find('input.primary_hidden').each(function (index, input){ | ||
selected.push( $(this).val() ); | ||
}); | ||
$.each(secondary, function(index, secondaryItem){ | ||
var ok = 1; | ||
$.each(selected, function(index2, selectedItem){ | ||
if( dependencyJson[selectedItem].indexOf(secondaryItem) != -1 ){ | ||
ok =0; | ||
} | ||
}); | ||
if(ok){ | ||
thisField.find('input.secondary_list[value="'+secondaryItem+'"]').prop('checked', false); | ||
thisField.find('input.secondary_list[value="'+secondaryItem+'"]').prop('disabled', false); | ||
} | ||
}); | ||
} | ||
}); | ||
thisField.find('.secondary_list').click(function(){ | ||
var idCurrent = $(this).data('id'); | ||
if($(this).is(':checked')){ | ||
//add hidden field with this value | ||
var nameInput = thisField.find('.hidden_fields_secondary').data('name'); | ||
var inputToAdd = $('<input type="hidden" class="secondary_hidden" name="'+nameInput+'[]" value="'+idCurrent+'">'); | ||
thisField.find('.hidden_fields_secondary').append(inputToAdd); | ||
}else{ | ||
//remove hidden field with this value | ||
thisField.find('input.secondary_hidden[value="'+idCurrent+'"]').remove(); | ||
} | ||
}); | ||
}); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!-- select2 --> | ||
<div class="form-group"> | ||
<label>{{ $field['label'] }}</label> | ||
<?php $entity_model = $crud->getModel();?> | ||
|
||
<div class="row"> | ||
@foreach ($field['model']::all() as $connected_entity_entry) | ||
<div class="col-sm-4"> | ||
<div class="checkbox"> | ||
<label> | ||
<input type="checkbox" | ||
@foreach ($field as $attribute => $value) | ||
@if (is_string($attribute) && $attribute != 'value') | ||
@if ($attribute=='name') | ||
{{ $attribute }}="{{ $value }}[]" | ||
@else | ||
{{ $attribute }}="{{ $value }}" | ||
@endif | ||
@endif | ||
@endforeach | ||
value="{{ $connected_entity_entry->id }}" | ||
|
||
@if( ( old( $field["name"] ) && in_array($connected_entity_entry->id, old( $field["name"])) ) || (isset($field['value']) && in_array($connected_entity_entry->id, $field['value']->lists('id', 'id')->toArray()))) | ||
checked = "checked" | ||
@endif > {{ $connected_entity_entry->{$field['attribute']} }} | ||
</label> | ||
</div> | ||
</div> | ||
@endforeach | ||
</div> | ||
</div> |
161 changes: 161 additions & 0 deletions
161
src/resources/views/fields/checklist_dependency.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
<!-- dependencyJson --> | ||
<div class="form-group checklist_dependency" data-entity ="{{ $field['field_unique_name'] }}"> | ||
<label>{{ $field['label'] }}</label> | ||
<?php | ||
$entity_model = $crud->getModel(); | ||
//short name for dependency fields | ||
$primary_dependency = $field['dependencies']['primary']; | ||
$secondary_dependency = $field['dependencies']['secondary']; | ||
//all items with relation | ||
$dependencies = $primary_dependency['model']::with($primary_dependency['entity_secondary'])->get(); | ||
$dependencyArray = []; | ||
//convert dependency array to simple matrix ( prymary id as key and array with secondaries id ) | ||
foreach($dependencies as $primary){ | ||
$dependencyArray[$primary->id] = []; | ||
foreach($primary->{$primary_dependency['entity_secondary']} as $secondary){ | ||
$dependencyArray[$primary->id][] = $secondary->id; | ||
} | ||
} | ||
//for update form, get initial state of the entity | ||
if( isset($id) && $id ){ | ||
//get entity with relations for primary dependency | ||
$entity_dependencies = $entity_model->with($primary_dependency['entity']) | ||
->with($primary_dependency['entity'].'.'.$primary_dependency['entity_secondary']) | ||
->where('id', $id) | ||
->first(); | ||
$secondaries_from_primary = []; | ||
//convert relation in array | ||
$primary_array = $entity_dependencies->{$primary_dependency['entity']}->toArray(); | ||
$secondary_ids = []; | ||
//create secondary dependency from primary relation, used to check what chekbox must be check from second checklist | ||
if( old($primary_dependency['name']) ) { | ||
foreach( old($primary_dependency['name']) as $primary_item ){ | ||
foreach($dependencyArray[$primary_item] as $second_item ){ | ||
$secondary_ids[$second_item] = $second_item; | ||
} | ||
} | ||
}else{ //create dependecies from relation if not from validate error | ||
foreach( $primary_array as $primary_item ){ | ||
foreach($primary_item[$secondary_dependency['entity']] as $second_item ){ | ||
$secondary_ids[$second_item['id']] = $second_item['id']; | ||
} | ||
} | ||
} | ||
} | ||
//json encode of dependency matrix | ||
$dependencyJson = json_encode($dependencyArray); | ||
?> | ||
<script> | ||
var {{ $field['field_unique_name'] }} = {!! $dependencyJson !!}; | ||
</script> | ||
<div class="row" > | ||
<div class="col-xs-12"> | ||
<label>{{ $primary_dependency['label'] }}</label> | ||
</div> | ||
|
||
<div class="hidden_fields_primary" data-name = "{{ $primary_dependency['name'] }}"> | ||
@if(isset($field['value'])) | ||
@if(old($primary_dependency['name'])) | ||
@foreach( old($primary_dependency['name']) as $item ) | ||
<input type="hidden" class="primary_hidden" name="{{ $primary_dependency['name'] }}[]" value="{{ $item }}"> | ||
@endforeach | ||
@else | ||
@foreach( $field['value'][0]->lists('id', 'id')->toArray() as $item ) | ||
<input type="hidden" class="primary_hidden" name="{{ $primary_dependency['name'] }}[]" value="{{ $item }}"> | ||
@endforeach | ||
@endif | ||
@endif | ||
</div> | ||
|
||
@foreach ($primary_dependency['model']::all() as $connected_entity_entry) | ||
<div class="col-sm-{{ isset($primary_dependency['number_columns']) ? intval(12/$primary_dependency['number_columns']) : '4'}}"> | ||
<div class="checkbox"> | ||
<label> | ||
<input type="checkbox" | ||
data-id = "{{ $connected_entity_entry->id }}" | ||
class = 'primary_list' | ||
@foreach ($primary_dependency as $attribute => $value) | ||
@if (is_string($attribute) && $attribute != 'value') | ||
@if ($attribute=='name') | ||
{{ $attribute }}="{{ $value }}_show[]" | ||
@else | ||
{{ $attribute }}="{{ $value }}" | ||
@endif | ||
@endif | ||
@endforeach | ||
value="{{ $connected_entity_entry->id }}" | ||
|
||
@if( ( isset($field['value']) && is_array($field['value']) && in_array($connected_entity_entry->id, $field['value'][0]->lists('id', 'id')->toArray())) || ( old($primary_dependency["name"]) && in_array($connected_entity_entry->id, old( $primary_dependency["name"])) ) ) | ||
checked = "checked" | ||
@endif > | ||
{{ $connected_entity_entry->{$primary_dependency['attribute']} }} | ||
|
||
</label> | ||
</div> | ||
</div> | ||
@endforeach | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col-xs-12"> | ||
<label>{{ $secondary_dependency['label'] }}</label> | ||
</div> | ||
|
||
<div class="hidden_fields_secondary" data-name="{{ $secondary_dependency['name'] }}"> | ||
@if(isset($field['value'])) | ||
@if(old($secondary_dependency['name'])) | ||
@foreach( old($secondary_dependency['name']) as $item ) | ||
<input type="hidden" class="secondary_hidden" name="{{ $secondary_dependency['name'] }}[]" value="{{ $item }}"> | ||
@endforeach | ||
@else | ||
@foreach( $field['value'][1]->lists('id', 'id')->toArray() as $item ) | ||
<input type="hidden" class="secondary_hidden" name="{{ $secondary_dependency['name'] }}[]" value="{{ $item }}"> | ||
@endforeach | ||
@endif | ||
@endif | ||
</div> | ||
|
||
@foreach ($secondary_dependency['model']::all() as $connected_entity_entry) | ||
<div class="col-sm-{{ isset($secondary_dependency['number_columns']) ? intval(12/$secondary_dependency['number_columns']) : '4'}}"> | ||
<div class="checkbox"> | ||
<label> | ||
<input type="checkbox" | ||
class = 'secondary_list' | ||
data-id = "{{ $connected_entity_entry->id }}" | ||
@foreach ($secondary_dependency as $attribute => $value) | ||
@if (is_string($attribute) && $attribute != 'value') | ||
@if ($attribute=='name') | ||
{{ $attribute }}="{{ $value }}_show[]" | ||
@else | ||
{{ $attribute }}="{{ $value }}" | ||
@endif | ||
@endif | ||
@endforeach | ||
value="{{ $connected_entity_entry->id }}" | ||
|
||
@if( ( isset($field['value']) && is_array($field['value']) && ( in_array($connected_entity_entry->id, $field['value'][1]->lists('id', 'id')->toArray()) || isset( $secondary_ids[$connected_entity_entry->id])) || ( old($secondary_dependency['name']) && in_array($connected_entity_entry->id, old($secondary_dependency['name'])) ))) | ||
checked = "checked" | ||
@if(isset( $secondary_ids[$connected_entity_entry->id])) | ||
disabled = disabled | ||
@endif | ||
@endif > {{ $connected_entity_entry->{$secondary_dependency['attribute']} }} | ||
</label> | ||
</div> | ||
</div> | ||
@endforeach | ||
</div> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.