No Description

rubrics_new.blade.php 55KB

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