No Description

rubrics_new.blade.php 56KB

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