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

@section('content')
	<header>
		<h1 class="module-title"><span class="glyphicon glyphicon-user"></span>{{ $title }}</h1>
    </header>
    {{ Alert::render() }}
    <div class="row btn-bar">
    	@if(!isset($myProfile))
    	<div class="btn-group pull-left">
			<a href="{{ url('admin/users') }}" 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($user, $formOptions) }}
	    <div class="row">
	    	<div class="col-md-6">
			    <div class="panel panel-default">
					<div class="panel-heading"><span class="glyphicon glyphicon-th-list"></span> {{ trans('users::label.user_info') }}</div>
					<div class="panel-body">
						<div class="form-group">
			    			<label for="inputName" class="col-md-3 control-label">{{ trans('users::label.name') }}</label>
			    			<div class="col-md-9">
			    				{{ Form::text('name', null, 
									array(
										"class" 		=> "form-control required",
										"id" 			=> "inputName",
										"placeholder"	=> trans('users::label.name')
								)) }}
			    			</div>
			    		</div>
			    		<div class="form-group">
			    			<label for="inputEmail" class="col-md-3 control-label">{{ trans('users::label.email') }}</label>
			    			<div class="col-md-9">
			    				{{ Form::email('email', null, 
									array(
										"class" 		=> "form-control required email",
										"id" 			=> "inputEmail",
										"placeholder"	=> trans('users::label.email')
								)) }}
			    			</div>
			    		</div>
			    		
					</div>
			    </div>
			    <div class="panel panel-default">
					<div class="panel-heading"><span class="glyphicon glyphicon-camera"></span> {{ trans('users::label.avatar') }}</div>
					<div class="panel-body">
						<div class="row">
							<div class="col-md-3">
								<img class="img-responsive users-avatar" src="{{ $user->photo('150') }}">
							</div>
							<div class="col-md-9">
								<div class="form-group">
									<label>
										{{ Form::file('avatar', 
											array(
												"class" 		=> "",
												"id" 			=> "inputAvatar"
										)) }}
									</label>
								</div>
								@if($user->exists && !empty($user->avatar))
								<div class="checkbox">
								    <label>
								    	{{ Form::checkbox('non-photo', '1', null) }} {{ trans('users::label.nonphoto') }}
								    </label>
								 </div>
								 @endif
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="col-md-6">
			    <div class="panel panel-default">
					<div class="panel-heading"><span class="glyphicon glyphicon-lock"></span> {{ trans('users::label.access_info') }}</div>
					<div class="panel-body">
					@if(!$user->exists)
							<div class="form-group">
				    			<label for="inputUsername" class="col-md-3 control-label">{{ trans('users::label.username') }}</label>
				    			<div class="col-md-9">
				    				{{ Form::text('username', null, 
										array(
											"class" 		=> "form-control required",
											"id" 			=> "inputUsername",
											"placeholder"	=> trans('users::label.username')
									)) }}
				    			</div>
				    		</div>
				    		<div class="form-group">
				    			<label for="password" class="col-md-3 control-label">{{ trans('users::label.password') }}</label>
				    			<div class="col-md-9">
				    				{{ Form::password('password',
										array(
											"class" 		=> "form-control required",
											"id" 			=> "password"
									)) }}
				    			</div>
				    		</div>
				    		<div class="form-group">
				    			<label for="password_confirmation" class="col-md-3 control-label">{{ trans('users::label.password_confirmation') }}</label>
				    			<div class="col-md-9">
				    				{{ Form::password('password_confirmation',
										array(
											"class" 		=> "form-control required",
											"id" 			=> "password_confirmation"
									)) }}
				    			</div>
				    		</div>
				    		
					@else
							<div class="form-group">
				    			<label for="inputUsername" class="col-md-3 control-label">{{ trans('users::label.username') }}</label>
				    			<div class="col-md-9">
				    				{{ Form::text('username', null, 
										array(
											"class" 		=> "form-control required",
											"id" 			=> "inputUsername",
											"placeholder"	=> trans('users::label.username'),
											"readonly"		=> "readonly",
											"disabled"		=> "disabled"
									)) }}
				    			</div>
				    		</div>
				    		<div class="form-group">
				    			<div class="col-md-9 col-md-offset-3">
				    				@if(isset($myProfile))
				    					<a href="/admin/users/change-my-password"><span class="glyphicon glyphicon-lock"></span> {{ trans('users::label.change_my_password') }}</a>
				    				@else
				    					<a href="/admin/users/change-password/{{ $user->id }}"><span class="glyphicon glyphicon-lock"></span> {{ trans('users::label.change_password') }}</a>
				    				@endif
				    				
				    			</div>
				    		</div>
				    		@if($user->id != Auth::user()->id)
				    			<div class="form-group">
					    			<div class="col-md-9 col-md-offset-3">
					    				<button type="button" id="btnDeleteUser" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span> {{ trans('users::label.delete_user') }}</button>
					    			</div>
					    		</div>
				    		@endif
					@endif
					@if(!isset($myProfile))
			    		<div class="form-group">
			    			<label for="inputStatus" class="col-md-3 control-label">{{ trans('users::label.status') }}</label>
			    			<div class="col-md-9">
			    				{{ Form::select('active', 
			    					array('1' => trans('users::label.active'), '0' => trans('users::label.inactive')),
			    					null, 
									array(
										"class" 		=> "form-control ",
										"id" 			=> "inputStatus",
										"placeholder"	=> trans('users::label.status')
								)) }}
			    			</div>
			    		</div>
			    		<div class="form-group">
			    			<label for="inputUserGroup" class="col-md-3 control-label">{{ trans('users::label.usergroup') }}</label>
			    			<div class="col-md-9">
			    				{{ Form::select('usergroup', 
			    					$userGroupsOptions,
			    					null, 
									array(
										"class" 		=> "form-control ",
										"id" 			=> "inputUserGroup",
								)) }}
			    			</div>
			    		</div>
		    		@endif
		    		</div>
			    </div>
			</div>
		</div>
	</form>
@stop

@section('scripts')
	{{ JavaScript::makeVar('msg_confirm_delete', trans('usergroups::message.confirm_delete_usergroup')) }}
	<script>
		// Para eliminar un usuario se muestra un cuadro de dialogo
		$('#btnDeleteUser').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({
			rules: {
				password: {
					required: true,
					minlength: 6
				},
				password_confirmation: {
					equalTo: "#password"
				},
				inputAvatar : {
					accept: "image/*"
				}
			}
		});

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