No Description

edit_assessment.blade.php 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. <div class="row">
  15. <div class="col-md-12">
  16. <h3 id="course">Course: {{{ $course->code }}}{{{ $course->number }}}-{{{ $course->section }}}</h3>
  17. {{ HTML::linkAction('ActivitiesController@show', 'Back to Activity', array($activity->id), array('class'=>'btn btn-default btn-sm pull-right')) }}
  18. <h3 id="activity" data-activity-id="{{{ $activity->id }}}">Activity: {{{ $activity->name}}} </h3>
  19. <table class="table table-striped table-condensed">
  20. <thead>
  21. <tr>
  22. <th></th>
  23. @foreach ($rubric_contents as $criterion)
  24. <th class="criterion-field" data-criterion-id="{{{ $criterion->id }}}">{{ $criterion->name}}</th>
  25. @endforeach
  26. </tr>
  27. </thead>
  28. <tbdody>
  29. <!-- For each student, display names and score selects -->
  30. @foreach ($students as $student)
  31. <tr>
  32. <td class="student-field" data-student-id={{ $student->id }}>{{{ $student->name }}}</td>
  33. @for ($i = 0; $i<sizeof($rubric_contents); $i++)
  34. <td class="score-field">
  35. <select name="" id="" class="form-control">
  36. <option value="0">0</option>
  37. <option value="1">1</option>
  38. <option value="2">2</option>
  39. <option value="3">3</option>
  40. <option value="4">4</option>
  41. <option value="5">5</option>
  42. <option value="6">6</option>
  43. <option value="7">7</option>
  44. <option value="8">8</option>
  45. </select>
  46. </td>
  47. @endfor
  48. </tr>
  49. @endforeach
  50. </tbdody>
  51. <tfoot>
  52. <tr>
  53. <td><strong>Total</strong></td>
  54. @for ($i = 0; $i<sizeof($rubric_contents); $i++)
  55. <td class="total"><strong></strong></td>
  56. @endfor
  57. </tr>
  58. </tfoot>
  59. </table>
  60. <div class="text-center">
  61. <button id="button-submit-assessment" class="btn btn-primary btn-lg">Save Assessment</button>
  62. </div>
  63. </div>
  64. </div>
  65. @stop
  66. @section ('javascript')
  67. // --------------------------------------------------------------------------
  68. // Events
  69. // --------------------------------------------------------------------------
  70. // Submit button is clicked
  71. $('#button-submit-assessment').on('click', function(e)
  72. {
  73. //TODO
  74. var expected_points = 6;
  75. var expected_percentage = 70;
  76. //Prevent page refresh
  77. e.preventDefault();
  78. // Row in the database
  79. var activity_id = $('#activity').data('activity-id');
  80. // Object to hold the score sum of each criterion
  81. var criteriaSumObject = new Object();
  82. // Object to hold how many students got at least the expected points
  83. var CriteriaAchievedCounter = new Object();
  84. // Object to hold all student evaluations
  85. var studentAssessments = new Array();
  86. // Iterate through all students
  87. $('tbody tr').each(function( index )
  88. {
  89. var ScoresObject = new Object(); // Scores column in database
  90. var CriterionObject = new Object(); // Objects inside ScoresObject
  91. var SingleStudentAssessment = new Object();
  92. SingleStudentAssessment.student_id = $(this).find('.student-field').data('student-id');
  93. // For each criterion, store the score in array
  94. $(this).children('td.score-field').each(function( index )
  95. {
  96. var scoreField = $(this);
  97. var criterion_id = $('.criterion-field').eq(index).data('criterion-id');
  98. var score = scoreField.children('select').find(':selected').val();
  99. ScoresObject[criterion_id]=score;
  100. // Initialize the index for the sum object, if it's undefined
  101. if(typeof(criteriaSumObject[criterion_id]) == 'undefined')
  102. {
  103. criteriaSumObject[criterion_id]=0;
  104. }
  105. // Add to this criterion's total
  106. criteriaSumObject[criterion_id]+=parseInt(score);
  107. // Initialize the index for the achieved criteria count object, if it's undefined
  108. if(typeof(CriteriaAchievedCounter[criterion_id]) == 'undefined')
  109. {
  110. CriteriaAchievedCounter[criterion_id]=0;
  111. }
  112. // Add to the achieved criteria count for this criterion, if the
  113. // score reaches or exceeds the expected points
  114. if(score >= expected_points)
  115. {
  116. CriteriaAchievedCounter[criterion_id]+=1;
  117. }
  118. });
  119. SingleStudentAssessment.scores = ScoresObject;
  120. console.log('student object: '+JSON.stringify(SingleStudentAssessment));
  121. var clone = jQuery.extend({}, SingleStudentAssessment);
  122. studentAssessments.push(clone);
  123. });
  124. console.log('students: '+JSON.stringify(studentAssessments));
  125. console.log('total points per criteria: '+JSON.stringify(criteriaSumObject));
  126. console.log('total of students that achieved each criterion ' +JSON.stringify(CriteriaAchievedCounter));
  127. // Iterate through all evaluated criteria, determining which were achieved
  128. // by comparing the completion percentage to the expected percentage
  129. var CriteriaAchievedResults = new Object();
  130. $.each(CriteriaAchievedCounter, function( index, value )
  131. {
  132. var x = CriteriaAchievedCounter[index];
  133. var y = $('tbody tr').length;
  134. if((x/y)*100 >= expected_percentage)
  135. {
  136. CriteriaAchievedResults[index]=1;
  137. }
  138. else
  139. {
  140. CriteriaAchievedResults[index]=0;
  141. }
  142. });
  143. console.log('criteria results: '+JSON.stringify(CriteriaAchievedResults));
  144. // Save activity to the database
  145. $.post
  146. (
  147. "{{ URL::action('ActivitiesController@saveAssessment') }}",
  148. {
  149. activity_id: activity_id,
  150. criteria_achievement: JSON.stringify(CriteriaAchievedResults),
  151. student_scores: JSON.stringify(studentAssessments)
  152. },
  153. function(data)
  154. {
  155. location.reload();
  156. }
  157. );
  158. });
  159. @stop