No Description

rubrics.blade.php 48KB

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