Browse Source

Antes de to

parent
commit
11aa1c8932

+ 227
- 0
app/controllers/Objective2Controller.php View File

@@ -55,6 +55,62 @@ class Objective2Controller extends \BaseController
55 55
 		return $objectives;
56 56
 	}
57 57
 
58
+	public function deletePCOBO()
59
+	{
60
+		$pcobo_id = Input::get('pcobo_id');
61
+		$criterion_id = Input::get('criterion_id');
62
+		//$objective_id  = Input::get('objective_id');
63
+		$outcome_id  = Input::get('outcome_id');
64
+		$program_id = Input::get('program_id');
65
+
66
+		$cri_hol_dom = DB::table('criterion_objective_outcome')
67
+			->where('objective_id', 0)
68
+			->where('criterion_id', $criterion_id)
69
+			->where('outcome_id', $outcome_id)
70
+			->first();
71
+
72
+
73
+		if (!isset($cri_hol_dom)) {
74
+			$cri_obj_out_id = DB::table('criterion_objective_outcome')->insertGetId(
75
+				array(
76
+					'objective_id' => 0,
77
+					'outcome_id' => $outcome_id,
78
+					'criterion_id' => $criterion_id
79
+				)
80
+			);
81
+		} else {
82
+			$cri_obj_out_id = $cri_hol_dom->id;
83
+			//no creo que esto pase pero
84
+
85
+			$exists_pair = DB::table("program_criterion_objective_outcome")
86
+				->where('program_id', $program_id)
87
+				->where('cri_obj_out_id', $cri_obj_out_id)
88
+				->first();
89
+
90
+			if (isset($exists_pair)) {
91
+				//se puede borrar la entrada
92
+				//porque el pareo de programa-criterio-dominio-holder ya existe, so borrar esta entrada borra duplicados. 
93
+
94
+				DB::table('program_criterion_objective_outcome')
95
+					->where('id', $pcobo_id)
96
+					->delete();
97
+				return 200;
98
+			}
99
+		}
100
+
101
+
102
+
103
+
104
+
105
+
106
+		DB::table('program_criterion_objective_outcome')
107
+			->where('id', $pcobo_id)->update(array(
108
+				'cri_obj_out_id' => $cri_obj_out_id
109
+			));
110
+
111
+		return 200;
112
+	}
113
+
58 114
 	public function isObjectiveUnique($input, $existing_Objective = NULL)
59 115
 	{
60 116
 
@@ -208,6 +264,177 @@ class Objective2Controller extends \BaseController
208 264
 			->get();
209 265
 	}
210 266
 
267
+	public function updatePCOBO()
268
+	{
269
+		//aqui entra si  cambia el viejo al nuevo
270
+
271
+		$criterion_id = Input::get('criterion_id');
272
+		$pcobo_id = Input::get("pcobo_id");
273
+		$cobo_id = Input::get("cobo_id");
274
+		$objective_id = Input::get("objective_id");
275
+		$outcome_id = Input::get("outcome_id");
276
+		$program_id = Input::get("program_id");
277
+		$old_crit = Input::get('old_crit');
278
+		$old_cobo_id = Input::get('old_cobo');
279
+		$old_pcobo_id = Input::get('old_pcobo');
280
+		$old_outcome_id = Input::get('old_outcome');
281
+
282
+
283
+
284
+
285
+
286
+		//Existe el pareo de este criterio, este dominio y este objetivo?
287
+
288
+		$existing_cobo_id = DB::table('criterion_objective_outcome')
289
+			->where('objective_id', $objective_id)
290
+			->where('outcome_id', $outcome_id)
291
+			->where('criterion_id', $criterion_id)
292
+			->first();
293
+
294
+		if (!isset($existing_cobo_id)) {
295
+			$insert_cobo_id = DB::table('criterion_objective_outcome')->insertGetId(array(
296
+				'criterion_id' => $criterion_id,
297
+				'outcome_id' => $outcome_id,
298
+				'objective_id' => $objective_id
299
+
300
+			));
301
+		} else $insert_cobo_id = $existing_cobo_id->id;
302
+
303
+		$it_exists = DB::table('program_criterion_objective_outcome')
304
+			->where('program_id', $program_id)
305
+			->where('cri_obj_out_id', $insert_cobo_id)
306
+			->first();
307
+
308
+		if (isset($it_exists)) {
309
+			return "DUPLICATE";
310
+		}
311
+
312
+		DB::table('program_criterion_objective_outcome')
313
+			->where("program_id", $program_id)
314
+			->where('cri_obj_out_id', $old_cobo_id)
315
+			->update(array(
316
+				//'program_id' => $program_id,
317
+				'cri_obj_out_id' => $insert_cobo_id
318
+			));
319
+
320
+
321
+
322
+		//now check if old criterion_objective_outcome is being used
323
+
324
+		$other_pcobo_exist = DB::table('program_criterion_objective_outcome')
325
+			->where("cri_obj_out_id", $old_cobo_id)
326
+			->first();
327
+
328
+
329
+		//si ningun otro programa tiene el pareo de este criterio con ese objetivo y ese dominio
330
+		//lo puedes borrar
331
+		if (!isset($other_pcobo_exist)) {
332
+			DB::table('criterion_objective_outcome')
333
+
334
+				->where('id', $old_cobo_id)
335
+				->delete();
336
+		}
337
+
338
+
339
+
340
+		//Ahora hay que ver que la relacion de program, crit y dominio existe.
341
+
342
+		$relationship_exists = DB::table('criterion_objective_outcome as cobo')
343
+			->join('program_criterion_objective_outcome as pcobo', 'pcobo.cri_obj_out_id', '=', 'cobo.id')
344
+			->where('criterion_id', $old_crit)
345
+			->where('outcome_id', $old_outcome_id)
346
+			->where('program_id', $program_id)
347
+			->first();
348
+
349
+		if (!isset($relationship_exists)) {
350
+			$new_cobo_id = DB::table('criterion_objective_outcome')
351
+				->insertGetId(array(
352
+					'criterion_id' => $old_crit,
353
+					'outcome_id' => $old_outcome_id,
354
+					'objective_id' => 0
355
+				));
356
+			DB::table('program_criterion_objective_outcome')
357
+				->insert(array(
358
+					'program_id' => $program_id,
359
+					'cri_obj_out_id' => $new_cobo_id
360
+				));
361
+		}
362
+
363
+
364
+
365
+
366
+
367
+
368
+
369
+
370
+
371
+		return 200;
372
+
373
+
374
+		//Aqui es insertar
375
+
376
+
377
+	}
378
+
379
+	public function insertPCOBO()
380
+	{
381
+		//aqui entra si  le da a add criterio, y escoje uno nuevo
382
+
383
+		$criterion_id = Input::get('criterion_id');
384
+		$pcobo_id = Input::get("pcobo_id");
385
+		$cobo_id = Input::get("cobo_id");
386
+		$objective_id = Input::get("objective_id");
387
+		$outcome_id = Input::get("outcome_id");
388
+		$program_id = Input::get("program_id");
389
+		Log::info(Input::all());
390
+
391
+
392
+		//doc se esta usando? ie, objetivo_id == 0?
393
+
394
+		//Existe el pareo de este criterio, este dominio y este objetivo?
395
+
396
+
397
+
398
+		$old_cobo_id = DB::table('criterion_objective_outcome')
399
+			->where('objective_id', $objective_id)
400
+			->where('outcome_id', $outcome_id)
401
+			->where('criterion_id', $criterion_id)
402
+			->first();
403
+
404
+		if (!isset($old_cobo_id)) {
405
+			$insert_cobo_id = DB::table('criterion_objective_outcome')->insertGetId(array(
406
+				'criterion_id' => $criterion_id,
407
+				'outcome_id' => $outcome_id,
408
+				'objective_id' => $objective_id
409
+
410
+			));
411
+		} else $insert_cobo_id = $old_cobo_id->id;
412
+
413
+		$it_exists = DB::table('program_criterion_objective_outcome')
414
+			->where('program_id', $program_id)
415
+			->where('cri_obj_out_id', $insert_cobo_id)
416
+			->first();
417
+
418
+		if (isset($it_exists)) {
419
+			return "DUPLICATE";
420
+		}
421
+
422
+		DB::table('program_criterion_objective_outcome')
423
+			->insert(array(
424
+				'program_id' => $program_id,
425
+				'cri_obj_out_id' => $insert_cobo_id
426
+			));
427
+
428
+
429
+
430
+		return 200;
431
+
432
+
433
+		//Aqui es insertar
434
+
435
+
436
+	}
437
+
211 438
 	public function fetchObjectiveWithTrashed()
212 439
 	{
213 440
 		$json = array();

+ 3
- 0
app/models/Outcome.php View File

@@ -275,8 +275,11 @@ class Outcome extends Eloquent
275 275
 	public function scopeObjectivesFromProgram($query, $programs)
276 276
 	{
277 277
 		return Objective::join('objective_program', 'objective_program.objective_id', '=', 'objectives.id')
278
+			->join('objective_outcome', 'objective_outcome.objective_id', '=', 'objectives.id')
278 279
 			//->join('programs', 'programs.id', '=', 'objective_program.program_id')
279 280
 			->whereIn("program_id", $programs)
281
+			->where('outcome_id', $this->id)
282
+
280 283
 			->where('objective_program.objective_id', '<>', '0')
281 284
 			->select('objectives.*')
282 285
 			->groupBy('objectives.id');

+ 2
- 0
app/models/Program.php View File

@@ -43,6 +43,8 @@ class Program extends Eloquent
43 43
 		if ($this->outcome_id) {
44 44
 			return Criterion::join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'criteria.id')
45 45
 				->join('program_criterion_objective_outcome', 'program_criterion_objective_outcome.cri_obj_out_id', '=', 'cobo.id')
46
+				->select('criteria.*', 'cobo.id as cobo_id', 'cobo.objective_id', 'cobo.outcome_id', 'cobo.criterion_id')
47
+				->addSelect('program_criterion_objective_outcome.id as pcobo_id')
46 48
 				->where('program_id', $this->id)
47 49
 				->where('outcome_id', $this->outcome_id)
48 50
 				->get();

+ 7
- 1
app/routes.php View File

@@ -303,6 +303,8 @@ Route::group(array('before' => 'auth|has_access'), function () {
303 303
         'uses' => 'CriteriaController@fetchAllCriterion'
304 304
     ));
305 305
 
306
+    Route::post('insertPCOBO', 'Objective2Controller@insertPCOBO');
307
+
306 308
 
307 309
     Route::get('viewFormative', array(
308 310
         'as' => 'viewFormative',
@@ -540,6 +542,7 @@ Route::group(array('before' => 'auth|has_access'), function () {
540 542
         // Print course (grouped sections) report
541 543
         Route::get('print_course/{code}/{number}/{semester_code}', 'CoursesController@print_course');
542 544
 
545
+
543 546
         // Assessment reports
544 547
         Route::get('program-assessment-report/{program_id}', 'OutcomesController@programAssessmentReport');
545 548
         Route::get('assessment-reports', 'OutcomesController@managerAssessmentReports');
@@ -551,11 +554,14 @@ Route::group(array('before' => 'auth|has_access'), function () {
551 554
         Route::post('fetchObjective', array('before' => 'csrf', 'uses' => 'ObjectivesController@fetchObjective'));
552 555
         Route::post('fetchObjectivesForCriteria', array('before' => 'csrf', 'uses' => 'ObjectivesController@fetchObjectivesForCriteria'));
553 556
 
554
-        //Objectives por Gabriel
557
+        //Objectives
555 558
         //Route::get('objective', 'Objective2Controller@edit');
556 559
         Route::post('createObjective', array('before' => 'csrf', 'uses' => 'Objective2Controller@create'));
557 560
         Route::post('updateObjective', array('before' => 'csrf', 'uses' => 'Objective2Controller@update'));
558 561
         Route::post('fetchObjectiveWithTrashed', array('before' => 'csrf', 'uses' => 'Objective2Controller@fetchObjectiveWithTrashed'));
562
+        Route::post('deletePCOBO', 'Objective2Controller@deletePCOBO');
563
+        Route::post('updatePCOBO', 'Objective2Controller@updatePCOBO');
564
+
559 565
 
560 566
         // Five year plans,
561 567
         Route::get('five-year-plans', 'FiveYearPlansController@index');

+ 234
- 22
app/views/global/view-objectives-criteria.blade.php View File

@@ -85,6 +85,8 @@
85 85
 
86 86
     </div>
87 87
 
88
+    
89
+
88 90
     <div id="match_criteria" class="modal fade" tabindex="-1" data-objective-id="0">
89 91
         <div class="modal-dialog">
90 92
             <div class="modal-content">
@@ -96,13 +98,14 @@
96 98
                     <p>The following criteria appear based on objective's programs and your available programs</p>
97 99
 
98 100
                     <div class ='form-group col-md-12'>
101
+                        <label for="match_criteria_program">Program</label>
99 102
                         <select id="match_criteria_program" class ='form-control selectpicker select_program' onchange="changeCriteriaDisplayed('#match_criteria_program')">
100 103
                             
101 104
                         </select>
102 105
                     </div>
103 106
                     <hr>
104
-
105
-                    <div id="program_objectives">
107
+                    <label>Criteria associated to program</label>
108
+                    <div id="program_objectives" class ='form-group col-md-12' >
106 109
 
107 110
                     </div>
108 111
 
@@ -113,12 +116,42 @@
113 116
 
114 117
                 </div>
115 118
                 <div class="modal-footer">
119
+                    <hr>
120
+                    <button type="button" class="btn btn-secondary" data-dismiss="modal" onclick="">Close</button>
121
+
122
+                </div>
123
+            </div>
124
+        </div>
125
+    </div>
126
+
127
+    
128
+    <div id="warning" class="modal fade" tabindex="-1" data-objective-id="0">
129
+        <div class="modal-dialog">
130
+            <div class="modal-content">
131
+                <div class="modal-header">
132
+                    <h5 class="modal-title" id = 'warning_title'></h5>
133
+                    <button type="button" class="close" data-dismiss="modal">&times;</button>
134
+                </div>
135
+                <div class="modal-body" id = "warning_body">
136
+                    
137
+
138
+                
139
+
140
+
141
+
142
+
143
+                </div>
144
+                <div class="modal-footer">
145
+                    <hr>
116 146
                     <button type="button" class="btn btn-secondary" data-dismiss="modal" onclick="$('#match_criteria').data('objective-id', '0');">Cancel</button>
117
-                    <button type="button" class="btn btn-primary" onclick = 'matchCriteriaToObjective("#match_criteria")'>Save</button>
147
+                    <button  id='warning_delete' type="button" class="btn btn-primary" onclick = ''>Delete</button>
118 148
                 </div>
119 149
             </div>
120 150
         </div>
121 151
     </div>
152
+
153
+
154
+    
122 155
     <script>
123 156
         $(document).ready(function() {
124 157
             // --------------------------------------------------------------------------
@@ -222,6 +255,31 @@
222 255
             })
223 256
         });
224 257
 
258
+        function postDeleteCrit(criterion_id ,program_id ,outcome_id ,objective_id ,cobo_id ,pcobo_id){
259
+            
260
+            $.post(
261
+                "{{URL::action('Objective2Controller@deletePCOBO')}}",
262
+                {
263
+                    criterion_id:criterion_id,
264
+                    program_id:program_id,
265
+                    outcome_id:outcome_id,
266
+                    objective_id:objective_id,
267
+                    cobo_id:cobo_id,
268
+                    pcobo_id:pcobo_id
269
+                },
270
+                function (status){
271
+
272
+                    if(status == 200){
273
+                    $('.selected_criteria_to_delete').parent().parent().remove();
274
+                    }
275
+                    else{
276
+                        alert("something went wrong, try again later.");
277
+                    }
278
+                    
279
+                }
280
+            )
281
+        }
282
+
225 283
 
226 284
         function createSelectForModal(options){
227 285
             
@@ -234,7 +292,8 @@
234 292
             })
235 293
             select = $('<select>',{
236 294
                 'class':'selectpicker form-control criteria_select',
237
-                'name':'criteria[]'
295
+                'name':'criteria[]',
296
+                'onchange':'saveChanges(this)'
238 297
 
239 298
             }).html(options);
240 299
             div_rem_button = $('<div>',
@@ -245,7 +304,7 @@
245 304
             rem_button = $('<button>',{
246 305
                 'type':'button',
247 306
                 'class':'btn btn-primary',
248
-                'onclick':'$(this).parent().parent().remove()'
307
+                'onclick':'deleteCriterion(this);'
249 308
             }).html("<span class='glyphicon glyphicon-remove'></span>")
250 309
 
251 310
             div_select.append(select);
@@ -257,6 +316,97 @@
257 316
 
258 317
         }
259 318
 
319
+        function saveChanges(select){
320
+            
321
+            //Create if old-cobo doesnt exist
322
+
323
+            option = $(select).find(':selected');
324
+            
325
+            criterion_id = option.val()
326
+            if(criterion_id ==0){
327
+                return;
328
+            }
329
+            pcobo_id = option.data('pcobo-id')
330
+            cobo_id = option.data('cobo-id');
331
+            objective_id = option.data('objective-id')
332
+            outcome_id =  option.data('outcome-id');
333
+            program_id = option.data('program-id')
334
+
335
+            dict_to_send = {};
336
+   
337
+            if($(select).data('old-pcobo') ===undefined){
338
+               dict_to_send=    {
339
+                        criterion_id:criterion_id,
340
+                        pcobo_id:pcobo_id,
341
+                        cobo_id:cobo_id,
342
+                        objective_id:objective_id,
343
+                        outcome_id:outcome_id,
344
+                        program_id:program_id
345
+                    } 
346
+                url = "{{URL::action('Objective2Controller@insertPCOBO')}}";
347
+
348
+                   
349
+            }
350
+            else{
351
+
352
+                url= "{{URL::action('Objective2Controller@updatePCOBO')}}";
353
+
354
+
355
+                old_crit = $(select).data('old-criterion')
356
+                old_outcome= $(select).data('old-outcome')
357
+                old_cobo = $(select).data('old-cobo')
358
+                old_pcobo = $(select).data('old-pcobo')
359
+                dict_to_send ={
360
+                        criterion_id:criterion_id,
361
+                        pcobo_id:pcobo_id,
362
+                        cobo_id:cobo_id,
363
+                        objective_id:objective_id,
364
+                        outcome_id:outcome_id,
365
+                        program_id:program_id,
366
+                        old_crit:old_crit,
367
+                        old_outcome:old_outcome,
368
+                        old_cobo:old_cobo,
369
+                        old_pcobo:old_pcobo
370
+
371
+                        
372
+                    } 
373
+
374
+                    
375
+                
376
+
377
+            }
378
+
379
+            $.post(
380
+                    url,
381
+                    dict_to_send,
382
+                    function(code){
383
+                        if(code == "DUPLICATE"){
384
+                            alert("This criteria is already paired to this objective")
385
+                            $(select).val(0)
386
+                            $(select).selectpicker('refresh');
387
+                        }
388
+                        else if (code==200){
389
+                          
390
+                            
391
+                            $(select).attr('data-old-pcobo', pcobo_id)
392
+                            $(select).attr('data-old-cobo', cobo_id)
393
+                            $(select).attr('data-old-criterion', criterion_id)
394
+                            $(select).attr('data-old-outcome', outcome_id)
395
+                            $(select).attr('data-old-objective', objective_id)
396
+
397
+
398
+                        }
399
+                    }
400
+                )
401
+                
402
+            
403
+          
404
+
405
+
406
+        }
407
+
408
+    
409
+
260 410
         function fetchCriteria(a){
261 411
             objective_id = $(a).data('objective-id');
262 412
             objective_text = $("#objective-"+objective_id).html()
@@ -307,16 +457,28 @@
307 457
                         $.each(criteria, function(ind, cri){
308 458
 
309 459
                             if(cri.objective_id == objective_id && cri.outcome_id == outcome_id){
460
+                                dictionary_to_keep = {
461
+                                'value':cri.criterion_id,
462
+                                'data-program-id':program.id,
463
+                                'data-outcome-id':outcome_id,
464
+                                'data-objective-id':objective_id,
465
+                                'data-cobo-id':cri.cobo_id,
466
+                                'data-pcobo-id':cri.pcobo_id
467
+                                
468
+                            }
310 469
                                 option = $("<option>",{
311 470
                                 'value':cri.criterion_id,
312 471
                                 'data-program-id':program.id,
313 472
                                 'data-outcome-id':outcome_id,
473
+                                'data-objective-id':objective_id,
474
+                                'data-cobo-id':cri.cobo_id,
475
+                                'data-pcobo-id':cri.pcobo_id
314 476
                                 
315 477
                             }).html(cri.name)
316 478
                            // option.prop('selected', true);
317 479
 
318 480
                             
319
-                            selected_options.push(cri.criterion_id);
481
+                            selected_options.push(dictionary_to_keep);
320 482
                             
321 483
                             
322 484
                             
@@ -328,9 +490,14 @@
328 490
                                 'value':cri.criterion_id,
329 491
                                 'data-program-id':program.id,
330 492
                                 'data-outcome-id':outcome_id,
493
+                                'data-objective-id':objective_id,
494
+                                'data-cobo-id':cri.cobo_id,
495
+                                'data-pcobo-id':cri.pcobo_id
496
+
331 497
                                 
332 498
                             }).html(cri.name)
333 499
                         }
500
+                        
334 501
                   
335 502
 
336 503
                             options_html += option.prop('outerHTML');
@@ -353,20 +520,27 @@
353 520
                         $('#program_objectives').append(prog_div);
354 521
                         select = createSelectForModal(options_html)
355 522
 
356
-                        select.find('.remove_btn').hide()
523
+                        select.find('div.remove-btn').hide()
357 524
                         prog_div.append(select);
358 525
                         $('select.criteria_select').selectpicker('refresh');
359
-
360
-                        $.each(selected_options, function(ind, cri_id){
361
-
362
-                            the_picker = select.find('select.criteria_select').first();
363
-                            the_picker.val(cri_id);
364
-
365
-                            select = createSelectForModal(options_html)
366
-                            prog_div.append(select)
367
-                           // $('.criteria_select').selectpicker('refresh');
368
-                        })
369
-
526
+                        if(selected_options){
527
+                            $.each(selected_options, function(ind, cri){
528
+
529
+                                the_picker = select.find('select.criteria_select').first();
530
+                                the_picker.val(cri['value']);
531
+                                the_picker.attr('data-old-pcobo', cri['data-pcobo-id'])
532
+                                the_picker.attr('data-old-cobo', cri['data-cobo-id'])
533
+                                the_picker.attr('data-old-criterion', cri['value'])
534
+                                the_picker.attr('data-old-outcome', cri['data-outcome-id'])
535
+                                the_picker.attr('data-old-objective', cri['data-objective-id'])
536
+
537
+                                select = createSelectForModal(options_html)
538
+                                prog_div.append(select)
539
+                            // $('.criteria_select').selectpicker('refresh');
540
+                            })
541
+                            // to remove the last one
542
+                            select.remove();
543
+                        }
370 544
                         //prog_div.append(select)
371 545
 
372 546
                        // $('#program_objectives').append(prog_div);
@@ -374,6 +548,7 @@
374 548
                         $('select.criteria_select').selectpicker('refresh');
375 549
 
376 550
                         prog_div.append(createAddCriteriaButton("program-"+program.id))
551
+                        
377 552
 
378 553
                     
379 554
                     })
@@ -393,17 +568,54 @@
393 568
                 }
394 569
             )
395 570
         }
571
+        
572
+        wr = "#warning"
573
+        function deleteCriterion(button){
574
+            select =  $(button).parent().parent().find('select.criteria_select');
575
+
576
+            $('.selected_criteria_to_delete').removeClass('selected_criteria_to_delete');
577
+
578
+            $(button).addClass('selected_criteria_to_delete');
579
+          
580
+            criterion_id = $(select).val()
581
+            if(criterion_id ==0){
582
+                $(button).parent().parent().remove()
583
+                return
584
+            }
585
+            option = $(select).find(':selected');
586
+            name = $(select).find(':selected').html();
587
+            program_id = $(option).data('program-id')
588
+            outcome_id = $(option).data('outcome-id')
589
+            objective_id = $(option).data('objective-id')
590
+            cobo_id = $(option).data('cobo-id')
591
+            pcobo_id = $(option).data('pcobo-id')
592
+            $(wr+'_title').html("Are you sure you want to remove this Criterion?")
593
+            $(wr+"_delete").attr('onclick', 'postDeleteCrit('+criterion_id+' ,'+program_id+' ,'+outcome_id+' ,'+objective_id+' ,'+cobo_id+' ,'+pcobo_id+'); $("'+wr+'").modal("hide") ');
594
+            $(wr+'_body').html("<p>You are about to detach <strong>"+ name+"</strong> </p>")
595
+            $(wr).modal('show');
596
+        }
396 597
 
397 598
         function createAddCriteriaButton(program_div_id){
398 599
 
399
-
600
+            div= $("<div>",{
601
+                'class':'col-md-12'
602
+            });
603
+            
400 604
             button = $("<button>", {
401 605
                 'class':'add_criteria btn btn-secondary',
402 606
                 'type':'button',
403
-                'onclick':'addSelect('+program_div_id+')'
404
-                
405
-            }).html("+ Add Criteria");
607
+                'onclick':'addSelect("#'+program_div_id+'")',
608
+                'style':'float: right'  
609
+            }).html(" <span class = 'glyphicon glyphicon-plus'></span> Add Criteria");
610
+            div.append(button)
611
+            div.append('<br><br>')
612
+            return div;
613
+        }
406 614
 
615
+        function addSelect(program_div_id){
616
+            options = $(program_div_id).children('.removable_div').first().find('select.criteria_select').html();
617
+            $(program_div_id).children(".removable_div").last().after(createSelectForModal(options));
618
+            $('select.criteria_select').selectpicker('refresh');
407 619
         }
408 620
 
409 621
         $('.view-scales').on('click', function() {