No Description

users.blade.php 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. @extends('layouts.master')
  2. @section('navigation')
  3. @include('local.managers.admins._new_navigation')
  4. @stop
  5. @section('main')
  6. <!-- Edit User -->
  7. <div class="modal fade" id="modal-edit-user">
  8. <div class="modal-dialog modal-sm">
  9. <div class="modal-content">
  10. <div class="modal-header">
  11. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
  12. aria-hidden="true">&times;</span></button>
  13. <h4 class="modal-title">Edit User</h4>
  14. </div>
  15. <div class="modal-body">
  16. {{ Form::open(['action' => ['UsersController@update']]) }}
  17. <input name="id" id="id" type="hidden"></input>
  18. <div class="form-group">
  19. <label for="name" class="control-label">Name</label>
  20. <p id="name" name="name" class="form-control-static"></p>
  21. </div>
  22. <div class="form-group">
  23. <!-- <label for="email" class="control-label">Email</label> -->
  24. {{ Form::label('email', 'Email') }}
  25. {{ Form::email('email', Input::old('email'), ['class' => 'form-control']) }}
  26. <span style="color: red;">Changing the email may cause the user to lose access to OLAS.</span>
  27. </div>
  28. <!--
  29. <div class="form-group">
  30. <label for="" class="control-label">Email</label>
  31. <p id="email" name="email" class="form-control-static"></p>
  32. <!~~
  33. {{ Form::label('email', 'Email') }}
  34. <input id="email" type="email" name="email" class="role form-control" value="">
  35. </input>
  36. ~~>
  37. </div>
  38. -->
  39. <div class="form-group">
  40. {{ Form::label('role', 'Role') }}
  41. <select id="role" name="role" class="role form-control">
  42. <option value="1">Administrator</option>
  43. <option value="2">School Coordinator</option>
  44. <option value="3">Program Coordinator</option>
  45. <option value="4">Professor</option>
  46. </select>
  47. </div>
  48. <div class="form-group">
  49. {{ Form::label('school', 'School or College') }}
  50. <select name="school" class="school form-control">
  51. <option value="0">All</option>
  52. @foreach ($schools as $school)
  53. <option value="{{ $school->id }}">
  54. {{ $school->name }}
  55. </option>
  56. @endforeach
  57. </select>
  58. </div>
  59. {{ Form::label('program', 'Program(s)') }}
  60. <div class="programs">
  61. <div class="form-group">
  62. <select class="program form-control" name="programs[]"></select>
  63. </div>
  64. </div>
  65. <p id="add-program-wrapper" class="text-right">
  66. <button id="add-program" class="add-program btn-xs btn btn-success"><span
  67. class="glyphicon glyphicon-plus"></span></button>
  68. </p>
  69. <div class="form-group">
  70. {{ Form::label('has_access', 'Active (has access)') }}
  71. <select name="has_access" id="has_access" class="form-control">
  72. <option value="1">Yes</option>
  73. <option value="0">No</option>
  74. </select>
  75. </div>
  76. </div>
  77. <div class="modal-footer">
  78. <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  79. <button name="submit_roles" class="btn btn-primary" value="Save" type="submit">Save</button>
  80. {{ Form::close() }}
  81. </div>
  82. </div><!-- /.modal-content -->
  83. </div><!-- /.modal-dialog -->
  84. </div><!-- /.modal -->
  85. <!-- New User -->
  86. <div class="modal fade" id="modal-new-user">
  87. <div class="modal-dialog modal-sm">
  88. <div class="modal-content">
  89. <div class="modal-header">
  90. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
  91. aria-hidden="true">&times;</span></button>
  92. <h4 class="modal-title">New User</h4>
  93. </div>
  94. <div class="modal-body">
  95. {{ Form::open(['action' => ['UsersController@store']]) }}
  96. <input name="new_id" id="new_id" type="hidden"></input>
  97. <div class="form-group">
  98. <label for="new_first_name" class="control-label">Name</label>
  99. {{ Form::text('new_first_name', Input::old('new_first_name'), ['class' => 'form-control']) }}
  100. </div>
  101. <div class="form-group">
  102. <label for="new_surnames" class="control-label">Surnames</label>
  103. {{ Form::text('new_surnames', Input::old('new_surnames'), ['class' => 'form-control']) }}
  104. </div>
  105. <div class="form-group">
  106. <label for="new_email" class="control-label">Email</label>
  107. {{ Form::text('new_email', Input::old('new_email'), ['class' => 'form-control']) }}
  108. </div>
  109. <div class="form-group">
  110. {{ Form::label('new_role', 'Role') }}
  111. <select id="new_role" name="new_role" class="role form-control">
  112. <option value="1">Administrator</option>
  113. <option value="2">School Coordinator</option>
  114. <option value="3">Program Coordinator</option>
  115. <option value="4">Professor</option>
  116. </select>
  117. </div>
  118. <div class="form-group">
  119. {{ Form::label('new_school', 'School or College') }}
  120. <select id="new_school" name="new_school" class="school form-control">
  121. <option value="0">All</option>
  122. @foreach ($schools as $school)
  123. <option value="{{ $school->id }}">
  124. {{ $school->name }}
  125. </option>
  126. @endforeach
  127. </select>
  128. </div>
  129. {{ Form::label('new_programs', 'Program(s)') }}
  130. <div class="programs">
  131. <div class="form-group">
  132. <select class="program form-control" name="new_programs[]"></select>
  133. </div>
  134. </div>
  135. <p id="new-add-program-wrapper" class="text-right">
  136. <button id="new-add-program" class="add-program btn-xs btn btn-success"><span
  137. class="add-program glyphicon glyphicon-plus"></span></button>
  138. </p>
  139. </div>
  140. <div class="modal-footer">
  141. <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  142. <button name="submit_new_user" class="btn btn-primary" value="Save" type="submit">Save</button>
  143. {{ Form::close() }}
  144. </div>
  145. </div><!-- /.modal-content -->
  146. </div><!-- /.modal-dialog -->
  147. </div><!-- /.modal -->
  148. <div class="row">
  149. <div class="col-md-12">
  150. @if (count($users))
  151. <div class="table-responsive">
  152. <table id="user_table" class="table table-striped table-condensed datatable-user">
  153. <thead>
  154. <tr>
  155. <th>Name</th>
  156. <th>College/School</th>
  157. <th>Program(s)</th>
  158. <th>Email</th>
  159. <th>Role</th>
  160. <th>Active</th>
  161. <th>Office Phone</th>
  162. <th>Cell Phone</th>
  163. <th>Edit</th>
  164. </tr>
  165. </thead>
  166. <tfoot>
  167. <tr class="column-search">
  168. <th><input class="column-search-bar form-control" type="text" placeholder="Search" /></th>
  169. <th><select class="column-search-select form-control">
  170. <option value=""></option>
  171. </select></th>
  172. <th><input class="column-search-bar form-control" type="text" placeholder="Search" /></th>
  173. <th><input class="column-search-bar form-control" type="text" placeholder="Search" /></th>
  174. <th><select class="column-search-select form-control">
  175. <option value=""></option>
  176. </select></th>
  177. <th><select class="column-search-select form-control">
  178. <option value=""></option>
  179. </select></th>
  180. <th><input class="column-search-bar form-control" type="text" placeholder="Search" /></th>
  181. <th><input class="column-search-bar form-control" type="text" placeholder="Search" /></th>
  182. <th></th>
  183. </tr>
  184. </tfoot>
  185. <tbody>
  186. @foreach ($users as $user)
  187. <tr>
  188. <td data-user-id="{{ $user->id }}" class="user-name">{{ $user->surnames }},
  189. {{ $user->first_name }}</td>
  190. <!-- If user has school, set school data -->
  191. @if ($user->school_id)
  192. <td class="user-school" data-school-id="{{ $user->school_id }}">
  193. {{ $user->school->name }}
  194. </td>
  195. @elseif(count($user->programs) > 0)
  196. <td class="user-school" data-school-id="{{ $user->programs[0]->school_id }}">
  197. {{ $user->programs[0]->school->name }}
  198. </td>
  199. @else
  200. <td>
  201. All
  202. </td>
  203. @endif
  204. <!-- If user has programs, set program data -->
  205. @if (count($user->programs))
  206. <td class="user-program">
  207. @foreach ($user->programs as $program)
  208. <p data-program-id="{{ $program->id }}">{{ $program->name }}</p>
  209. @endforeach
  210. </td>
  211. @else
  212. <td>
  213. All
  214. </td>
  215. @endif
  216. <td class="user-email">{{ $user->email }}</td>
  217. @if ($user->role == 4)
  218. <td data-role-number="4" class="user-role">Professor</td>
  219. @elseif($user->role == 3)
  220. <td data-role-number="3" class="user-role">Program Coordinator</td>
  221. @elseif($user->role == 2)
  222. <td data-role-number="2" class="user-role">School Coordinator</td>
  223. @elseif($user->role == 1)
  224. <td data-role-number="1" class="user-role">Administrator</td>
  225. @endif
  226. @if ($user->has_access)
  227. <td class="user-has-access" data-value="1">Yes</td>
  228. @else
  229. <td class="user-has-access" data-value="0">No</td>
  230. @endif
  231. <td class="col-md-2">
  232. {{ $user->office_phone }}
  233. @if ($user->office_extension)
  234. x. {{ $user->office_extension }}
  235. @endif
  236. </td>
  237. <td>
  238. {{ $user->cell_phone }}
  239. </td>
  240. <td>
  241. <span class="glyphicon glyphicon-pencil edit-user icon-btn"></span>
  242. </td>
  243. </tr>
  244. @endforeach
  245. </tbody>
  246. </table>
  247. </div>
  248. <div>
  249. <button class="btn btn-primary pull-right" id="new_user"><span class="glyphicon glyphicon-plus"></span>
  250. New User</button>
  251. </div>
  252. <br><br>
  253. @endif
  254. </div>
  255. </div>
  256. <div class="row">
  257. <div class="col-md-3">
  258. <h3>User Access</h3>
  259. <p>Use this section to control application access. Select the preferred access level and click 'Update'.</p>
  260. {{ Form::open(['action' => 'UsersController@updateAccess']) }}
  261. <div class="form-group">
  262. <select name="access_level" class="form-control">
  263. @if ($access_level == 1)
  264. <option selected="selected" value="1">Only Administrators</option>
  265. @else
  266. <option value="1">Only Administrators</option>
  267. @endif
  268. @if ($access_level == 2)
  269. <option selected="selected" value="2">Only Administrators and School Coordinators</option>
  270. @else
  271. <option value="2">Only Administrators and School Coordinators</option>
  272. @endif
  273. @if ($access_level == 3)
  274. <option selected="selected" value="3">Only Administrators, School Coordinators, and Program
  275. Coordinators</option>
  276. @else
  277. <option value="3">Only Administrators, School Coordinators, and Program Coordinators</option>
  278. @endif
  279. @if ($access_level == 4)
  280. <option selected="selected" value="4">All users</option>
  281. @else
  282. <option value="4">All Users</option>
  283. @endif
  284. </select>
  285. </div>
  286. <button type="submit" class="btn btn-primary">Update</button>
  287. {{ Form::close() }}
  288. </div>
  289. </div>
  290. @stop
  291. @section('included-js')
  292. @include('global._datatables_js')
  293. @stop
  294. @section('javascript')
  295. // ------------------------------------------------------------------------
  296. // Page Load
  297. // ------------------------------------------------------------------------
  298. // ------------------------------------------------------------------------
  299. // Events
  300. // ------------------------------------------------------------------------
  301. function triggerEditModal(element)
  302. {
  303. // Set static info in modal
  304. var user= element.closest('tr');
  305. $('#id').val(user.find('.user-name').data('user-id'));
  306. $('#name').text(user.find('.user-name').text());
  307. /* $('#email').text(user.find('.user-email').text()); */
  308. $('#email').val(user.find('.user-email').text());
  309. $('#has_access').val(user.find('.user-has-access').data('value'));
  310. // Select the selected user's current role
  311. var currentRole= user.find('.user-role').data('role-number');
  312. $('.role option[value="'+currentRole+'"]').prop('selected', true);
  313. selectSchoolandProgram(user, currentRole, $('#modal-edit-user'));
  314. //Open modal
  315. $('#modal-edit-user').modal();
  316. }
  317. // When user clicks on button to edit a user on the list
  318. $('.edit-user').on('click', function(e){
  319. triggerEditModal($(this));
  320. });
  321. // After user changes page (table is redrawn), bind modal trigger events
  322. $('table').on('draw.dt', function(e){
  323. // When user clicks on button to edit a user on the list
  324. $('.edit-user').on('click', function(e){
  325. triggerEditModal($(this));
  326. });
  327. });
  328. // When user clicks on button to create new user
  329. $('#new_user').on('click', function()
  330. {
  331. var modal = $('#modal-new-user');
  332. modal.find('.add-program').hide();
  333. // Remove all but first program
  334. modal.find('.program').not(':first').parent().remove();
  335. /* Select Admin role and "All" school and program */
  336. $('#new_role option[value="1"]').prop('selected', true);
  337. $('#new_school option[value="0"]').prop('selected', true);
  338. modal.find('.program option[value="0"]').prop('selected', true);
  339. fetchPrograms(modal);
  340. /* Disable school and program */
  341. $('#new_school').prop('disabled', true);
  342. modal.find('.program').prop('disabled', true);
  343. //Open modal
  344. modal.modal();
  345. });
  346. // Remove a program from the list
  347. $('.remove-program').on('click', function(e)
  348. {
  349. if($(this).parent().siblings().length > 0)
  350. $(this).parent().remove();
  351. });
  352. // On role change
  353. $('.role').on('change', function()
  354. {
  355. var modal = $(this).closest('.modal');
  356. switch($(this).find(':selected').val())
  357. {
  358. /* If admin, set both to All and disable selection on both*/
  359. case '1':
  360. modal.find('.school option[value="0"]').prop('selected', true);
  361. modal.find('.program option[value="0"]').prop('selected', true);
  362. modal.find('.school').prop('disabled', true);
  363. modal.find('.program').prop('disabled', true);
  364. // Remove all but first program
  365. modal.find('.program').not(':first').parent().remove();
  366. // Remove delete button and fix width of select
  367. modal.find('.program').removeClass('shortened-select');
  368. $('.remove-program').remove();
  369. //Hide button to add program
  370. modal.find('.add-program').hide();
  371. break;
  372. /* If scoord, set program to all and disable it */
  373. case '2':
  374. /* Disable "All" option in schools and program */
  375. modal.find('.school option[value="0"]').attr('disabled', true);
  376. if(modal.find('.school').find(':selected').val() == 0)
  377. {
  378. modal.find('.school option:enabled:first').prop('selected', true);
  379. }
  380. modal.find('.program option[value="0"]').prop('selected', true);
  381. modal.find('.school').prop('disabled', false);
  382. modal.find('.program').prop('disabled', true);
  383. // Remove all but first program
  384. modal.find('.program').not(':first').parent().remove();
  385. // Remove delete button and fix width of select
  386. modal.find('.program').removeClass('shortened-select');
  387. $('.remove-program').remove();
  388. //Hide button to add program
  389. modal.find('.add-program').hide();
  390. break;
  391. /* If pcoord or professor, enable everything */
  392. case '3':
  393. case '4':
  394. /* Disable "All" option in school */
  395. modal.find('.school option[value="0"]').attr('disabled', true);
  396. /* Enable School and select an available option for school*/
  397. modal.find('.school').prop('disabled', false);
  398. if(modal.find('.school').find(':selected').val() == 0)
  399. {
  400. modal.find('.school option:enabled:first').prop('selected', true);
  401. }
  402. /* Enable program*/
  403. modal.find('.program').prop('disabled', false);
  404. // If it only has one child (most likely when changing from admin or scoord)
  405. if(modal.find('.programs').children().length == 1)
  406. {
  407. /* Fetch programs for the available school */
  408. fetchPrograms(modal);
  409. /* Disable "All" option in schools and program */
  410. modal.find('.program option[value="0"]').attr('disabled', true);
  411. /* Select available option */
  412. modal.find('.program option:enabled:first').prop('selected', true);
  413. }
  414. else
  415. {
  416. /* Disable "All" option in schools and program */
  417. modal.find('.program option[value="0"]').attr('disabled', true);
  418. }
  419. // Add delete button and fix width of select
  420. modal.find('.program').addClass('shortened-select');
  421. modal.find('.program').each(function() {
  422. if($(this).siblings().length ==0)
  423. {
  424. $(this).parent().append(
  425. ' <span class="remove-program glyphicon glyphicon-remove text-primary icon-btn"></span>'
  426. );
  427. }
  428. });
  429. $('.remove-program').on('click', function(e)
  430. {
  431. if($(this).parent().siblings().length > 0)
  432. $(this).parent().remove();
  433. });
  434. //Hide button to add program
  435. modal.find('.add-program').show();
  436. break;
  437. default:
  438. break;
  439. }
  440. });
  441. $('.school').on('change', function()
  442. {
  443. var modal = $(this).closest('.modal');
  444. switch(modal.find('.role').find(':selected').val())
  445. {
  446. case '3':
  447. case '4':
  448. // Remove all but first program
  449. modal.find('.program').not(':first').parent().remove();
  450. fetchPrograms(modal);
  451. modal.find('.program option[value="0"]').attr('disabled', true);
  452. modal.find('.program option:enabled:first').prop('selected', true);
  453. break;
  454. }
  455. });
  456. $('.add-program').on('click', function(e)
  457. {
  458. e.preventDefault();
  459. var modal = $(this).closest('.modal');
  460. var clone = modal.find('.program:last')
  461. .parent()
  462. .clone();
  463. // Change name
  464. clone
  465. .children('select')
  466. .attr('name', 'programs[]');
  467. // Append
  468. modal.find('.programs').append(clone);
  469. modal.find('.remove-program').on('click', function(e)
  470. {
  471. if($(this).parent().siblings().length > 0)
  472. $(this).parent().remove();
  473. });
  474. });
  475. // ------------------------------------------------------------------------
  476. // Functions
  477. // ------------------------------------------------------------------------
  478. function selectSchoolandProgram(user, role, modal)
  479. {
  480. modal.find('.add-program').hide();
  481. switch(role)
  482. {
  483. case 1:
  484. fetchPrograms(modal);
  485. /* Select "All" in school and program */
  486. $('.school option[value="0"]').prop('selected', true);
  487. modal.find('.program option[value="0"]').prop('selected', true);
  488. /* Disable school and program */
  489. $('.school').prop('disabled', true);
  490. modal.find('.program').prop('disabled', true);
  491. break;
  492. case 2:
  493. /* Find and select user's school */
  494. var school_id = user.find('.user-school').data('school-id');
  495. $('.school option[value="'+school_id+'"]').prop('selected', true);
  496. /* Fetch programs */
  497. fetchPrograms(modal);
  498. /* Disable "All" option in school and select the next one*/
  499. $('.school option[value="0"]').attr('disabled', true);
  500. /* Disable all options in program */
  501. modal.find('.program').prop('disabled', true);
  502. break;
  503. case 3:
  504. case 4:
  505. /* Make sure school and program are not disabled */
  506. $('.school').prop('disabled', false);
  507. modal.find('.program').prop('disabled', false);
  508. var school_id = user.find('.user-school').data('school-id');
  509. $('.school option[value="'+school_id+'"]').prop('selected', true);
  510. var program_ids = new Array();
  511. modal.find('.programs').empty();
  512. user.find('.user-program').children().each(function(index, value)
  513. {
  514. $(this).parent().siblings().find('.remove-program').prop('disabled', true);
  515. var program_id = $(this).data('program-id');
  516. modal.find('.programs').append(
  517. '<div class="form-group">'+
  518. '<select class="program form-control shortened-select" name="programs[]"></select>'+
  519. ' <span class="remove-program glyphicon glyphicon-remove text-primary icon-btn"></span>'+
  520. '</div>'
  521. );
  522. $('.remove-program').on('click', function(e)
  523. {
  524. if($(this).parent().siblings().length > 0)
  525. $(this).parent().remove();
  526. });
  527. fetchPrograms(modal);
  528. program_ids.push(program_id);
  529. });
  530. for(var i =0; i < program_ids.length; i++)
  531. {
  532. var program_id=program_ids[i];
  533. modal.find('.program:eq('+i+') option[value="'+program_id+'" ]').prop('selected', true);
  534. }
  535. modal.find('.add-program').show();
  536. /* Disable "All"
  537. option in school and program*/
  538. $('.school option[value="0"]').attr('disabled', true);
  539. modal.find('.program option[value="0"]').attr('disabled', true);
  540. break;
  541. }
  542. }
  543. // Fetch programs associated to a specific school
  544. function fetchPrograms(modal, index = 1)
  545. {
  546. //If school is set to All, do not search for programs
  547. if(modal.find('.school').find(':selected').val()!=0)
  548. {
  549. $.ajax({
  550. type: 'POST',
  551. url: "{{ URL::action('ProgramsController@fetch') }}",
  552. data: { id: modal.find('.school').find(':selected').val()},
  553. success: function(data)
  554. {
  555. modal.find('.program').empty();
  556. modal.find('.program').append('<option value="0">All</option>');
  557. data.forEach( function (program)
  558. {
  559. modal.find('.program')
  560. .append('<option value="'+program.id+'">'+program.name+'</option>');
  561. });
  562. },
  563. async:false
  564. });
  565. }
  566. else
  567. {
  568. modal.find('.program').empty();
  569. modal.find('.program').append('<option value="0">All</option>');
  570. }
  571. }
  572. @stop