Aucune description

users.blade.php 27KB

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