Sin descripción

rubrics.blade.php 48KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364
  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 data.scales[current_criterion.id]){
  668. scale = data.scales[current_criterion.id][scaleIndex];
  669. str+='<td class="editable" data-id-value ="'+scale.scale_id+'" data-type="textarea">'+scale.description+'</td>';
  670. }
  671. copyright = temp_criterion[temp_c].copyright;
  672. notes = temp_criterion[temp_c].notes;
  673. if(copyright == null){
  674. copyright = '';
  675. }
  676. if(notes==null) notes ='';
  677. str += '<td class = "editable" data-type = "textarea">'+copyright+'</td>';
  678. str+= '<td class = "editable" data-type = "textarea">'+notes+'</td>';
  679. str+='<th><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></th></tr>';
  680. $('table tbody').append(str);
  681. // Enable X-Edtable on this new row
  682. $('.editable').editable({
  683. unsavedclass: null,
  684. rows: 4
  685. });
  686. // Turn on tooltips again (because content is dynamic)
  687. $('[data-toggle="tooltip"]').tooltip();
  688. refreshSelects();
  689. }
  690. /*
  691. var contents = JSON.parse(data.contents);
  692. contents.forEach(function (data)
  693. {
  694. // Append the fetched data
  695. 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>';
  696. var subcriteria = '';
  697. if(data.subcriteria){
  698. var subcriteria_array = data.subcriteria;
  699. subcriteria = '<ul class="subcriteria list-unstyled">';
  700. subcriteria_array.forEach(function (value) {
  701. subcriteria += '<li>'+value+'</li>';
  702. });
  703. subcriteria += '</ul>';
  704. }
  705. if(data.notes)
  706. {
  707. str+='<span><em data-toggle="tooltip" data-placement="top" title="'+data.notes+'">'+data.name+'</em></span><sup></sup>'+subcriteria;
  708. }
  709. else
  710. {
  711. str+='<span>'+data.name+'</span><sup></sup>'+subcriteria;
  712. }
  713. str+='</td><td class="editable" data-type="textarea">'+data.description12+'</td>'
  714. +'<td class="editable" data-type="textarea">'+data.description34+'</td>'
  715. +'<td class="editable" data-type="textarea">'+data.description56+'</td>'
  716. +'<td class="editable" data-type="textarea">'+data.description78+'</td>'
  717. +'<th><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></th></tr>';
  718. $('table tbody').append(str);
  719. // Build copyright list
  720. buildCopyrightList();
  721. // Enable X-Edtable on this new row
  722. $('.editable').editable({
  723. unsavedclass: null,
  724. rows: 4
  725. });
  726. // Turn on tooltips again (because content is dynamic)
  727. $('[data-toggle="tooltip"]').tooltip();
  728. refreshSelects();
  729. }); */
  730. // Sortable rows
  731. $('.table').sortable({
  732. handle: 'span.glyphicon.glyphicon-move',
  733. containerSelector: 'table',
  734. itemPath: '> tbody',
  735. itemSelector: 'tr',
  736. placeholder: '<tr class="placeholder"><th><span class="glyphicon glyphicon-arrow-right"></span></th></tr>'
  737. });
  738. // Build Copyright List
  739. buildCopyrightList();
  740. var selected = $('#select-template').find(':selected');
  741. var programs = {{ json_encode(Auth::user()->programs->lists('id')) }};
  742. var template_program = selected.data('template-program-id');
  743. if(
  744. {{ Auth::user()->role }}==1
  745. || ({{ Auth::user()->role }}==2 && selected.data('admin')!=1)
  746. || ({{ Auth::user()->role }}==3
  747. && programs.includes(selected.data('template-program-id'))
  748. && selected.data('admin')!=1
  749. )
  750. )
  751. {
  752. $('#button-confirm-delete-rubric').prop('disabled', false);
  753. $('#button-confirm-update-rubric').prop('disabled', false);
  754. }
  755. else
  756. {
  757. // Disable update and edit
  758. $('#button-confirm-delete-rubric').prop('disabled', true);
  759. $('#button-confirm-update-rubric').prop('disabled', true);
  760. }
  761. // Enable print button
  762. $('#button-print-rubric').prop('disabled', false);
  763. },
  764. 'json',
  765. );
  766. }
  767. // Checks whether the user wants to save a rubric with a name that already exists
  768. function nameExists()
  769. {
  770. var duplicates = false;
  771. $('#select-template option').each(function()
  772. {
  773. var optionName = $(this).text().trim();
  774. if($('#rubric-name').val().trim()===optionName)
  775. {
  776. duplicates = true;
  777. }
  778. });
  779. refreshSelects();
  780. return duplicates;
  781. }
  782. //Enable disable program select
  783. function toggleProgramSelect(school)
  784. {
  785. if(school.find(':selected').data('school-id') <1)
  786. {
  787. $('#select-program option[data-program-id="0"]').prop('selected', true);
  788. $('#select-program').prop('disabled', true);
  789. }
  790. else
  791. {
  792. fetchPrograms(school);
  793. $('#select-program').prop('disabled', false);
  794. }
  795. refreshSelects();
  796. }
  797. fetchObjective($('#select-outcome'));
  798. // --------------------------------------------------------------------------
  799. // Events
  800. // --------------------------------------------------------------------------
  801. // Toggle visibility for accordion panels
  802. $('.panel-heading').on('click', function()
  803. {
  804. if($(this).find('.glyphicon').hasClass('glyphicon-triangle-right'))
  805. {
  806. $(this).find('.glyphicon').removeClass('glyphicon-triangle-right');
  807. $(this).find('.glyphicon').addClass('glyphicon-triangle-bottom');
  808. }
  809. else if($(this).find('.glyphicon').hasClass('glyphicon-triangle-bottom'))
  810. {
  811. $(this).find('.glyphicon').removeClass('glyphicon-triangle-bottom');
  812. $(this).find('.glyphicon').addClass('glyphicon-triangle-right');
  813. }
  814. $(this).siblings('.panel-body').stop().slideToggle();
  815. });
  816. // When trying to change the template, ask the user to confirm and reset the
  817. // rubric if s/he does
  818. $('#select-template').on('change', function()
  819. {
  820. // If changing to custom template, reset
  821. if($('#select-template').find(':selected').data('template-id')=='0')
  822. {
  823. $('#rubric-container').hide();
  824. $('#rubric-name').val('');
  825. $('tbody').empty();
  826. // Disable delete, update and print buttons
  827. $('#button-confirm-delete-rubric').prop('disabled', true);
  828. $('#button-confirm-update-rubric').prop('disabled', true);
  829. $('#button-print-rubric').prop('disabled', true);
  830. }
  831. // Otherwise, load the selected template
  832. else
  833. {
  834. loadTemplate();
  835. //If user is admin, or the templates id matches user's, or the template
  836. // id's school matches user, allow editing
  837. /*var selected = $('#select-template').find(':selected');
  838. var programs = {{ json_encode(Auth::user()->programs->lists('id')) }};
  839. var template_program = selected.data('template-program-id');
  840. var dataset = selected.dataSet.templateProgramId;
  841. if(
  842. {{ Auth::user()->role }}==1
  843. || ({{ Auth::user()->role }}==2 && selected.data('admin')!=1)
  844. || ({{ Auth::user()->role }}==3
  845. && programs.includes(selected.data('template-program-id'))
  846. && selected.data('admin')!=1
  847. )
  848. )
  849. {
  850. $('#button-confirm-delete-rubric').prop('disabled', false);
  851. $('#button-confirm-update-rubric').prop('disabled', false);
  852. }
  853. else
  854. {
  855. // Disable update and edit
  856. $('#button-confirm-delete-rubric').prop('disabled', true);
  857. $('#button-confirm-update-rubric').prop('disabled', true);
  858. }
  859. // Enable print button
  860. $('#button-print-rubric').prop('disabled', false);
  861. */
  862. }
  863. });
  864. function changeTable(){
  865. amount_of_scales = parseInt($('#number_of_scales').find(':selected').val());
  866. counter2 = 0;
  867. maximum = parseInt($('#max_score').find(":selected").val());
  868. newScaleHeaders = '<th></th><th>Criterion</th>';
  869. editableTitles = '<th></th><th></th>';
  870. counter = 0;
  871. division = maximum/amount_of_scales;
  872. if(amount_of_scales==1){
  873. newScaleHeaders+= "<th>Score (1 - "+maximum+")</th>";
  874. editableTitles += "<th class = 'editable' data-type = 'textarea'>Click to edit Title </th>"
  875. }
  876. else if(maximum!= amount_of_scales){
  877. while(counter <amount_of_scales){
  878. minimumScore = 1+(counter*division);
  879. maximumScore = (1+counter)*division;
  880. newScaleHeaders+= "<th>Scale "+ (counter +1) + " ("+minimumScore+" - "+maximumScore+")</th>";
  881. editableTitles+="<th class = 'editable' data-type = 'textarea'>Click to edit Title "+(counter+1)+"</th>"
  882. counter++;
  883. }
  884. }else{
  885. while(counter <amount_of_scales){
  886. newScaleHeaders+= "<th>Scale "+ (counter +1) + " </th>";
  887. editableTitles+="<th class = 'editable' data-type = 'textarea'>Click to edit Title "+(counter+1)+"</th>"
  888. counter++;
  889. }
  890. }
  891. newScaleHeaders += '<th>Outcomes</th><th></th>';
  892. editableTitles += '<th></th><th></th>';
  893. $('#theScaleTitles').html(editableTitles);
  894. $("#criterion-header").html(newScaleHeaders);
  895. $('#allCriteria').html(' ');
  896. }
  897. // When a school changes, update its programs. If all is selected, disable
  898. $('#select-school').on('change', function()
  899. {
  900. toggleProgramSelect($(this));
  901. });
  902. $('#max_score').on('change', function(){
  903. var max = parseInt($('#max_score').find(':selected').val());
  904. var stringToScales = "<option value= '1'>Cuantitative Rubric </option>";
  905. selectedValue = 1;
  906. valueBefore = 0;
  907. for(i=2; i<=20; i++){
  908. if(max%i==0){
  909. stringToScales += "<option value= '"+i+"'>"+i+"-Scale Rubric</option>";
  910. selectedValue = i - valueBefore;
  911. valueBefore = i;
  912. }
  913. }
  914. $('#number_of_scales').html(stringToScales);
  915. $('#number_of_scales').selectpicker('refresh');
  916. $('#number_of_scales').val(selectedValue);
  917. $('#number_of_scales').selectpicker('refresh');
  918. var expected_points = Math.floor(max *0.7);
  919. var expected_points_html = '';
  920. for(i=1; i<max; i++){
  921. expected_points_html += '<option value="'+i+'"> '+i+'</option>';
  922. }
  923. $('#expected_points').html(expected_points_html);
  924. refreshSelects();
  925. $('#expected_points').val(expected_points);
  926. refreshSelects();
  927. changeTable();
  928. fetchCriteria($('#select-outcome'), $('#select-objective'))
  929. })
  930. $('#number_of_scales').on('change', function(){
  931. changeTable();
  932. })
  933. // When a learning outcome changes, update its criteria
  934. /*$('#select-outcome, input[name=criteria-filter]').on('change', function()
  935. {
  936. fetchCriteria($('#select-outcome'));
  937. });
  938. */
  939. // When the add button is clicked
  940. $('#button-add-criterion').on('click', function(e)
  941. {
  942. //Prevent page refresh
  943. e.preventDefault();
  944. //Add new criterion
  945. addCriterion();
  946. });
  947. // When the create or update buttons are clicked (.save)
  948. $('.save').on('click', function(e)
  949. {
  950. //Prevent page refresh
  951. e.preventDefault();
  952. // Empty field validation
  953. var emptyFields=false;
  954. $('#allCriteria').children('td').each(function()
  955. {
  956. if (($(this).text() == "" || $(this).text() == "Empty") && !($(this).hasClass('nullable')) )
  957. {
  958. emptyFields=true;
  959. }
  960. });
  961. // If any fields are empty, display error
  962. if(emptyFields || $.trim($('#rubric-name').val())=='')
  963. {
  964. $('#js-error-row').show();
  965. $('#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.');
  966. return;
  967. }
  968. else
  969. {
  970. $('#js-error-row').hide();
  971. }
  972. // Check whether a rubric with the written name already exists
  973. if($(this).attr('id')=='button-create-rubric' && nameExists())
  974. {
  975. $('#js-error-row').show();
  976. $('#js-error-row').find('#error-message').text('Error: A template with that name already exists.');
  977. return;
  978. }
  979. else
  980. {
  981. $('#js-error-row').hide();
  982. }
  983. var criterionObject = new Object();
  984. var criteriaArray = new Array();
  985. var criteria = [];
  986. var titles = [];
  987. var amount_of_scales =parseInt($('#number_of_scales').find(':selected').val())+2;
  988. var max = parseInt($('#max_score').find(':selected').val());
  989. // For each criterion in the rubric, get its value and put it into an array
  990. $('tbody tr').each(function( index )
  991. {
  992. criteria.push($(this).data('criterion-id'));
  993. });
  994. $('.editable').each(function(index){
  995. titles.push($(this).text());
  996. })
  997. //console.log('school', $('#select-school').find(':selected').data('school-id') );
  998. //console.log('program', $('#select-program').find(':selected').data('program-id') );
  999. if($(this).attr('id')=='button-create-rubric')
  1000. {
  1001. // Create
  1002. $.post
  1003. (
  1004. "{{ URL::to('saveTemplate') }}",
  1005. {
  1006. name: $('#rubric-name').val(),
  1007. school_id: $('#select-school').find(':selected').data('school-id'),
  1008. program_id: $('#select-program').find(':selected').data('program-id'),
  1009. expected_percentage: $('#expected_percentage').find(':selected').val(),
  1010. expected_points: $('#expected_points').find(':selected').val(),
  1011. is_visible: $('input[name=is_visible]:checked').val(),
  1012. criteria : criteria,
  1013. //scales: scales,
  1014. max_score : max,
  1015. /*copyright : copyright,
  1016. notes :notes*/
  1017. titles: titles
  1018. },
  1019. function(data)
  1020. {
  1021. location.reload(true);
  1022. }
  1023. );
  1024. }
  1025. else
  1026. {
  1027. console.log('school', $('#select-school').find(':selected').data('school-id') );
  1028. console.log('program', $('#select-program').find(':selected').data('program-id') );
  1029. // Update database
  1030. $.post
  1031. (
  1032. "{{ URL::to('updateTemplate') }}",
  1033. {
  1034. id: $('#select-template').find(':selected').data('template-id'),
  1035. name: $('#rubric-name').val(),
  1036. school_id: $('#select-school').find(':selected').data('school-id'),
  1037. program_id: $('#select-program').find(':selected').data('program-id'),
  1038. expected_percentage: $('#expected_percentage').find(':selected').val(),
  1039. expected_points: $('#expected_points').find(':selected').val(),
  1040. is_visible: $('input[name=is_visible]:checked').val(),
  1041. criteria : criteria,
  1042. scales: scales,
  1043. max_score : max,
  1044. copyright :copyright,
  1045. notes:notes
  1046. },
  1047. function(data)
  1048. {
  1049. location.reload(true);
  1050. }
  1051. );
  1052. }
  1053. });
  1054. // When the confirm delete button is clicked
  1055. $('#button-delete-rubric').on('click', function(e)
  1056. {
  1057. $('#modal-confirm-delete').modal('hide');
  1058. // Delete from database
  1059. $.post
  1060. (
  1061. "{{ URL::to('deleteTemplate') }}",
  1062. {
  1063. id: $('#select-template').find(':selected').data('template-id')
  1064. },
  1065. function(data)
  1066. {
  1067. location.reload();
  1068. }
  1069. );
  1070. });
  1071. // Remove a criterion and hide the table if it was the only one
  1072. $('table').on('click', 'span.glyphicon-remove', function(e)
  1073. {
  1074. $(this).closest('tr').remove();
  1075. if(!$('tbody').children().length)
  1076. {
  1077. $('#rubric-container').hide();
  1078. }
  1079. buildCopyrightList();
  1080. });
  1081. // When print button is clicked, redirect to print page
  1082. $('#button-print-rubric').on('click', function(e)
  1083. {
  1084. e.preventDefault();
  1085. window.location = "printRubric/"+$('#select-template').find(':selected').data('template-id');
  1086. });
  1087. </script>
  1088. @stop
  1089. @section('included-js')
  1090. <!-- jQuery Sortable Tables -->
  1091. <script src="{{ asset('vendor/jQuerySortable/jquery-sortable-min.js') }}"></script>
  1092. <!-- X-Editable js -->
  1093. <script src="{{ asset('vendor/xeditable/bootstrap-editable.min.js') }}"></script>
  1094. @stop
  1095. @section('javascript')
  1096. // --------------------------------------------------------------------------
  1097. // Page load
  1098. // --------------------------------------------------------------------------
  1099. $('#updated-text').hide();
  1100. // Enable/disable program selection depending on school selection if user is
  1101. // admin
  1102. if({{Auth::user()->role}}==1)
  1103. toggleProgramSelect($('#select-school'));
  1104. // Fetch criteria of first outcome
  1105. fetchCriteria($('#select-outcome'), $('#select-objective'));
  1106. changeTable();
  1107. // Hide table
  1108. $('#rubric-container').hide();
  1109. // Disable Update and Delete Buttons by default
  1110. $('#button-confirm-update-rubric').prop('disabled', true);
  1111. $('#button-confirm-delete-rubric').prop('disabled', true);
  1112. $('#button-print-rubric').prop('disabled', true);
  1113. // Sortable rows
  1114. $('.table').sortable({
  1115. handle: 'span.glyphicon.glyphicon-move',
  1116. containerSelector: 'table',
  1117. itemPath: '> tbody',
  1118. itemSelector: 'tr',
  1119. placeholder: '<tr class="placeholder"><th><span class="glyphicon glyphicon-arrow-right"></span></th></tr>'
  1120. });
  1121. @stop