Nav apraksta

users.blade.php 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  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. @else
  226. <td data-role-number="0" class="user-role">Undefined</td>
  227. @endif
  228. @if ($user->has_access)
  229. <td class="user-has-access" data-value="1">Yes</td>
  230. @else
  231. <td class="user-has-access" data-value="0">No</td>
  232. @endif
  233. <td class="col-md-2">
  234. {{ $user->office_phone }}
  235. @if ($user->office_extension)
  236. x. {{ $user->office_extension }}
  237. @endif
  238. </td>
  239. <td>
  240. {{ $user->cell_phone }}
  241. </td>
  242. <td>
  243. <span class="glyphicon glyphicon-pencil edit-user icon-btn"></span>
  244. </td>
  245. </tr>
  246. @endforeach
  247. </tbody>
  248. </table>
  249. </div>
  250. <div>
  251. <button class="btn btn-primary pull-right" id="new_user"><span class="glyphicon glyphicon-plus"></span>
  252. New User</button>
  253. </div>
  254. <br><br>
  255. @endif
  256. </div>
  257. </div>
  258. <div class="row">
  259. <div class="col-md-3">
  260. <h3>User Access</h3>
  261. <p>Use this section to control application access. Select the preferred access level and click 'Update'.</p>
  262. {{ Form::open(['action' => 'UsersController@updateAccess']) }}
  263. <div class="form-group">
  264. <select name="access_level" class="form-control">
  265. @if ($access_level == 1)
  266. <option selected="selected" value="1">Only Administrators</option>
  267. @else
  268. <option value="1">Only Administrators</option>
  269. @endif
  270. @if ($access_level == 2)
  271. <option selected="selected" value="2">Only Administrators and School Coordinators</option>
  272. @else
  273. <option value="2">Only Administrators and School Coordinators</option>
  274. @endif
  275. @if ($access_level == 3)
  276. <option selected="selected" value="3">Only Administrators, School Coordinators, and Program
  277. Coordinators</option>
  278. @else
  279. <option value="3">Only Administrators, School Coordinators, and Program Coordinators</option>
  280. @endif
  281. @if ($access_level == 4)
  282. <option selected="selected" value="4">All users</option>
  283. @else
  284. <option value="4">All Users</option>
  285. @endif
  286. </select>
  287. </div>
  288. <button type="submit" class="btn btn-primary">Update</button>
  289. {{ Form::close() }}
  290. </div>
  291. </div>
  292. @stop
  293. @section('included-js')
  294. @include('global._datatables_js')
  295. @stop
  296. @section('javascript')
  297. // ------------------------------------------------------------------------
  298. // Page Load
  299. // ------------------------------------------------------------------------
  300. // ------------------------------------------------------------------------
  301. // Events
  302. // ------------------------------------------------------------------------
  303. function triggerEditModal(element)
  304. {
  305. // Set static info in modal
  306. var user= element.closest('tr');
  307. $('#id').val(user.find('.user-name').data('user-id'));
  308. $('#name').text(user.find('.user-name').text());
  309. /* $('#email').text(user.find('.user-email').text()); */
  310. $('#email').val(user.find('.user-email').text());
  311. $('#has_access').val(user.find('.user-has-access').data('value'));
  312. // Select the selected user's current role
  313. var currentRole= user.find('.user-role').data('role-number');
  314. $('.role option[value="'+currentRole+'"]').prop('selected', true);
  315. selectSchoolandProgram(user, currentRole, $('#modal-edit-user'));
  316. //Open modal
  317. $('#modal-edit-user').modal();
  318. }
  319. // When user clicks on button to edit a user on the list
  320. $('.edit-user').on('click', function(e){
  321. triggerEditModal($(this));
  322. });
  323. // After user changes page (table is redrawn), bind modal trigger events
  324. $('table').on('draw.dt', function(e){
  325. // When user clicks on button to edit a user on the list
  326. $('.edit-user').on('click', function(e){
  327. triggerEditModal($(this));
  328. });
  329. });
  330. // When user clicks on button to create new user
  331. $('#new_user').on('click', function()
  332. {
  333. var modal = $('#modal-new-user');
  334. modal.find('.add-program').hide();
  335. // Remove all but first program
  336. modal.find('.program').not(':first').parent().remove();
  337. /* Select Admin role and "All" school and program */
  338. $('#new_role option[value="1"]').prop('selected', true);
  339. $('#new_school option[value="0"]').prop('selected', true);
  340. modal.find('.program option[value="0"]').prop('selected', true);
  341. fetchPrograms(modal);
  342. /* Disable school and program */
  343. $('#new_school').prop('disabled', true);
  344. modal.find('.program').prop('disabled', true);
  345. //Open modal
  346. modal.modal();
  347. });
  348. // Remove a program from the list
  349. $('.remove-program').on('click', function(e)
  350. {
  351. if($(this).parent().siblings().length > 0)
  352. $(this).parent().remove();
  353. });
  354. // On role change
  355. $('.role').on('change', function()
  356. {
  357. var modal = $(this).closest('.modal');
  358. switch($(this).find(':selected').val())
  359. {
  360. /* If admin, set both to All and disable selection on both*/
  361. case '1':
  362. modal.find('.school option[value="0"]').prop('selected', true);
  363. modal.find('.program option[value="0"]').prop('selected', true);
  364. modal.find('.school').prop('disabled', true);
  365. modal.find('.program').prop('disabled', true);
  366. // Remove all but first program
  367. modal.find('.program').not(':first').parent().remove();
  368. // Remove delete button and fix width of select
  369. modal.find('.program').removeClass('shortened-select');
  370. $('.remove-program').remove();
  371. //Hide button to add program
  372. modal.find('.add-program').hide();
  373. break;
  374. /* If scoord, set program to all and disable it */
  375. case '2':
  376. /* Disable "All" option in schools and program */
  377. modal.find('.school option[value="0"]').attr('disabled', true);
  378. if(modal.find('.school').find(':selected').val() == 0)
  379. {
  380. modal.find('.school option:enabled:first').prop('selected', true);
  381. }
  382. modal.find('.program option[value="0"]').prop('selected', true);
  383. modal.find('.school').prop('disabled', false);
  384. modal.find('.program').prop('disabled', true);
  385. // Remove all but first program
  386. modal.find('.program').not(':first').parent().remove();
  387. // Remove delete button and fix width of select
  388. modal.find('.program').removeClass('shortened-select');
  389. $('.remove-program').remove();
  390. //Hide button to add program
  391. modal.find('.add-program').hide();
  392. break;
  393. /* If pcoord or professor, enable everything */
  394. case '3':
  395. case '4':
  396. /* Disable "All" option in school */
  397. modal.find('.school option[value="0"]').attr('disabled', true);
  398. /* Enable School and select an available option for school*/
  399. modal.find('.school').prop('disabled', false);
  400. if(modal.find('.school').find(':selected').val() == 0)
  401. {
  402. modal.find('.school option:enabled:first').prop('selected', true);
  403. }
  404. /* Enable program*/
  405. modal.find('.program').prop('disabled', false);
  406. // If it only has one child (most likely when changing from admin or scoord)
  407. if(modal.find('.programs').children().length == 1)
  408. {
  409. /* Fetch programs for the available school */
  410. fetchPrograms(modal);
  411. /* Disable "All" option in schools and program */
  412. modal.find('.program option[value="0"]').attr('disabled', true);
  413. /* Select available option */
  414. modal.find('.program option:enabled:first').prop('selected', true);
  415. }
  416. else
  417. {
  418. /* Disable "All" option in schools and program */
  419. modal.find('.program option[value="0"]').attr('disabled', true);
  420. }
  421. // Add delete button and fix width of select
  422. modal.find('.program').addClass('shortened-select');
  423. modal.find('.program').each(function() {
  424. if($(this).siblings().length ==0)
  425. {
  426. $(this).parent().append(
  427. ' <span class="remove-program glyphicon glyphicon-remove text-primary icon-btn"></span>'
  428. );
  429. }
  430. });
  431. $('.remove-program').on('click', function(e)
  432. {
  433. if($(this).parent().siblings().length > 0)
  434. $(this).parent().remove();
  435. });
  436. //Hide button to add program
  437. modal.find('.add-program').show();
  438. break;
  439. default:
  440. break;
  441. }
  442. });
  443. $('.school').on('change', function()
  444. {
  445. var modal = $(this).closest('.modal');
  446. switch(modal.find('.role').find(':selected').val())
  447. {
  448. case '3':
  449. case '4':
  450. // Remove all but first program
  451. modal.find('.program').not(':first').parent().remove();
  452. fetchPrograms(modal);
  453. modal.find('.program option[value="0"]').attr('disabled', true);
  454. modal.find('.program option:enabled:first').prop('selected', true);
  455. break;
  456. }
  457. });
  458. $('.add-program').on('click', function(e)
  459. {
  460. e.preventDefault();
  461. var modal = $(this).closest('.modal');
  462. var clone = modal.find('.program:last')
  463. .parent()
  464. .clone();
  465. // Change name
  466. clone
  467. .children('select')
  468. .attr('name', 'programs[]');
  469. // Append
  470. modal.find('.programs').append(clone);
  471. modal.find('.remove-program').on('click', function(e)
  472. {
  473. if($(this).parent().siblings().length > 0)
  474. $(this).parent().remove();
  475. });
  476. });
  477. // ------------------------------------------------------------------------
  478. // Functions
  479. // ------------------------------------------------------------------------
  480. function selectSchoolandProgram(user, role, modal)
  481. {
  482. modal.find('.add-program').hide();
  483. switch(role)
  484. {
  485. case 1:
  486. fetchPrograms(modal);
  487. /* Select "All" in school and program */
  488. $('.school option[value="0"]').prop('selected', true);
  489. modal.find('.program option[value="0"]').prop('selected', true);
  490. /* Disable school and program */
  491. $('.school').prop('disabled', true);
  492. modal.find('.program').prop('disabled', true);
  493. break;
  494. case 2:
  495. /* Find and select user's school */
  496. var school_id = user.find('.user-school').data('school-id');
  497. $('.school option[value="'+school_id+'"]').prop('selected', true);
  498. /* Fetch programs */
  499. fetchPrograms(modal);
  500. /* Disable "All" option in school and select the next one*/
  501. $('.school option[value="0"]').attr('disabled', true);
  502. /* Disable all options in program */
  503. modal.find('.program').prop('disabled', true);
  504. break;
  505. case 3:
  506. case 4:
  507. /* Make sure school and program are not disabled */
  508. $('.school').prop('disabled', false);
  509. modal.find('.program').prop('disabled', false);
  510. var school_id = user.find('.user-school').data('school-id');
  511. $('.school option[value="'+school_id+'"]').prop('selected', true);
  512. var program_ids = new Array();
  513. modal.find('.programs').empty();
  514. user.find('.user-program').children().each(function(index, value)
  515. {
  516. $(this).parent().siblings().find('.remove-program').prop('disabled', true);
  517. var program_id = $(this).data('program-id');
  518. modal.find('.programs').append(
  519. '<div class="form-group">'+
  520. '<select class="program form-control shortened-select" name="programs[]"></select>'+
  521. ' <span class="remove-program glyphicon glyphicon-remove text-primary icon-btn"></span>'+
  522. '</div>'
  523. );
  524. $('.remove-program').on('click', function(e)
  525. {
  526. if($(this).parent().siblings().length > 0)
  527. $(this).parent().remove();
  528. });
  529. fetchPrograms(modal);
  530. program_ids.push(program_id);
  531. });
  532. for(var i =0; i < program_ids.length; i++)
  533. {
  534. var program_id=program_ids[i];
  535. modal.find('.program:eq('+i+') option[value="'+program_id+'" ]').prop('selected', true);
  536. }
  537. modal.find('.add-program').show();
  538. /* Disable "All"
  539. option in school and program*/
  540. $('.school option[value="0"]').attr('disabled', true);
  541. modal.find('.program option[value="0"]').attr('disabled', true);
  542. break;
  543. }
  544. }
  545. // Fetch programs associated to a specific school
  546. function fetchPrograms(modal, index = 1)
  547. {
  548. //If school is set to All, do not search for programs
  549. if(modal.find('.school').find(':selected').val()!=0)
  550. {
  551. $.ajax({
  552. type: 'POST',
  553. url: "{{ URL::action('ProgramsController@fetch') }}",
  554. data: { id: modal.find('.school').find(':selected').val()},
  555. success: function(data)
  556. {
  557. modal.find('.program').empty();
  558. modal.find('.program').append('<option value="0">All</option>');
  559. data.forEach( function (program)
  560. {
  561. modal.find('.program')
  562. .append('<option value="'+program.id+'">'+program.name+'</option>');
  563. });
  564. },
  565. async:false
  566. });
  567. }
  568. else
  569. {
  570. modal.find('.program').empty();
  571. modal.find('.program').append('<option value="0">All</option>');
  572. }
  573. }
  574. @stop