Nav apraksta

rubrics.blade.php 48KB

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