Nenhuma descrição

rubrics.blade.php 36KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  1. @extends('layouts.master')
  2. @section('navigation')
  3. @if(Auth::user()->role==1)
  4. @include('local.managers.admins._navigation')
  5. @elseif(Auth::user()->role==2)
  6. @include('local.managers.sCoords._navigation')
  7. @elseif(Auth::user()->role==3)
  8. @include('local.managers.pCoords._navigation')
  9. @endif
  10. @stop
  11. @section('main')
  12. <!-- Update Rubric Modal -->
  13. <div class="modal fade" id="modal-confirm-update">
  14. <div class="modal-dialog modal-sm">
  15. <div class="modal-content">
  16. <div class="modal-header">
  17. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  18. <h4 class="modal-title">Update Rubric</h4>
  19. </div>
  20. <div class="modal-body">
  21. <p>Speak to any coordinators and/or professors in your School or
  22. Program that may be affected when you update this rubric. <strong>Professors
  23. that have already used this rubric will keep a copy of it as
  24. they used it, not an updated one.</strong></p>
  25. <p>Do you want to update this rubric?</p>
  26. </div>
  27. <div class="modal-footer">
  28. <button type="button" class="btn btn-default" data-dismiss="modal">No</button>
  29. <button id="button-update-rubric" class="btn btn-primary save">Update</button>
  30. </div>
  31. </div><!-- /.modal-content -->
  32. </div><!-- /.modal-dialog -->
  33. </div><!-- /.modal -->
  34. <!-- Delete Rubric Modal -->
  35. <div class="modal fade" id="modal-confirm-delete">
  36. <div class="modal-dialog modal-sm">
  37. <div class="modal-content">
  38. <div class="modal-header">
  39. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  40. <h4 class="modal-title">Delete Rubric</h4>
  41. </div>
  42. <div class="modal-body">
  43. <p>Please note: By deleting this rubric, it will no longer be available
  44. to your school's or program's professors. However, professors that
  45. have already used it will keep a copy in their activities. Speak to
  46. any coordinators and/or professors in your School or Program that may be affected.</p>
  47. <p>Are you sure you want to delete this rubric?</p>
  48. </div>
  49. <div class="modal-footer">
  50. <button type="button" class="btn btn-default" data-dismiss="modal">No</button>
  51. <button id="button-delete-rubric" class="btn btn-primary">Delete</button>
  52. </div>
  53. </div><!-- /.modal-content -->
  54. </div><!-- /.modal-dialog -->
  55. </div><!-- /.modal -->
  56. <div class="row">
  57. <div class="col-md-12">
  58. <div class="panel panel-default">
  59. <div class="panel-heading">
  60. <span class="glyphicon glyphicon-triangle-bottom"></span>
  61. General Information
  62. </div>
  63. <div class="panel-body">
  64. <form>
  65. <div class="form-group">
  66. <label>Select a template, or create your own rubric</label>
  67. <select id="select-template" class="form-control selectpicker">
  68. <option data-template-id="0">Custom</option>
  69. @foreach ($templates as $template)
  70. @if($template->school_id==NULL && $template->program_id==NULL)
  71. <option
  72. data-template-id="{{ $template->id }}"
  73. data-template-program-id="{{ $template->program_id }}"
  74. data-admin="1"
  75. >
  76. {{{ $template->name }}}
  77. </option>
  78. @else
  79. <option
  80. data-template-id="{{ $template->id }}"
  81. data-template-program-id="{{ $template->program_id }}"
  82. >
  83. {{{ $template->name }}}
  84. </option>
  85. @endif
  86. @endforeach
  87. </select>
  88. </div>
  89. <!-- If user is admin s/he can pick which schools can view the rubric -->
  90. @if(Auth::user()->role==1)
  91. <div class="form-group">
  92. <label>Select the School this rubric will be visible from</label>
  93. <select id="select-school" class="form-control selectpicker">
  94. <option data-school-id="0">All</option>
  95. @foreach ($schools as $school)
  96. <option data-school-id="{{ $school->id }}">
  97. {{ $school->name }}
  98. </option>
  99. @endforeach
  100. </select>
  101. </div>
  102. @endif
  103. <!-- If user is admin or school coordinator, s/he can pick which programs -->
  104. @if(Auth::user()->role==1 || Auth::user()->role==2)
  105. <div class="form-group">
  106. <label>Select the Program this rubric belongs to</label>
  107. <select id="select-program" class="form-control selectpicker">
  108. <option data-program-id="0">All</option>
  109. @foreach ($programs as $program)
  110. <option
  111. data-program-id="{{ $program->id }}"
  112. data-program-program-id="{{ $program->program_id }}"
  113. >
  114. {{ $program->name }}
  115. </option>
  116. @endforeach
  117. </select>
  118. </div>
  119. @endif
  120. </form>
  121. <label for="">Select the lower bound for passing criteria</label>
  122. <form class="form-inline">
  123. <div class="form-group">
  124. <!-- Select percentage. If there is a rubric, select the saved value -->
  125. <select id="expected_percentage" class="form-control selectpicker">
  126. @for($i = 50; $i <= 100; $i++)
  127. @if($i==70)
  128. <option selected="selected" value="{{ $i }}">{{ $i }}</option>
  129. @else
  130. <option value="{{ $i }}">{{ $i }}</option>
  131. @endif
  132. @endfor
  133. </select>
  134. % of all students must score at least
  135. <!-- Select points. If there is a rubric, select the saved value -->
  136. <select id="expected_points" class="form-control selectpicker">
  137. @for($i = 5; $i <= 8; $i++)
  138. @if($i==5)
  139. <option selected="selected" value="{{ $i }}">{{ $i }}</option>
  140. @else
  141. <option value="{{ $i }}">{{ $i }}</option>
  142. @endif
  143. @endfor
  144. </select>
  145. point(s) in a criterion for it to pass.
  146. </div>
  147. </form>
  148. <br>
  149. <form>
  150. <div class="form-group">
  151. <label>Select Status (you can change this later)</label>
  152. <div class="radio">
  153. <label>
  154. <input type="radio" name="is_visible" id="is_visible0" value="0" checked>
  155. This rubric is <strong>not complete</strong> yet and will not be available to professors.
  156. </label>
  157. </div>
  158. <div class="radio">
  159. <label>
  160. <input type="radio" name="is_visible" id="is_visible1" value="1">
  161. This rubric is <strong>complete</strong> and will be available to professors.
  162. </label>
  163. </div>
  164. </div>
  165. </form>
  166. <div>
  167. <p class="small">Note: You can hide or show this section by clicking on its heading. You may want to hide it to have more space. </p>
  168. </div>
  169. </div>
  170. </div>
  171. <div class="well">
  172. <form>
  173. <div class="form-group">
  174. <label>Select a Learning Outcome</label>
  175. <select id="select-outcome" class="form-control selectpicker">
  176. @foreach ($outcomes as $outcome)
  177. <option data-outcome-id="{{ $outcome->id }}">{{ $outcome->name }}</option>
  178. @endforeach
  179. </select>
  180. </div>
  181. @if(Auth::user()->role != '1')
  182. <label>Filter Criteria</label>
  183. <div class="form-group">
  184. <label class="radio-inline">
  185. <input type="radio" checked name="criteria-filter" id="criteria-all" value="all"> All Criteria
  186. </label>
  187. <label class="radio-inline">
  188. <input type="radio" name="criteria-filter" id="criteria-school" value="school"> Criteria from my School
  189. </label>
  190. @if(Auth::user()->role == '3')
  191. <label class="radio-inline">
  192. <input type="radio" name="criteria-filter" id="criteria-program" value="program"> Criteria from my Program(s)
  193. </label>
  194. @endif
  195. </div>
  196. @endif
  197. <div class="form-group">
  198. <label>Select a Criterion</label><span id="updated-text" class="text-success small"> updated</span>
  199. <select id="select-criterion" class="form-control selectpicker">
  200. </select>
  201. </div>
  202. <button id="button-add-criterion" class="btn btn-md btn-primary center-block"> <span class="glyphicon glyphicon-plus"></span> Add Criterion to Rubric</button>
  203. </form>
  204. </div>
  205. </div>
  206. </div>
  207. <div id="rubric-container" class="row">
  208. <div class="col-md-12">
  209. <table class="table table-striped table-condensed">
  210. <thead><tr><th colspan="6 "><input id="rubric-name" type="text" class="form-control input-lg" placeholder="Rubric Name"></th></tr></thead>
  211. <thead>
  212. <tr>
  213. <th></th>
  214. <th>Criterion</th>
  215. <th>Beginning (1-2)</th>
  216. <th>In Progress (3-4)</th>
  217. <th>Good (5-6)</th>
  218. <th>Excellent (7-8)</th>
  219. <th></th>
  220. </tr>
  221. </thead>
  222. <tbody>
  223. </tbody>
  224. </table>
  225. <div id="copyright-info">
  226. <hr>
  227. <p class="small"><strong>Copyright Information</strong></p>
  228. <ul id="copyright-list" class="list-unstyled small">
  229. </ul>
  230. <hr>
  231. </div>
  232. <div class="text-center">
  233. <div class="btn-group" role="group" aria-label="...">
  234. <button id="button-create-rubric" class="btn btn-lg btn-primary save">
  235. <span class="glyphicon glyphicon-floppy-disk"></span>
  236. Create
  237. </button>
  238. <button id="button-confirm-update-rubric" data-toggle="modal" data-target="#modal-confirm-update" class="btn btn-lg btn-primary">
  239. <span class="glyphicon glyphicon-pencil"></span>
  240. Update
  241. </button>
  242. <button id="button-confirm-delete-rubric" data-toggle="modal" data-target="#modal-confirm-delete" class="btn btn-lg btn-primary">
  243. <span class="glyphicon glyphicon-remove"></span>
  244. Delete
  245. </button>
  246. <button id="button-print-rubric" class="btn btn-lg btn-primary"><span class="glyphicon glyphicon-print"></span> Print <span class="small">(saved version)</span></button>
  247. </div>
  248. </div>
  249. </div>
  250. </div>
  251. @stop
  252. @section('included-js')
  253. <!-- jQuery Sortable Tables -->
  254. <script src="{{ asset('vendor/jQuerySortable/jquery-sortable-min.js') }}"></script>
  255. <!-- X-Editable js -->
  256. <script src="{{ asset('vendor/xeditable/bootstrap-editable.min.js') }}"></script>
  257. @stop
  258. @section('javascript')
  259. // --------------------------------------------------------------------------
  260. // Page load
  261. // --------------------------------------------------------------------------
  262. $('#updated-text').hide();
  263. // Enable/disable program selection depending on school selection if user is
  264. // admin
  265. if({{Auth::user()->role}}==1)
  266. toggleProgramSelect($('#select-school'));
  267. // Fetch criteria of first outcome
  268. fetchCriteria($('#select-outcome'));
  269. // Hide table
  270. $('#rubric-container').hide();
  271. // Disable Update and Delete Buttons by default
  272. $('#button-confirm-update-rubric').prop('disabled', true);
  273. $('#button-confirm-delete-rubric').prop('disabled', true);
  274. $('#button-print-rubric').prop('disabled', true);
  275. // Sortable rows
  276. $('.table').sortable({
  277. handle: 'span.glyphicon.glyphicon-move',
  278. containerSelector: 'table',
  279. itemPath: '> tbody',
  280. itemSelector: 'tr',
  281. placeholder: '<tr class="placeholder"><th><span class="glyphicon glyphicon-arrow-right"></span></th></tr>'
  282. });
  283. // --------------------------------------------------------------------------
  284. // Functions
  285. // --------------------------------------------------------------------------
  286. // Fetch criteria associated to a specific learning outcome
  287. function fetchCriteria(outcome)
  288. {
  289. $.post
  290. (
  291. "{{ URL::route('fetchCriteria') }}",
  292. {
  293. id: outcome.find(':selected').data('outcome-id'),
  294. filter: $('input[name=criteria-filter]:checked').val()
  295. },
  296. function(data)
  297. {
  298. $('#select-criterion').empty();
  299. // Append criteria
  300. data.forEach( function (arrayItem)
  301. {
  302. $('#select-criterion')
  303. .append('<option data-criterion-id="'+arrayItem.id+'" >'+arrayItem.name+'</option>');
  304. });
  305. // If there are no criteria assigned to the selected outcome, disable the
  306. // input and the button used to add criteria.
  307. if(!$('#select-criterion').children().length)
  308. {
  309. $('#select-criterion').prop('disabled', true);
  310. $('#button-add-criterion').prop('disabled', true);
  311. }
  312. // Otherwise, enable both the input and the button
  313. else
  314. {
  315. $('#select-criterion').prop('disabled', false);
  316. $('#button-add-criterion').prop('disabled', false);
  317. }
  318. $('#updated-text').fadeIn('slow').fadeOut('slow');
  319. refreshSelects();
  320. }
  321. );
  322. }
  323. // Add a new criterion to the rubric
  324. function addCriterion()
  325. {
  326. // Show the rubric container
  327. if(!$('tbody').children().length)
  328. {
  329. $('#rubric-container').show();
  330. }
  331. // Get the selected criterion's id
  332. var id= parseInt($('#select-criterion').find(':selected').data('criterion-id'));
  333. // Check for duplicates
  334. var duplicates=false;
  335. $('tbody tr').each(function()
  336. {
  337. if ($(this).data('criterion-id') == id)
  338. {
  339. duplicates=true;
  340. }
  341. });
  342. // If there are any, display an error
  343. if(duplicates)
  344. {
  345. $('#js-error-row').show();
  346. $('#js-error-row').find('#error-message').text('Error: The selected criterion was already added.');
  347. return;
  348. }
  349. // Otherwise, hide the error container
  350. else
  351. {
  352. $('#js-error-row').hide();
  353. }
  354. // Fetch information of the criterion selected
  355. $.post
  356. (
  357. "{{ URL::route('fetchCriterion') }}",
  358. { id: id},
  359. function(data)
  360. {
  361. // Append the fetched data
  362. var str ='<tr data-assoc-outcome-id="'+data.outcome_id+'"'
  363. +'data-criterion-id="'+data.id+'" data-criterion-copyright="'+data.copyright+'" data-criterion-notes="'+data.notes+'"><th><span class="glyphicon glyphicon-move"></span></th><td>';
  364. var subcriteria = '';
  365. if(data.subcriteria){
  366. var subcriteria_array = JSON.parse(data.subcriteria);
  367. subcriteria = '<ul class="subcriteria list-unstyled">';
  368. subcriteria_array.forEach(function (value) {
  369. subcriteria += '<li>'+value+'</li>';
  370. });
  371. subcriteria += '</ul>';
  372. }
  373. if(data.notes)
  374. {
  375. str+='<span><em data-toggle="tooltip" data-placement="top" title="'+data.notes+'">'+data.name+'</em></span><sup></sup>'+subcriteria;
  376. }
  377. else
  378. {
  379. str+='<span>'+data.name+'</span><sup></sup>'+subcriteria;
  380. }
  381. str+='</td><td class="editable" data-type="textarea">'+data.description12+'</td>'
  382. +'<td class="editable" data-type="textarea">'+data.description34+'</td>'
  383. +'<td class="editable" data-type="textarea">'+data.description56+'</td>'
  384. +'<td class="editable" data-type="textarea">'+data.description78+'</td>'
  385. +'<th><span class="glyphicon glyphicon-remove icon-btn" aria-hidden="true"></span></th></tr>';
  386. $('table tbody').append(str);
  387. // Build copyright list
  388. buildCopyrightList();
  389. // Enable X-Edtable on this new row
  390. $('.editable').editable({
  391. unsavedclass: null,
  392. rows: 4
  393. });
  394. // Turn on tooltips again (because content is dynamic)
  395. $('[data-toggle="tooltip"]').tooltip();
  396. // Sortable rows
  397. $('.table').sortable({
  398. handle: 'span.glyphicon.glyphicon-move',
  399. containerSelector: 'table',
  400. itemPath: '> tbody',
  401. itemSelector: 'tr',
  402. placeholder: '<tr class="placeholder"><th><span class="glyphicon glyphicon-arrow-right"></span></th></tr>'
  403. });
  404. }
  405. );
  406. }
  407. // Fetch single criterion
  408. function fetchCriterion(criterion)
  409. {
  410. $.post
  411. (
  412. "{{ URL::route('fetchCriterion') }}",
  413. { id: outcome.find(':selected').data('outcome-id')},
  414. function(data)
  415. {
  416. $('#select-criterion').empty();
  417. data.forEach( function (arrayItem)
  418. {
  419. $('#select-criterion')
  420. .append('<option data-criterion-id="'+arrayItem.id+'" >'+arrayItem.name+'</option>');
  421. });
  422. $('#select-criterion').append('<option data-criterion-id="0">Custom</option>');
  423. refreshSelects();
  424. }
  425. );
  426. }
  427. // Build list from copyright info in rubric
  428. function buildCopyrightList()
  429. {
  430. // Empty the copyright list
  431. $('#copyright-list').empty();
  432. $('tbody tr').each(function( index )
  433. {
  434. var criterion = $(this);
  435. // If there's copyright info
  436. if(criterion.data('criterion-copyright')!=null)
  437. {
  438. var copyright = criterion.data('criterion-copyright');
  439. // If there is anything in the copyright list
  440. if($('#copyright-list li').length>0)
  441. {
  442. // Check copyright list for the same copyright text
  443. var found = false;
  444. $('#copyright-list li').each(function()
  445. {
  446. // If found, give the string its number
  447. if(copyright==$(this).find('span').text())
  448. {
  449. copyrightNumber = Number.parseInt($(this).find('sup').text());
  450. console.log('a: '+copyrightNumber);
  451. criterion.children('td:nth-child(2)').find('sup').text(copyrightNumber);
  452. found =true;
  453. //to break
  454. return false;
  455. }
  456. });
  457. // Otherwise, give it the next number and append a new item to the
  458. // list
  459. if(!found)
  460. {
  461. var copyrightNumber = $('#copyright-list li').length+1;
  462. console.log('b: '+copyrightNumber);
  463. console.log(criterion.children('td:nth-child(2)').find('sup').length);
  464. criterion.children('td:nth-child(2)').find('sup').text(copyrightNumber);
  465. $('#copyright-list').append('<li><sup>'+copyrightNumber+' </sup><span>'+copyright+'<span></li>');
  466. }
  467. }
  468. // Otherwise, give it number 1 and append it
  469. else
  470. {
  471. criterion.children('td:nth-child(2)').find('sup').text('1');
  472. $('#copyright-list').append('<li><sup>1 </sup><span>'+copyright+'<span></li>');
  473. }
  474. }
  475. });
  476. if($('#copyright-info li').length>0)
  477. {
  478. $('#copyright-info').show();
  479. }
  480. else
  481. {
  482. $('#copyright-info').hide();
  483. }
  484. }
  485. function refreshSelects()
  486. {
  487. $('#select-template').selectpicker('refresh');
  488. $('#select-school').selectpicker('refresh');
  489. $('#select-program').selectpicker('refresh');
  490. $('#select-outcome').selectpicker('refresh');
  491. $('#select-criterion').selectpicker('refresh');
  492. $('#expected_percentage').selectpicker('refresh');
  493. $('#expected_points').selectpicker('refresh');
  494. }
  495. // Fetch programs associated to a specific school
  496. function fetchPrograms(school)
  497. {
  498. $.ajax({
  499. type: 'POST',
  500. url: "{{ URL::action('ProgramsController@fetch') }}",
  501. data: { id: school.find(':selected').data('school-id')},
  502. success: function(data)
  503. {
  504. $('#select-program').empty();
  505. $('#select-program').append('<option data-program-id="0">All</option>');
  506. data.forEach( function (program)
  507. {
  508. $('#select-program')
  509. .append('<option data-program-id="'+program.id+'" >'+program.name+'</option>');
  510. });
  511. },
  512. async:false
  513. });
  514. if($('#select-school').find(':selected').data('school-id')!=0)
  515. $('#select-program').prop('disabled', false);
  516. else
  517. $('#select-program').prop('disabled', true);
  518. refreshSelects();
  519. }
  520. // Load a template. This function is different from the one for professors
  521. function loadTemplate()
  522. {
  523. $.post
  524. (
  525. "{{ URL::to('loadTemplate') }}",
  526. { id: $('#select-template').find(':selected').data('template-id')},
  527. function(data)
  528. {
  529. // Show the container and empty all rows
  530. $('#rubric-container').show();
  531. $('tbody').empty();
  532. //Set the name of the rubric
  533. $('#rubric-name').val(data.name);
  534. // Set school id to 0, then to the saved value if it exists
  535. $('#select-school option[data-school-id="0"]').prop('selected', true);
  536. $('#select-school option[data-school-id="'+data.school_id+'"]').prop('selected', true);
  537. // Fetch programs associated to that school
  538. fetchPrograms($('#select-school'));
  539. // Set program id to 0, then to the saved value if it exists
  540. $('#select-program option[data-program-id="0"]').prop('selected', true);
  541. $('#select-program option[data-program-id="'+data.program_id+'"]').prop('selected', true);
  542. // Set expected values
  543. console.log(data.expected_percentage);
  544. console.log(data.expected_points);
  545. $('#expected_percentage option[value="'+data.expected_percentage+'"]').attr('selected', true);
  546. $('#expected_points option[value="'+data.expected_points+'"]').attr('selected', true);
  547. // Set visibility
  548. var is_visible = JSON.parse(data.is_visible);
  549. if(is_visible)
  550. {
  551. $('#is_visible0').prop('checked', false);
  552. $('#is_visible1').prop('checked', true);
  553. }
  554. else
  555. {
  556. $('#is_visible1').prop('checked', false);
  557. $('#is_visible0').prop('checked', true);
  558. }
  559. // Set the contents of the rubric
  560. var contents = JSON.parse(data.contents);
  561. contents.forEach(function (data)
  562. {
  563. // Append the fetched data
  564. var str ='<tr data-assoc-outcome-id="'+data.outcome_id+'"'
  565. +'data-criterion-id="'+data.id+'" data-criterion-copyright="'+data.copyright+'" data-criterion-notes="'+data.notes+'"><th><span class="glyphicon glyphicon-move"></span></th><td>';
  566. var subcriteria = '';
  567. if(data.subcriteria){
  568. var subcriteria_array = data.subcriteria;
  569. subcriteria = '<ul class="subcriteria list-unstyled">';
  570. subcriteria_array.forEach(function (value) {
  571. subcriteria += '<li>'+value+'</li>';
  572. });
  573. subcriteria += '</ul>';
  574. }
  575. if(data.notes)
  576. {
  577. str+='<span><em data-toggle="tooltip" data-placement="top" title="'+data.notes+'">'+data.name+'</em></span><sup></sup>'+subcriteria;
  578. }
  579. else
  580. {
  581. str+='<span>'+data.name+'</span><sup></sup>'+subcriteria;
  582. }
  583. str+='</td><td class="editable" data-type="textarea">'+data.description12+'</td>'
  584. +'<td class="editable" data-type="textarea">'+data.description34+'</td>'
  585. +'<td class="editable" data-type="textarea">'+data.description56+'</td>'
  586. +'<td class="editable" data-type="textarea">'+data.description78+'</td>'
  587. +'<th><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></th></tr>';
  588. $('table tbody').append(str);
  589. // Build copyright list
  590. buildCopyrightList();
  591. // Enable X-Edtable on this new row
  592. $('.editable').editable({
  593. unsavedclass: null,
  594. rows: 4
  595. });
  596. // Turn on tooltips again (because content is dynamic)
  597. $('[data-toggle="tooltip"]').tooltip();
  598. refreshSelects();
  599. });
  600. // Sortable rows
  601. $('.table').sortable({
  602. handle: 'span.glyphicon.glyphicon-move',
  603. containerSelector: 'table',
  604. itemPath: '> tbody',
  605. itemSelector: 'tr',
  606. placeholder: '<tr class="placeholder"><th><span class="glyphicon glyphicon-arrow-right"></span></th></tr>'
  607. });
  608. // Build Copyright List
  609. buildCopyrightList();
  610. }
  611. );
  612. }
  613. // Checks whether the user wants to save a rubric with a name that already exists
  614. function nameExists()
  615. {
  616. var duplicates = false;
  617. $('#select-template option').each(function()
  618. {
  619. var optionName = $(this).text().trim();
  620. if($('#rubric-name').val().trim()===optionName)
  621. {
  622. duplicates = true;
  623. }
  624. });
  625. refreshSelects();
  626. return duplicates;
  627. }
  628. //Enable disable program select
  629. function toggleProgramSelect(school)
  630. {
  631. if(school.find(':selected').data('school-id')<1)
  632. {
  633. $('#select-program option[data-program-id="0"]').prop('selected', true);
  634. $('#select-program').prop('disabled', true);
  635. }
  636. else
  637. {
  638. fetchPrograms(school);
  639. $('#select-program').prop('disabled', false);
  640. }
  641. refreshSelects();
  642. }
  643. // --------------------------------------------------------------------------
  644. // Events
  645. // --------------------------------------------------------------------------
  646. // Toggle visibility for accordion panels
  647. $('.panel-heading').on('click', function()
  648. {
  649. if($(this).find('.glyphicon').hasClass('glyphicon-triangle-right'))
  650. {
  651. $(this).find('.glyphicon').removeClass('glyphicon-triangle-right');
  652. $(this).find('.glyphicon').addClass('glyphicon-triangle-bottom');
  653. }
  654. else if($(this).find('.glyphicon').hasClass('glyphicon-triangle-bottom'))
  655. {
  656. $(this).find('.glyphicon').removeClass('glyphicon-triangle-bottom');
  657. $(this).find('.glyphicon').addClass('glyphicon-triangle-right');
  658. }
  659. $(this).siblings('.panel-body').stop().slideToggle();
  660. });
  661. // When trying to change the template, ask the user to confirm and reset the
  662. // rubric if s/he does
  663. $('#select-template').on('change', function()
  664. {
  665. // If changing to custom template, reset
  666. if($('#select-template').find(':selected').data('template-id')=='0')
  667. {
  668. $('#rubric-container').hide();
  669. $('#rubric-name').val('');
  670. $('tbody').empty();
  671. // Disable delete, update and print buttons
  672. $('#button-confirm-delete-rubric').prop('disabled', true);
  673. $('#button-confirm-update-rubric').prop('disabled', true);
  674. $('#button-print-rubric').prop('disabled', true);
  675. }
  676. // Otherwise, load the selected template
  677. else
  678. {
  679. loadTemplate();
  680. //If user is admin, or the templates id matches user's, or the template
  681. // id's school matches user, allow editing
  682. var selected = $('#select-template').find(':selected');
  683. var programs = {{ json_encode(Auth::user()->programs->lists('id')) }};
  684. if(
  685. {{ Auth::user()->role }}==1
  686. || ({{ Auth::user()->role }}==2 && selected.data('admin')!=1)
  687. || ({{ Auth::user()->role }}==3
  688. && $.inArray(selected.data('template-program-id'), programs)
  689. && selected.data('admin')!=1
  690. )
  691. )
  692. {
  693. $('#button-confirm-delete-rubric').prop('disabled', false);
  694. $('#button-confirm-update-rubric').prop('disabled', false);
  695. }
  696. else
  697. {
  698. // Disable update and edit
  699. $('#button-confirm-delete-rubric').prop('disabled', true);
  700. $('#button-confirm-update-rubric').prop('disabled', true);
  701. }
  702. // Enable print button
  703. $('#button-print-rubric').prop('disabled', false);
  704. }
  705. });
  706. // When a school changes, update its programs. If all is selected, disable
  707. $('#select-school').on('change', function()
  708. {
  709. toggleProgramSelect($(this));
  710. });
  711. // When a learning outcome changes, update its criteria
  712. $('#select-outcome, input[name=criteria-filter]').on('change', function()
  713. {
  714. fetchCriteria($('#select-outcome'));
  715. });
  716. // When the add button is clicked
  717. $('#button-add-criterion').on('click', function(e)
  718. {
  719. //Prevent page refresh
  720. e.preventDefault();
  721. //Add new criterion
  722. addCriterion();
  723. });
  724. // When the create or update buttons are clicked (.save)
  725. $('.save').on('click', function(e)
  726. {
  727. //Prevent page refresh
  728. e.preventDefault();
  729. // Empty field validation
  730. var emptyFields=false;
  731. $('td').each(function()
  732. {
  733. if ($(this).text() == "" || $(this).text() == "Empty")
  734. {
  735. emptyFields=true;
  736. }
  737. });
  738. // If any fields are empty, display error
  739. if(emptyFields || $.trim($('#rubric-name').val())=='')
  740. {
  741. $('#js-error-row').show();
  742. $('#js-error-row').find('#error-message').text('Error: Please fill all the fields. Make sure your rubric has a name.');
  743. return;
  744. }
  745. else
  746. {
  747. $('#js-error-row').hide();
  748. }
  749. // Check whether a rubric with the written name already exists
  750. if($(this).attr('id')=='button-create-rubric' && nameExists())
  751. {
  752. $('#js-error-row').show();
  753. $('#js-error-row').find('#error-message').text('Error: A template with that name already exists.');
  754. return;
  755. }
  756. else
  757. {
  758. $('#js-error-row').hide();
  759. }
  760. var criterionObject = new Object();
  761. var criteriaArray = new Array();
  762. // For each criterion in the rubric, get its value and put it into an array
  763. $('tbody tr').each(function( index )
  764. {
  765. criterionObject.id = $(this).data('criterion-id');
  766. criterionObject.outcome_id = $(this).data('assoc-outcome-id');
  767. criterionObject.name = $(this).children('td:nth-child(2)').find('span').text();
  768. var subcriteriaArray = new Array();
  769. $(this).children('td:nth-child(2)').find('.subcriteria li').each(function(index){
  770. subcriteriaArray.push($(this).text());
  771. });
  772. criterionObject.subcriteria = subcriteriaArray;
  773. criterionObject.description12 = $(this).children('td:nth-child(3)').text();
  774. criterionObject.description34 = $(this).children('td:nth-child(4)').text();
  775. criterionObject.description56 = $(this).children('td:nth-child(5)').text();
  776. criterionObject.description78 = $(this).children('td:nth-child(6)').text();
  777. criterionObject.copyright = $(this).data('criterion-copyright');
  778. criterionObject.notes = $(this).data('criterion-notes');
  779. // Clone the object and push it into the array
  780. var clone = jQuery.extend({}, criterionObject);
  781. criteriaArray.push(clone);
  782. });
  783. //console.log('school', $('#select-school').find(':selected').data('school-id') );
  784. //console.log('program', $('#select-program').find(':selected').data('program-id') );
  785. if($(this).attr('id')=='button-create-rubric')
  786. {
  787. // Create
  788. $.post
  789. (
  790. "{{ URL::to('saveTemplate') }}",
  791. {
  792. name: $('#rubric-name').val(),
  793. contents: JSON.stringify(criteriaArray),
  794. school_id: $('#select-school').find(':selected').data('school-id'),
  795. program_id: $('#select-program').find(':selected').data('program-id'),
  796. expected_percentage: $('#expected_percentage').find(':selected').val(),
  797. expected_points: $('#expected_points').find(':selected').val(),
  798. is_visible: $('input[name=is_visible]:checked').val()
  799. },
  800. function(data)
  801. {
  802. location.reload(true);
  803. }
  804. );
  805. }
  806. else
  807. {
  808. console.log('school', $('#select-school').find(':selected').data('school-id') );
  809. console.log('program', $('#select-program').find(':selected').data('program-id') );
  810. // Update database
  811. $.post
  812. (
  813. "{{ URL::to('updateTemplate') }}",
  814. {
  815. id: $('#select-template').find(':selected').data('template-id'),
  816. name: $('#rubric-name').val(),
  817. contents: JSON.stringify(criteriaArray),
  818. school_id: $('#select-school').find(':selected').data('school-id'),
  819. program_id: $('#select-program').find(':selected').data('program-id'),
  820. expected_percentage: $('#expected_percentage').find(':selected').val(),
  821. expected_points: $('#expected_points').find(':selected').val(),
  822. is_visible: $('input[name=is_visible]:checked').val()
  823. },
  824. function(data)
  825. {
  826. location.reload(true);
  827. }
  828. );
  829. }
  830. });
  831. // When the confirm delete button is clicked
  832. $('#button-delete-rubric').on('click', function(e)
  833. {
  834. $('#modal-confirm-delete').modal('hide');
  835. // Delete from database
  836. $.post
  837. (
  838. "{{ URL::to('deleteTemplate') }}",
  839. {
  840. id: $('#select-template').find(':selected').data('template-id')
  841. },
  842. function(data)
  843. {
  844. location.reload();
  845. }
  846. );
  847. });
  848. // Remove a criterion and hide the table if it was the only one
  849. $('table').on('click', 'span.glyphicon-remove', function(e)
  850. {
  851. $(this).closest('tr').remove();
  852. if(!$('tbody').children().length)
  853. {
  854. $('#rubric-container').hide();
  855. }
  856. buildCopyrightList();
  857. });
  858. // When print button is clicked, redirect to print page
  859. $('#button-print-rubric').on('click', function(e)
  860. {
  861. e.preventDefault();
  862. window.location = "printRubric/"+$('#select-template').find(':selected').data('template-id');
  863. });
  864. @stop