Nav apraksta

rubrics.blade.php 48KB

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