Nav apraksta

rubrics.blade.php 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  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($activity->rubric_id!=NULL)
  39. <span id="assigned_rubric" class="hidden" data-assigned-rubric="{{{ $activity->rubric_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($activity->rubric_id!=NULL && $template->name == Rubric::find($activity->rubric_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>Copyright 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 += '';
  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 buildCopyrightList()
  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('criterion-copyright')!=null)
  186. {
  187. var copyright = criterion.data('criterion-copyright');
  188. // If there is anything in the copyright list
  189. if($('#copyright-list li').length>0)
  190. {
  191. // Check copyright list for the same copyright text
  192. var found = false;
  193. $('#copyright-list li').each(function()
  194. {
  195. // If found, give the string its number
  196. if(copyright==$(this).find('span').text())
  197. {
  198. copyrightNumber = Number.parseInt($(this).find('sup').text());
  199. criterion.children('td:nth-child(1)').find('sup').text(copyrightNumber);
  200. found =true;
  201. //to break
  202. return false;
  203. }
  204. });
  205. // Otherwise, give it the next number and append a new item to the
  206. // list
  207. if(!found)
  208. {
  209. var copyrightNumber = $('#copyright-list li').length+1;
  210. criterion.children('td:nth-child(1)').find('sup').text(copyrightNumber);
  211. $('#copyright-list').append('<li><sup>'+copyrightNumber+' </sup><span>'+copyright+'<span></li>');
  212. }
  213. }
  214. // Otherwise, give it number 1 and append it
  215. else
  216. {
  217. criterion.children('td:nth-child(1)').find('sup').text('1');
  218. $('#copyright-list').append('<li><sup>1 </sup><span>'+copyright+'<span></li>');
  219. }
  220. }
  221. });
  222. if($('#copyright-info li').length>0)
  223. {
  224. $('#copyright-info').show();
  225. }
  226. else
  227. {
  228. $('#copyright-info').hide();
  229. }
  230. }
  231. // Load a template
  232. function loadTemplate()
  233. {
  234. $.post
  235. (
  236. "{{ URL::to('loadTemplate') }}",
  237. { id: $('#select-template').find(':selected').data('template-id')},
  238. function(data)
  239. {
  240. // Show the container and empty all rows
  241. $('#rubric-container').show();
  242. $('tbody').empty();
  243. //Set the name of the rubric
  244. $('#rubric-name').val(data.template.name);
  245. $('#expected_percentage').text(data.template.expected_percentage);
  246. $('#expected_points').text(data.template.expected_points)
  247. $('#max').val(data.template.max_score);
  248. $('#num_of_scales').val(data.template.num_scales);
  249. changeTable();
  250. // Set the contents of the rubric
  251. var temp_criterion = data.criterion;
  252. for(temp_c in temp_criterion){
  253. 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+'">';
  254. current_criterion = temp_criterion[temp_c]
  255. var subcriteria ='';
  256. if(current_criterion.subcriteria){
  257. var subcriteria_array = current_criterion.subcriteria;
  258. subcriteria = '<ul class="subcriteria list-unstyled">';
  259. subcriteria_array.forEach(function (value) {
  260. subcriteria += '<li>'+value+'</li>';
  261. });
  262. subcriteria += '</ul>';
  263. }
  264. if(current_criterion.notes)
  265. {
  266. str+='<td><span><em data-toggle="tooltip" data-placement="top" title="'+current_criterion.notes+'">'+current_criterion.name+'</em></span><sup></sup>'+subcriteria+'</td>';
  267. }
  268. else
  269. {
  270. str+='<td><span>'+current_criterion.name+'</span><sup></sup>'+subcriteria+'</td>';
  271. }
  272. for(scaleIndex in data.scales[current_criterion.id]){
  273. scale = data.scales[current_criterion.id][scaleIndex];
  274. str+='<td data-scale-id ="'+scale.id+'">'+scale.description+'</td>';
  275. }
  276. str+='</tr>';
  277. $('table tbody').append(str);
  278. buildCopyrightList();
  279. // Turn on tooltips again (because content is dynamic)
  280. $('[data-toggle="tooltip"]').tooltip();
  281. }
  282. /*
  283. var contents = JSON.parse(data.contents);
  284. contents.forEach(function (data)
  285. {
  286. // Append the fetched data
  287. 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>';
  288. var subcriteria = '';
  289. if(data.subcriteria){
  290. var subcriteria_array = data.subcriteria;
  291. subcriteria = '<ul class="subcriteria list-unstyled">';
  292. subcriteria_array.forEach(function (value) {
  293. subcriteria += '<li>'+value+'</li>';
  294. });
  295. subcriteria += '</ul>';
  296. }
  297. if(data.notes)
  298. {
  299. str+='<span><em data-toggle="tooltip" data-placement="top" title="'+data.notes+'">'+data.name+'</em></span><sup></sup>'+subcriteria;
  300. }
  301. else
  302. {
  303. str+='<span>'+data.name+'</span><sup></sup>'+subcriteria;
  304. }
  305. str+='</td><td class="editable" data-type="textarea">'+data.description12+'</td>'
  306. +'<td class="editable" data-type="textarea">'+data.description34+'</td>'
  307. +'<td class="editable" data-type="textarea">'+data.description56+'</td>'
  308. +'<td class="editable" data-type="textarea">'+data.description78+'</td>'
  309. +'<th><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></th></tr>';
  310. $('table tbody').append(str);
  311. // Build copyright list
  312. buildCopyrightList();
  313. // Enable X-Edtable on this new row
  314. $('.editable').editable({
  315. unsavedclass: null,
  316. rows: 4
  317. });
  318. // Turn on tooltips again (because content is dynamic)
  319. $('[data-toggle="tooltip"]').tooltip();
  320. }); */
  321. // Build Copyright List
  322. buildCopyrightList();
  323. },
  324. 'json',
  325. );
  326. }
  327. /*
  328. console.log($('#expected_percentage').text());
  329. console.log($('#expected_points').text());
  330. // Set expected values
  331. $('#expected_percentage').text(data.expected_percentage);
  332. $('#expected_points').text(data.expected_points);
  333. // Set the contents of the rubric
  334. var contents = JSON.parse(data.contents);
  335. contents.forEach(function (criterion)
  336. {
  337. var str ='<tr data-assoc-outcome-id="'+criterion.outcome_id+'"'
  338. +'data-criterion-id="'+criterion.id+'" data-criterion-copyright="'+criterion.copyright+'" data-criterion-notes="'+criterion.notes+'">';
  339. var subcriteria = '';
  340. if(criterion.subcriteria){
  341. var subcriteria_array = criterion.subcriteria;
  342. subcriteria = '<ul class="subcriteria list-unstyled">';
  343. subcriteria_array.forEach(function (value) {
  344. subcriteria += '<li>'+value+'</li>';
  345. });
  346. subcriteria += '</ul>';
  347. }
  348. // If the criterion has notes, set the tooltip with them
  349. if(criterion.notes)
  350. {
  351. str+='<td><span><em data-toggle="tooltip" data-placement="top" title="'+criterion.notes+'">'+criterion.name+'</em></span><sup></sup>'+subcriteria+'</td>';
  352. }
  353. else
  354. {
  355. str+='<td><span>'+criterion.name+'</span><sup></sup>'+subcriteria+'</td>';
  356. }
  357. // Add the descriptions
  358. str+='<td>'+criterion.description12.replace(/\n/gi, '<br>')+'</td>'
  359. +'<td>'+criterion.description34.replace(/\n/gi, '<br>')+'</td>'
  360. +'<td>'+criterion.description56.replace(/\n/gi, '<br>')+'</td>'
  361. +'<td>'+criterion.description78.replace(/\n/gi, '<br>')+'</td></tr>';
  362. // Append the string to the table
  363. $('table tbody').append(str);
  364. // Turn on tooltips again (because content is dynamic)
  365. $('[data-toggle="tooltip"]').tooltip();
  366. });
  367. // Build Copyright List
  368. buildCopyrightList();
  369. }
  370. );
  371. }
  372. */
  373. // --------------------------------------------------------------------------
  374. // Events
  375. // --------------------------------------------------------------------------
  376. // When trying to change the template, ask the user to confirm and reset the
  377. // rubric if s/he does
  378. $('#select-template').on('change', function()
  379. {
  380. loadTemplate();
  381. });
  382. // When a learning outcome changes, update its criteria
  383. $('#select-outcome').on('change', function()
  384. {
  385. fetchCriteria($(this));
  386. });
  387. // When save button is clicked
  388. $('#button-save-rubric').on('click', function(e)
  389. {
  390. //Prevent page refresh
  391. e.preventDefault();
  392. var criteria = [];
  393. scales = [];
  394. max_score = $('#max').val();
  395. // For each criterion in the rubric, get its value and put it into an array
  396. $('tbody tr').each(function( index )
  397. {
  398. criteria.push($(this).data('criterion-id'));
  399. each_criterion_scale =[];
  400. $(this).children('td').each(function(index){
  401. if(index!=0)
  402. each_criterion_scale.push($(this).text());
  403. })
  404. scales.push(each_criterion_scale);
  405. /*
  406. criterionObject.id = $(this).data('criterion-id');
  407. criterionObject.outcome_id = $(this).data('assoc-outcome-id');
  408. criterionObject.name = $(this).children('td:nth-child(1)').find('span').text();
  409. var subcriteriaArray = new Array();
  410. $(this).children('td:nth-child(1)').find('.subcriteria li').each(function(index){
  411. subcriteriaArray.push($(this).text());
  412. });
  413. criterionObject.subcriteria = subcriteriaArray;
  414. criterionObject.description12 = $(this).children('td:nth-child(2)').html().replace(/<br>/gi, '\n');
  415. criterionObject.description34 = $(this).children('td:nth-child(3)').html().replace(/<br>/gi, '\n');
  416. criterionObject.description56 = $(this).children('td:nth-child(4)').html().replace(/<br>/gi, '\n');
  417. criterionObject.description78 = $(this).children('td:nth-child(5)').html().replace(/<br>/gi, '\n');
  418. criterionObject.copyright = $(this).data('criterion-copyright');
  419. criterionObject.notes = $(this).data('criterion-notes');
  420. // Clone the object and push it into the array
  421. var clone = jQuery.extend({}, criterionObject);
  422. criteriaArray.push(clone);
  423. */
  424. });
  425. // If activity does not have a rubric, create it
  426. if($('#assigned_rubric').length === 0)
  427. {
  428. $('#js-error-row').hide();
  429. // Create
  430. $.post
  431. (
  432. "{{ URL::to('professor/saveRubric') }}",
  433. {
  434. name: $('#select-template').find(':selected').text(),
  435. activity_id: parseInt($('#activity_id').val()),
  436. contents: " ",
  437. expected_percentage: $('#expected_percentage').text(),
  438. expected_points: $('#expected_points').text(),
  439. criteria: criteria,
  440. scales: scales,
  441. max_score:max_score
  442. },
  443. function(data)
  444. {
  445. location.replace(data);
  446. }
  447. );
  448. }
  449. // Else, update it
  450. else
  451. {
  452. // Update database
  453. $.post
  454. (
  455. "{{ URL::to('professor/updateRubric') }}",
  456. {
  457. id: $('#assigned_rubric').data('assigned-rubric'),
  458. name: $('#select-template').find(':selected').text(),
  459. contents: JSON.stringify(criteriaArray),
  460. expected_percentage: $('#expected_percentage').text(),
  461. expected_points: $('#expected_points').text()
  462. },
  463. function(data)
  464. {
  465. location.replace(data);
  466. }
  467. );
  468. }
  469. });
  470. // When Ok button is clicked, redirect to previous page
  471. // When save button is clicked
  472. $('#button-redirect').on('click', function(e)
  473. {
  474. e.preventDefault();
  475. history.go(-1);
  476. });
  477. @stop