Nav apraksta

rubrics.blade.php 48KB

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