Parcourir la source

final de features

Gabriel Santiago Plaza il y a 2 ans
Parent
révision
4331c0a5d8

+ 57
- 0
app/controllers/ThreeYearPlanController.php Voir le fichier

@@ -1099,4 +1099,61 @@ class ThreeYearPlanController extends \BaseController
1099 1099
     }
1100 1100
     return 200;
1101 1101
   }
1102
+
1103
+  public function pairEveryCourse()
1104
+  {
1105
+    Log::info(Input::all());
1106
+    $typ_id = Input::get('typ_id');
1107
+    $program_id = Input::get('program_id');
1108
+    $pairing_array = Input::get('pairing_array');
1109
+    $type_of_work = Input::get("type_of_work");
1110
+
1111
+    //$typ_id = Input::get('typ_id');
1112
+    //$outcome_id = Input::get('outcome_id');
1113
+    //$semester_id = Input::get('semester_id');
1114
+    //$objective_id = Input::get('objective_id');
1115
+    //$previous_course_id = Input::get('previous_course_id');
1116
+    //$new_course_id = Input::get('new_course_id');
1117
+
1118
+    // get program_id
1119
+    //$program_id = Input::get('program_id');
1120
+
1121
+
1122
+    if ($type_of_work == 'este_semestre') {
1123
+      foreach ($pairing_array as $course_array) {
1124
+        Input::replace([
1125
+          'outcome_id' => $course_array[0],
1126
+          'semester_id' => $course_array[1],
1127
+          'objective_id' => $course_array[2],
1128
+          'new_course_id' => $course_array[3],
1129
+          'typ_id' => $typ_id,
1130
+          'previous_course_id' => 'nothing_selected',
1131
+          'program_id' => $program_id,
1132
+
1133
+
1134
+        ]);
1135
+        if ($this->section3_on_change() != 'update succes?')
1136
+          return 0;
1137
+      }
1138
+    } else {
1139
+      foreach ($pairing_array as $semester_array) {
1140
+        foreach ($semester_array as $course_array) {
1141
+          Input::replace([
1142
+            'outcome_id' => $course_array[0],
1143
+            'semester_id' => $course_array[1],
1144
+            'objective_id' => $course_array[2],
1145
+            'new_course_id' => $course_array[3],
1146
+            'typ_id' => $typ_id,
1147
+            'previous_course_id' => 'nothing_selected',
1148
+            'program_id' => $program_id,
1149
+
1150
+
1151
+          ]);
1152
+          if ($this->section3_on_change() != 'update succes?')
1153
+            return 0;
1154
+        }
1155
+      }
1156
+    }
1157
+    return 200;
1158
+  }
1102 1159
 }

+ 1
- 0
app/routes.php Voir le fichier

@@ -254,6 +254,7 @@ Route::group(array('before' => 'auth|has_access'), function () {
254 254
 
255 255
 
256 256
     Route::post('pairEveryObjective', "ThreeYearPlanController@pairEveryObjective");
257
+    Route::post('pairEveryCourse', "ThreeYearPlanController@pairEveryCourse");
257 258
     //View annual plans and report
258 259
 
259 260
     Route::get('{annual_report_or_plan}/show/{program_id}', "AnnualPlansController@annualPlansShow");

+ 115
- 9
app/views/global/view-three-year-plan.blade.php Voir le fichier

@@ -354,11 +354,80 @@
354 354
 
355 355
     <script>
356 356
 
357
+        function fetchPairingArraysForCourses(select_semester_selector, out_sem_obj_course_array, course_ids, outcome_id){
358
+
359
+            dict_to_send = {};
360
+            //always the same
361
+            
362
+
363
+            
364
+
365
+            dict_to_send['este_semestre']=  returnArrayReadyPerSelector(select_semester_selector, outcome_id, course_ids);
366
+
367
+            //array_por_semestre = [];
368
+            dict_to_send['por_semestre'] =[];
369
+
370
+
371
+            select_semester_selector.parent().children('.semester-course-selection').each(function(ind, div){
372
+                dict_to_send['por_semestre'].push(returnArrayReadyPerSelector(div, outcome_id, course_ids));
373
+            });
374
+
375
+            //dict_to_send['por_semestre'] = array_por_semestre;
376
+            return JSON.stringify(dict_to_send) ;
377
+
378
+        }
379
+        function returnArrayReadyPerSelector(selector, outcome_id, course_ids){
380
+                array_to_return =[];
381
+                semester_id = $(selector).data('semester-id');
382
+                $(selector).children("div.select-course-selection").each(function(ind, div){
383
+                    var objective_id = $(div).data('objective-id');
384
+                    $.each(course_ids, function(ind, course_id){
385
+                        array_to_return.push([outcome_id,semester_id,objective_id, course_id ])
386
+                    })
387
+                });
388
+            
389
+                return array_to_return;
390
+            }
391
+  
392
+        
393
+
357 394
         function showParingObjectiveModal(button){
358 395
             modal = "#pairingModal"
359 396
 
360 397
             
361 398
 
399
+ 
400
+            is_obj = false;
401
+            if($(button).html()=="Copy Courses to each Objective"){
402
+                $(modal+'Title').html("Would you like to pair these Courses to each Objective in this Outcome");
403
+                $(modal+'Body').html(
404
+                "<label> Please select if you would like to pair these courses on this semester only or on each semester of this Outcome</label>"
405
+                );
406
+                select_semester = $("<select>",{
407
+                    'class':'selectpicker form-control',
408
+                    'id':'selectPorSemestre'
409
+                });
410
+                option = $("<option>", {
411
+                    'value': 'por_semestre'
412
+                }).html("For each Semester and Objective in this Outcome")
413
+
414
+                select_semester.append(option);
415
+                option = $("<option>", {
416
+                    'value': 'este_semestre'
417
+                }).html("For each Objective in this Semester and Outcome");
418
+                select_semester.append(option);
419
+                
420
+                $(modal+'Body').append(select_semester);
421
+                $('.selectpicker').selectpicker('refresh');
422
+               
423
+                }
424
+            else{
425
+                $(modal+'Title').html("Would you like to pair these Objective to each Semester in this Outcome");
426
+                $(modal+'Body').html("This action will pair these Objectives to each Semester of this Outcome.<br> This action is reversable")
427
+
428
+                is_obj = true;
429
+
430
+            }
362 431
             select_course_selector = $(button).parent().parent().parent();
363 432
             objective_selectors= select_course_selector.find("div:not([style*='display: none'])");
364 433
             selects = objective_selectors.find('select');
@@ -369,34 +438,50 @@
369 438
             var semester_id;
370 439
             var outcome_id;
371 440
             var objectives_ids = [];
441
+            var course_ids = [];
372 442
             $.each(selects, function(ind, select){
373 443
                 splited = $(select).val().split('-');
374 444
                 semester_id = splited[1];
375 445
                 outcome_id = splited[0];
376 446
                 objectives_ids.push(splited[2]);
447
+                if(!is_obj){
448
+                    course_ids.push(splited[3]);
449
+                }
450
+
377 451
                 array_to_send.push(splited);
378 452
             })
379 453
 
380
-            whole_outcome_div = select_course_selector.parent().parent();
454
+            if(!is_obj){
455
+
456
+                two_possible_arrays = fetchPairingArraysForCourses(select_course_selector.parent(), array_to_send, course_ids, outcome_id);
457
+
458
+
459
+            }
460
+
461
+            else{
462
+                whole_outcome_div = select_course_selector.parent().parent();
381 463
             whole_outcome_div.children('div.semester-course-selection').each(function(ind, div){
382 464
                 if($(div).data('semester-id')== semester_id){
383 465
                     return;
384 466
                 }
385
-                div_semester = $(div).data('semester-id');
467
+                
468
+                    div_semester = $(div).data('semester-id');
386 469
                 $.each(objectives_ids, function(ind, obj){
387 470
                     array_to_send.push([outcome_id, div_semester, obj]);
388 471
                 })
472
+                
473
+                
389 474
             })
390 475
 
476
+            }
477
+
391 478
             if($(button).html()=="Copy Courses to each Objective"){
392
-                $(modal+'Title').html("Would you like to pair these Courses to each Objective in this Outcome");
393
-                $(modal+'Body').html("This action will pair each Course in each Objective and each Semester of this Outcome.<br> This action is reversable")
394
-                $(modal+"SubmitButton").attr('onclick', 'pairEveryCourse(['+array_to_send.toString()+'])')
479
+                $(modal+"SubmitButton").attr('onclick', 'pairEveryCourse('+two_possible_arrays+')');
480
+       
395 481
             }
396 482
             else{
397
-                $(modal+'Title').html("Would you like to pair these Objective to each Semester in this Outcome");
398
-                $(modal+'Body').html("This action will pair each Objective on each Semester of this Outcome.<br> This action is reversable")
399 483
                 $(modal+"SubmitButton").attr('onclick', 'pairEveryObjective(['+array_to_send.toString()+'])')
484
+       
400 485
             }
401 486
 
402 487
             
@@ -405,6 +490,26 @@
405 490
             $(modal).modal('show');
406 491
 
407 492
         }
493
+
494
+        function pairEveryCourse(two_possible_arrays){
495
+           // two_possible_arrays = JSON.parse(two_possible_arrays);
496
+
497
+            pair_array = two_possible_arrays[$('#selectPorSemestre').val()];
498
+
499
+            var typ_id = $('#table-cycles').data('typ-id');
500
+            $.post(
501
+                "{{URL::action('ThreeYearPlanController@pairEveryCourse')}}", {
502
+                    pairing_array:pair_array,
503
+                    typ_id:typ_id,
504
+                    program_id:{{$program_id}},
505
+                    type_of_work: $('#selectPorSemestre').val()
506
+                },
507
+                function(data){
508
+                    if(data==200)
509
+                    $(".go-to-3").trigger('click');
510
+                }
511
+            )
512
+        }
408 513
         function pairEveryObjective(selected_objectives){
409 514
 
410 515
             var typ_id = $('#table-cycles').data('typ-id');
@@ -906,7 +1011,7 @@
906 1011
 
907 1012
         // in section 2 and 3, add selects for choosing more objectives and courses, respectively
908 1013
         $('.add-objective-course').on('click', function(e) {
909
-            var new_select = $(this).parent().parent().find('.objective-selector-0').clone(true);
1014
+            var new_select = $(this).parent().parent().parent().find('.objective-selector-0').clone(true);
910 1015
             new_select.attr('class', 'objective-selector');
911 1016
             new_select.show();
912 1017
             $(this).parent().before(new_select);
@@ -916,7 +1021,7 @@
916 1021
 
917 1022
         // go to section 3
918 1023
         $('.go-to-3').on('click', function(e) {
919
-            window.scrollTo(0, 0);
1024
+            //window.scrollTo(0, 0);
920 1025
             $(".panel-body").hide();;
921 1026
             $("#section3").show();;
922 1027
 
@@ -965,6 +1070,7 @@
965 1070
                                 var new_select = select_area.find(
966 1071
                                     '.select-course-selection-0').clone(true);
967 1072
                                 new_select.attr('class', 'select-course-selection');
1073
+                                new_select.attr('data-objective-id', objective_id);
968 1074
                                 new_select.find('label').html('');
969 1075
                                 new_select.find('.objective-selector-0').before(
970 1076
                                     '<p>Objective: <b>' + objective_text +