No Description

rubrics_new.blade.php 55KB

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