@extends('dashboard::master')
{{--
    Autor: Giovanni López O.
    @gmlo_89
--}}
@section('head')
	
@stop

@section('content')
	<header>
		<h1 class="module-title"><span class="glyphicon glyphicon-briefcase"></span>{{ $title }}</h1>
    </header>
    {{ Alert::render() }}
    <div class="row btn-bar">
    	@if(!isset($myProfile))
    	<div class="btn-group pull-left">
			<a href="{{ url('admin/usergroups') }}" class="btn btn-default">{{ trans('dashboard::label.go_back') }}</a>
		</div>
		@endif
		<button tyle="button" data-click="submit" data-target="#frmPrincipal" class="btn btn-info pull-right">{{ trans('dashboard::label.save') }}</button>
    </div>
   
    {{ Form::model($group, $formOptions) }}
	    <div class="row">
	    	<div class="col-md-12">
			    <div class="panel panel-default">
					<div class="panel-heading"><span class="glyphicon glyphicon-th-list"></span> {{ trans('usergroups::label.user_group_info') }}</div>
					<div class="panel-body">
						<div class="form-group">
			    			<label for="inputName" class="col-md-3 control-label">{{ trans('usergroups::label.name') }}</label>
			    			<div class="col-md-9">
			    				{{ Form::text('name', null, 
									array(
										"class" 		=> "form-control required",
										"id" 			=> "inputName",
										"placeholder"	=> trans('usergroups::label.name')
								)) }}
			    			</div>
			    		</div>
			    		@if($group->exists)
			    			<div class="form-group">
				    			<div class="col-md-9 col-md-offset-3">
				    				<button type="button" id="btnDeleteUserGroups" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span> {{ trans('usergroups::label.delete') }}</button>
				    			</div>
				    		</div>
			    		@endif
					</div>
			    </div>
			    <div class="panel panel-default">
					<div class="panel-heading"><span class="glyphicon glyphicon-th-list"></span> {{ trans('usergroups::label.permissions') }}</div>
					<div class="panel-body">
						@foreach ($modules as $module)
							<div class="col-md-6">
								<legend>{{ $module->title }}</legend>
								@foreach ($module->actions as $key => $value)
									<?php $module_name = 'action_'.$module->name.'@'.$key; ?>
									<div class="form-group">
										<label class="col-md-3 control-label">{{ $value }}</label>
										<div class="col-md-9">
									    	{{ Form::checkbox(
									    		$module_name, 
									    		1, 
									    		Session::has($module_name)?Session::get($module_name):null, 
									    		array(
									    			'data-toggle' => 'checkbox',
									    			'data-on-text' => trans('dashboard::label.yes'),
									    			'data-off-text' => trans('dashboard::label.no'),
									    			'data-size' 	=> 'normal',
									    			'data-on-color' 	=> 'success',
									    			'data-off-color' 	=> 'danger'
									    			)); }}
									    </div>
									</div>
								@endforeach
							</div>
						@endforeach
					</div>
			    </div>
			</div>
		</div>
	</form>
@stop

@section('scripts')
	{{ JavaScript::makeVar('msg_confirm_delete', trans('usergroups::message.confirm_delete_usergroup')) }}
	<script>
		// Para eliminar un grupo de usuario se muestra un cuadro de dialogo
		$('#btnDeleteUserGroups').click(function(event) {
			bootbox.confirm(inncore.msg_confirm_delete, function(result) {
				if(result)
				{
					$("#frmPrincipal input, #frmPrincipal textarea, #frmPrincipal select").rules("remove");
					$("#frmPrincipal input[name='_method']").val("DELETE");
					$("#frmPrincipal").submit();
				}
			});
		});
		



		$('#frmPrincipal').validate();
		
		$(document).ready(function() {
		    
		});
	</script>
@stop