forked from crocodic-studio/crudbooster
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
rajakodings
committed
May 11, 2019
1 parent
b3147ee
commit c49c81b
Showing
15 changed files
with
211 additions
and
77 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
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,6 @@ | ||
<style> | ||
.datepicker[readonly] { | ||
cursor: pointer; | ||
background: #fefefe; | ||
} | ||
</style> |
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,6 @@ | ||
<style> | ||
.datetimepicker[readonly] { | ||
cursor: pointer; | ||
background: #fefefe; | ||
} | ||
</style> |
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,5 @@ | ||
<?php | ||
|
||
cb()->routeGroupBackend(function () { | ||
cb()->routePost("select-lookup",'\crocodicstudio\crudbooster\types\select\SelectController@postLookup'); | ||
}); |
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,37 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: User | ||
* Date: 5/10/2019 | ||
* Time: 10:38 PM | ||
*/ | ||
|
||
namespace crocodicstudio\crudbooster\types\select; | ||
|
||
use Illuminate\Routing\Controller as BaseController; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class SelectController extends BaseController | ||
{ | ||
public function postLookup() { | ||
$foreignKey = decrypt(request('foreign_key')); | ||
$foreignValue = request('foreign_value'); | ||
$table = decrypt(request('table')); | ||
$sqlCondition = decrypt(request('sql_condition')); | ||
if($foreignKey && $foreignValue && $table) { | ||
|
||
$data = DB::table($table) | ||
->where($foreignKey, $foreignValue); | ||
if($sqlCondition) { | ||
$data->whereRaw($sqlCondition); | ||
} | ||
|
||
$data = $data->get(); | ||
|
||
return response()->json(['status'=>true, 'data'=>$data]); | ||
|
||
}else{ | ||
return response()->json(['status'=>false]); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,16 +1,55 @@ | ||
@include("types::layout_header") | ||
<?php /** @var \crocodicstudio\crudbooster\types\select\SelectModel $column */?> | ||
<select style="width: 100%" class="form-control select2" | ||
<select style="width: 100%" id="select-{{ $column->getName() }}" class="form-control select2" | ||
{{ $column->getRequired()?'required':''}} | ||
{{ $column->getReadonly()?'readonly':''}} | ||
{{ $column->getDisabled()?'disabled':''}} | ||
name="{{ $column->getName() }}" id="{{ $column->getName() }}"> | ||
<option value="">** Select a {{ $column->getLabel() }}</option> | ||
<?php | ||
$columnValue = old($column->getName())?:($column->getDefaultValue())?:$column->getValue(); | ||
?> | ||
@foreach($column->getOptions() as $key=>$value) | ||
<option {{ $columnValue==$key?'selected':'' }} value="{{ $key }}">{{ $value }}</option> | ||
@endforeach | ||
@if(!$column->getForeignKey()) | ||
<?php | ||
$columnValue = old($column->getName())?:($column->getDefaultValue())?:$column->getValue(); | ||
?> | ||
@foreach($column->getOptions() as $key=>$value) | ||
<option {{ $columnValue==$key?'selected':'' }} value="{{ $key }}">{{ $value }}</option> | ||
@endforeach | ||
@endif | ||
</select> | ||
|
||
@if($column->getForeignKey()) | ||
@push('bottom') | ||
<script> | ||
$(function () { | ||
let value = "{{ old($column->getName())?:($column->getDefaultValue())?:$column->getValue() }}"; | ||
$("#select-{{ $column->getForeignKey() }}").change(function () { | ||
let foreign_value = $(this).val(); | ||
$.post("{{ cb()->getAdminUrl("select-lookup") }}",{ | ||
_token:"{{csrf_token()}}", | ||
foreign_key:"{{ encrypt($column->getForeignKey()) }}", | ||
foreign_value: foreign_value, | ||
table:"{{ encrypt($column->getOptionsFromTable()['table']) }}", | ||
sql_condition:"{{ encrypt($column->getOptionsFromTable()['sql_condition']) }}" | ||
},function (resp) { | ||
if(resp.status) { | ||
var opt = "<option value=''>** Select a {{ $column->getLabel() }}</option>"; | ||
$.each(resp.data,function (i,obj) { | ||
opt += "<option value='"+obj.{{ $column->getOptionsFromTable()['key_field'] }}+"'>"+obj.{{ $column->getOptionsFromTable()['display_field'] }}+"</option>"; | ||
}) | ||
$("#select-{{ $column->getName() }}").select2("val",""); | ||
$("#select-{{ $column->getName() }}").val(""); | ||
$("#select-{{ $column->getName() }}").html(opt); | ||
if(value) { | ||
$("#select-{{ $column->getName() }}").val(value); | ||
$("#select-{{ $column->getName() }}").select2({ | ||
placeholder:"** Select a {{ $column->getLabel() }}" | ||
}) | ||
} | ||
} | ||
}) | ||
}).trigger("change"); | ||
}) | ||
</script> | ||
@endpush | ||
@endif | ||
@include("types::layout_footer") |
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.