No Description

rubrics_new.blade.php 56KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555
  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. // console.log(str);
  530. var subcriteria = '';
  531. if(data.criterion.subcriteria){
  532. var subcriteria_array = JSON.parse(data.criterion.subcriteria);
  533. subcriteria = '<ul class="subcriteria list-unstyled">';
  534. subcriteria_array.forEach(function (value) {
  535. subcriteria += '<li>'+value+'</li>';
  536. });
  537. subcriteria += '</ul>';
  538. }
  539. if(notes)
  540. {
  541. str+='<span><em data-toggle="tooltip" data-placement="top" title="'+notes+'">'+data.criterion.name+'</em></span><sup></sup>'+subcriteria+'</td>';
  542. }
  543. else
  544. {
  545. str+='<span>'+data.criterion.name+'</span><sup></sup>'+subcriteria+'</td>';
  546. }
  547. numberOfScale = $('#number_of_scales').find(':selected').val();
  548. for(i=0; i<numberOfScale; i++){
  549. str+='<td>'+data.scales[i].description+'</td>';
  550. }
  551. str+= '<td>'+data.outcomes+'</td>'
  552. str +='<th><span class="glyphicon glyphicon-remove icon-btn" aria-hidden="true"></span></th></tr>';
  553. console.log(str);
  554. $('table tbody').append(str);
  555. // Build copyright list
  556. buildCopyrightList();
  557. // Enable X-Edtable on this new row
  558. $('.editable').editable({
  559. unsavedclass: null,
  560. rows: 4
  561. });
  562. // Turn on tooltips again (because content is dynamic)
  563. $('[data-toggle="tooltip"]').tooltip();
  564. // Sortable rows
  565. $('.table').sortable({
  566. handle: 'span.glyphicon.glyphicon-move',
  567. containerSelector: 'table',
  568. itemPath: '> tbody',
  569. itemSelector: 'tr',
  570. placeholder: '<tr class="placeholder"><th><span class="glyphicon glyphicon-arrow-right"></span></th></tr>'
  571. });
  572. },
  573. 'json',
  574. );
  575. }
  576. // Fetch single criterion
  577. function fetchCriterion(criterion)
  578. {
  579. $.post
  580. (
  581. "{{ URL::route('fetchCriterion') }}",
  582. { id: outcome.find(':selected').data('outcome-id')},
  583. function(data)
  584. {
  585. $('#select-criterion').empty();
  586. data.forEach( function (arrayItem)
  587. {
  588. $('#select-criterion')
  589. .append('<option data-criterion-id="'+arrayItem.id+'" >'+arrayItem.name+'</option>');
  590. });
  591. $('#select-criterion').append('<option data-criterion-id="0">Custom</option>');
  592. refreshSelects();
  593. }
  594. );
  595. }
  596. // Build list from copyright info in rubric
  597. function buildCopyrightList()
  598. {
  599. // Empty the copyright list
  600. $('#copyright-list').empty();
  601. $('tbody tr').each(function( index )
  602. {
  603. var criterion = $(this);
  604. // If there's copyright info
  605. if(criterion.data('criterion-copyright')!=null){
  606. var copyright = criterion.data('criterion-copyright');
  607. if($('#copyright-list li').length>0)
  608. {
  609. var found = false;
  610. $('#copyright-list li').each(function()
  611. {
  612. // If found, give the string its number
  613. if(copyright==$(this).find('span').text())
  614. {
  615. copyrightNumber = Number.parseInt($(this).find('sup').text());
  616. console.log('a: '+copyrightNumber);
  617. criterion.children('td:nth-child(2)').find('sup').text(copyrightNumber);
  618. found =true;
  619. //to break
  620. return false;
  621. }
  622. });
  623. // Otherwise, give it the next number and append a new item to the
  624. // list
  625. if(!found)
  626. {
  627. var copyrightNumber = $('#copyright-list li').length+1;
  628. console.log('b: '+copyrightNumber);
  629. console.log(criterion.children('td:nth-child(2)').find('sup').length);
  630. criterion.children('td:nth-child(2)').find('sup').text(copyrightNumber);
  631. $('#copyright-list').append('<li><sup>'+copyrightNumber+' </sup><span>'+copyright+'<span></li>');
  632. }
  633. }
  634. else
  635. {
  636. criterion.children('td:nth-child(2)').find('sup').text('1');
  637. $('#copyright-list').append('<li><sup>1 </sup><span>'+copyright+'<span></li>');
  638. }
  639. }
  640. });
  641. if($('#copyright-info li').length>0)
  642. {
  643. $('#copyright-info').show();
  644. }
  645. else
  646. {
  647. $('#copyright-info').hide();
  648. }}
  649. /* if(criterion.data('criterion-copyright')!=null)
  650. {
  651. var copyright = criterion.data('criterion-copyright');
  652. // If there is anything in the copyright list
  653. if($('#copyright-list li').length>0)
  654. {
  655. // Check copyright list for the same copyright text
  656. var found = false;
  657. $('#copyright-list li').each(function()
  658. {
  659. // If found, give the string its number
  660. if(copyright==$(this).find('span').text())
  661. {
  662. copyrightNumber = Number.parseInt($(this).find('sup').text());
  663. console.log('a: '+copyrightNumber);
  664. criterion.children('td:nth-child(2)').find('sup').text(copyrightNumber);
  665. found =true;
  666. //to break
  667. return false;
  668. }
  669. });
  670. // Otherwise, give it the next number and append a new item to the
  671. // list
  672. if(!found)
  673. {
  674. var copyrightNumber = $('#copyright-list li').length+1;
  675. console.log('b: '+copyrightNumber);
  676. console.log(criterion.children('td:nth-child(2)').find('sup').length);
  677. criterion.children('td:nth-child(2)').find('sup').text(copyrightNumber);
  678. $('#copyright-list').append('<li><sup>'+copyrightNumber+' </sup><span>'+copyright+'<span></li>');
  679. }
  680. }
  681. // Otherwise, give it number 1 and append it
  682. else
  683. {
  684. criterion.children('td:nth-child(2)').find('sup').text('1');
  685. $('#copyright-list').append('<li><sup>1 </sup><span>'+copyright+'<span></li>');
  686. }
  687. }
  688. });
  689. if($('#copyright-info li').length>0)
  690. {
  691. $('#copyright-info').show();
  692. }
  693. else
  694. {
  695. $('#copyright-info').hide();
  696. }
  697. }
  698. */
  699. function refreshSelects()
  700. {
  701. $('#select-template').selectpicker('refresh');
  702. $('#select-school').selectpicker('refresh');
  703. $('#select-program').selectpicker('refresh');
  704. $('#select-outcome').selectpicker('refresh');
  705. $('#select-criterion').selectpicker('refresh');
  706. $('#expected_percentage').selectpicker('refresh');
  707. $('#expected_points').selectpicker('refresh');
  708. $('#number_of_scales').selectpicker('refresh');
  709. $('#select-objective').selectpicker('refresh');
  710. }
  711. // Fetch programs associated to a specific school
  712. function fetchPrograms(school)
  713. {
  714. $.ajax({
  715. type: 'POST',
  716. url: "{{ URL::action('ProgramsController@fetch') }}",
  717. data: { id: school.find(':selected').data('school-id')},
  718. success: function(data)
  719. {
  720. $('#select-program').empty();
  721. $('#select-program').append('<option data-program-id="0">All</option>');
  722. data.forEach( function (program)
  723. {
  724. $('#select-program')
  725. .append('<option data-program-id="'+program.id+'" >'+program.name+'</option>');
  726. });
  727. },
  728. async:false
  729. });
  730. if($('#select-school').find(':selected').data('school-id')!=0)
  731. $('#select-program').prop('disabled', false);
  732. else
  733. $('#select-program').prop('disabled', true);
  734. refreshSelects();
  735. }
  736. // Load a template. This function is different from the one for professors
  737. function loadTemplate()
  738. {
  739. $.post
  740. (
  741. "{{ URL::to('loadTemplate') }}",
  742. { id: $('#select-template').find(':selected').data('template-id')},
  743. function(data)
  744. {
  745. // Show the container and empty all rows
  746. $('#rubric-container').show();
  747. $('tbody').empty();
  748. //Set the name of the rubric
  749. $('#rubric-name').val(data.template.name);
  750. console.log(data.template.school_id);
  751. console.log($('#select-school'));
  752. // Set school id to 0, then to the saved value if it exists
  753. $('#select-school option[data-school-id="0"]').prop('selected', true);
  754. $('#select-school option[data-school-id="'+data.template.school_id+'"]').prop('selected', true);
  755. console.log($('#select-school'));
  756. // Fetch programs associated to that school
  757. fetchPrograms($('#select-school'));
  758. // Set program id to 0, then to the saved value if it exists
  759. $('#select-program option[data-program-id="0"]').prop('selected', true);
  760. $('#select-program option[data-program-id="'+data.template.program_id+'"]').prop('selected', true);
  761. // Set expected values
  762. console.log(data.template.expected_percentage);
  763. console.log(data.template.expected_points);
  764. console.log(data.template.max_score);
  765. $('#max_score').val(data.template.max_score);
  766. $('#max_score').trigger("change");
  767. $('#expected_percentage').val(data.template.expected_percentage);
  768. $('#expected_points').val(data.template.expected_points);
  769. $('#number_of_scales').val(data.template.num_scales);
  770. refreshSelects();
  771. changeTable();
  772. // Set visibility
  773. var is_visible = data.template.is_visible;
  774. if(is_visible)
  775. {
  776. $('#is_visible0').prop('checked', false);
  777. $('#is_visible1').prop('checked', true);
  778. }
  779. else
  780. {
  781. $('#is_visible1').prop('checked', false);
  782. $('#is_visible0').prop('checked', true);
  783. }
  784. // Set the contents of the rubric
  785. var temp_criterion = data.criterion;
  786. console.log(temp_criterion);
  787. for(temp_c in temp_criterion){
  788. current_criterion = temp_criterion[temp_c]
  789. console.log(current_criterion.program_ids);
  790. objectives = JSON.stringify(current_criterion.objectives);
  791. //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>';
  792. 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>";
  793. console.log(str);
  794. var subcriteria ='';
  795. if(current_criterion.subcriteria){
  796. var subcriteria_array = JSON.parse(current_criterion.subcriteria);
  797. subcriteria = '<ul class="subcriteria list-unstyled">';
  798. subcriteria_array.forEach(function (value) {
  799. subcriteria += '<li>'+value+'</li>';
  800. });
  801. subcriteria += '</ul>';
  802. }
  803. if(current_criterion.notes)
  804. {
  805. str+='<span><em data-toggle="tooltip" data-placement="top" title="'+current_criterion.notes+'">'+current_criterion.name+'</em></span><sup></sup>'+subcriteria;
  806. }
  807. else
  808. {
  809. str+='<span>'+current_criterion.name+'</span><sup></sup>'+subcriteria;
  810. }
  811. str+= '</td>';
  812. for(scaleIndex in current_criterion.scales){
  813. scale = current_criterion.scales[scaleIndex];
  814. str+='<td>'+scale.description+'</td>';
  815. }
  816. str+= '<td>'+current_criterion.outcomes+'</td>'
  817. str+='<th><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></th></tr>';
  818. console.log(str);
  819. $('table tbody').append(str);
  820. // Enable X-Edtable on this new row
  821. $('.editable').editable({
  822. unsavedclass: null,
  823. rows: 4
  824. });
  825. // Turn on tooltips again (because content is dynamic)
  826. $('[data-toggle="tooltip"]').tooltip();
  827. refreshSelects();
  828. }
  829. /*
  830. var contents = JSON.parse(data.contents);
  831. contents.forEach(function (data)
  832. {
  833. // Append the fetched data
  834. 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>';
  835. var subcriteria = '';
  836. if(data.subcriteria){
  837. var subcriteria_array = data.subcriteria;
  838. subcriteria = '<ul class="subcriteria list-unstyled">';
  839. subcriteria_array.forEach(function (value) {
  840. subcriteria += '<li>'+value+'</li>';
  841. });
  842. subcriteria += '</ul>';
  843. }
  844. if(data.notes)
  845. {
  846. str+='<span><em data-toggle="tooltip" data-placement="top" title="'+data.notes+'">'+data.name+'</em></span><sup></sup>'+subcriteria;
  847. }
  848. else
  849. {
  850. str+='<span>'+data.name+'</span><sup></sup>'+subcriteria;
  851. }
  852. str+='</td><td class="editable" data-type="textarea">'+data.description12+'</td>'
  853. +'<td class="editable" data-type="textarea">'+data.description34+'</td>'
  854. +'<td class="editable" data-type="textarea">'+data.description56+'</td>'
  855. +'<td class="editable" data-type="textarea">'+data.description78+'</td>'
  856. +'<th><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></th></tr>';
  857. $('table tbody').append(str);
  858. // Build copyright list
  859. buildCopyrightList();
  860. // Enable X-Edtable on this new row
  861. $('.editable').editable({
  862. unsavedclass: null,
  863. rows: 4
  864. });
  865. // Turn on tooltips again (because content is dynamic)
  866. $('[data-toggle="tooltip"]').tooltip();
  867. refreshSelects();
  868. }); */
  869. // Sortable rows
  870. $('.table').sortable({
  871. handle: 'span.glyphicon.glyphicon-move',
  872. containerSelector: 'table',
  873. itemPath: '> tbody',
  874. itemSelector: 'tr',
  875. placeholder: '<tr class="placeholder"><th><span class="glyphicon glyphicon-arrow-right"></span></th></tr>'
  876. });
  877. // Build Copyright List
  878. buildCopyrightList();
  879. $('.editable').each(function (index){
  880. $(this).text(data.titles[index].text);
  881. })
  882. var selected = $('#select-template').find(':selected');
  883. var programs = {{ json_encode(Auth::user()->programs->lists('id')) }};
  884. var template_program = selected.data('template-program-id');
  885. // console.log(selected.data('template-program-id'));
  886. // console.log(programs.includes(selected.data('template-program-id').toString()));
  887. if(
  888. {{ Auth::user()->role }}==1
  889. || ({{ Auth::user()->role }}==2 && selected.data('admin')!=1)
  890. || ({{ Auth::user()->role }}==3
  891. && programs.includes(selected.data('template-program-id').toString())
  892. && selected.data('admin')!=1
  893. )
  894. )
  895. {
  896. $('#button-confirm-delete-rubric').prop('disabled', false);
  897. $('#button-confirm-update-rubric').prop('disabled', false);
  898. }
  899. else
  900. {
  901. // Disable update and edit
  902. $('#button-confirm-delete-rubric').prop('disabled', true);
  903. $('#button-confirm-update-rubric').prop('disabled', true);
  904. }
  905. // Enable print button
  906. $('#button-print-rubric').prop('disabled', false);
  907. fetchCriteria($('#select-outcome'), $('#select-objective'));
  908. },
  909. 'json',
  910. );
  911. }
  912. // Checks whether the user wants to save a rubric with a name that already exists
  913. function nameExists()
  914. {
  915. var duplicates = false;
  916. $('#select-template option').each(function()
  917. {
  918. var optionName = $(this).text().trim();
  919. if($('#rubric-name').val().trim()===optionName)
  920. {
  921. duplicates = true;
  922. }
  923. });
  924. refreshSelects();
  925. return duplicates;
  926. }
  927. //Enable disable program select
  928. function toggleProgramSelect(school)
  929. {
  930. if(school.find(':selected').data('school-id') <1)
  931. {
  932. $('#select-program option[data-program-id="0"]').prop('selected', true);
  933. $('#select-program').prop('disabled', true);
  934. }
  935. else
  936. {
  937. console.log(school);
  938. fetchPrograms(school);
  939. $('#select-program').prop('disabled', false);
  940. }
  941. refreshSelects();
  942. }
  943. fetchObjective($('#select-outcome'));
  944. // --------------------------------------------------------------------------
  945. // Events
  946. // --------------------------------------------------------------------------
  947. // Toggle visibility for accordion panels
  948. $('.panel-heading').on('click', function()
  949. {
  950. if($(this).find('.glyphicon').hasClass('glyphicon-triangle-right'))
  951. {
  952. $(this).find('.glyphicon').removeClass('glyphicon-triangle-right');
  953. $(this).find('.glyphicon').addClass('glyphicon-triangle-bottom');
  954. }
  955. else if($(this).find('.glyphicon').hasClass('glyphicon-triangle-bottom'))
  956. {
  957. $(this).find('.glyphicon').removeClass('glyphicon-triangle-bottom');
  958. $(this).find('.glyphicon').addClass('glyphicon-triangle-right');
  959. }
  960. $(this).siblings('.panel-body').stop().slideToggle();
  961. });
  962. // Fetch criteria everytime something changes
  963. $('#select-objective').on('change', function(){
  964. fetchCriteria($('#select-outcome'), $('#select-objective'));
  965. })
  966. $("#number_of_scales").on('change', function(){
  967. fetchCriteria($('#select-outcome'), $('#select-objective'));
  968. })
  969. // When trying to change the template, ask the user to confirm and reset the
  970. // rubric if s/he does
  971. $('#select-template').on('change', function()
  972. {
  973. // If changing to custom template, reset
  974. if($('#select-template').find(':selected').data('template-id')=='0')
  975. {
  976. $('#rubric-container').hide();
  977. $('#rubric-name').val('');
  978. $('tbody').empty();
  979. // Disable delete, update and print buttons
  980. $('#button-confirm-delete-rubric').prop('disabled', true);
  981. $('#button-confirm-update-rubric').prop('disabled', true);
  982. $('#button-print-rubric').prop('disabled', true);
  983. }
  984. // Otherwise, load the selected template
  985. else
  986. {
  987. loadTemplate();
  988. //If user is admin, or the templates id matches user's, or the template
  989. // id's school matches user, allow editing
  990. var selected = $('#select-template').find(':selected');
  991. var programs = {{ json_encode(Auth::user()->programs->lists('id')) }};
  992. var template_program = selected.data('template-program-id');
  993. <!-- var dataset = selected.dataSet.templateProgramId; -->
  994. if(
  995. {{ Auth::user()->role }}==1
  996. || ({{ Auth::user()->role }}==2 && selected.data('admin')!=1)
  997. || ({{ Auth::user()->role }}==3
  998. && programs.includes(selected.data('template-program-id'))
  999. && selected.data('admin')!=1
  1000. )
  1001. )
  1002. {
  1003. $('#button-confirm-delete-rubric').prop('disabled', false);
  1004. $('#button-confirm-update-rubric').prop('disabled', false);
  1005. }
  1006. else
  1007. {
  1008. // Disable update and edit
  1009. $('#button-confirm-delete-rubric').prop('disabled', true);
  1010. $('#button-confirm-update-rubric').prop('disabled', true);
  1011. }
  1012. if($('#select-template').find(':selected').data('unmatch-criteria')=='1')
  1013. {
  1014. $('#button-confirm-delete-rubric').prop('disabled', true);
  1015. $('#button-confirm-update-rubric').prop('disabled', true);
  1016. $('#button-create-rubric').prop('disabled', true);
  1017. }
  1018. else
  1019. {
  1020. $('#button-create-rubric').prop('disabled', false);
  1021. }
  1022. // Enable print button
  1023. $('#button-print-rubric').prop('disabled', false);
  1024. }
  1025. });
  1026. function changeTable(){
  1027. amount_of_scales = parseInt($('#number_of_scales').find(':selected').val());
  1028. counter2 = 0;
  1029. maximum = parseInt($('#max_score').find(":selected").val());
  1030. newScaleHeaders = '<th></th><th>Criterion</th>';
  1031. editableTitles = '<th></th><th></th>';
  1032. counter = 0;
  1033. division = maximum/amount_of_scales;
  1034. if(amount_of_scales==1){
  1035. newScaleHeaders+= "<th>Score (1 - "+maximum+")</th>";
  1036. editableTitles += "<th class = 'editable' data-type = 'textarea'>Click to edit Title </th>"
  1037. }
  1038. else if(maximum!= amount_of_scales){
  1039. while(counter <amount_of_scales){
  1040. minimumScore = 1+(counter*division);
  1041. maximumScore = (1+counter)*division;
  1042. newScaleHeaders+= "<th>Scale "+ (counter +1) + " ("+minimumScore+" - "+maximumScore+")</th>";
  1043. editableTitles+="<th class = 'editable' data-type = 'textarea'>Click to edit Title "+(counter+1)+"</th>"
  1044. counter++;
  1045. }
  1046. }else{
  1047. while(counter <amount_of_scales){
  1048. newScaleHeaders+= "<th>Scale "+ (counter +1) + " </th>";
  1049. editableTitles+="<th class = 'editable' data-type = 'textarea'>Click to edit Title "+(counter+1)+"</th>"
  1050. counter++;
  1051. }
  1052. }
  1053. newScaleHeaders += '<th>Outcomes</th><th></th>';
  1054. editableTitles += '<th></th><th></th>';
  1055. $('#theScaleTitles').html(editableTitles);
  1056. $("#criterion-header").html(newScaleHeaders);
  1057. $('#allCriteria').html(' ');
  1058. }
  1059. // When a school changes, update its programs. If all is selected, disable
  1060. $('#select-school').on('change', function()
  1061. {
  1062. toggleProgramSelect($(this));
  1063. });
  1064. $('#max_score').on('change', function(){
  1065. var max = parseInt($('#max_score').find(':selected').val());
  1066. var stringToScales = "<option value= '1'>Cuantitative Rubric </option>";
  1067. selectedValue = 1;
  1068. valueBefore = 0;
  1069. for(i=2; i<=20; i++){
  1070. if(max%i==0){
  1071. stringToScales += "<option value= '"+i+"'>"+i+"-Scale Rubric</option>";
  1072. selectedValue = i - valueBefore;
  1073. valueBefore = i;
  1074. }
  1075. }
  1076. $('#number_of_scales').html(stringToScales);
  1077. $('#number_of_scales').selectpicker('refresh');
  1078. $('#number_of_scales').val(selectedValue);
  1079. $('#number_of_scales').selectpicker('refresh');
  1080. var expected_points = Math.floor(max *0.7);
  1081. var expected_points_html = '';
  1082. for(i=1; i<max; i++){
  1083. expected_points_html += '<option value="'+i+'"> '+i+'</option>';
  1084. }
  1085. $('#expected_points').html(expected_points_html);
  1086. refreshSelects();
  1087. $('#expected_points').val(expected_points);
  1088. refreshSelects();
  1089. changeTable();
  1090. fetchCriteria($('#select-outcome'), $('#select-objective'))
  1091. })
  1092. $('#number_of_scales').on('change', function(){
  1093. changeTable();
  1094. $('#rubric-container').hide();
  1095. $('#rubric-name').val('');
  1096. $('tbody').empty();
  1097. })
  1098. // When a learning outcome changes, update its criteria
  1099. /*$('#select-outcome, input[name=criteria-filter]').on('change', function()
  1100. {
  1101. fetchCriteria($('#select-outcome'));
  1102. });
  1103. */
  1104. // When the add button is clicked
  1105. $('#button-add-criterion').on('click', function(e)
  1106. {
  1107. //Prevent page refresh
  1108. e.preventDefault();
  1109. //Add new criterion
  1110. addCriterion();
  1111. });
  1112. // When the create or update buttons are clicked (.save)
  1113. $('.save').on('click', function(e)
  1114. {
  1115. //Prevent page refresh
  1116. e.preventDefault();
  1117. var emptyFields=false;
  1118. $('#allCriteria').children('td').each(function()
  1119. {
  1120. if (($(this).text() == "" || $(this).text() == "Empty") && !($(this).hasClass('nullable')) )
  1121. {
  1122. emptyFields=true;
  1123. }
  1124. });
  1125. // If any fields are empty, display error
  1126. if(emptyFields || $.trim($('#rubric-name').val())=='')
  1127. {
  1128. $('#js-error-row').show();
  1129. $('#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.');
  1130. return;
  1131. }
  1132. else
  1133. {
  1134. $('#js-error-row').hide();
  1135. }
  1136. // Check whether a rubric with the written name already exists
  1137. if($(this).attr('id')=='button-create-rubric' && nameExists())
  1138. {
  1139. $('#js-error-row').show();
  1140. $('#js-error-row').find('#error-message').text('Error: A template with that name already exists.');
  1141. return;
  1142. }
  1143. else
  1144. {
  1145. $('#js-error-row').hide();
  1146. }
  1147. program_id = $('#select-program').find(':selected').data('program-id')
  1148. if(program_id == 0){
  1149. $('#modal-title-rubric').html("All criteria will be associated with this school's programs");
  1150. htmlString = "<h5>The following criteria and objectives will be matched with all programs</h5>"
  1151. htmlString += "<ol style='list-style-position: inside'>"
  1152. $('tbody tr').each(function( index )
  1153. {
  1154. objectives = $(this).data('assoc-objectives');
  1155. htmlString += "<li>" +$(this).data('criterion-name');
  1156. htmlString += "<br><h5>This criterion is associated with these objectives</h5>"
  1157. htmlString +="<ul style='padding-left: 5%; list-style-position: inside'>"
  1158. for(index in objectives){
  1159. objective_string = objectives[index];
  1160. htmlString +="<li>"+objective_string+"</li>";
  1161. }
  1162. htmlString += "</ul>"
  1163. htmlString +="</li>"
  1164. htmlString+= "<br>";
  1165. });
  1166. htmlString +='</ol>';
  1167. $("#modal-body-rubric").html(htmlString);
  1168. }
  1169. else{
  1170. $('#modal-title-rubric').html('Some criteria will be associated with this program');
  1171. $('tbody tr').each(function( index )
  1172. {
  1173. htmlString = '';
  1174. console.log($(this));
  1175. if(typeof $(this).data('program_ids')!== 'undefined')
  1176. {
  1177. program_ids = $(this).data('program_ids');
  1178. console.log("ids"+program_ids);
  1179. console.log("ids"+$(this).data('program_ids'));
  1180. }
  1181. else if(typeof $(this).data('program-ids')!== 'undefined')
  1182. {
  1183. program_ids = $(this).data('program-ids')
  1184. console.log("Ids"+program_ids);
  1185. }
  1186. else
  1187. {
  1188. program_ids = [];
  1189. console.log(" "+program_ids);
  1190. }
  1191. console.log(program_ids);
  1192. // program_ids = $(this).data('program_ids')
  1193. if(!program_ids.includes(program_id) ){
  1194. title = "<h6>The following criteria and objectives will be matched with this program</h6>"
  1195. htmlString += "<ol style='list-style-position: inside'>"
  1196. objectives = $(this).data('assoc-objectives');
  1197. //objectives = objectives.split(',');
  1198. htmlString += "<li>" +$(this).data('criterion-name');
  1199. htmlString += "<br><h6>This criterion is associated with these objectives</h6>"
  1200. htmlString +="<ul style='padding-left: 5%; list-style-position: inside'>"
  1201. for(index in objectives){
  1202. objective_string = objectives[index];
  1203. htmlString +="<li>"+objective_string+"</li>";
  1204. }
  1205. htmlString += "</ul>"
  1206. htmlString +="</li>"
  1207. htmlString+= "<br>";
  1208. }
  1209. if(htmlString != ''){
  1210. $("#modal-body-rubric").html(title);
  1211. $("#modal-body-rubric").append(htmlString);
  1212. }
  1213. });
  1214. }
  1215. $('#rubric-modal').modal('toggle');
  1216. $('#saveButton').data('button-id',$(this).attr('id'));
  1217. });
  1218. // When the confirm delete button is clicked
  1219. $('#button-delete-rubric').on('click', function(e)
  1220. {
  1221. $('#modal-confirm-delete').modal('hide');
  1222. // Delete from database
  1223. $.post
  1224. (
  1225. "{{ URL::to('deleteTemplate') }}",
  1226. {
  1227. id: $('#select-template').find(':selected').data('template-id')
  1228. },
  1229. function(data)
  1230. {
  1231. location.reload();
  1232. }
  1233. );
  1234. });
  1235. // Remove a criterion and hide the table if it was the only one
  1236. $('table').on('click', 'span.glyphicon-remove', function(e)
  1237. {
  1238. $(this).closest('tr').remove();
  1239. if(!$('tbody').children().length)
  1240. {
  1241. $('#rubric-container').hide();
  1242. }
  1243. buildCopyrightList();
  1244. });
  1245. // When print button is clicked, redirect to print page
  1246. $('#button-print-rubric').on('click', function(e)
  1247. {
  1248. e.preventDefault();
  1249. window.location = "printRubric/"+$('#select-template').find(':selected').data('template-id');
  1250. });
  1251. // --------------------------------------------------------------------------
  1252. // Page load
  1253. // --------------------------------------------------------------------------
  1254. $('#updated-text').hide();
  1255. // Enable/disable program selection depending on school selection if user is
  1256. // admin
  1257. if({{Auth::user()->role}}==1)
  1258. toggleProgramSelect($('#select-school'));
  1259. // Fetch criteria of first outcome
  1260. fetchCriteria($('#select-outcome'), $('#select-objective'));
  1261. changeTable();
  1262. // Hide table
  1263. $('#rubric-container').hide();
  1264. // Disable Update and Delete Buttons by default
  1265. $('#button-confirm-update-rubric').prop('disabled', true);
  1266. $('#button-confirm-delete-rubric').prop('disabled', true);
  1267. $('#button-print-rubric').prop('disabled', true);
  1268. // Sortable rows
  1269. $('.table').sortable({
  1270. handle: 'span.glyphicon.glyphicon-move',
  1271. containerSelector: 'table',
  1272. itemPath: '> tbody',
  1273. itemSelector: 'tr',
  1274. placeholder: '<tr class="placeholder"><th><span class="glyphicon glyphicon-arrow-right"></span></th></tr>'
  1275. });
  1276. @stop