Brak opisu

rubrics.blade.php 48KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  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 = 0; $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" onchange="fetchObjective(this)">
  176. @foreach ($outcomes as $outcome)
  177. <option data-outcome-id="{{ $outcome->id }}">{{ $outcome->name }}</option>
  178. @endforeach
  179. </select>
  180. </div>
  181. <div class="form-group">
  182. <label>Select an Objective</label>
  183. <select id="select-objective" class="form-control selectpicker" onchange="fetchCriteria($('#select-outcome'), this)">
  184. </select>
  185. </div>
  186. <div class="form-group">
  187. <label>Select the Maximum Score</label>
  188. <select id="max_score" class="form-control selectpicker">
  189. @for($i = 1; $i <= 100; $i++)
  190. @if($i==8)
  191. <option selected="selected" value="{{ $i }}">{{ $i }}</option>
  192. @else
  193. <option value="{{ $i }}">{{ $i }}</option>
  194. @endif
  195. @endfor
  196. </select>
  197. </div>
  198. <div class="form-group">
  199. <label>Select the Type of Rubric</label>
  200. <select id="number_of_scales" class="form-control selectpicker">
  201. @for($i = 1; $i <= 20; $i++)
  202. @if(8%$i == 0)
  203. @if($i==1)
  204. <option value="{{ $i }}">Cuantitative Rubric</option>
  205. @elseif($i==4)
  206. <option selected="selected" value="{{ $i }}">{{ $i }}-Scale Rubric</option>
  207. @else
  208. <option value="{{ $i }}">{{ $i }}-Scale Rubric</option>
  209. @endif
  210. @endif
  211. @endfor
  212. </select>
  213. <div>
  214. @if(Auth::user()->role != '1')
  215. <label>Filter Criteria</label>
  216. <div class="form-group">
  217. <label class="radio-inline">
  218. <input type="radio" checked name="criteria-filter" id="criteria-all" value="all"> All Criteria
  219. </label>
  220. <label class="radio-inline">
  221. <input type="radio" name="criteria-filter" id="criteria-school" value="school"> Criteria from my School
  222. </label>
  223. @if(Auth::user()->role == '3')
  224. <label class="radio-inline">
  225. <input type="radio" name="criteria-filter" id="criteria-program" value="program"> Criteria from my Program(s)
  226. </label>
  227. @endif
  228. </div>
  229. @endif
  230. <div class="form-group">
  231. <label>Select a Criterion</label><span id="updated-text" class="text-success small"> updated</span>
  232. <select id="select-criterion" class="form-control selectpicker">
  233. </select>
  234. </div>
  235. <button id="button-add-criterion" class="btn btn-md btn-primary center-block"> <span class="glyphicon glyphicon-plus"></span> Add Criterion to Rubric</button>
  236. </form>
  237. </div>
  238. </div>
  239. </div>
  240. <div id="rubric-container" class="row">
  241. <div class="col-md-12">
  242. <table class="table table-striped table-condensed" style="table-layout: fixed">
  243. <thead id="theHead"><tr><th colspan="7 "><input id="rubric-name" type="text" class="form-control input-lg" placeholder="Rubric Name"></th></tr></thead>
  244. <thead>
  245. <tr id ="criterion-header">
  246. <th></th>
  247. <th></th>
  248. </tr>
  249. </thead>
  250. <tbody id = "allCriteria">
  251. </tbody>
  252. </table>
  253. <div id="copyright-info">
  254. <hr>
  255. <p class="small"><strong>Outcomes Evaluated</strong></p>
  256. <ul id="copyright-list" class="list-unstyled small">
  257. </ul>
  258. <hr>
  259. </div>
  260. <div class="text-center">
  261. <div class="btn-group" role="group" aria-label="...">
  262. <button id="button-create-rubric" class="btn btn-lg btn-primary save">
  263. <span class="glyphicon glyphicon-floppy-disk"></span>
  264. Create
  265. </button>
  266. <button id="button-confirm-update-rubric" data-toggle="modal" data-target="#modal-confirm-update" class="btn btn-lg btn-primary">
  267. <span class="glyphicon glyphicon-pencil"></span>
  268. Update
  269. </button>
  270. <button id="button-confirm-delete-rubric" data-toggle="modal" data-target="#modal-confirm-delete" class="btn btn-lg btn-primary">
  271. <span class="glyphicon glyphicon-remove"></span>
  272. Delete
  273. </button>
  274. <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>
  275. </div>
  276. </div>
  277. </div>
  278. </div>
  279. <script>
  280. // --------------------------------------------------------------------------
  281. // Functions
  282. // --------------------------------------------------------------------------
  283. function fetchObjective(outcome){
  284. $.post(
  285. "{{URL::route('fetchObjectivesForSelect')}}",
  286. {
  287. outcomeID:$(outcome).find(':selected').data('outcome-id'),
  288. },
  289. function(data){
  290. options = '';
  291. for(objective_index in data){
  292. options += '<option value = "'+data[objective_index].objective_id+'">'+data[objective_index].text+'</option>';
  293. }
  294. $('#select-objective').html(options);
  295. $('#select-objective').selectpicker('refresh');
  296. fetchCriteria($('#select-outcome'), $('#select-objective'));
  297. }, 'json',
  298. );
  299. }
  300. // Fetch criteria associated to a specific learning outcome
  301. function fetchCriteria(outcome, objective)
  302. {
  303. $.post
  304. (
  305. "{{ URL::route('fetchCriteria') }}",
  306. {
  307. id: outcome.find(':selected').data('outcome-id'),
  308. filter: $('input[name=criteria-filter]:checked').val()
  309. },
  310. function(data)
  311. {
  312. $('#select-criterion').empty();
  313. // Append criteria
  314. data.forEach( function (arrayItem)
  315. {
  316. $('#select-criterion')
  317. .append('<option data-criterion-id="'+arrayItem.id+'" >'+arrayItem.name+'</option>');
  318. });
  319. // If there are no criteria assigned to the selected outcome, disable the
  320. // input and the button used to add criteria.
  321. if(!$('#select-criterion').children().length)
  322. {
  323. $('#select-criterion').prop('disabled', true);
  324. $('#button-add-criterion').prop('disabled', true);
  325. }
  326. // Otherwise, enable both the input and the button
  327. else
  328. {
  329. $('#select-criterion').prop('disabled', false);
  330. $('#button-add-criterion').prop('disabled', false);
  331. }
  332. $('#updated-text').fadeIn('slow').fadeOut('slow');
  333. refreshSelects();
  334. }
  335. );
  336. }
  337. // Add a new criterion to the rubric
  338. function addCriterion()
  339. {
  340. // Show the rubric container
  341. if(!$('tbody').children().length)
  342. {
  343. $('#rubric-container').show();
  344. }
  345. // Get the selected criterion's id
  346. var id= parseInt($('#select-criterion').find(':selected').data('criterion-id'));
  347. // Check for duplicates
  348. var duplicates=false;
  349. numberOfScale = $('#number_of_scales').find(':selected').val();
  350. $('tbody tr').each(function()
  351. {
  352. if ($(this).data('criterion-id') == id)
  353. {
  354. duplicates=true;
  355. }
  356. });
  357. // If there are any, display an error
  358. if(duplicates)
  359. {
  360. $('#js-error-row').show();
  361. $('#js-error-row').find('#error-message').text('Error: The selected criterion was already added.');
  362. return;
  363. }
  364. // Otherwise, hide the error container
  365. else
  366. {
  367. $('#js-error-row').hide();
  368. }
  369. // Fetch information of the criterion selected
  370. $.post
  371. (
  372. "{{ URL::route('fetchCriterionWithTemplate') }}",
  373. { id: id,
  374. numberOfScale: numberOfScale },
  375. function(data)
  376. {
  377. // Append the fetched data
  378. copyright = null;
  379. notes = null;
  380. if(data.crit_info.length){
  381. copyright = data.crit_info[0].copyright;
  382. notes = data.crit_info[0].notes;
  383. }
  384. var str ='<tr data-criterion-id="'+data.criterion.id+'" data-criterion-copyright="'+copyright+'" data-criterion-notes="'+notes+'" data-outcomes = "'+data.outcomes+'"><th><span class="glyphicon glyphicon-move"></span></th><td>';
  385. var subcriteria = '';
  386. if(data.criterion.subcriteria){
  387. var subcriteria_array = JSON.parse(data.criterion.subcriteria);
  388. subcriteria = '<ul class="subcriteria list-unstyled">';
  389. subcriteria_array.forEach(function (value) {
  390. subcriteria += '<li>'+value+'</li>';
  391. });
  392. subcriteria += '</ul>';
  393. }
  394. if(notes)
  395. {
  396. str+='<span><em data-toggle="tooltip" data-placement="top" title="'+notes+'">'+data.criterion.name+'</em></span><sup></sup>'+subcriteria+'</td>';
  397. }
  398. else
  399. {
  400. str+='<span>'+data.criterion.name+'</span><sup></sup>'+subcriteria+'</td>';
  401. }
  402. numberOfScale = $('#number_of_scales').find(':selected').val();
  403. if(data.scales.length)
  404. for(i=0; i<numberOfScale; i++){
  405. str+='<td class="editable" data-type="textarea">'+data.scales[i].description+'</td>';
  406. }
  407. else{
  408. for(i=0; i<numberOfScale; i++){
  409. str+='<td class="editable" data-type="textarea"></td>';
  410. }
  411. }
  412. str+= '<td>'+data.outcomes+'</td>'
  413. str +='<th><span class="glyphicon glyphicon-remove icon-btn" aria-hidden="true"></span></th></tr>';
  414. $('table tbody').append(str);
  415. // Build copyright list
  416. buildCopyrightList();
  417. // Enable X-Edtable on this new row
  418. $('.editable').editable({
  419. unsavedclass: null,
  420. rows: 4
  421. });
  422. // Turn on tooltips again (because content is dynamic)
  423. $('[data-toggle="tooltip"]').tooltip();
  424. // Sortable rows
  425. $('.table').sortable({
  426. handle: 'span.glyphicon.glyphicon-move',
  427. containerSelector: 'table',
  428. itemPath: '> tbody',
  429. itemSelector: 'tr',
  430. placeholder: '<tr class="placeholder"><th><span class="glyphicon glyphicon-arrow-right"></span></th></tr>'
  431. });
  432. },
  433. 'json',
  434. );
  435. }
  436. // Fetch single criterion
  437. function fetchCriterion(criterion)
  438. {
  439. $.post
  440. (
  441. "{{ URL::route('fetchCriterion') }}",
  442. { id: outcome.find(':selected').data('outcome-id')},
  443. function(data)
  444. {
  445. $('#select-criterion').empty();
  446. data.forEach( function (arrayItem)
  447. {
  448. $('#select-criterion')
  449. .append('<option data-criterion-id="'+arrayItem.id+'" >'+arrayItem.name+'</option>');
  450. });
  451. $('#select-criterion').append('<option data-criterion-id="0">Custom</option>');
  452. refreshSelects();
  453. }
  454. );
  455. }
  456. // Build list from copyright info in rubric
  457. function buildCopyrightList()
  458. {
  459. // Empty the copyright list
  460. $('#copyright-list').empty();
  461. $('tbody tr').each(function( index )
  462. {
  463. var criterion = $(this);
  464. // If there's copyright info
  465. if(criterion.data('copyright')!=null){
  466. var copyright = criterion.data('copyright');
  467. if($('#copyright-list li').length>0)
  468. {
  469. var found = false;
  470. $('#copyright-list li').each(function()
  471. {
  472. // If found, give the string its number
  473. if(copyright==$(this).find('span').text())
  474. {
  475. copyrightNumber = Number.parseInt($(this).find('sup').text());
  476. console.log('a: '+copyrightNumber);
  477. criterion.children('td:nth-child(2)').find('sup').text(copyrightNumber);
  478. found =true;
  479. //to break
  480. return false;
  481. }
  482. });
  483. // Otherwise, give it the next number and append a new item to the
  484. // list
  485. if(!found)
  486. {
  487. var copyrightNumber = $('#copyright-list li').length+1;
  488. console.log('b: '+copyrightNumber);
  489. console.log(criterion.children('td:nth-child(2)').find('sup').length);
  490. criterion.children('td:nth-child(2)').find('sup').text(copyrightNumber);
  491. $('#copyright-list').append('<li><sup>'+copyrightNumber+' </sup><span>'+copyright+'<span></li>');
  492. }
  493. }
  494. else
  495. {
  496. criterion.children('td:nth-child(2)').find('sup').text('1');
  497. $('#copyright-list').append('<li><sup>1 </sup><span>'+copyright+'<span></li>');
  498. }
  499. }
  500. });
  501. if($('#copyright-info li').length>0)
  502. {
  503. $('#copyright-info').show();
  504. }
  505. else
  506. {
  507. $('#copyright-info').hide();
  508. }}
  509. /* if(criterion.data('criterion-copyright')!=null)
  510. {
  511. var copyright = criterion.data('criterion-copyright');
  512. // If there is anything in the copyright list
  513. if($('#copyright-list li').length>0)
  514. {
  515. // Check copyright list for the same copyright text
  516. var found = false;
  517. $('#copyright-list li').each(function()
  518. {
  519. // If found, give the string its number
  520. if(copyright==$(this).find('span').text())
  521. {
  522. copyrightNumber = Number.parseInt($(this).find('sup').text());
  523. console.log('a: '+copyrightNumber);
  524. criterion.children('td:nth-child(2)').find('sup').text(copyrightNumber);
  525. found =true;
  526. //to break
  527. return false;
  528. }
  529. });
  530. // Otherwise, give it the next number and append a new item to the
  531. // list
  532. if(!found)
  533. {
  534. var copyrightNumber = $('#copyright-list li').length+1;
  535. console.log('b: '+copyrightNumber);
  536. console.log(criterion.children('td:nth-child(2)').find('sup').length);
  537. criterion.children('td:nth-child(2)').find('sup').text(copyrightNumber);
  538. $('#copyright-list').append('<li><sup>'+copyrightNumber+' </sup><span>'+copyright+'<span></li>');
  539. }
  540. }
  541. // Otherwise, give it number 1 and append it
  542. else
  543. {
  544. criterion.children('td:nth-child(2)').find('sup').text('1');
  545. $('#copyright-list').append('<li><sup>1 </sup><span>'+copyright+'<span></li>');
  546. }
  547. }
  548. });
  549. if($('#copyright-info li').length>0)
  550. {
  551. $('#copyright-info').show();
  552. }
  553. else
  554. {
  555. $('#copyright-info').hide();
  556. }
  557. }
  558. */
  559. function refreshSelects()
  560. {
  561. $('#select-template').selectpicker('refresh');
  562. $('#select-school').selectpicker('refresh');
  563. $('#select-program').selectpicker('refresh');
  564. $('#select-outcome').selectpicker('refresh');
  565. $('#select-criterion').selectpicker('refresh');
  566. $('#expected_percentage').selectpicker('refresh');
  567. $('#expected_points').selectpicker('refresh');
  568. $('#number_of_scales').selectpicker('refresh');
  569. }
  570. // Fetch programs associated to a specific school
  571. function fetchPrograms(school)
  572. {
  573. $.ajax({
  574. type: 'POST',
  575. url: "{{ URL::action('ProgramsController@fetch') }}",
  576. data: { id: school.find(':selected').data('school-id')},
  577. success: function(data)
  578. {
  579. $('#select-program').empty();
  580. $('#select-program').append('<option data-program-id="0">All</option>');
  581. data.forEach( function (program)
  582. {
  583. $('#select-program')
  584. .append('<option data-program-id="'+program.id+'" >'+program.name+'</option>');
  585. });
  586. },
  587. async:false
  588. });
  589. if($('#select-school').find(':selected').data('school-id')!=0)
  590. $('#select-program').prop('disabled', false);
  591. else
  592. $('#select-program').prop('disabled', true);
  593. refreshSelects();
  594. }
  595. // Load a template. This function is different from the one for professors
  596. function loadTemplate()
  597. {
  598. $.post
  599. (
  600. "{{ URL::to('loadTemplate') }}",
  601. { id: $('#select-template').find(':selected').data('template-id')},
  602. function(data)
  603. {
  604. // Show the container and empty all rows
  605. $('#rubric-container').show();
  606. $('tbody').empty();
  607. //Set the name of the rubric
  608. $('#rubric-name').val(data.template.name);
  609. // Set school id to 0, then to the saved value if it exists
  610. $('#select-school option[data-school-id="0"]').prop('selected', true);
  611. $('#select-school option[data-school-id="'+data.template.school_id+'"]').prop('selected', true);
  612. // Fetch programs associated to that school
  613. fetchPrograms($('#select-school'));
  614. // Set program id to 0, then to the saved value if it exists
  615. $('#select-program option[data-program-id="0"]').prop('selected', true);
  616. $('#select-program option[data-program-id="'+data.template.program_id+'"]').prop('selected', true);
  617. // Set expected values
  618. console.log(data.template.expected_percentage);
  619. console.log(data.template.expected_points);
  620. console.log(data.template.max_score);
  621. $('#max_score').val(data.template.max_score);
  622. $('#max_score').trigger("change");
  623. $('#expected_percentage').val(data.template.expected_percentage);
  624. $('#expected_points').val(data.template.expected_points);
  625. $('#number_of_scales').val(data.template.num_scales);
  626. refreshSelects();
  627. changeTable();
  628. // Set visibility
  629. var is_visible = data.template.is_visible;
  630. if(is_visible)
  631. {
  632. $('#is_visible0').prop('checked', false);
  633. $('#is_visible1').prop('checked', true);
  634. }
  635. else
  636. {
  637. $('#is_visible1').prop('checked', false);
  638. $('#is_visible0').prop('checked', true);
  639. }
  640. // Set the contents of the rubric
  641. var temp_criterion = data.criterion;
  642. for(temp_c in temp_criterion){
  643. var str = '<tr data-criterion-id="'+temp_criterion[temp_c].criterion_id+'" data-criterion-copyright="'+temp_criterion[temp_c].copyright+'" data-criterion-notes="'+temp_criterion[temp_c].notes+'" data-outcomes = "'+temp_criterion[temp_c].outcomes+'"><th><span class="glyphicon glyphicon-move"></span></th><td>';
  644. current_criterion = temp_criterion[temp_c]
  645. var subcriteria ='';
  646. if(current_criterion.subcriteria){
  647. var subcriteria_array = JSON.parse(current_criterion.subcriteria);
  648. subcriteria = '<ul class="subcriteria list-unstyled">';
  649. subcriteria_array.forEach(function (value) {
  650. subcriteria += '<li>'+value+'</li>';
  651. });
  652. subcriteria += '</ul>';
  653. }
  654. if(current_criterion.notes)
  655. {
  656. str+='<span><em data-toggle="tooltip" data-placement="top" title="'+current_criterion.notes+'">'+current_criterion.name+'</em></span><sup></sup>'+subcriteria;
  657. }
  658. else
  659. {
  660. str+='<span>'+current_criterion.name+'</span><sup></sup>'+subcriteria;
  661. }
  662. str+= '</td>';
  663. for(scaleIndex in data.scales[current_criterion.id]){
  664. scale = data.scales[current_criterion.id][scaleIndex];
  665. str+='<td class="editable" data-id-value ="'+scale.scale_id+'" data-type="textarea">'+scale.description+'</td>';
  666. }
  667. copyright = temp_criterion[temp_c].copyright;
  668. notes = temp_criterion[temp_c].notes;
  669. if(copyright == null){
  670. copyright = '';
  671. }
  672. if(notes==null) notes ='';
  673. str += '<td class = "editable" data-type = "textarea">'+copyright+'</td>';
  674. str+= '<td class = "editable" data-type = "textarea">'+notes+'</td>';
  675. str+='<th><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></th></tr>';
  676. $('table tbody').append(str);
  677. // Enable X-Edtable on this new row
  678. $('.editable').editable({
  679. unsavedclass: null,
  680. rows: 4
  681. });
  682. // Turn on tooltips again (because content is dynamic)
  683. $('[data-toggle="tooltip"]').tooltip();
  684. refreshSelects();
  685. }
  686. /*
  687. var contents = JSON.parse(data.contents);
  688. contents.forEach(function (data)
  689. {
  690. // Append the fetched data
  691. var str ='<tr data-criterion-id="'+data.id+'" data-criterion-copyright="'+data.copyright+'" data-criterion-notes="'+data.notes+'"><th><span class="glyphicon glyphicon-move"></span></th><td>';
  692. var subcriteria = '';
  693. if(data.subcriteria){
  694. var subcriteria_array = data.subcriteria;
  695. subcriteria = '<ul class="subcriteria list-unstyled">';
  696. subcriteria_array.forEach(function (value) {
  697. subcriteria += '<li>'+value+'</li>';
  698. });
  699. subcriteria += '</ul>';
  700. }
  701. if(data.notes)
  702. {
  703. str+='<span><em data-toggle="tooltip" data-placement="top" title="'+data.notes+'">'+data.name+'</em></span><sup></sup>'+subcriteria;
  704. }
  705. else
  706. {
  707. str+='<span>'+data.name+'</span><sup></sup>'+subcriteria;
  708. }
  709. str+='</td><td class="editable" data-type="textarea">'+data.description12+'</td>'
  710. +'<td class="editable" data-type="textarea">'+data.description34+'</td>'
  711. +'<td class="editable" data-type="textarea">'+data.description56+'</td>'
  712. +'<td class="editable" data-type="textarea">'+data.description78+'</td>'
  713. +'<th><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></th></tr>';
  714. $('table tbody').append(str);
  715. // Build copyright list
  716. buildCopyrightList();
  717. // Enable X-Edtable on this new row
  718. $('.editable').editable({
  719. unsavedclass: null,
  720. rows: 4
  721. });
  722. // Turn on tooltips again (because content is dynamic)
  723. $('[data-toggle="tooltip"]').tooltip();
  724. refreshSelects();
  725. }); */
  726. // Sortable rows
  727. $('.table').sortable({
  728. handle: 'span.glyphicon.glyphicon-move',
  729. containerSelector: 'table',
  730. itemPath: '> tbody',
  731. itemSelector: 'tr',
  732. placeholder: '<tr class="placeholder"><th><span class="glyphicon glyphicon-arrow-right"></span></th></tr>'
  733. });
  734. // Build Copyright List
  735. buildCopyrightList();
  736. var selected = $('#select-template').find(':selected');
  737. var programs = {{ json_encode(Auth::user()->programs->lists('id')) }};
  738. var template_program = selected.data('template-program-id');
  739. if(
  740. {{ Auth::user()->role }}==1
  741. || ({{ Auth::user()->role }}==2 && selected.data('admin')!=1)
  742. || ({{ Auth::user()->role }}==3
  743. && programs.includes(selected.data('template-program-id'))
  744. && selected.data('admin')!=1
  745. )
  746. )
  747. {
  748. $('#button-confirm-delete-rubric').prop('disabled', false);
  749. $('#button-confirm-update-rubric').prop('disabled', false);
  750. }
  751. else
  752. {
  753. // Disable update and edit
  754. $('#button-confirm-delete-rubric').prop('disabled', true);
  755. $('#button-confirm-update-rubric').prop('disabled', true);
  756. }
  757. // Enable print button
  758. $('#button-print-rubric').prop('disabled', false);
  759. },
  760. 'json',
  761. );
  762. }
  763. // Checks whether the user wants to save a rubric with a name that already exists
  764. function nameExists()
  765. {
  766. var duplicates = false;
  767. $('#select-template option').each(function()
  768. {
  769. var optionName = $(this).text().trim();
  770. if($('#rubric-name').val().trim()===optionName)
  771. {
  772. duplicates = true;
  773. }
  774. });
  775. refreshSelects();
  776. return duplicates;
  777. }
  778. //Enable disable program select
  779. function toggleProgramSelect(school)
  780. {
  781. if(school.find(':selected').data('school-id') <1)
  782. {
  783. $('#select-program option[data-program-id="0"]').prop('selected', true);
  784. $('#select-program').prop('disabled', true);
  785. }
  786. else
  787. {
  788. fetchPrograms(school);
  789. $('#select-program').prop('disabled', false);
  790. }
  791. refreshSelects();
  792. }
  793. // --------------------------------------------------------------------------
  794. // Events
  795. // --------------------------------------------------------------------------
  796. // Toggle visibility for accordion panels
  797. $('.panel-heading').on('click', function()
  798. {
  799. if($(this).find('.glyphicon').hasClass('glyphicon-triangle-right'))
  800. {
  801. $(this).find('.glyphicon').removeClass('glyphicon-triangle-right');
  802. $(this).find('.glyphicon').addClass('glyphicon-triangle-bottom');
  803. }
  804. else if($(this).find('.glyphicon').hasClass('glyphicon-triangle-bottom'))
  805. {
  806. $(this).find('.glyphicon').removeClass('glyphicon-triangle-bottom');
  807. $(this).find('.glyphicon').addClass('glyphicon-triangle-right');
  808. }
  809. $(this).siblings('.panel-body').stop().slideToggle();
  810. });
  811. // When trying to change the template, ask the user to confirm and reset the
  812. // rubric if s/he does
  813. $('#select-template').on('change', function()
  814. {
  815. // If changing to custom template, reset
  816. if($('#select-template').find(':selected').data('template-id')=='0')
  817. {
  818. $('#rubric-container').hide();
  819. $('#rubric-name').val('');
  820. $('tbody').empty();
  821. // Disable delete, update and print buttons
  822. $('#button-confirm-delete-rubric').prop('disabled', true);
  823. $('#button-confirm-update-rubric').prop('disabled', true);
  824. $('#button-print-rubric').prop('disabled', true);
  825. }
  826. // Otherwise, load the selected template
  827. else
  828. {
  829. loadTemplate();
  830. //If user is admin, or the templates id matches user's, or the template
  831. // id's school matches user, allow editing
  832. /*var selected = $('#select-template').find(':selected');
  833. var programs = {{ json_encode(Auth::user()->programs->lists('id')) }};
  834. var template_program = selected.data('template-program-id');
  835. var dataset = selected.dataSet.templateProgramId;
  836. if(
  837. {{ Auth::user()->role }}==1
  838. || ({{ Auth::user()->role }}==2 && selected.data('admin')!=1)
  839. || ({{ Auth::user()->role }}==3
  840. && programs.includes(selected.data('template-program-id'))
  841. && selected.data('admin')!=1
  842. )
  843. )
  844. {
  845. $('#button-confirm-delete-rubric').prop('disabled', false);
  846. $('#button-confirm-update-rubric').prop('disabled', false);
  847. }
  848. else
  849. {
  850. // Disable update and edit
  851. $('#button-confirm-delete-rubric').prop('disabled', true);
  852. $('#button-confirm-update-rubric').prop('disabled', true);
  853. }
  854. // Enable print button
  855. $('#button-print-rubric').prop('disabled', false);
  856. */
  857. }
  858. });
  859. function changeTable(){
  860. amount_of_scales = parseInt($('#number_of_scales').find(':selected').val());
  861. counter2 = 0;
  862. maximum = parseInt($('#max_score').find(":selected").val());
  863. newScaleHeaders = '<th></th><th>Criterion</th>';
  864. counter = 0;
  865. division = maximum/amount_of_scales;
  866. if(amount_of_scales==1){
  867. newScaleHeaders+= "<th class = 'editable' data-type = 'textarea'>Score (1 - "+maximum+")</th>";
  868. }
  869. else if(maximum!= amount_of_scales){
  870. while(counter <amount_of_scales){
  871. minimumScore = 1+(counter*division);
  872. maximumScore = (1+counter)*division;
  873. newScaleHeaders+= "<th class = 'editable' data-type = 'textarea'>Scale "+ (counter +1) + " ("+minimumScore+" - "+maximumScore+")</th>";
  874. counter++;
  875. }
  876. }else{
  877. while(counter <amount_of_scales){
  878. newScaleHeaders+= "<th>Scale "+ (counter +1) + " </th>";
  879. counter++;
  880. }
  881. }
  882. newScaleHeaders += '<th>Outcomes</th><th></th>';
  883. $("#criterion-header").html(newScaleHeaders);
  884. $('#allCriteria').html(' ');
  885. }
  886. // When a school changes, update its programs. If all is selected, disable
  887. $('#select-school').on('change', function()
  888. {
  889. toggleProgramSelect($(this));
  890. });
  891. $('#max_score').on('change', function(){
  892. var max = parseInt($('#max_score').find(':selected').val());
  893. var stringToScales = "<option value= '1'>Cuantitative Rubric </option>";
  894. selectedValue = 1;
  895. valueBefore = 0;
  896. for(i=2; i<=20; i++){
  897. if(max%i==0){
  898. stringToScales += "<option value= '"+i+"'>"+i+"-Scale Rubric</option>";
  899. selectedValue = i - valueBefore;
  900. valueBefore = i;
  901. }
  902. }
  903. $('#number_of_scales').html(stringToScales);
  904. $('#number_of_scales').selectpicker('refresh');
  905. $('#number_of_scales').val(selectedValue);
  906. $('#number_of_scales').selectpicker('refresh');
  907. var expected_points = Math.floor(max *0.7);
  908. var expected_points_html = '';
  909. for(i=1; i<max; i++){
  910. expected_points_html += '<option value="'+i+'"> '+i+'</option>';
  911. }
  912. $('#expected_points').html(expected_points_html);
  913. refreshSelects();
  914. $('#expected_points').val(expected_points);
  915. refreshSelects();
  916. changeTable();
  917. })
  918. $('#number_of_scales').on('change', function(){
  919. changeTable();
  920. })
  921. // When a learning outcome changes, update its criteria
  922. /*$('#select-outcome, input[name=criteria-filter]').on('change', function()
  923. {
  924. fetchCriteria($('#select-outcome'));
  925. });
  926. */
  927. // When the add button is clicked
  928. $('#button-add-criterion').on('click', function(e)
  929. {
  930. //Prevent page refresh
  931. e.preventDefault();
  932. //Add new criterion
  933. addCriterion();
  934. });
  935. // When the create or update buttons are clicked (.save)
  936. $('.save').on('click', function(e)
  937. {
  938. //Prevent page refresh
  939. e.preventDefault();
  940. // Empty field validation
  941. var emptyFields=false;
  942. $('#allCriteria').children('td').each(function()
  943. {
  944. if (($(this).text() == "" || $(this).text() == "Empty") && !($(this).hasClass('nullable')) )
  945. {
  946. emptyFields=true;
  947. }
  948. });
  949. // If any fields are empty, display error
  950. if(emptyFields || $.trim($('#rubric-name').val())=='')
  951. {
  952. $('#js-error-row').show();
  953. $('#js-error-row').find('#error-message').text('Error: Please fill all the fields. Make sure your rubric has a name and all scale scores are filled.');
  954. return;
  955. }
  956. else
  957. {
  958. $('#js-error-row').hide();
  959. }
  960. // Check whether a rubric with the written name already exists
  961. if($(this).attr('id')=='button-create-rubric' && nameExists())
  962. {
  963. $('#js-error-row').show();
  964. $('#js-error-row').find('#error-message').text('Error: A template with that name already exists.');
  965. return;
  966. }
  967. else
  968. {
  969. $('#js-error-row').hide();
  970. }
  971. var criterionObject = new Object();
  972. var criteriaArray = new Array();
  973. var criteria = [];
  974. scales = [];
  975. scalesMaxArray =[];
  976. scalesMinArray =[];
  977. scales_id =[];
  978. copyright = [];
  979. notes = [];
  980. var amount_of_scales =parseInt($('#number_of_scales').find(':selected').val())+2;
  981. var max = parseInt($('#max_score').find(':selected').val());
  982. // For each criterion in the rubric, get its value and put it into an array
  983. $('tbody tr').each(function( index )
  984. {
  985. criteria.push($(this).data('criterion-id'));
  986. each_criterion_scale = [];
  987. for(i=2; i<amount_of_scales; i++){
  988. each_criterion_scale.push($(this.children[i]).text());
  989. }
  990. copyright.push($(this.children[i]).text());
  991. i+=1;
  992. notes.push($(this.children[i]).text());
  993. scales.push(each_criterion_scale);
  994. // Clone the object and push it into the array
  995. });
  996. //console.log('school', $('#select-school').find(':selected').data('school-id') );
  997. //console.log('program', $('#select-program').find(':selected').data('program-id') );
  998. if($(this).attr('id')=='button-create-rubric')
  999. {
  1000. // Create
  1001. $.post
  1002. (
  1003. "{{ URL::to('saveTemplate') }}",
  1004. {
  1005. name: $('#rubric-name').val(),
  1006. school_id: $('#select-school').find(':selected').data('school-id'),
  1007. program_id: $('#select-program').find(':selected').data('program-id'),
  1008. expected_percentage: $('#expected_percentage').find(':selected').val(),
  1009. expected_points: $('#expected_points').find(':selected').val(),
  1010. is_visible: $('input[name=is_visible]:checked').val(),
  1011. criteria : criteria,
  1012. scales: scales,
  1013. max_score : max,
  1014. copyright : copyright,
  1015. notes :notes
  1016. },
  1017. function(data)
  1018. {
  1019. location.reload(true);
  1020. }
  1021. );
  1022. }
  1023. else
  1024. {
  1025. console.log('school', $('#select-school').find(':selected').data('school-id') );
  1026. console.log('program', $('#select-program').find(':selected').data('program-id') );
  1027. // Update database
  1028. $.post
  1029. (
  1030. "{{ URL::to('updateTemplate') }}",
  1031. {
  1032. id: $('#select-template').find(':selected').data('template-id'),
  1033. name: $('#rubric-name').val(),
  1034. school_id: $('#select-school').find(':selected').data('school-id'),
  1035. program_id: $('#select-program').find(':selected').data('program-id'),
  1036. expected_percentage: $('#expected_percentage').find(':selected').val(),
  1037. expected_points: $('#expected_points').find(':selected').val(),
  1038. is_visible: $('input[name=is_visible]:checked').val(),
  1039. criteria : criteria,
  1040. scales: scales,
  1041. max_score : max,
  1042. copyright :copyright,
  1043. notes:notes
  1044. },
  1045. function(data)
  1046. {
  1047. location.reload(true);
  1048. }
  1049. );
  1050. }
  1051. });
  1052. // When the confirm delete button is clicked
  1053. $('#button-delete-rubric').on('click', function(e)
  1054. {
  1055. $('#modal-confirm-delete').modal('hide');
  1056. // Delete from database
  1057. $.post
  1058. (
  1059. "{{ URL::to('deleteTemplate') }}",
  1060. {
  1061. id: $('#select-template').find(':selected').data('template-id')
  1062. },
  1063. function(data)
  1064. {
  1065. location.reload();
  1066. }
  1067. );
  1068. });
  1069. // Remove a criterion and hide the table if it was the only one
  1070. $('table').on('click', 'span.glyphicon-remove', function(e)
  1071. {
  1072. $(this).closest('tr').remove();
  1073. if(!$('tbody').children().length)
  1074. {
  1075. $('#rubric-container').hide();
  1076. }
  1077. buildCopyrightList();
  1078. });
  1079. // When print button is clicked, redirect to print page
  1080. $('#button-print-rubric').on('click', function(e)
  1081. {
  1082. e.preventDefault();
  1083. window.location = "printRubric/"+$('#select-template').find(':selected').data('template-id');
  1084. });
  1085. </script>
  1086. @stop
  1087. @section('included-js')
  1088. <!-- jQuery Sortable Tables -->
  1089. <script src="{{ asset('vendor/jQuerySortable/jquery-sortable-min.js') }}"></script>
  1090. <!-- X-Editable js -->
  1091. <script src="{{ asset('vendor/xeditable/bootstrap-editable.min.js') }}"></script>
  1092. @stop
  1093. @section('javascript')
  1094. // --------------------------------------------------------------------------
  1095. // Page load
  1096. // --------------------------------------------------------------------------
  1097. $('#updated-text').hide();
  1098. // Enable/disable program selection depending on school selection if user is
  1099. // admin
  1100. if({{Auth::user()->role}}==1)
  1101. toggleProgramSelect($('#select-school'));
  1102. // Fetch criteria of first outcome
  1103. fetchCriteria($('#select-outcome'));
  1104. changeTable();
  1105. // Hide table
  1106. $('#rubric-container').hide();
  1107. // Disable Update and Delete Buttons by default
  1108. $('#button-confirm-update-rubric').prop('disabled', true);
  1109. $('#button-confirm-delete-rubric').prop('disabled', true);
  1110. $('#button-print-rubric').prop('disabled', true);
  1111. // Sortable rows
  1112. $('.table').sortable({
  1113. handle: 'span.glyphicon.glyphicon-move',
  1114. containerSelector: 'table',
  1115. itemPath: '> tbody',
  1116. itemSelector: 'tr',
  1117. placeholder: '<tr class="placeholder"><th><span class="glyphicon glyphicon-arrow-right"></span></th></tr>'
  1118. });
  1119. @stop