Nessuna descrizione

rubrics.blade.php 47KB

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