Nav apraksta

rubrics.blade.php 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  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" style="table-layout: fixed">
  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(data){
  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 class ='titles' data-title-id ="+data.titles[counter].title_id+">"+data.titles[counter].text+" (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 class ='titles' data-title-id = "+data.titles[counter].title_id+">"+data.titles[counter].text+" ("+minimumScore+" - "+maximumScore+")</th>";
  112. counter++;
  113. }
  114. }else{
  115. while(counter <amount_of_scales){
  116. newScaleHeaders+= "<th class ='titles' data-title-id ="+data.titles[counter].title_id+"> "+data.titles[counter].text+ " </th>";
  117. counter++;
  118. }
  119. }
  120. newScaleHeaders += '<th>Outcomes</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 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. var copyright = criterion.data('criterion-copyright');
  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(copyright==$(this).find('span').text())
  194. {
  195. copyrightNumber = Number.parseInt($(this).find('sup').text());
  196. console.log('a: '+copyrightNumber);
  197. criterion.children('td:nth-child(2)').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(2)').find('sup').length);
  210. criterion.children('td:nth-child(2)').find('sup').text(copyrightNumber);
  211. $('#copyright-list').append('<li><sup>'+copyrightNumber+' </sup><span>'+copyright+'<span></li>');
  212. }
  213. }
  214. else
  215. {
  216. criterion.children('td:nth-child(2)').find('sup').text('1');
  217. $('#copyright-list').append('<li><sup>1 </sup><span>'+copyright+'<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(data);
  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 current_criterion.scales){
  271. scale = current_criterion.scales[scaleIndex];
  272. str+='<td>'+scale.description+'</td>';
  273. }
  274. str+= '<td>'+current_criterion.outcomes+'</td>';
  275. str+='</tr>';
  276. $('table tbody').append(str);
  277. buildCopyrightList();
  278. // Turn on tooltips again (because content is dynamic)
  279. $('[data-toggle="tooltip"]').tooltip();
  280. }
  281. /*
  282. var contents = JSON.parse(data.contents);
  283. contents.forEach(function (data)
  284. {
  285. // Append the fetched data
  286. 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>';
  287. var subcriteria = '';
  288. if(data.subcriteria){
  289. var subcriteria_array = data.subcriteria;
  290. subcriteria = '<ul class="subcriteria list-unstyled">';
  291. subcriteria_array.forEach(function (value) {
  292. subcriteria += '<li>'+value+'</li>';
  293. });
  294. subcriteria += '</ul>';
  295. }
  296. if(data.notes)
  297. {
  298. str+='<span><em data-toggle="tooltip" data-placement="top" title="'+data.notes+'">'+data.name+'</em></span><sup></sup>'+subcriteria;
  299. }
  300. else
  301. {
  302. str+='<span>'+data.name+'</span><sup></sup>'+subcriteria;
  303. }
  304. str+='</td><td class="editable" data-type="textarea">'+data.description12+'</td>'
  305. +'<td class="editable" data-type="textarea">'+data.description34+'</td>'
  306. +'<td class="editable" data-type="textarea">'+data.description56+'</td>'
  307. +'<td class="editable" data-type="textarea">'+data.description78+'</td>'
  308. +'<th><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></th></tr>';
  309. $('table tbody').append(str);
  310. // Build copyright list
  311. buildCopyrightList();
  312. // Enable X-Edtable on this new row
  313. $('.editable').editable({
  314. unsavedclass: null,
  315. rows: 4
  316. });
  317. // Turn on tooltips again (because content is dynamic)
  318. $('[data-toggle="tooltip"]').tooltip();
  319. }); */
  320. // Build Copyright List
  321. buildCopyrightList();
  322. },
  323. 'json',
  324. );
  325. }
  326. /*
  327. console.log($('#expected_percentage').text());
  328. console.log($('#expected_points').text());
  329. // Set expected values
  330. $('#expected_percentage').text(data.expected_percentage);
  331. $('#expected_points').text(data.expected_points);
  332. // Set the contents of the rubric
  333. var contents = JSON.parse(data.contents);
  334. contents.forEach(function (criterion)
  335. {
  336. var str ='<tr data-assoc-outcome-id="'+criterion.outcome_id+'"'
  337. +'data-criterion-id="'+criterion.id+'" data-criterion-copyright="'+criterion.copyright+'" data-criterion-notes="'+criterion.notes+'">';
  338. var subcriteria = '';
  339. if(criterion.subcriteria){
  340. var subcriteria_array = criterion.subcriteria;
  341. subcriteria = '<ul class="subcriteria list-unstyled">';
  342. subcriteria_array.forEach(function (value) {
  343. subcriteria += '<li>'+value+'</li>';
  344. });
  345. subcriteria += '</ul>';
  346. }
  347. // If the criterion has notes, set the tooltip with them
  348. if(criterion.notes)
  349. {
  350. str+='<td><span><em data-toggle="tooltip" data-placement="top" title="'+criterion.notes+'">'+criterion.name+'</em></span><sup></sup>'+subcriteria+'</td>';
  351. }
  352. else
  353. {
  354. str+='<td><span>'+criterion.name+'</span><sup></sup>'+subcriteria+'</td>';
  355. }
  356. // Add the descriptions
  357. str+='<td>'+criterion.description12.replace(/\n/gi, '<br>')+'</td>'
  358. +'<td>'+criterion.description34.replace(/\n/gi, '<br>')+'</td>'
  359. +'<td>'+criterion.description56.replace(/\n/gi, '<br>')+'</td>'
  360. +'<td>'+criterion.description78.replace(/\n/gi, '<br>')+'</td></tr>';
  361. // Append the string to the table
  362. $('table tbody').append(str);
  363. // Turn on tooltips again (because content is dynamic)
  364. $('[data-toggle="tooltip"]').tooltip();
  365. });
  366. // Build Copyright List
  367. buildCopyrightList();
  368. }
  369. );
  370. }
  371. */
  372. // --------------------------------------------------------------------------
  373. // Events
  374. // --------------------------------------------------------------------------
  375. // When trying to change the template, ask the user to confirm and reset the
  376. // rubric if s/he does
  377. $('#select-template').on('change', function()
  378. {
  379. loadTemplate();
  380. });
  381. // When a learning outcome changes, update its criteria
  382. $('#select-outcome').on('change', function()
  383. {
  384. fetchCriteria($(this));
  385. });
  386. // When save button is clicked
  387. $('#button-save-rubric').on('click', function(e)
  388. {
  389. //Prevent page refresh
  390. e.preventDefault();
  391. var criteria = [];
  392. var titles = [];
  393. max_score = $('#max').val();
  394. // For each criterion in the rubric, get its value and put it into an array
  395. $('tbody tr').each(function( index )
  396. {
  397. criteria.push($(this).data('criterion-id'));
  398. /*
  399. criterionObject.id = $(this).data('criterion-id');
  400. criterionObject.outcome_id = $(this).data('assoc-outcome-id');
  401. criterionObject.name = $(this).children('td:nth-child(1)').find('span').text();
  402. var subcriteriaArray = new Array();
  403. $(this).children('td:nth-child(1)').find('.subcriteria li').each(function(index){
  404. subcriteriaArray.push($(this).text());
  405. });
  406. criterionObject.subcriteria = subcriteriaArray;
  407. criterionObject.description12 = $(this).children('td:nth-child(2)').html().replace(/<br>/gi, '\n');
  408. criterionObject.description34 = $(this).children('td:nth-child(3)').html().replace(/<br>/gi, '\n');
  409. criterionObject.description56 = $(this).children('td:nth-child(4)').html().replace(/<br>/gi, '\n');
  410. criterionObject.description78 = $(this).children('td:nth-child(5)').html().replace(/<br>/gi, '\n');
  411. criterionObject.copyright = $(this).data('criterion-copyright');
  412. criterionObject.notes = $(this).data('criterion-notes');
  413. // Clone the object and push it into the array
  414. var clone = jQuery.extend({}, criterionObject);
  415. criteriaArray.push(clone);
  416. */
  417. });
  418. $('.titles').each(function(index){
  419. titles.push($(this).data('title-id'));
  420. });
  421. // If activity does not have a rubric, create it
  422. if($('#assigned_rubric').length === 0)
  423. {
  424. $('#js-error-row').hide();
  425. // Create
  426. $.post
  427. (
  428. "{{ URL::to('professor/saveRubric') }}",
  429. {
  430. name: $('#select-template').find(':selected').text(),
  431. activity_id: parseInt($('#activity_id').val()),
  432. expected_percentage: $('#expected_percentage').text(),
  433. expected_points: $('#expected_points').text(),
  434. criteria: criteria,
  435. titles:titles,
  436. max_score:max_score
  437. },
  438. function(data)
  439. {
  440. location.replace(data);
  441. }
  442. );
  443. }
  444. // Else, update it
  445. else
  446. {
  447. // Update database
  448. $.post
  449. (
  450. "{{ URL::to('professor/updateRubric') }}",
  451. {
  452. id: $('#assigned_rubric').data('assigned-rubric'),
  453. name: $('#select-template').find(':selected').text(),
  454. activity_id: parseInt($('#activity_id').val()),
  455. expected_percentage: $('#expected_percentage').text(),
  456. expected_points: $('#expected_points').text(),
  457. criteria: criteria,
  458. titles:titles,
  459. max_score:max_score
  460. },
  461. function(data)
  462. {
  463. location.replace(data);
  464. }
  465. );
  466. }
  467. });
  468. // When Ok button is clicked, redirect to previous page
  469. // When save button is clicked
  470. $('#button-redirect').on('click', function(e)
  471. {
  472. e.preventDefault();
  473. history.go(-1);
  474. });
  475. @stop