No Description

rubrics_new.blade.php 56KB

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