Skip to content

Instantly share code, notes, and snippets.

@phanngoc
Created June 16, 2015 13:08
Show Gist options
  • Save phanngoc/b4a992b6225ebf9438c5 to your computer and use it in GitHub Desktop.
Save phanngoc/b4a992b6225ebf9438c5 to your computer and use it in GitHub Desktop.
@extends ('layouts.master')
@section ('head.title')
{{trans('messages.list_group')}}
@stop
@section ('head.css')
<link href="plugins/datatables/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
@stop
@section('body.content')
<div class="content-wrapper">
<section class="content-header">
<h1>
{{trans('messages.group_management')}}
</h1>
<ol class="breadcrumb">
<li><a href="{{ route('index') }}"><i class="fa fa-dashboard"></i> {{trans('messages.dashboard')}}</a></li>
<li><a href="{{ route('groups.index') }}">{{trans('messages.group')}}</a></li>
<li class="active">{{trans('messages.list_group')}}</li>
</ol>
</section>
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title">{{trans('messages.list_group')}}</h3>
</div>
<div class="box-body">
<div class="inner-box-body">
<div class="row header-calendar">
<div class="filter-fullname col-md-2">
<label>Search name:</label>
<input id="search-name" />
</div>
<div class="wrappickerdate col-md-2 pull-right">
<label>Choose Month/Year</label>
<input id="datepicker" />
</div>
</div>
<div id="calendar">
<div id="datafullname" style="display:none"></div>
<div class="sidebar-calendar">
<table>
<thead>
<tr><th><div class="nameitem">Fullname</div></th></tr>
</thead>
<tbody>
<tr class="itemblank">
<td><div class="nameitem"></div></td>
</tr>
@foreach($employees as $key => $value)
<tr>
<!-- <td><div class="nameitem">{{ $value->id }}</div></td> -->
<td><div class="nameitem">{{ $value->lastname }} {{ $value->firstname }}</div></td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="content-calendar">
<div id="datacalendar" style="display:none"></div>
<table>
<thead>
<tr>
<?php
for ($i=1;$i<=31;$i++)
{
echo "<th><div class='item'>Day ".$i."</div></th>";
}
?>
</tr>
</thead>
<tbody>
<tr class="itemblank">
<td><div class="item"></div></td>
</tr>
<?php
foreach($employees as $key => $value)
{
$calendar = $value->calendar;
?>
<tr>
<?php
for ($i=1;$i<=31;$i++)
{
?>
<td><div class="item"><?php echo $calendar->{'n'.$i};?></div></td>
<?php
}
?>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div><!-- /.box-body -->
</div>
</div>
</div>
</section>
</div>
<style type="text/css">
#calendar {
display: block;
width: 100%;
height: 390px;
position: relative;
}
#calendar .sidebar-calendar {
display: block;
width: 175px;
height: 390px;
position: absolute;
left: 0px;
top: 0px;
overflow: scroll;
}
#calendar .content-calendar {
display: block;
height: 390px;
position: absolute;
left: 176px;
top: 0px;
overflow: scroll;
}
.nameitem {
display: block;
height: 40px;
min-width: 170px;
border: 1px solid #c3c7c9;
}
.item {
display: block;
height: 40px;
width: 40px;
border: 1px solid #c3c7c9;
font-weight: bold;
}
/* #calendar .content-calendar table{
position: relative;
}*/
.content-calendar thead,
.sidebar-calendar thead {
/* position: fixed;
top : 0px;*/
position: absolute;
background-color: #086ca5;
color: white;
/* top: 0px;*/
}
.ui-datepicker-calendar {
display: none;
}
.ui-widget-header {
color : black !important;
}
.header-calendar{
margin-bottom: 10px;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
var width_content = $('#calendar').width() - 175;
$('.content-calendar').css('width', width_content);
$('#datepicker').datepicker({
dateFormat: "mm/yy",
changeMonth: true,
changeYear: true,
showButtonPanel: true,
onClose: function(dateText, inst) {
function isDonePressed() {
return ($('#ui-datepicker-div').html().indexOf('ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all ui-state-hover') > -1);
}
if (isDonePressed()) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1)).trigger('change');
$('.date-picker').focusout() //Added to remove focus from datepicker input box on selecting date
}
},
beforeShow: function(input, inst) {
inst.dpDiv.addClass('month_year_datepicker')
if ((datestr = $(this).val()).length > 0) {
year = datestr.substring(datestr.length - 4, datestr.length);
month = datestr.substring(0, 2);
$(this).datepicker('option', 'defaultDate', new Date(year, month - 1, 1));
$(this).datepicker('setDate', new Date(year, month - 1, 1));
$(".ui-datepicker-calendar").hide();
}
}
});
$('.content-calendar').scroll(function(e) {
$('.sidebar-calendar').scrollTop($(this).scrollTop());
$('.content-calendar thead')
.animate({
"marginTop": $(this).scrollTop() + "px"
}, 0);
$('.sidebar-calendar thead')
.animate({
"marginTop": $(this).scrollTop() + "px"
}, 0);
});
$('.sidebar-calendar').scroll(function(e) {
$('.content-calendar').scrollTop($(this).scrollTop());
$('.sidebar-calendar thead')
.animate({
"marginTop": $(this).scrollTop() + "px"
}, 0);
$('.content-calendar thead')
.animate({
"marginTop": $(this).scrollTop() + "px"
}, 0);
});
$('.content-calendar').on('dblclick', '.item', function() {
var val = $(this).text();
$(this).attr('class', 'item1');
$(this).html('<input type="text" value="' + val + '" style="z-index:10000;"/>');
$(this).children('input').focus();
$(this).focusout(function() {
console.log('focusout');
$(this).html($(this).children('input').val());
$(this).unbind("focusout");
$(this).attr('class', 'item');
});
});
$('#search-name').keyup(function() {
var textsearch = $(this).val();
var htmlbuild = '';
var indexsearchs = [];
$('#datafullname tr').each(function(key, value) {
var text = $(value).find('.nameitem').text();
console.log(text.toLowerCase() + "|" + textsearch.toLowerCase());
if (text.toLowerCase().indexOf(textsearch.toLowerCase()) >= 0 || $(this).hasClass("itemblank")) {
indexsearchs.push(key);
htmlbuild += $("<div />").append($(this).clone()).html();
}
});
$('.sidebar-calendar table tbody').empty();
$('.sidebar-calendar table tbody').append(htmlbuild);
var htmlcalendar_build = '';
$('#datacalendar tr').each(function(key, value) {
console.log(key);
if (indexsearchs.indexOf(key) >= 0 || $(this).hasClass("itemblank")) {
//console.log($(value).parent().clone().html());
htmlcalendar_build += $("<div />").append($(value).clone()).html();
}
});
$('.content-calendar table tbody').empty();
$('.content-calendar table tbody').append(htmlcalendar_build);
});
$('#datafullname').append($('.sidebar-calendar table tbody').html());
$('#datacalendar').append($('.content-calendar table tbody').html());
});
</script>
@stop
<?php
namespace App\Http\Controllers;
use App\Calendar;
use App\Employee;
use App\Http\Requests\AddFeatureRequest;
use Illuminate\Http\Request;
class CalendarController extends AdminController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index() {
$employees = Employee::all();
foreach ($employees as $key => $value) {
$calendar = Calendar::where('employee_id', '=', $value->id)->first();
$employees[$key]->calendar = $calendar;
}
return view('calendar.calendar', compact('employees'));
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create() {
$module = Module::all();
$feature = Feature::all();
return view('features.addfeature', compact('module', 'feature'));
}
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(AddFeatureRequest $request) {
$feature = new FeatureNode();
$feature->module_id = $request['id_module'];
$feature->name_feature = $request['name_feature'];
$feature->description = $request['description'];
$feature->url_action = $request['action'];
$feature->parent_id = $request['id_parent'];
// dd($feature->description);
// $module = Module::find($feature->module_id);
// $features = $module->feature()->save($feature);
// create relation
// $nodenew = FeatureNode::find($feature->id);
$data = array();
$data['module_id'] = $request['id_module'];
$data['name_feature'] = $request['name_feature'];
$data['description'] = $request['description'];
$data['url_action'] = $request['action'];
$data['parent_id'] = $request['id_parent'];
$feature = null;
if ($request['id_parent'] != 0) {
$nodeparent = FeatureNode::find($request['id_parent']);
$feature = FeatureNode::create($data, $nodeparent);
// $nodeparent->children()->create($data);
// $nodenew->appendTo($nodeparent)->save();
// $nodenew->parent()->associate($data)->save();
} else {
$feature = FeatureNode::create($data);
// $nodenew->makeRoot()->save();
// $feature->save();
// $feature->makeRoot()->save();
}
return redirect()->route('features.index')->with('messageOk', ' Add successfully');
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id) {
$feature = Feature::find($id);
$features = Feature::all();
$modules = Module::all();
if (is_null($feature)) {
return redirect()->route('features.listfeature');
}
return View('features.editfeature', compact('feature', 'features', 'modules'));
}
public function postFeature() {
$id = isset($_GET['id']) ? (int) $_GET['id'] : false;
$features = Feature::where('module_id', '=', $id)->get();
$data = array();
foreach ($features as $key => $value) {
$item = array("id" => $value->id, "name" => $value->name_feature);
array_push($data, $item);
}
echo json_encode($data);
//return View('features.addfeature', compact('feature'));
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id, Request $request) {
$feature = Feature::find($id);
$feature->update([
'name_feature' => $request['feature_name'],
'description' => $request['description'],
'url_action' => $request['action'],
'parent_id' => $request['parent_id'],
'module_id' => $request['module_id'],
]);
$feature->attachGroup($request['group_id']);
$nodenew = FeatureNode::find($id);
if ($request['parent_id'] != 0) {
$nodeparent = FeatureNode::find($request['parent_id']);
$nodenew->appendTo($nodeparent)->save();
} else {
$nodenew->saveAsRoot();
}
return redirect()->route('features.index')->with('messageOk', 'user update successfully');
}
public function test() {
$items = FeatureNode::hasChildren()->get();
$items->linkNodes();
dd($items);
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id) {
$feature = FeatureNode::find($id);
//$feature->module()->detach();
$feature->delete();
return redirect()->route('features.index');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment