No Description

rubrics.blade.php 42KB

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