No Description

rubrics.blade.php 42KB

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