@extends('layouts.master') @section('navigation') @include('local.managers.admins._navigation') @stop @section('main')
@if(count($users))
@foreach ($users as $user) @if($user->school_id) @elseif(count($user->programs)>0) @else @endif @if(count($user->programs)) @else @endif @if($user->role==4) @elseif($user->role==3) @elseif($user->role==2) @elseif($user->role==1) @endif @if($user->has_access) @else @endif @endforeach
Name College/School Program(s) Email Role Active Office Phone Cell Phone Edit
{{ $user->surnames }}, {{ $user->first_name }} {{ $user->school->name }} {{ $user->programs[0]->school->name }} All @foreach ($user->programs as $program)

{{ $program->name }}

@endforeach
All {{ $user->email }}ProfessorProgram CoordinatorSchool CoordinatorAdministratorYesNo {{ $user->office_phone }} @if($user->office_extension) x. {{ $user->office_extension }} @endif {{ $user->cell_phone }}


@endif

User Access

Use this section to control application access. Select the preferred access level and click 'Update'.

{{ Form::open(array('action' => 'UsersController@updateAccess')) }}
{{ Form::close() }}
@stop @section('included-js') @include('global._datatables_js') @stop @section('javascript') // ------------------------------------------------------------------------ // Page Load // ------------------------------------------------------------------------ // ------------------------------------------------------------------------ // Events // ------------------------------------------------------------------------ function triggerEditModal(element) { // Set static info in modal var user= element.closest('tr'); $('#id').val(user.find('.user-name').data('user-id')); $('#name').text(user.find('.user-name').text()); $('#email').text(user.find('.user-email').text()); $('#has_access').val(user.find('.user-has-access').data('value')); // Select the selected user's current role var currentRole= user.find('.user-role').data('role-number'); $('.role option[value="'+currentRole+'"]').prop('selected', true); selectSchoolandProgram(user, currentRole, $('#modal-edit-user')); //Open modal $('#modal-edit-user').modal(); } // When user clicks on button to edit a user on the list $('.edit-user').on('click', function(e){ triggerEditModal($(this)); }); // After user changes page (table is redrawn), bind modal trigger events $('table').on('draw.dt', function(e){ // When user clicks on button to edit a user on the list $('.edit-user').on('click', function(e){ triggerEditModal($(this)); }); }); // When user clicks on button to create new user $('#new_user').on('click', function() { var modal = $('#modal-new-user'); modal.find('.add-program').hide(); // Remove all but first program modal.find('.program').not(':first').parent().remove(); $('#new_role option[value="1"]').prop('selected', true); $('#new_school option[value="0"]').prop('selected', true); modal.find('.program option[value="0"]').prop('selected', true); fetchPrograms(modal); $('#new_school').prop('disabled', true); modal.find('.program').prop('disabled', true); //Open modal modal.modal(); }); // Remove a program from the list $('.remove-program').on('click', function(e) { if($(this).parent().siblings().length > 0) $(this).parent().remove(); }); // On role change $('.role').on('change', function() { var modal = $(this).closest('.modal'); switch($(this).find(':selected').val()) { case '1': modal.find('.school option[value="0"]').prop('selected', true); modal.find('.program option[value="0"]').prop('selected', true); modal.find('.school').prop('disabled', true); modal.find('.program').prop('disabled', true); // Remove all but first program modal.find('.program').not(':first').parent().remove(); // Remove delete button and fix width of select modal.find('.program').removeClass('shortened-select'); $('.remove-program').remove(); //Hide button to add program modal.find('.add-program').hide(); break; case '2': modal.find('.school option[value="0"]').attr('disabled', true); if(modal.find('.school').find(':selected').val() == 0) { modal.find('.school option:enabled:first').prop('selected', true); } modal.find('.program option[value="0"]').prop('selected', true); modal.find('.school').prop('disabled', false); modal.find('.program').prop('disabled', true); // Remove all but first program modal.find('.program').not(':first').parent().remove(); // Remove delete button and fix width of select modal.find('.program').removeClass('shortened-select'); $('.remove-program').remove(); //Hide button to add program modal.find('.add-program').hide(); break; case '3': case '4': modal.find('.school option[value="0"]').attr('disabled', true); modal.find('.school').prop('disabled', false); if(modal.find('.school').find(':selected').val() == 0) { modal.find('.school option:enabled:first').prop('selected', true); } modal.find('.program').prop('disabled', false); // If it only has one child (most likely when changing from admin or scoord) if(modal.find('.programs').children().length == 1) { fetchPrograms(modal); modal.find('.program option[value="0"]').attr('disabled', true); modal.find('.program option:enabled:first').prop('selected', true); } else { modal.find('.program option[value="0"]').attr('disabled', true); } // Add delete button and fix width of select modal.find('.program').addClass('shortened-select'); modal.find('.program').each(function() { if($(this).siblings().length ==0) { $(this).parent().append( ' ' ); } }); $('.remove-program').on('click', function(e) { if($(this).parent().siblings().length > 0) $(this).parent().remove(); }); //Hide button to add program modal.find('.add-program').show(); break; default: break; } }); $('.school').on('change', function() { var modal = $(this).closest('.modal'); switch(modal.find('.role').find(':selected').val()) { case '3': case '4': // Remove all but first program modal.find('.program').not(':first').parent().remove(); fetchPrograms(modal); modal.find('.program option[value="0"]').attr('disabled', true); modal.find('.program option:enabled:first').prop('selected', true); break; } }); $('.add-program').on('click', function(e) { e.preventDefault(); var modal = $(this).closest('.modal'); var clone = modal.find('.program:last') .parent() .clone(); // Change name clone .children('select') .attr('name', 'programs[]'); // Append modal.find('.programs').append(clone); modal.find('.remove-program').on('click', function(e) { if($(this).parent().siblings().length > 0) $(this).parent().remove(); }); }); // ------------------------------------------------------------------------ // Functions // ------------------------------------------------------------------------ function selectSchoolandProgram(user, role, modal) { modal.find('.add-program').hide(); switch(role) { case 1: fetchPrograms(modal); $('.school option[value="0"]').prop('selected', true); modal.find('.program option[value="0"]').prop('selected', true); $('.school').prop('disabled', true); modal.find('.program').prop('disabled', true); break; case 2: var school_id = user.find('.user-school').data('school-id'); $('.school option[value="'+school_id+'"]').prop('selected', true); fetchPrograms(modal); $('.school option[value="0"]').attr('disabled', true); modal.find('.program').prop('disabled', true); break; case 3: case 4: $('.school').prop('disabled', false); modal.find('.program').prop('disabled', false); var school_id = user.find('.user-school').data('school-id'); $('.school option[value="'+school_id+'"]').prop('selected', true); var program_ids = new Array(); modal.find('.programs').empty(); user.find('.user-program').children().each(function(index, value) { $(this).parent().siblings().find('.remove-program').prop('disabled', true); var program_id = $(this).data('program-id'); modal.find('.programs').append( '
'+ ''+ ' '+ '
' ); $('.remove-program').on('click', function(e) { if($(this).parent().siblings().length > 0) $(this).parent().remove(); }); fetchPrograms(modal); program_ids.push(program_id); }); for(var i =0; i < program_ids.length; i++) { var program_id = program_ids[i]; modal.find('.program:eq('+i+') option[value="'+program_id+'"]').prop('selected', true); } modal.find('.add-program').show(); $('.school option[value="0"]').attr('disabled', true); modal.find('.program option[value="0"]').attr('disabled', true); break; } } // Fetch programs associated to a specific school function fetchPrograms(modal, index = 1) { //If school is set to All, do not search for programs if(modal.find('.school').find(':selected').val()!=0) { $.ajax({ type: 'POST', url: "{{ URL::action('ProgramsController@fetch') }}", data: { id: modal.find('.school').find(':selected').val()}, success: function(data) { modal.find('.program').empty(); modal.find('.program').append(''); data.forEach( function (program) { modal.find('.program') .append(''); }); }, async:false }); } else { modal.find('.program').empty(); modal.find('.program').append(''); } } @stop