Bez popisu

rubrics.blade.php 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. @extends('layouts.master')
  2. @section('navigation')
  3. @if($role==1)
  4. @include('local.managers.admins._navigation')
  5. @elseif($role==2)
  6. @include('local.managers.sCoords._navigation')
  7. @elseif($role==3)
  8. @include('local.managers.pCoords._navigation')
  9. @else
  10. @include('local.professors._navigation')
  11. @endif
  12. @stop
  13. @section('main')
  14. <!-- No rubric modal -->
  15. <div class="modal fade" id="modal-no-rubric">
  16. <div class="modal-dialog modal-sm">
  17. <div class="modal-content">
  18. <div class="modal-header">
  19. <h4 class="modal-title">No Rubric Available</h4>
  20. </div>
  21. <div class="modal-body">
  22. There are no existing rubrics for your School. Please contact your Program's Coordinator. You will be redirected to the previous page.
  23. </div>
  24. <div class="modal-footer">
  25. <button id="button-redirect" class="btn btn-primary">Ok</button>
  26. </div>
  27. </div><!-- /.modal-content -->
  28. </div><!-- /.modal-dialog -->
  29. </div><!-- /.modal -->
  30. <div class="row">
  31. <div class="col-md-12">
  32. <div>
  33. {{ HTML::linkAction('ActivitiesController@show', 'Back to Activity', array($activity->id), array('class'=>'btn btn-default btn-sm pull-right')) }}
  34. <br>
  35. <br>
  36. </div>
  37. <div class="well">
  38. @if(count($activity->rubric)!=0)
  39. <span id="assigned_rubric" class="hidden" data-assigned-rubric="{{{ $activity->rubric[0]->id }}}"></span>
  40. @endif
  41. <input id="activity_id" type="hidden" value="{{{ $activity->id}}}">
  42. <div class="form-group">
  43. <label>Select a Rubric:</label>
  44. <select id="select-template" class="form-control selectpicker">
  45. @foreach ($templates as $template)
  46. @if(count($activity->rubric)!=0 && $template->name == Rubric::find($activity->rubric[0]->id)->name)
  47. <option data-template-id="{{ $template->id }}" class="template" selected="selected">{{ $template->name }}</option>
  48. @else
  49. <option data-template-id="{{ $template->id }}" class="template">{{ $template->name }}</option>
  50. @endif
  51. @endforeach
  52. </select>
  53. </div>
  54. <input type='hidden' id='max' name= 'max' value="0">
  55. <input type ='hidden' id='num_of_scales' name ='num_of_scales' value ='0'>
  56. <div class="form-group">
  57. <label>Expected Criteria Outcome: </label>
  58. <!-- Select percentage. If there is a rubric, select the saved value -->
  59. <strong>
  60. <span id="expected_percentage">
  61. </span>%
  62. </strong> of all students must score at least
  63. <!-- Select points. If there is a rubric, select the saved value -->
  64. <strong>
  65. <span id="expected_points">
  66. </span>
  67. </strong>
  68. points in a criterion for it to pass.
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. <div id="rubric-container" class="row">
  74. <div class="col-md-12">
  75. <table class="table">
  76. <thead><tr><th colspan="6 "><h3 id="rubric-name"></h3></th></tr></thead>
  77. <thead><tr id ="criterion-header"><th>Criterion</th><th>Beginning (1-2)</th><th>In Progress (3-4)</th><th>Good (5-6)</th><th>Excellent (7-8)</th></tr></thead>
  78. <tbody>
  79. </tbody>
  80. </table>
  81. <div id="copyright-info">
  82. <hr>
  83. <p class="small"><strong>Outcome Information</strong></p>
  84. <ul id="copyright-list" class="list-unstyled small">
  85. </ul>
  86. <hr>
  87. </div>
  88. @if($activity->outcomes_attempted!=NULL)
  89. <div class="alert alert-info" role="alert">This activity has already been assessed. Changing the rubric will delete all saved scores.</div>
  90. @endif
  91. <div class="text-center">
  92. <button id="button-save-rubric" class="btn btn-lg btn-primary save"><span class="glyphicon glyphicon-floppy-disk"></span> Save</button>
  93. </div>
  94. </div>
  95. </div>
  96. <script>
  97. function changeTable(){
  98. amount_of_scales = parseInt($('#num_of_scales').val());
  99. counter2 = 0;
  100. maximum = parseInt($('#max').val());
  101. newScaleHeaders = '<th>Criterion</th>';
  102. counter = 0;
  103. division = maximum/amount_of_scales;
  104. if(amount_of_scales==1){
  105. newScaleHeaders+= "<th>Score (1 - "+maximum+")</th>";
  106. }
  107. else if(maximum!= amount_of_scales){
  108. while(counter <amount_of_scales){
  109. minimumScore = 1+(counter*division);
  110. maximumScore = (1+counter)*division;
  111. newScaleHeaders+= "<th>Scale "+ (counter +1) + " ("+minimumScore+" - "+maximumScore+")</th>";
  112. counter++;
  113. }
  114. }else{
  115. while(counter <amount_of_scales){
  116. newScaleHeaders+= "<th>Scale "+ (counter +1) + " </th>";
  117. counter++;
  118. }
  119. }
  120. newScaleHeaders += '<th>Copyright</th><th>Notes</th>';
  121. $("#criterion-header").html(newScaleHeaders);
  122. }
  123. </script>
  124. @stop
  125. @section('javascript')
  126. // --------------------------------------------------------------------------
  127. // Page load
  128. // --------------------------------------------------------------------------
  129. console.log({{ $activity }});
  130. //If there are no rubrics to show, alert user and redirect.
  131. if($('#select-template').children().length)
  132. loadTemplate();
  133. else
  134. {
  135. $('#modal-no-rubric').modal({
  136. backdrop: 'static'
  137. });
  138. }
  139. // --------------------------------------------------------------------------
  140. // Functions
  141. // --------------------------------------------------------------------------
  142. // Fetch criteria associated to a specific learning outcome
  143. function fetchCriteria(outcome)
  144. {
  145. $.post
  146. (
  147. "{{ URL::route('fetchCriteria') }}",
  148. { id: outcome.find(':selected').data('outcome-id')},
  149. function(data)
  150. {
  151. $('#select-criterion').empty();
  152. data.forEach( function (arrayItem)
  153. {
  154. // If criterion does not belong to a user, display it
  155. if(arrayItem.user_id==null)
  156. {
  157. $('#select-criterion')
  158. .append('<option data-criterion-id="'+arrayItem.id+'" >'+arrayItem.name+'</option>');
  159. }
  160. // If it does, but the user is the one logged on, display.
  161. // Otherwise, ignore
  162. else if(arrayItem.user_id!="" && {{{Auth::id()}}}==arrayItem.user_id )
  163. {
  164. $('#select-criterion')
  165. .append('<option data-criterion-id="'+arrayItem.id+'" >'+arrayItem.name+'</option>');
  166. }
  167. });
  168. // Add custom option
  169. $('#select-criterion')
  170. .append('<option data-criterion-id="0">Custom</option>');
  171. $('#select-criterion').prop('disabled', false);
  172. $('#button-add-criterion').prop('disabled', false);
  173. }
  174. );
  175. }
  176. // Build list from copyright info in rubric
  177. function buildOutcomeList()
  178. {
  179. // Empty the copyright list
  180. $('#copyright-list').empty();
  181. $('tbody tr').each(function( index )
  182. {
  183. var criterion = $(this);
  184. // If there's copyright info
  185. if(criterion.data('outcomes')!=null){
  186. var outcomes = criterion.data('outcomes');
  187. if($('#copyright-list li').length>0)
  188. {
  189. var found = false;
  190. $('#copyright-list li').each(function()
  191. {
  192. // If found, give the string its number
  193. if(outcomes==$(this).find('span').text())
  194. {
  195. copyrightNumber = Number.parseInt($(this).find('sup').text());
  196. console.log('a: '+copyrightNumber);
  197. criterion.children('td:nth-child(1)').find('sup').text(copyrightNumber);
  198. found =true;
  199. //to break
  200. return false;
  201. }
  202. });
  203. // Otherwise, give it the next number and append a new item to the
  204. // list
  205. if(!found)
  206. {
  207. var copyrightNumber = $('#copyright-list li').length+1;
  208. console.log('b: '+copyrightNumber);
  209. console.log(criterion.children('td:nth-child(1)').find('sup').length);
  210. criterion.children('td:nth-child(1)').find('sup').text(copyrightNumber);
  211. $('#copyright-list').append('<li><sup>'+copyrightNumber+' </sup><span>'+outcomes+'<span></li>');
  212. }
  213. }
  214. else
  215. {
  216. criterion.children('td:nth-child(1)').find('sup').text('1');
  217. $('#copyright-list').append('<li><sup>1 </sup><span>'+outcomes+'<span></li>');
  218. }
  219. }
  220. });
  221. if($('#copyright-info li').length>0)
  222. {
  223. $('#copyright-info').show();
  224. }
  225. else
  226. {
  227. $('#copyright-info').hide();
  228. }}
  229. // Load a template
  230. function loadTemplate()
  231. {
  232. $.post
  233. (
  234. "{{ URL::to('loadTemplate') }}",
  235. { id: $('#select-template').find(':selected').data('template-id')},
  236. function(data)
  237. {
  238. // Show the container and empty all rows
  239. $('#rubric-container').show();
  240. $('tbody').empty();
  241. //Set the name of the rubric
  242. $('#rubric-name').val(data.template.name);
  243. $('#expected_percentage').text(data.template.expected_percentage);
  244. $('#expected_points').text(data.template.expected_points)
  245. $('#max').val(data.template.max_score);
  246. $('#num_of_scales').val(data.template.num_scales);
  247. changeTable();
  248. // Set the contents of the rubric
  249. var temp_criterion = data.criterion;
  250. for(temp_c in temp_criterion){
  251. 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+'">';
  252. current_criterion = temp_criterion[temp_c]
  253. var subcriteria ='';
  254. if(current_criterion.subcriteria){
  255. var subcriteria_array = JSON.parse(current_criterion.subcriteria);
  256. subcriteria = '<ul class="subcriteria list-unstyled">';
  257. subcriteria_array.forEach(function (value) {
  258. subcriteria += '<li>'+value+'</li>';
  259. });
  260. subcriteria += '</ul>';
  261. }
  262. if(current_criterion.notes)
  263. {
  264. str+='<td><span><em data-toggle="tooltip" data-placement="top" title="'+current_criterion.notes+'">'+current_criterion.name+'</em></span><sup></sup>'+subcriteria+'</td>';
  265. }
  266. else
  267. {
  268. str+='<td><span>'+current_criterion.name+'</span><sup></sup>'+subcriteria+'</td>';
  269. }
  270. for(scaleIndex in data.scales[current_criterion.id]){
  271. scale = data.scales[current_criterion.id][scaleIndex];
  272. str+='<td data-scale-id ="'+scale.id+'">'+scale.description+'</td>';
  273. }
  274. copyright = temp_criterion[temp_c].copyright;
  275. notes = temp_criterion[temp_c].notes;
  276. if(copyright == null){
  277. copyright = '';
  278. }
  279. if(notes==null) notes ='';
  280. str+= '<td >'+copyright+'</td>';
  281. str+= '<td>'+notes+'</td>';
  282. str+='</tr>';
  283. $('table tbody').append(str);
  284. buildOutcomeList();
  285. // Turn on tooltips again (because content is dynamic)
  286. $('[data-toggle="tooltip"]').tooltip();
  287. }
  288. /*
  289. var contents = JSON.parse(data.contents);
  290. contents.forEach(function (data)
  291. {
  292. // Append the fetched data
  293. 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>';
  294. var subcriteria = '';
  295. if(data.subcriteria){
  296. var subcriteria_array = data.subcriteria;
  297. subcriteria = '<ul class="subcriteria list-unstyled">';
  298. subcriteria_array.forEach(function (value) {
  299. subcriteria += '<li>'+value+'</li>';
  300. });
  301. subcriteria += '</ul>';
  302. }
  303. if(data.notes)
  304. {
  305. str+='<span><em data-toggle="tooltip" data-placement="top" title="'+data.notes+'">'+data.name+'</em></span><sup></sup>'+subcriteria;
  306. }
  307. else
  308. {
  309. str+='<span>'+data.name+'</span><sup></sup>'+subcriteria;
  310. }
  311. str+='</td><td class="editable" data-type="textarea">'+data.description12+'</td>'
  312. +'<td class="editable" data-type="textarea">'+data.description34+'</td>'
  313. +'<td class="editable" data-type="textarea">'+data.description56+'</td>'
  314. +'<td class="editable" data-type="textarea">'+data.description78+'</td>'
  315. +'<th><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></th></tr>';
  316. $('table tbody').append(str);
  317. // Build copyright list
  318. buildOutcomeList();
  319. // Enable X-Edtable on this new row
  320. $('.editable').editable({
  321. unsavedclass: null,
  322. rows: 4
  323. });
  324. // Turn on tooltips again (because content is dynamic)
  325. $('[data-toggle="tooltip"]').tooltip();
  326. }); */
  327. // Build Copyright List
  328. buildOutcomeList();
  329. },
  330. 'json',
  331. );
  332. }
  333. /*
  334. console.log($('#expected_percentage').text());
  335. console.log($('#expected_points').text());
  336. // Set expected values
  337. $('#expected_percentage').text(data.expected_percentage);
  338. $('#expected_points').text(data.expected_points);
  339. // Set the contents of the rubric
  340. var contents = JSON.parse(data.contents);
  341. contents.forEach(function (criterion)
  342. {
  343. var str ='<tr data-assoc-outcome-id="'+criterion.outcome_id+'"'
  344. +'data-criterion-id="'+criterion.id+'" data-criterion-copyright="'+criterion.copyright+'" data-criterion-notes="'+criterion.notes+'">';
  345. var subcriteria = '';
  346. if(criterion.subcriteria){
  347. var subcriteria_array = criterion.subcriteria;
  348. subcriteria = '<ul class="subcriteria list-unstyled">';
  349. subcriteria_array.forEach(function (value) {
  350. subcriteria += '<li>'+value+'</li>';
  351. });
  352. subcriteria += '</ul>';
  353. }
  354. // If the criterion has notes, set the tooltip with them
  355. if(criterion.notes)
  356. {
  357. str+='<td><span><em data-toggle="tooltip" data-placement="top" title="'+criterion.notes+'">'+criterion.name+'</em></span><sup></sup>'+subcriteria+'</td>';
  358. }
  359. else
  360. {
  361. str+='<td><span>'+criterion.name+'</span><sup></sup>'+subcriteria+'</td>';
  362. }
  363. // Add the descriptions
  364. str+='<td>'+criterion.description12.replace(/\n/gi, '<br>')+'</td>'
  365. +'<td>'+criterion.description34.replace(/\n/gi, '<br>')+'</td>'
  366. +'<td>'+criterion.description56.replace(/\n/gi, '<br>')+'</td>'
  367. +'<td>'+criterion.description78.replace(/\n/gi, '<br>')+'</td></tr>';
  368. // Append the string to the table
  369. $('table tbody').append(str);
  370. // Turn on tooltips again (because content is dynamic)
  371. $('[data-toggle="tooltip"]').tooltip();
  372. });
  373. // Build Copyright List
  374. buildOutcomeList();
  375. }
  376. );
  377. }
  378. */
  379. // --------------------------------------------------------------------------
  380. // Events
  381. // --------------------------------------------------------------------------
  382. // When trying to change the template, ask the user to confirm and reset the
  383. // rubric if s/he does
  384. $('#select-template').on('change', function()
  385. {
  386. loadTemplate();
  387. });
  388. // When a learning outcome changes, update its criteria
  389. $('#select-outcome').on('change', function()
  390. {
  391. fetchCriteria($(this));
  392. });
  393. // When save button is clicked
  394. $('#button-save-rubric').on('click', function(e)
  395. {
  396. //Prevent page refresh
  397. e.preventDefault();
  398. var criteria = [];
  399. scales = [];
  400. max_score = $('#max').val();
  401. // For each criterion in the rubric, get its value and put it into an array
  402. $('tbody tr').each(function( index )
  403. {
  404. criteria.push($(this).data('criterion-id'));
  405. each_criterion_scale =[];
  406. $(this).children('td').each(function(index){
  407. if(index!=0 )
  408. each_criterion_scale.push($(this).text());
  409. })
  410. each_criterion_scale.pop();
  411. each_criterion_scale.pop();
  412. scales.push(each_criterion_scale);
  413. /*
  414. criterionObject.id = $(this).data('criterion-id');
  415. criterionObject.outcome_id = $(this).data('assoc-outcome-id');
  416. criterionObject.name = $(this).children('td:nth-child(1)').find('span').text();
  417. var subcriteriaArray = new Array();
  418. $(this).children('td:nth-child(1)').find('.subcriteria li').each(function(index){
  419. subcriteriaArray.push($(this).text());
  420. });
  421. criterionObject.subcriteria = subcriteriaArray;
  422. criterionObject.description12 = $(this).children('td:nth-child(2)').html().replace(/<br>/gi, '\n');
  423. criterionObject.description34 = $(this).children('td:nth-child(3)').html().replace(/<br>/gi, '\n');
  424. criterionObject.description56 = $(this).children('td:nth-child(4)').html().replace(/<br>/gi, '\n');
  425. criterionObject.description78 = $(this).children('td:nth-child(5)').html().replace(/<br>/gi, '\n');
  426. criterionObject.copyright = $(this).data('criterion-copyright');
  427. criterionObject.notes = $(this).data('criterion-notes');
  428. // Clone the object and push it into the array
  429. var clone = jQuery.extend({}, criterionObject);
  430. criteriaArray.push(clone);
  431. */
  432. });
  433. // If activity does not have a rubric, create it
  434. if($('#assigned_rubric').length === 0)
  435. {
  436. $('#js-error-row').hide();
  437. // Create
  438. $.post
  439. (
  440. "{{ URL::to('professor/saveRubric') }}",
  441. {
  442. name: $('#select-template').find(':selected').text(),
  443. activity_id: parseInt($('#activity_id').val()),
  444. expected_percentage: $('#expected_percentage').text(),
  445. expected_points: $('#expected_points').text(),
  446. criteria: criteria,
  447. scales: scales,
  448. max_score:max_score
  449. },
  450. function(data)
  451. {
  452. location.replace(data);
  453. }
  454. );
  455. }
  456. // Else, update it
  457. else
  458. {
  459. // Update database
  460. $.post
  461. (
  462. "{{ URL::to('professor/updateRubric') }}",
  463. {
  464. id: $('#assigned_rubric').data('assigned-rubric'),
  465. name: $('#select-template').find(':selected').text(),
  466. activity_id: parseInt($('#activity_id').val()),
  467. expected_percentage: $('#expected_percentage').text(),
  468. expected_points: $('#expected_points').text(),
  469. criteria: criteria,
  470. scales: scales,
  471. max_score:max_score
  472. },
  473. function(data)
  474. {
  475. location.replace(data);
  476. }
  477. );
  478. }
  479. });
  480. // When Ok button is clicked, redirect to previous page
  481. // When save button is clicked
  482. $('#button-redirect').on('click', function(e)
  483. {
  484. e.preventDefault();
  485. history.go(-1);
  486. });
  487. @stop