Gabriel Santiago Plaza 3 роки тому
джерело
коміт
79789abf3a

+ 14
- 12
app/controllers/ActivitiesController.php Переглянути файл

@@ -513,18 +513,19 @@ class ActivitiesController extends \BaseController
513 513
                 DB::table('activities')
514 514
                     ->where('id', Input::get('id'))
515 515
                     ->update(array(
516
-                        'draft' => 0,
517
-                        'outcomes_attempted' => NULL,
518
-                        'outcomes_achieved' => NULL,
519
-                        'criteria_achieved' => NULL,
520
-                        'transforming_actions' => NULL,
516
+                        'draft' => 1,
521 517
                         'assessment_comments' => NULL,
522
-                        'criteria_achieved_percentage' => NULL,
518
+
519
+
520
+
523 521
                         'updated_at' => date('Y-m-d H:i:s')
524 522
                     ));
525 523
 
526 524
                 // Delete students score
527
-                DB::table('assessments')->where('activity_id', $activity->id)->delete();
525
+
526
+                DB::table('assessments')
527
+                    ->join('activity_criterion', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
528
+                    ->where('activity_id', $activity->id)->delete();
528 529
 
529 530
                 // Recalculate course outcomes
530 531
                 /*$activities = DB::table('activities')
@@ -615,7 +616,7 @@ class ActivitiesController extends \BaseController
615 616
 
616 617
         if (Activity::destroy($id)) {
617 618
             // Recalculate course outcomes
618
-            $activities = $course->activities;
619
+            /*$activities = $course->activities;
619 620
 
620 621
             // Check if any assessed activties remain
621 622
             $remainingAssessed = false;
@@ -664,17 +665,18 @@ class ActivitiesController extends \BaseController
664 665
             } else {
665 666
                 $course->outcomes_achieved = NULL;
666 667
                 $course->outcomes_attempted = NULL;
667
-            }
668
+            } */
668 669
 
669
-            if ($course->save()) {
670
+            /*if ($course->save()) {
670 671
                 Session::flash('status', 'success');
671 672
                 Session::flash('message', 'Activity deleted.');
672 673
             } else {
673 674
                 Session::flash('status', 'danger');
674 675
                 Session::flash('message', 'Error deleting activity. Try again later.');
675 676
                 return Redirect::back();
676
-            }
677
-
677
+            }*/
678
+            Session::flash('status', 'success');
679
+            Session::flash('message', 'Activity deleted.');
678 680
             return Redirect::action('CoursesController@show', array($course->id));
679 681
         } else {
680 682
             Session::flash('status', 'danger');

+ 3
- 1
app/controllers/CriteriaController.php Переглянути файл

@@ -161,16 +161,18 @@ class CriteriaController extends \BaseController
161 161
         }*/
162 162
 
163 163
         $criterion =  DB::table('criteria')->where('id', Input::get('id'))->first();
164
+        if (!$criterion) return $criterion;
164 165
         $criterion->outcomes = DB::table('criterion_objective_outcome')
165 166
             ->join('outcomes', 'outcomes.id', '=', 'criterion_objective_outcome.outcome_id')
166 167
             ->where('criterion_id', $criterion->id)
168
+            ->select('outcomes.*')
167 169
             ->distinct()
168 170
             ->get();
169 171
 
170 172
         foreach ($criterion->outcomes as $outcome) {
171 173
             $outcome->assoc_objectives = DB::table('objective_outcome')
172 174
                 ->join('objectives', 'objectives.id', '=', 'objective_outcome.objective_id')
173
-                ->where('outcome_id', $outcome->outcome_id)
175
+                ->where('outcome_id', $outcome->id)
174 176
                 ->get();
175 177
             $outcome->objectives_criteria = DB::table('criterion_objective_outcome')
176 178
                 ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')

+ 2
- 0
app/controllers/ObjectivesController.php Переглянути файл

@@ -243,6 +243,8 @@ class ObjectivesController extends \BaseController
243 243
 
244 244
     $criteria_scales = DB::table('criteria')
245 245
       ->join('criterion_objective_outcome as cobo', 'criterion_id', '=', 'criteria.id')
246
+      ->join('program_criterion', 'cobo.criterion_id', '=', 'program_criterion.criterion_id')
247
+      ->whereIn('program_id', $program_ids)
246 248
       ->where('objective_id', $objective->id)
247 249
       ->select('num_scales')
248 250
       ->orderBy('num_scales', 'DESC')

+ 79
- 4
app/controllers/OutcomesController.php Переглянути файл

@@ -410,7 +410,7 @@ class OutcomesController extends \BaseController
410 410
         if (Input::get('filter')) {
411 411
             switch (Input::get('filter')) {
412 412
                 case 'all':
413
-                    return DB::table('criteria')
413
+                    $criteria = DB::table('criteria')
414 414
                         ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
415 415
                         ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
416 416
                         ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
@@ -419,6 +419,19 @@ class OutcomesController extends \BaseController
419 419
                         ->select('criterion_id as id', 'name')
420 420
                         ->orderBy('name', 'ASC')
421 421
                         ->get();
422
+
423
+                    foreach ($criteria as $criterion) {
424
+                        $criterion->program_ids = json_encode(DB::table('program_criterion')
425
+                            ->where('criterion_id', $criterion->id)
426
+                            ->lists('program_id'));
427
+                        $criterion->objectives = json_encode(DB::table('criterion_objective_outcome')
428
+                            ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
429
+                            ->where('criterion_id', $criterion->id)
430
+                            ->select('objectives.*')
431
+                            ->distinct()
432
+                            ->lists('text'));
433
+                    }
434
+                    return $criteria;
422 435
                     break;
423 436
 
424 437
                 case 'school':
@@ -438,6 +451,17 @@ class OutcomesController extends \BaseController
438 451
                             ->select('criterion_id as id', 'name')
439 452
                             ->orderBy('name', 'ASC')
440 453
                             ->get();
454
+                        foreach ($criteria as $criterion) {
455
+                            $criterion->program_ids = json_encode(DB::table('program_criterion')
456
+                                ->where('criterion_id', $criterion->id)
457
+                                ->lists('program_id'));
458
+                            $criterion->objectives = json_encode(DB::table('criterion_objective_outcome')
459
+                                ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
460
+                                ->where('criterion_id', $criterion->id)
461
+                                ->select('objectives.*')
462
+                                ->distinct()
463
+                                ->lists('text'));
464
+                        }
441 465
                         // Return all criteria belonging to any of those programs
442 466
                         return $criteria;
443 467
                     }
@@ -446,9 +470,10 @@ class OutcomesController extends \BaseController
446 470
                     else {
447 471
 
448 472
                         // Fetch all the programs from the user's school;
473
+                        // Fetch all the programs from the user's school;
449 474
                         $program_ids = DB::table('programs')->where('school_id', Auth::user()->programs[0]->school->id)->lists('id');
450 475
 
451
-                        return DB::table('criteria')
476
+                        $criteria = DB::table('criteria')
452 477
                             ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
453 478
                             ->join('program_criterion', 'program_criterion.criterion_id', '=', 'criteria.id')
454 479
                             ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
@@ -459,6 +484,19 @@ class OutcomesController extends \BaseController
459 484
                             ->select('criterion_id as id', 'name')
460 485
                             ->orderBy('name', 'ASC')
461 486
                             ->get();
487
+
488
+                        foreach ($criteria as $criterion) {
489
+                            $criterion->program_ids = json_encode(DB::table('program_criterion')
490
+                                ->where('criterion_id', $criterion->id)
491
+                                ->lists('program_id'));
492
+                            $criterion->objectives = json_encode(DB::table('criterion_objective_outcome')
493
+                                ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
494
+                                ->where('criterion_id', $criterion->id)
495
+                                ->select('objectives.*')
496
+                                ->distinct()
497
+                                ->lists('text'));
498
+                        }
499
+                        return $criteria;
462 500
                     }
463 501
 
464 502
                     break;
@@ -475,11 +513,22 @@ class OutcomesController extends \BaseController
475 513
                         ->select('criterion_id as id', 'name')
476 514
                         ->orderBy('name', 'ASC')
477 515
                         ->get();
516
+                    foreach ($criteria as $criterion) {
517
+                        $criterion->program_ids = json_encode(DB::table('program_criterion')
518
+                            ->where('criterion_id', $criterion->id)
519
+                            ->lists('program_id'));
520
+                        $criterion->objectives = json_encode(DB::table('criterion_objective_outcome')
521
+                            ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
522
+                            ->where('criterion_id', $criterion->id)
523
+                            ->select('objectives.*')
524
+                            ->distinct()
525
+                            ->lists('text'));
526
+                    }
478 527
                     return $criteria;
479 528
                     break;
480 529
 
481 530
                 default:
482
-                    return DB::table('criteria')
531
+                    $criteria = DB::table('criteria')
483 532
                         ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
484 533
                         ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
485 534
                         ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
@@ -488,10 +537,23 @@ class OutcomesController extends \BaseController
488 537
                         ->select('criterion_id as id', 'name')
489 538
                         ->orderBy('name', 'ASC')
490 539
                         ->get();
540
+
541
+                    foreach ($criteria as $criterion) {
542
+                        $criterion->program_ids = json_encode(DB::table('program_criterion')
543
+                            ->where('criterion_id', $criterion->id)
544
+                            ->lists('program_id'));
545
+                        $criterion->objectives = json_encode(DB::table('criterion_objective_outcome')
546
+                            ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
547
+                            ->where('criterion_id', $criterion->id)
548
+                            ->select('objectives.*')
549
+                            ->distinct()
550
+                            ->lists('text'));
551
+                    }
552
+                    return $criteria;
491 553
                     break;
492 554
             }
493 555
         } else {
494
-            return DB::table('criteria')
556
+            $criteria = DB::table('criteria')
495 557
                 ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
496 558
                 ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
497 559
                 ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
@@ -500,6 +562,19 @@ class OutcomesController extends \BaseController
500 562
                 ->select('criterion_id as id', 'name')
501 563
                 ->orderBy('name', 'ASC')
502 564
                 ->get();
565
+
566
+            foreach ($criteria as $criterion) {
567
+                $criterion->program_ids = json_encode(DB::table('program_criterion')
568
+                    ->where('criterion_id', $criterion->id)
569
+                    ->lists('program_id'));
570
+                $criterion->objectives = json_encode(DB::table('criterion_objective_outcome')
571
+                    ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
572
+                    ->where('criterion_id', $criterion->id)
573
+                    ->select('objectives.*')
574
+                    ->distinct()
575
+                    ->lists('text'));
576
+            }
577
+            return $criteria;
503 578
         }
504 579
     }
505 580
 

+ 96
- 77
app/views/local/managers/admins/criteria.blade.php Переглянути файл

@@ -119,7 +119,7 @@
119 119
                 Edit
120 120
             </div>
121 121
             <div class="panel-body">
122
-                {{ Form::open(array('action' => 'CriteriaController@update')) }}
122
+                {{ Form::open(array('action' => 'CriteriaController@update','id'=>'update_criterion')) }}
123 123
                 <button class="btn btn-md btn-secondary filterButton">
124 124
                     <span class="glyphicon glyphicon-plus">
125 125
                     </span>
@@ -163,7 +163,7 @@
163 163
                     <div id='assocOutcomeGroup0' data-value="1">
164 164
                         <div class="form-group col-md-12">
165 165
                             <label>Outcome 1</label>
166
-                            {{ Form::select('outcome[]', $outcomes, null, ['class'=>'form-control selectpicker', 'id'=>'assoc_outcome_0', 'onchange'=>'fetchAssocObjective("assoc_outcome_0")']) }}
166
+                            {{ Form::select('outcome[]', $outcomes, null, ['class'=>'form-control selectpicker', 'id'=>'assoc_outcome_0', 'onchange'=>'fetchObjectiveForSelect("assoc_outcome_0", "assoc_objectiveGroupFor0")']) }}
167 167
     
168 168
                         </div>
169 169
     <div id='assoc_objectiveGroupFor0' data-value="1">
@@ -549,8 +549,8 @@ function addOutcomeTest() {
549 549
         $div.remove();
550 550
         $div = document.getElementById(closeObj);
551 551
         $div.remove();
552
-        //counter = parseInt($('#'+objectiveGroup).data("value"));
553
-        //$('#'+objectiveGroup).data("value", counter-1);
552
+        counter = parseInt($('#'+objectiveGroup).data("value"));
553
+        $('#'+objectiveGroup).data("value", counter-1);
554 554
 
555 555
 
556 556
     }
@@ -653,7 +653,7 @@ function addOutcomeTest() {
653 653
             'name': "outcome[]",
654 654
             'data-live-search': 'true',
655 655
             'id': 'assoc_outcome_' + assocOutcomeCounter.toString(),
656
-            'onchange': 'fetchAssocObjective("assoc_outcome_' + assocOutcomeCounter.toString() + '", "assoc_objectiveGroupFor'+assocOutcomeCounter+'")'
656
+            'onchange': 'fetchObjectiveForSelect("assoc_outcome_' + assocOutcomeCounter.toString() + '", "assoc_objectiveGroupFor'+assocOutcomeCounter+'")'
657 657
 
658 658
         });
659 659
         var $div = $('<div/>', {
@@ -763,7 +763,7 @@ function addOutcomeTest() {
763 763
                 allOutcomes: allOutcomes
764 764
             },
765 765
 
766
-            function(json) {
766
+            function(varArray) {
767 767
 
768 768
                 optionName = '<option value ="0">Nothing Selected</option>';
769 769
                 for(outcome in varArray.outcomes){
@@ -789,16 +789,16 @@ function addOutcomeTest() {
789 789
                 }
790 790
 
791 791
                 for (var i = allObjectives.length - 1; i > 0; i--) {
792
-                    deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString(), 'assoc_objectiveGroup');
793
-                }
794
-                for(var i=1; i<allObjectives.length; i++){
792
+                    deleteObjective('assoc_objectiveForm_' + objectiveGroup +'_'+i, 'assoc_closeObj_'+objectiveGroup+'_' + i.toString(), objectiveGroup);
793
+               }
794
+               /* for(var i=1; i<allObjectives.length; i++){
795 795
                     addAssocObjective();
796 796
                     $('#assoc_objective_'+i.toString()).selectpicker('refresh');
797 797
                     if($("#assoc_objective_"+i.toString()+" option[value='"+allObjectives[i].value+"']").length>0){
798 798
                     $("#assoc_objective_"+i.toString()).val(allObjectives[i].value);
799 799
                     $("#assoc_objective_"+i.toString()).selectpicker("refresh");
800 800
                     }
801
-                }
801
+                }*/
802 802
 
803 803
 
804 804
 
@@ -935,10 +935,25 @@ function addOutcomeTest() {
935 935
             "{{ URL::action('CriteriaController@fetchCriterionWithTrashed') }}", {
936 936
                 id: id
937 937
             },
938
-            function(json) {
938
+            function(criterion) {
939
+
940
+                
941
+if (!(criterion.length)) {
942
+    name = ' ';
943
+    var subcriteria = '';
944
+    copyright = null;
945
+    notes = null;
946
+    $('#status').val(0);
947
+    maximum = 1;
948
+    $('#assoc_maximum_score').val(1);
939 949
 
940
-                if (!(json.activity_criterion.length)) {
941 950
 
951
+}
952
+
953
+
954
+else { 
955
+criterion = criterion[0];
956
+if (!(criterion.activity_criterion.length)) {
942 957
 $('#DeleteButton').prop('disabled', false);
943 958
 $("#update_the_criterion").val('Update');
944 959
 $("#update_criterion").attr('action', "{{ URL::action('CriteriaController@update')}}")
@@ -952,48 +967,38 @@ $('#alert_placeholder').html('<div class="alert alert-danger alert-dismissible"
952 967
 
953 968
 }
954 969
 
955
-                if (!(json.criteria.length)) {
956
-                    name = ' ';
957
-                    var subcriteria = '';
958
-                    copyright = null;
959
-                    notes = null;
960
-                    $('#status').val(0);
961
-                    maximum = 1;
962
-                    $('#assoc_maximum_score').val(1);
963
-
964
-
965
-                } else {
966
-                    var name = json.criteria[0].name;
967
-                    if (json.criteria[0].subcriteria) {
968
-                        subcriteria = JSON.parse(json.criteria[0].subcriteria).join('\n');
969
-                    } else {
970
+              
971
+var name = criterion.name;
972
+                    if (criterion.subcriteria) {
973
+                        subcriteria = JSON.parse(criterion.subcriteria).join('\n');
974
+ } else {
970 975
                         subcriteria = "";
971 976
                     }
972
-                    if (json.criteria[0].copyright) {
973
-                        var copyright = json.criteria[0].copyright;
977
+                    if (criterion.copyright) {
978
+                        var copyright = criterion.copyright;
974 979
                     } else {
975 980
                         var copyright = ''
976 981
                     }
977
-                    if (json.criteria[0].notes) notes = json.criteria[0].notes;
978
-                    else notes = '';
982
+                    if (criterion.notes) notes = criterion.notes;
983
+                   else notes = '';
979 984
 
980 985
                     // Display info
981 986
                     $('#criterion_name').val(name);
982 987
                     $('#criterion_subcriteria').text(subcriteria);
983
-                    if (json.criteria[0].deleted_at)
984
-                        $('#status').val(0);
988
+                    if (criterion.deleted_at)
989
+                       $('#status').val(0);
985 990
                     else
986 991
                         $('#status').val(1);
987
-                    $('#assoc_maximum_score').val(json.criteria[0].maximum_score);
988
-                    var maximum = json.criteria[0].maximum_score;
992
+                        $('#assoc_maximum_score').val(criterion.max_score);
993
+                    var maximum = criterion.max_score;
989 994
 
990 995
                     addOptions("Num_assoc_scale", "assoc_maximum_score", "Assoc_Scales");
991
-                    $('#Num_assoc_scale').val(json.criteria[0].num_scales)
992
-                    $('#Num_assoc_scale').selectpicker('refresh');
996
+                    $('#Num_assoc_scale').val(criterion.num_scales)
997
+                   $('#Num_assoc_scale').selectpicker('refresh');
993 998
                     $('#Num_assoc_scale').trigger('change');
994 999
 
995
-                    for(i=0; i<json.criteria[0].num_scales;i++){
996
-                        $('#assoc_scale_'+i).val(json.scales[i].description);
1000
+                    for(i=0; i<criterion.num_scales;i++){
1001
+                        $('#assoc_scale_'+i).val(criterion.scales[i].description);
997 1002
                     }
998 1003
                     // If copyright or notes aren't empty, load them
999 1004
 
@@ -1014,8 +1019,8 @@ $('#alert_placeholder').html('<div class="alert alert-danger alert-dismissible"
1014 1019
 
1015 1020
                 // Select associated outcome
1016 1021
                 try {
1017
-                    assocOutcomeCounter= parseInt($("#assocOutcomeGroup0").data('value'));
1018
-                    for (var i = assocOutcomeCounter - 1; i > 0; i--) {
1022
+                    assocOutcomeCounter = parseInt($("#assocOutcomeGroup0").data('value'));
1023
+                   for (var i = assocOutcomeCounter - 1; i > 0; i--) {
1019 1024
                         $('#assoc_close_button'+i).click();
1020 1025
                                }
1021 1026
                     $('#assocOutcomeGroup0').data('value', 1); 
@@ -1023,36 +1028,45 @@ $('#alert_placeholder').html('<div class="alert alert-danger alert-dismissible"
1023 1028
                     var Notran = true;
1024 1029
                 }
1025 1030
 
1026
-                if (json.outcomes.length) 
1031
+                if (criterion.outcomes.length) 
1027 1032
                     {
1028
-                    $('#assoc_outcome_0').val(json.outcomes[0].id);
1029
-                    $('#assoc_outcome_0').selectpicker('refresh');
1033
+                    $('#assoc_outcome_0').val(criterion.outcomes[0].id);
1034
+                     $('#assoc_outcome_0').selectpicker('refresh');
1030 1035
 
1031
-                    var first_outcome_id = json.outcomes[0].id;
1036
+                     var first_outcome = criterion.outcomes[0];
1032 1037
                     options = "<option value ='0'>Nothing Selected</option>";
1038
+                    $(first_outcome.assoc_objectives).each(function(index, objective){
1033 1039
 
1034
-                    for(objective_index  in json.objectives_assoc[first_outcome_id]){
1040
+options += '<option value ="('+first_outcome.id+','+objective.objective_id+')">'+
1041
+    objective.text+'</option>';
1042
+
1043
+})
1044
+                    /*for(objective_index  in json.objectives_assoc[first_outcome_id]){
1035 1045
                         objective = json.objectives_assoc[first_outcome_id][objective_index]
1036 1046
                         options += '<option value ="('+first_outcome_id+','+objective.objective_id+')">'+
1037 1047
                             objective.text+'</option>';
1038
-                    }
1048
+                    }*/
1039 1049
                     $('#assoc_objective_0_counter_1').html(options);
1040 1050
                     $('#assoc_objective_0_counter_1').selectpicker('refresh');
1041 1051
                     
1042
-                    if(json.objectives[first_outcome_id].length){
1043
-                        objective_id = json.objectives[first_outcome_id][0].objective_id;
1044
-                    value = '('+first_outcome_id+','+objective_id+')';
1052
+                    if(first_outcome.objectives_criteria.length){
1053
+                        objective_id = first_outcome.objectives_criteria[0].objective_id;
1054
+                    value = '('+first_outcome.id+','+objective_id+')';
1045 1055
                     $('#assoc_objective_0_counter_1').val(value);
1046 1056
                     $('#assoc_objective_0_counter_1').selectpicker('refresh');
1047 1057
 
1048 1058
                     }
1049
-                    
1059
+                    if($("#assoc_objectiveGroupFor0").find(".btn-primary").length>0){
1060
+                        $("#assoc_objectiveGroupFor0").find(".btn-primary").each(function(){
1061
+                            $(this).click()
1062
+                        })
1063
+                    }
1050 1064
 
1051
-                    for(var i =1; i<json.objectives[first_outcome_id].length; i++ ){
1065
+                    for(var i =1; i<first_outcome.objectives_criteria.length; i++ ){
1052 1066
                         addAssocObjective("assoc_objectiveGroupFor0", "assoc_objective_0");
1053
-                        objective_id = json.objectives[first_outcome_id][i].objective_id;
1054
-                        value = "("+first_outcome_id+","+objective_id+")";
1055
-                        $('#assoc_objective_0_counter_'+(i+1)).val(value);
1067
+                        objective_id = first_outcome.objectives_criteria[i].objective_id;
1068
+                        value = "("+first_outcome.id+","+objective_id+")";
1069
+                       $('#assoc_objective_0_counter_'+(i+1)).val(value);
1056 1070
                         $('#assoc_objective_0_counter_'+(i+1)).selectpicker('refresh');
1057 1071
                         
1058 1072
 
@@ -1067,35 +1081,41 @@ $('#alert_placeholder').html('<div class="alert alert-danger alert-dismissible"
1067 1081
 
1068 1082
 
1069 1083
                
1070
-                for (var i = 1; i < json.outcomes.length; i++) {
1084
+                for (var i = 1; i < criterion.outcomes.length; i++) {
1071 1085
                     addAssocOutcome(true);
1072 1086
 
1073 1087
 
1074
-                    $('#assoc_outcome_' + i.toString()).val(json.outcomes[i].id);
1075
-                    $('#assoc_outcome_' + i.toString()).selectpicker('refresh');
1088
+                    $('#assoc_outcome_' + i.toString()).val(criterion.outcomes[i].id);
1089
+                   $('#assoc_outcome_' + i.toString()).selectpicker('refresh');
1076 1090
 
1077
-                    var outcome_id = json.outcomes[i].id;
1078
-                    options = "<option value ='0'>Nothing Selected</option>";
1091
+                   var outcome = criterion.outcomes[i];
1092
+                  options = "<option value ='0'>Nothing Selected</option>";
1079 1093
 
1080
-                    for(objective_index  in json.objectives_assoc[outcome_id]){
1081
-                        objective = json.objectives_assoc[outcome_id][objective_index]
1082
-                        options += '<option value ="('+outcome_id+','+objective.objective_id+')">'+
1083
-                            objective.text+'</option>';
1084
-                    }
1094
+                  $(outcome.assoc_objectives).each(function(index, objective){
1095
+
1096
+options += '<option value ="('+outcome.id+','+objective.objective_id+')">'+
1097
+    objective.text+'</option>';
1098
+
1099
+})
1100
+                    //for(objective_index  in json.objectives_assoc[outcome_id]){
1101
+                    //    objective = json.objectives_assoc[outcome_id][objective_index]
1102
+                    //    options += '<option value ="('+outcome_id+','+objective.objective_id+')">'+
1103
+                    //        objective.text+'</option>';
1104
+                    //}
1085 1105
                     $('#assoc_objective_'+i+'_counter_1').html(options);
1086 1106
                     $('#assoc_objective_'+i+'_counter_1').selectpicker('refresh');
1087
-                    if(json.objectives[outcome_id].length){
1088
-                        objective_id = json.objectives[outcome_id][0].objective_id;
1089
-                        value = "("+outcome_id+","+objective_id+")"
1090
-                    $('#assoc_objective_'+i+'_counter_1').val(value);
1107
+                    if(outcome.objectives_criteria.length){
1108
+                        objective_id = outcome.objectives_criteria[0].objective_id;
1109
+                        value = "("+outcome.id+","+objective_id+")"
1110
+                                       $('#assoc_objective_'+i+'_counter_1').val(value);
1091 1111
                     $('#assoc_objective_'+i+'_counter_1').selectpicker('refresh')
1092 1112
                     }
1093 1113
                     
1094 1114
 
1095
-                    for(var j =1; i<json.objectives[outcome_id].length; i++ ){
1115
+                    for(var j =1; j<outcome.objectives_criteria.length; j++ ){
1096 1116
                         addAssocObjective("assoc_objectiveGroupFor"+i, "assoc_objective_"+i);
1097
-                        objective_id = json.objectives[outcome_id][j].objective_id;
1098
-                        value = "("+outcome_id+","+objective_id+")";
1117
+                        objective_id =outcome.objectives_criteria[j].objective_id;
1118
+                        value = "("+outcome.id+","+objective_id+")";
1099 1119
                         $('#assoc_objective_'+i+'_counter_'+(j+1)).val(value);
1100 1120
                         $('#assoc_objective_'+i+'_counter_'+(j+1)).selectpicker('refresh');
1101 1121
                         
@@ -1169,22 +1189,21 @@ $('#alert_placeholder').html('<div class="alert alert-danger alert-dismissible"
1169 1189
 
1170 1190
 
1171 1191
                 // Select associated program
1172
-                var program_length = json.program.length;
1192
+                var program_length = criterion.program.length;
1173 1193
                 $('input[type=checkbox]').prop('checked', false);
1174 1194
 
1175 1195
                 for (var i = 0; i < program_length; i++) {
1176
-                    $('#assoc_program_id_' + json.program[i].program_id).prop("checked", true);
1196
+                    $('#assoc_program_id_' + criterion.program[i].program_id).prop("checked", true);
1177 1197
                 }
1178 1198
 
1179
-
1180 1199
                 // Select status
1181 1200
 
1182 1201
 
1183 1202
 
1184 1203
 
1185 1204
 
1186
-            },
1187
-            'json'
1205
+            }
1206
+            
1188 1207
         );
1189 1208
     }
1190 1209
 </script>@stop

+ 103
- 75
app/views/local/managers/pCoords/criteria.blade.php Переглянути файл

@@ -36,7 +36,7 @@
36 36
                             </div>
37 37
                         </div>
38 38
                         <input type='hidden' name='counterObjective' id='counterObjective' value=1>
39
-                        <button class='btn btn-md btn-secondary button-add-objective' onclick='addObjectiveTest("objectiveGroupFor0", "objective_0")'>
39
+                        <button  class='btn btn-md btn-secondary button-add-objective' onclick='addObjectiveTest("objectiveGroupFor0", "objective_0")'>
40 40
                             <span class='glyphicon glyphicon-plus'>
41 41
 
42 42
                             </span>
@@ -117,7 +117,7 @@
117 117
                 Edit
118 118
             </div>
119 119
             <div class="panel-body">
120
-                {{ Form::open(array('action' => 'CriteriaController@update', 'id'=>'update_criterion')) }}
120
+                {{ Form::open(array('action' => 'CriteriaController@update','id'=>'update_criterion')) }}
121 121
 
122 122
                 <button class="btn btn-md btn-secondary filterButton">
123 123
                     <span class="glyphicon glyphicon-plus">
@@ -163,8 +163,8 @@
163 163
                     <div id='assocOutcomeGroup0' data-value="1">
164 164
                         <div class="form-group col-md-12">
165 165
                             <label>Outcome 1</label>
166
-                            {{ Form::select('outcome[]', $outcomes, null, ['class'=>'form-control selectpicker', 'id'=>'assoc_outcome_0', 'onchange'=>'fetchAssocObjective("assoc_outcome_0")']) }}
167
-
166
+                            {{ Form::select('outcome[]', $outcomes, null, ['class'=>'form-control selectpicker', 'id'=>'assoc_outcome_0', 'onchange'=>'fetchObjectiveForSelect("assoc_outcome_0", "assoc_objectiveGroupFor0")']) }}
167
+    
168 168
                         </div>
169 169
                         <div id='assoc_objectiveGroupFor0' data-value="1">
170 170
                             <div class="form-group col-md-11">
@@ -547,8 +547,8 @@
547 547
         $div.remove();
548 548
         $div = document.getElementById(closeObj);
549 549
         $div.remove();
550
-        //counter = parseInt($('#'+objectiveGroup).data("value"));
551
-        // $('#'+objectiveGroup).data("value", counter-1);
550
+        counter = parseInt($('#'+objectiveGroup).data("value"));
551
+         $('#'+objectiveGroup).data("value", counter-1);
552 552
 
553 553
 
554 554
     }
@@ -651,7 +651,7 @@
651 651
             'name': "outcome[]",
652 652
             'data-live-search': 'true',
653 653
             'id': 'assoc_outcome_' + assocOutcomeCounter.toString(),
654
-            'onchange': 'fetchAssocObjective("assoc_outcome_' + assocOutcomeCounter.toString() + '", "assoc_objectiveGroupFor' + assocOutcomeCounter + '")'
654
+            'onchange': 'fetchObjectiveForSelect("assoc_outcome_' + assocOutcomeCounter.toString() + '", "assoc_objectiveGroupFor' + assocOutcomeCounter + '")'
655 655
 
656 656
         });
657 657
         var $div = $('<div/>', {
@@ -759,7 +759,7 @@
759 759
                 allOutcomes: allOutcomes
760 760
             },
761 761
 
762
-            function(json) {
762
+            function(varArray) {
763 763
 
764 764
                 optionName = '<option value ="0">Nothing Selected</option>';
765 765
                 for (outcome in varArray.outcomes) {
@@ -785,16 +785,16 @@
785 785
                 }
786 786
 
787 787
                 for (var i = allObjectives.length - 1; i > 0; i--) {
788
-                    deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString(), 'assoc_objectiveGroup');
788
+                    deleteObjective('assoc_objectiveForm_' + objectiveGroup +'_'+i, 'assoc_closeObj_'+objectiveGroup+'_' + i.toString(), objectiveGroup);
789 789
                 }
790
-                for (var i = 1; i < allObjectives.length; i++) {
790
+                /*for (var i = 1; i < allObjectives.length; i++) {
791 791
                     addAssocObjective();
792 792
                     $('#assoc_objective_' + i.toString()).selectpicker('refresh');
793 793
                     if ($("#assoc_objective_" + i.toString() + " option[value='" + allObjectives[i].value + "']").length > 0) {
794 794
                         $("#assoc_objective_" + i.toString()).val(allObjectives[i].value);
795 795
                         $("#assoc_objective_" + i.toString()).selectpicker("refresh");
796 796
                     }
797
-                }
797
+                }*/
798 798
 
799 799
 
800 800
 
@@ -932,9 +932,28 @@
932 932
             "{{ URL::action('CriteriaController@fetchCriterionWithTrashed') }}", {
933 933
                 id: id
934 934
             },
935
-            function(json) {
935
+                function(criterion) {
936
+
937
+                
938
+if (!(criterion.length)) {
939
+    name = ' ';
940
+    var subcriteria = '';
941
+    copyright = null;
942
+    notes = null;
943
+    $('#status').val(0);
944
+    maximum = 1;
945
+    $('#assoc_maximum_score').val(1);
936 946
 
937
-                if (!(json.activity_criterion.length)) {
947
+
948
+}
949
+
950
+
951
+else { 
952
+criterion = criterion[0];
953
+if (!(criterion.activity_criterion.length)) {
954
+
955
+
956
+              
938 957
 
939 958
                     $('#DeleteButton').prop('disabled', false);
940 959
                     $("#update_the_criterion").val('Update');
@@ -947,50 +966,38 @@
947 966
                     $('#alert_placeholder').html('<div class="alert alert-danger alert-dismissible" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button> <strong>Warning!</strong> The criterion is already used in assessments. Editting the criterion will actually create a new criterion </div>');
948 967
 
949 968
                 }
950
-
951
-                if (!(json.criteria.length)) {
952
-                    name = ' ';
953
-                    var subcriteria = '';
954
-                    copyright = null;
955
-                    notes = null;
956
-                    $('#status').val(0);
957
-                    maximum = 1;
958
-                    $('#assoc_maximum_score').val(1);
959
-
960
-
961
-                } else {
962
-                    var name = json.criteria[0].name;
963
-                    if (json.criteria[0].subcriteria) {
964
-                        subcriteria = JSON.parse(json.criteria[0].subcriteria).join('\n');
969
+                var name = criterion.name;
970
+                    if (criterion.subcriteria) {
971
+                        subcriteria = JSON.parse(criterion.subcriteria).join('\n');
965 972
                     } else {
966 973
                         subcriteria = "";
967 974
                     }
968
-                    if (json.criteria[0].copyright) {
969
-                        var copyright = json.criteria[0].copyright;
970
-                    } else {
975
+                    if (criterion.copyright) {
976
+                        var copyright = criterion.copyright;
977
+                 } else {
971 978
                         var copyright = ''
972 979
                     }
973
-                    if (json.criteria[0].notes) notes = json.criteria[0].notes;
974
-                    else notes = '';
980
+                    if (criterion.notes) notes = criterion.notes;
981
+                     else notes = '';
975 982
 
976 983
                     // Display info
977 984
                     $('#criterion_name').val(name);
978 985
                     $('#criterion_subcriteria').text(subcriteria);
979
-                    if (json.criteria[0].deleted_at)
986
+                    if (criterion.deleted_at)
980 987
                         $('#status').val(0);
981 988
                     else
982 989
                         $('#status').val(1);
983
-                    $('#assoc_maximum_score').val(json.criteria[0].max_score);
984
-                    var maximum = json.criteria[0].max_score;
990
+                        $('#assoc_maximum_score').val(criterion.max_score);
991
+                    var maximum = criterion.max_score;
985 992
 
986 993
                     addOptions("Num_assoc_scale", "assoc_maximum_score", "Assoc_Scales");
987
-                    $('#Num_assoc_scale').val(json.criteria[0].num_scales)
988
-                    $('#Num_assoc_scale').selectpicker('refresh');
994
+                    $('#Num_assoc_scale').val(criterion.num_scales)
995
+                  $('#Num_assoc_scale').selectpicker('refresh');
989 996
                     $('#Num_assoc_scale').trigger('change');
990 997
 
991
-                    for (i = 0; i < json.criteria[0].num_scales; i++) {
992
-                        $('#assoc_scale_' + i).val(json.scales[i].description);
993
-                    }
998
+                    for(i=0; i<criterion.num_scales;i++){
999
+                        $('#assoc_scale_'+i).val(criterion.scales[i].description);
1000
+                     }
994 1001
 
995 1002
 
996 1003
 
@@ -1022,36 +1029,48 @@
1022 1029
                     var Notran = true;
1023 1030
                 }
1024 1031
 
1025
-                if (json.outcomes.length) {
1026
-                    $('#assoc_outcome_0').val(json.outcomes[0].id);
1027
-                    $('#assoc_outcome_0').selectpicker('refresh');
1032
+                if (criterion.outcomes.length) 
1033
+                    {
1034
+                    $('#assoc_outcome_0').val(criterion.outcomes[0].id);
1035
+                                    $('#assoc_outcome_0').selectpicker('refresh');
1028 1036
 
1029
-                    var first_outcome_id = json.outcomes[0].id;
1030
-                    options = "<option value ='0'>Nothing Selected</option>";
1037
+                                    var first_outcome = criterion.outcomes[0];
1038
+                   options = "<option value ='0'>Nothing Selected</option>";
1039
+                   $(first_outcome.assoc_objectives).each(function(index, objective){
1040
+
1041
+options += '<option value ="('+first_outcome.id+','+objective.objective_id+')">'+
1042
+    objective.text+'</option>';
1031 1043
 
1032
-                    for (objective_index in json.objectives_assoc[first_outcome_id]) {
1044
+})
1045
+                    /*for (objective_index in json.objectives_assoc[first_outcome_id]) {
1033 1046
                         objective = json.objectives_assoc[first_outcome_id][objective_index]
1034 1047
                         options += '<option value ="(' + first_outcome_id + ',' + objective.objective_id + ')">' +
1035 1048
                             objective.text + '</option>';
1036
-                    }
1049
+                    }*/
1037 1050
                     $('#assoc_objective_0_counter_1').html(options);
1038 1051
                     $('#assoc_objective_0_counter_1').selectpicker('refresh');
1039 1052
 
1040
-                    if (json.objectives[first_outcome_id].length) {
1041
-                        objective_id = json.objectives[first_outcome_id][0].objective_id;
1042
-                        value = '(' + first_outcome_id + ',' + objective_id + ')';
1043
-                        $('#assoc_objective_0_counter_1').val(value);
1053
+                    if(first_outcome.objectives_criteria.length){
1054
+                        objective_id = first_outcome.objectives_criteria[0].objective_id;
1055
+                    value = '('+first_outcome.id+','+objective_id+')';
1056
+                  $('#assoc_objective_0_counter_1').val(value);
1044 1057
                         $('#assoc_objective_0_counter_1').selectpicker('refresh');
1045 1058
 
1046 1059
                     }
1047 1060
 
1061
+                    if($("#assoc_objectiveGroupFor0").find(".btn-primary").length>0){
1062
+                        $("#assoc_objectiveGroupFor0").find(".btn-primary").each(function(){
1063
+                            $(this).click()
1064
+                        })
1065
+                    }
1048 1066
 
1049
-                    for (var i = 1; i < json.objectives[first_outcome_id].length; i++) {
1067
+                    for(var i =1; i<first_outcome.objectives_criteria.length; i++ ){
1050 1068
                         addAssocObjective("assoc_objectiveGroupFor0", "assoc_objective_0");
1051
-                        objective_id = json.objectives[first_outcome_id][i].objective_id;
1052
-                        value = "(" + first_outcome_id + "," + objective_id + ")";
1053
-                        $('#assoc_objective_0_counter_' + (i + 1)).val(value);
1054
-                        $('#assoc_objective_0_counter_' + (i + 1)).selectpicker('refresh');
1069
+                        objective_id = first_outcome.objectives_criteria[i].objective_id;
1070
+                        value = "("+first_outcome.id+","+objective_id+")";
1071
+                        $('#assoc_objective_0_counter_'+(i+1)).val(value);
1072
+                        $('#assoc_objective_0_counter_'+(i+1)).selectpicker('refresh');
1073
+                        
1055 1074
 
1056 1075
 
1057 1076
 
@@ -1065,37 +1084,46 @@
1065 1084
 
1066 1085
 
1067 1086
 
1068
-                for (var i = 1; i < json.outcomes.length; i++) {
1069
-                    addAssocOutcome(true);
1087
+                for (var i = 1; i < criterion.outcomes.length; i++) {
1088
+                                   addAssocOutcome(true);
1070 1089
 
1071 1090
 
1072
-                    $('#assoc_outcome_' + i.toString()).val(json.outcomes[i].id);
1073
-                    $('#assoc_outcome_' + i.toString()).selectpicker('refresh');
1091
+                                   $('#assoc_outcome_' + i.toString()).val(criterion.outcomes[i].id);
1092
+                   $('#assoc_outcome_' + i.toString()).selectpicker('refresh');
1074 1093
 
1075
-                    var outcome_id = json.outcomes[i].id;
1094
+                    var outcome = criterion.outcomes[i];
1076 1095
                     options = "<option value ='0'>Nothing Selected</option>";
1077 1096
 
1078
-                    for (objective_index in json.objectives_assoc[outcome_id]) {
1097
+                   
1098
+                    $(outcome.assoc_objectives).each(function(index, objective){
1099
+
1100
+options += '<option value ="('+outcome.id+','+objective.objective_id+')">'+
1101
+    objective.text+'</option>';
1102
+
1103
+})
1104
+                    /*for (objective_index in json.objectives_assoc[outcome_id]) {
1079 1105
                         objective = json.objectives_assoc[outcome_id][objective_index]
1080 1106
                         options += '<option value ="(' + outcome_id + ',' + objective.objective_id + ')">' +
1081 1107
                             objective.text + '</option>';
1082
-                    }
1108
+                    }*/
1083 1109
                     $('#assoc_objective_' + i + '_counter_1').html(options);
1084 1110
                     $('#assoc_objective_' + i + '_counter_1').selectpicker('refresh');
1085
-                    if (json.objectives[outcome_id].length) {
1086
-                        objective_id = json.objectives[outcome_id][0].objective_id;
1087
-                        value = "(" + outcome_id + "," + objective_id + ")"
1088
-                        $('#assoc_objective_' + i + '_counter_1').val(value);
1089
-                        $('#assoc_objective_' + i + '_counter_1').selectpicker('refresh')
1111
+                    if(outcome.objectives_criteria.length){
1112
+                        objective_id = outcome.objectives_criteria[0].objective_id;
1113
+                        value = "("+outcome.id+","+objective_id+")"
1114
+                    $('#assoc_objective_'+i+'_counter_1').val(value);
1115
+                    $('#assoc_objective_'+i+'_counter_1').selectpicker('refresh')
1090 1116
                     }
1117
+                                        }
1091 1118
 
1092 1119
 
1093
-                    for (var j = 1; i < json.objectives[outcome_id].length; i++) {
1094
-                        addAssocObjective("assoc_objectiveGroupFor" + i, "assoc_objective_" + i);
1095
-                        objective_id = json.objectives[outcome_id][j].objective_id;
1096
-                        value = "(" + outcome_id + "," + objective_id + ")";
1097
-                        $('#assoc_objective_' + i + '_counter_' + (j + 1)).val(value);
1098
-                        $('#assoc_objective_' + i + '_counter_' + (j + 1)).selectpicker('refresh');
1120
+                                        for(var j =1; j<outcome.objectives_criteria.length; j++ ){
1121
+                        addAssocObjective("assoc_objectiveGroupFor"+i, "assoc_objective_"+i);
1122
+                        objective_id =outcome.objectives_criteria[j].objective_id;
1123
+                        value = "("+outcome.id+","+objective_id+")";
1124
+                        $('#assoc_objective_'+i+'_counter_'+(j+1)).val(value);
1125
+                        $('#assoc_objective_'+i+'_counter_'+(j+1)).selectpicker('refresh');
1126
+                        
1099 1127
 
1100 1128
 
1101 1129
                     }

+ 88
- 64
app/views/local/managers/sCoords/criteria.blade.php Переглянути файл

@@ -157,7 +157,7 @@
157 157
                     <div id='assocOutcomeGroup0' data-value="1">
158 158
                         <div class="form-group col-md-12">
159 159
                             <label>Outcome 1</label>
160
-                            {{ Form::select('outcome[]', $outcomes, null, ['class'=>'form-control selectpicker', 'id'=>'assoc_outcome_0', 'onchange'=>'fetchAssocObjective("assoc_outcome_0")']) }}
160
+                            {{ Form::select('outcome[]', $outcomes, null, ['class'=>'form-control selectpicker', 'id'=>'assoc_outcome_0', 'onchange'=>'fetchObjectiveForSelect("assoc_outcome_0", "assoc_objectiveGroupFor0")']) }}
161 161
     
162 162
                         </div>
163 163
     <div id='assoc_objectiveGroupFor0' data-value="1">
@@ -543,8 +543,8 @@ function addOutcomeTest() {
543 543
         $div.remove();
544 544
         $div = document.getElementById(closeObj);
545 545
         $div.remove();
546
-        //counter = parseInt($('#'+objectiveGroup).data("value"));
547
-        //$('#'+objectiveGroup).data("value", counter-1);
546
+        counter = parseInt($('#'+objectiveGroup).data("value"));
547
+        $('#'+objectiveGroup).data("value", counter-1);
548 548
 
549 549
 
550 550
     }
@@ -647,7 +647,7 @@ function addOutcomeTest() {
647 647
             'name': "outcome[]",
648 648
             'data-live-search': 'true',
649 649
             'id': 'assoc_outcome_' + assocOutcomeCounter.toString(),
650
-            'onchange': 'fetchAssocObjective("assoc_outcome_' + assocOutcomeCounter.toString() + '", "assoc_objectiveGroupFor'+assocOutcomeCounter+'")'
650
+            'onchange': 'fetchObjectiveForSelect("assoc_outcome_' + assocOutcomeCounter.toString() + '", "assoc_objectiveGroupFor'+assocOutcomeCounter+'")'
651 651
 
652 652
         });
653 653
         var $div = $('<div/>', {
@@ -757,7 +757,7 @@ function addOutcomeTest() {
757 757
                 allOutcomes: allOutcomes
758 758
             },
759 759
 
760
-            function(json) {
760
+            function(varArray) {
761 761
 
762 762
                 optionName = '<option value ="0">Nothing Selected</option>';
763 763
                 for(outcome in varArray.outcomes){
@@ -783,16 +783,16 @@ function addOutcomeTest() {
783 783
                 }
784 784
 
785 785
                 for (var i = allObjectives.length - 1; i > 0; i--) {
786
-                    deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString(), 'assoc_objectiveGroup');
786
+                    deleteObjective('assoc_objectiveForm_' + objectiveGroup +'_'+i, 'assoc_closeObj_'+objectiveGroup+'_' + i.toString(), objectiveGroup);
787 787
                 }
788
-                for(var i=1; i<allObjectives.length; i++){
788
+ /*               for(var i=1; i<allObjectives.length; i++){
789 789
                     addAssocObjective();
790 790
                     $('#assoc_objective_'+i.toString()).selectpicker('refresh');
791 791
                     if($("#assoc_objective_"+i.toString()+" option[value='"+allObjectives[i].value+"']").length>0){
792 792
                     $("#assoc_objective_"+i.toString()).val(allObjectives[i].value);
793 793
                     $("#assoc_objective_"+i.toString()).selectpicker("refresh");
794 794
                     }
795
-                }
795
+                }*/
796 796
 
797 797
 
798 798
 
@@ -929,9 +929,25 @@ function addOutcomeTest() {
929 929
             "{{ URL::action('CriteriaController@fetchCriterionWithTrashed') }}", {
930 930
                 id: id
931 931
             },
932
-            function(json) {
932
+            function(criterion) {
933 933
 
934
-                if (!(json.activity_criterion.length)) {
934
+                
935
+                if (!(criterion.length)) {
936
+                    name = ' ';
937
+                    var subcriteria = '';
938
+                    copyright = null;
939
+                    notes = null;
940
+                    $('#status').val(0);
941
+                    maximum = 1;
942
+                    $('#assoc_maximum_score').val(1);
943
+
944
+
945
+                }
946
+               
947
+
948
+ else { 
949
+     criterion = criterion[0];
950
+     if (!(criterion.activity_criterion.length)) {
935 951
 
936 952
 $('#DeleteButton').prop('disabled', false);
937 953
 $("#update_the_criterion").val('Update');
@@ -944,49 +960,37 @@ $("#update_criterion").attr('action', "{{ URL::action('CriteriaController@create
944 960
 $('#alert_placeholder').html('<div class="alert alert-danger alert-dismissible" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button> <strong>Warning!</strong> The criterion is already used in assessments. Editting the criterion will actually create a new criterion </div>');
945 961
 
946 962
 }
947
-
948
-                if (!(json.criteria.length)) {
949
-                    name = ' ';
950
-                    var subcriteria = '';
951
-                    copyright = null;
952
-                    notes = null;
953
-                    $('#status').val(0);
954
-                    maximum = 1;
955
-                    $('#assoc_maximum_score').val(1);
956
-
957
-
958
-                } else {
959
-                    var name = json.criteria[0].name;
960
-                    if (json.criteria[0].subcriteria) {
961
-                        subcriteria = JSON.parse(json.criteria[0].subcriteria).join('\n');
963
+                    var name = criterion.name;
964
+                    if (criterion.subcriteria) {
965
+                        subcriteria = JSON.parse(criterion.subcriteria).join('\n');
962 966
                     } else {
963 967
                         subcriteria = "";
964 968
                     }
965
-                    if (json.criteria[0].copyright) {
966
-                        var copyright = json.criteria[0].copyright;
969
+                    if (criterion.copyright) {
970
+                        var copyright = criterion.copyright;
967 971
                     } else {
968 972
                         var copyright = ''
969 973
                     }
970
-                    if (json.criteria[0].notes) notes = json.criteria[0].notes;
974
+                    if (criterion.notes) notes = criterion.notes;
971 975
                     else notes = '';
972 976
 
973 977
                     // Display info
974 978
                     $('#criterion_name').val(name);
975 979
                     $('#criterion_subcriteria').text(subcriteria);
976
-                    if (json.criteria[0].deleted_at)
980
+                    if (criterion.deleted_at)
977 981
                         $('#status').val(0);
978 982
                     else
979 983
                         $('#status').val(1);
980
-                    $('#assoc_maximum_score').val(json.criteria[0].max_score);
981
-                    var maximum = json.criteria[0].max_score;
984
+                    $('#assoc_maximum_score').val(criterion.max_score);
985
+                    var maximum = criterion.max_score;
982 986
 
983 987
                     addOptions("Num_assoc_scale", "assoc_maximum_score", "Assoc_Scales");
984
-                    $('#Num_assoc_scale').val(json.criteria[0].num_scales)
988
+                    $('#Num_assoc_scale').val(criterion.num_scales)
985 989
                     $('#Num_assoc_scale').selectpicker('refresh');
986 990
                     $('#Num_assoc_scale').trigger('change');
987 991
 
988
-                    for(i=0; i<json.criteria[0].num_scales;i++){
989
-                        $('#assoc_scale_'+i).val(json.scales[i].description);
992
+                    for(i=0; i<criterion.num_scales;i++){
993
+                        $('#assoc_scale_'+i).val(criterion.scales[i].description);
990 994
                     }
991 995
                     // If copyright or notes aren't empty, load them
992 996
 
@@ -1007,7 +1011,7 @@ $('#alert_placeholder').html('<div class="alert alert-danger alert-dismissible"
1007 1011
 
1008 1012
                 // Select associated outcome
1009 1013
                 try {
1010
-                    assocOutcomeCounter= parseInt($("#assocOutcomeGroup0").data('value'));
1014
+                    assocOutcomeCounter = parseInt($("#assocOutcomeGroup0").data('value'));
1011 1015
                     for (var i = assocOutcomeCounter - 1; i > 0; i--) {
1012 1016
                         $('#assoc_close_button'+i).click();
1013 1017
                                }
@@ -1016,35 +1020,48 @@ $('#alert_placeholder').html('<div class="alert alert-danger alert-dismissible"
1016 1020
                     var Notran = true;
1017 1021
                 }
1018 1022
 
1019
-                if (json.outcomes.length) 
1023
+                if (criterion.outcomes.length) 
1020 1024
                     {
1021
-                    $('#assoc_outcome_0').val(json.outcomes[0].id);
1025
+                    $('#assoc_outcome_0').val(criterion.outcomes[0].id);
1022 1026
                     $('#assoc_outcome_0').selectpicker('refresh');
1023 1027
 
1024
-                    var first_outcome_id = json.outcomes[0].id;
1028
+                    var first_outcome = criterion.outcomes[0];
1025 1029
                     options = "<option value ='0'>Nothing Selected</option>";
1030
+                        $(first_outcome.assoc_objectives).each(function(index, objective){
1026 1031
 
1027
-                    for(objective_index  in json.objectives_assoc[first_outcome_id]){
1032
+                        options += '<option value ="('+first_outcome.id+','+objective.objective_id+')">'+
1033
+                            objective.text+'</option>';
1034
+
1035
+                        })
1036
+                    /*for(objective_index  in json.objectives_assoc[first_outcome_id]){
1028 1037
                         objective = json.objectives_assoc[first_outcome_id][objective_index]
1029 1038
                         options += '<option value ="('+first_outcome_id+','+objective.objective_id+')">'+
1030 1039
                             objective.text+'</option>';
1031
-                    }
1040
+                    }*/
1032 1041
                     $('#assoc_objective_0_counter_1').html(options);
1033 1042
                     $('#assoc_objective_0_counter_1').selectpicker('refresh');
1034 1043
                     
1035
-                    if(json.objectives[first_outcome_id].length){
1036
-                        objective_id = json.objectives[first_outcome_id][0].objective_id;
1037
-                    value = '('+first_outcome_id+','+objective_id+')';
1044
+                    if(first_outcome.objectives_criteria.length){
1045
+                        objective_id = first_outcome.objectives_criteria[0].objective_id;
1046
+                    value = '('+first_outcome.id+','+objective_id+')';
1038 1047
                     $('#assoc_objective_0_counter_1').val(value);
1039 1048
                     $('#assoc_objective_0_counter_1').selectpicker('refresh');
1040 1049
 
1041 1050
                     }
1051
+
1052
+                    if($("#assoc_objectiveGroupFor0").find(".btn-primary").length>0){
1053
+                        $("#assoc_objectiveGroupFor0").find(".btn-primary").each(function(){
1054
+                            $(this).click()
1055
+                        })
1056
+                    }
1057
+
1058
+
1042 1059
                     
1043 1060
 
1044
-                    for(var i =1; i<json.objectives[first_outcome_id].length; i++ ){
1061
+                    for(var i =1; i<first_outcome.objectives_criteria.length; i++ ){
1045 1062
                         addAssocObjective("assoc_objectiveGroupFor0", "assoc_objective_0");
1046
-                        objective_id = json.objectives[first_outcome_id][i].objective_id;
1047
-                        value = "("+first_outcome_id+","+objective_id+")";
1063
+                        objective_id = first_outcome.objectives_criteria[i].objective_id;
1064
+                        value = "("+first_outcome.id+","+objective_id+")";
1048 1065
                         $('#assoc_objective_0_counter_'+(i+1)).val(value);
1049 1066
                         $('#assoc_objective_0_counter_'+(i+1)).selectpicker('refresh');
1050 1067
                         
@@ -1060,35 +1077,42 @@ $('#alert_placeholder').html('<div class="alert alert-danger alert-dismissible"
1060 1077
 
1061 1078
 
1062 1079
                
1063
-                for (var i = 1; i < json.outcomes.length; i++) {
1080
+                for (var i = 1; i < criterion.outcomes.length; i++) {
1064 1081
                     addAssocOutcome(true);
1065 1082
 
1066 1083
 
1067
-                    $('#assoc_outcome_' + i.toString()).val(json.outcomes[i].id);
1084
+                    $('#assoc_outcome_' + i.toString()).val(criterion.outcomes[i].id);
1068 1085
                     $('#assoc_outcome_' + i.toString()).selectpicker('refresh');
1069 1086
 
1070
-                    var outcome_id = json.outcomes[i].id;
1087
+                    var outcome = criterion.outcomes[i];
1071 1088
                     options = "<option value ='0'>Nothing Selected</option>";
1072 1089
 
1073
-                    for(objective_index  in json.objectives_assoc[outcome_id]){
1074
-                        objective = json.objectives_assoc[outcome_id][objective_index]
1075
-                        options += '<option value ="('+outcome_id+','+objective.objective_id+')">'+
1076
-                            objective.text+'</option>';
1077
-                    }
1090
+                    $(outcome.assoc_objectives).each(function(index, objective){
1091
+
1092
+options += '<option value ="('+outcome.id+','+objective.objective_id+')">'+
1093
+    objective.text+'</option>';
1094
+
1095
+})
1096
+                    //for(objective_index  in json.objectives_assoc[outcome_id]){
1097
+                    //    objective = json.objectives_assoc[outcome_id][objective_index]
1098
+                    //    options += '<option value ="('+outcome_id+','+objective.objective_id+')">'+
1099
+                    //        objective.text+'</option>';
1100
+                    // }
1078 1101
                     $('#assoc_objective_'+i+'_counter_1').html(options);
1079 1102
                     $('#assoc_objective_'+i+'_counter_1').selectpicker('refresh');
1080
-                    if(json.objectives[outcome_id].length){
1081
-                        objective_id = json.objectives[outcome_id][0].objective_id;
1082
-                        value = "("+outcome_id+","+objective_id+")"
1103
+
1104
+                    if(outcome.objectives_criteria.length){
1105
+                        objective_id = outcome.objectives_criteria[0].objective_id;
1106
+                        value = "("+outcome.id+","+objective_id+")"
1083 1107
                     $('#assoc_objective_'+i+'_counter_1').val(value);
1084 1108
                     $('#assoc_objective_'+i+'_counter_1').selectpicker('refresh')
1085 1109
                     }
1086 1110
                     
1087 1111
 
1088
-                    for(var j =1; i<json.objectives[outcome_id].length; i++ ){
1112
+                    for(var j =1; j<outcome.objectives_criteria.length; j++ ){
1089 1113
                         addAssocObjective("assoc_objectiveGroupFor"+i, "assoc_objective_"+i);
1090
-                        objective_id = json.objectives[outcome_id][j].objective_id;
1091
-                        value = "("+outcome_id+","+objective_id+")";
1114
+                        objective_id =outcome.objectives_criteria[j].objective_id;
1115
+                        value = "("+outcome.id+","+objective_id+")";
1092 1116
                         $('#assoc_objective_'+i+'_counter_'+(j+1)).val(value);
1093 1117
                         $('#assoc_objective_'+i+'_counter_'+(j+1)).selectpicker('refresh');
1094 1118
                         
@@ -1117,8 +1141,8 @@ $('#alert_placeholder').html('<div class="alert alert-danger alert-dismissible"
1117 1141
                 assocOutcomeCounter = 0;
1118 1142
                 var i = 0;
1119 1143
                 optionName = '<option value ="0">Nothing Selected</option>';
1120
-                for(outcome in json.outcomes_assoc){
1121
-                    optionName += '<optgroup label="' + json.outcomes_assoc[outcome][0].name + '">';
1144
+                for(outcome in criterion.outcomes_assoc){
1145
+                    optionName += '<optgroup label="' + criterion.outcomes_assoc[outcome][0].name + '">';
1122 1146
                     var objectiveForOutcome = json.objectives_assoc;
1123 1147
                     var objectives = objectiveForOutcome[outcome];
1124 1148
                     for (objective in objectives) {
@@ -1162,11 +1186,11 @@ $('#alert_placeholder').html('<div class="alert alert-danger alert-dismissible"
1162 1186
 
1163 1187
 
1164 1188
                 // Select associated program
1165
-                var program_length = json.program.length;
1189
+                var program_length = criterion.program.length;
1166 1190
                 $('input[type=checkbox]').prop('checked', false);
1167 1191
 
1168 1192
                 for (var i = 0; i < program_length; i++) {
1169
-                    $('#assoc_program_id_' + json.program[i].program_id).prop("checked", true);
1193
+                    $('#assoc_program_id_' + criterion.program[i].program_id).prop("checked", true);
1170 1194
                 }
1171 1195
 
1172 1196
 

+ 1
- 1
app/views/local/managers/shared/rubrics.blade.php Переглянути файл

@@ -383,7 +383,7 @@ function fetchCriteria(outcome, objective)
383 383
             data.forEach( function (arrayItem)
384 384
             {
385 385
                 $('#select-criterion')
386
-                    .append('<option data-criterion-id="'+arrayItem.id+'" >'+arrayItem.name+'</option>');
386
+                    .append('<option data-criterion-id="'+arrayItem.id+'" data-program-ids = "'+arrayItem.program_ids+'" data-assoc-objectives = "'arrayItem.objectives'">'+arrayItem.name+'</option>');
387 387
             });
388 388
 
389 389
             // If there are no criteria assigned to the selected outcome, disable the