Kaynağa Gözat

Update to Learning Outcomes edit page

The table now has 3 new columns of data that can be edited.
Added a form to create a new learning outcome.
onielm 4 yıl önce
ebeveyn
işleme
a748f26801

+ 85
- 3
app/controllers/OutcomesController.php Dosyayı Görüntüle

@@ -14,8 +14,11 @@ class OutcomesController extends \BaseController {
14 14
         $title = "Learning Outcomes";
15 15
         $outcomes = Outcome::withTrashed()->orderBy('name', 'ASC')->get();
16 16
         $schools = School::orderBy('name', 'ASC')->get();
17
+        // $semesters_ids = Session::get('semesters_ids');
18
+        // $semesters = Semester::whereIn('id',$semesters_ids)->get();
17 19
 
18 20
         return View::make('local.managers.admins.learning-outcomes', compact('title', 'outcomes', 'schools'));
21
+        //return View::make('local.managers.admins.learning-outcomes', compact('title', 'outcomes', 'schools','semesters'));
19 22
     }
20 23
 
21 24
     // TODO: Change to home page
@@ -295,6 +298,85 @@ class OutcomesController extends \BaseController {
295 298
         return;
296 299
     }
297 300
 
301
+    /**
302
+    *Copy of update(), but also updates activation_date, deactivation_date and level
303
+    */
304
+    public function updateMore()
305
+    {
306
+        $outcomeArray = json_decode(Input::get('outcomeArray'), true);
307
+        Session::flash('status', 'success');
308
+        Session::flash('message', 'Learning Outcomes updated.');
309
+
310
+        foreach ($outcomeArray as $outcomeObject)
311
+        {
312
+
313
+
314
+            $validator = Validator::make(
315
+                array(
316
+                    'name' => $outcomeObject['name'],
317
+                    'definition' => $outcomeObject['definition'],
318
+                    'expected_outcome' => $outcomeObject['expected_outcome']
319
+                    // TODO- validar los otros 3 valores
320
+                ),
321
+                array(
322
+                    'name' => 'required',
323
+                    'definition' => 'required',
324
+                    'expected_outcome' => 'required|numeric'
325
+                    // TODO- los requisitos de los otros 3 valores
326
+                )
327
+            );
328
+
329
+            if(!$validator->fails())
330
+            {
331
+                try
332
+                {
333
+                    $outcome = Outcome::withTrashed()
334
+                        ->where('id','=', $outcomeObject['id'])
335
+                        ->firstOrFail();
336
+                    $outcome->name = $outcomeObject['name'];
337
+                    $outcome->definition = $outcomeObject['definition'];
338
+                    $outcome->expected_outcome = $outcomeObject['expected_outcome'];
339
+                    $outcome->activation_date = $outcomeObject['activation_date'];
340
+                    $outcome->deactivation_date = $outcomeObject['deactivation_date'];
341
+                    $outcome->level = $outcomeObject['level'];
342
+                    $outcome->save();
343
+
344
+                    // If delete is 1, and outcome isn't already trashed, delete
345
+                    if($outcomeObject['delete']==1 && !$outcome->trashed())
346
+                        $outcome->delete();
347
+                    // If delete is 0, and outcome is already trashed, restore
348
+                    elseif($outcomeObject['delete']==0 && $outcome->trashed())
349
+                        $outcome->restore();
350
+                }
351
+
352
+                catch(Exception $e)
353
+                {
354
+
355
+                    Session::flash('message', $e->getMessage());
356
+                }
357
+            }
358
+            else
359
+            {
360
+                /** Prepare error message */
361
+                $message = 'Error(s) updating the Learning Outcomes: <ul>';
362
+
363
+                foreach ($validator->messages()->all('<li>:message</li>') as $validationError)
364
+                {
365
+                    $message.=$validationError;
366
+                }
367
+
368
+                $message.='</ul>';
369
+
370
+                /** Send error message and old data */
371
+                Session::flash('status', 'danger');
372
+                Session::flash('message', $message);
373
+                return;
374
+            }
375
+        }
376
+
377
+        return;
378
+    }
379
+
298 380
     public function fetchCriteria()
299 381
     {
300 382
 
@@ -391,7 +473,7 @@ class OutcomesController extends \BaseController {
391 473
             /** Send error message and old data */
392 474
             Session::flash('status', 'warning');
393 475
             Session::flash('message', $message);
394
-            return Redirect::to('learning-outcomes-criteria')->withInput();
476
+            return Redirect::to('learning-outcomes')->withInput();
395 477
         }
396 478
         else
397 479
         {
@@ -405,7 +487,7 @@ class OutcomesController extends \BaseController {
405 487
             {
406 488
                 Session::flash('status', 'success');
407 489
                 Session::flash('message', '<p>Learning Outcome added.</p>');
408
-                return Redirect::to('learning-outcomes-criteria');
490
+                return Redirect::to('learning-outcomes');
409 491
             }
410 492
 
411 493
             /** If saving fails, send error message and old data */
@@ -413,7 +495,7 @@ class OutcomesController extends \BaseController {
413 495
             {
414 496
                 Session::flash('status', 'warning');
415 497
                 Session::flash('message', '<p>Error adding Learning Outcome. Please try again later.</p>');
416
-                return Redirect::to('learning-outcomes-criteria')->withInput();
498
+                return Redirect::to('learning-outcomes')->withInput();
417 499
             }
418 500
         }
419 501
     }

+ 1
- 0
app/routes.php Dosyayı Görüntüle

@@ -255,6 +255,7 @@ Route::group(array('before' => 'auth|has_access'), function()
255 255
         // TODO: Change later
256 256
         Route::get('new-learning-outcomes', 'OutcomesController@newIndex');
257 257
         Route::post('learning-outcomes/update', array('before' => 'csrf', 'uses' => 'OutcomesController@update'));
258
+        Route::post('learning-outcomes/update', array('before' => 'csrf', 'uses' => 'OutcomesController@updateMore'));
258 259
         Route::post('crtiteria/update', array('before' => 'csrf', 'uses'=>'CriteriaController@update'));
259 260
         Route::delete('crtiteria/delete', array('before' => 'csrf', 'uses'=>'CriteriaController@destroy'));
260 261
 

+ 91
- 11
app/views/local/managers/admins/learning-outcomes.blade.php Dosyayı Görüntüle

@@ -15,33 +15,110 @@
15 15
     <div class="row">
16 16
         <div class="col-md-12">
17 17
             <p>Click on the values you want to change. Invalid values will be rejected automatically. To save your changes, click the 'Save' button at the bottom of the page.</p>
18
-            <table class="table table-striped table-condensed editable-table">
18
+            <table class="table table-striped table-condensed editable-table" id='outcomes_table'>
19 19
                 <thead><tr class="center-text">
20 20
                     <th class="col-md-4">Learning Outcome</th>
21 21
                     <th class="col-md-7">Definition</th>
22 22
                     <th class="col-md-1">Expected Value</th>
23
+                    <th class="col-md-2">Activation date</th>
24
+                    <th class="col-md-2">Deactivation date</th>
25
+                    <th class="col-md-1">Level</th>
23 26
 
24 27
                 </thead>
25 28
                 <tbody>
26
-                @foreach ($outcomes as $outcome)
27
-                    <tr data-id="{{ $outcome->id }}">
28
-                        <td contenteditable="true" class="name col-md-4" >{{ $outcome->name }}</td>
29
-                        <td contenteditable="true" data-type="textarea" class="definition col-md-6" >{{ $outcome->definition }}</td>
30
-                        <td contenteditable="true" class="expected-outcome col-md-1" >{{ $outcome->expected_outcome }}</td>
31
-                    </tr>
32
-                @endforeach
29
+                  @foreach ($outcomes as $outcome)
30
+                    {{-- @foreach ($semesters as $semester) --}}
31
+                      {{-- display an outcome only if it is part of a currently selected semester --}}
32
+                      @if ((($outcome->deactivation_date == '0000-00-00') or ($outcome->deactivation_date == ''))
33
+                            // and ($outcome->activation_date >= $semester->start && $outcome->activation_date <= $semester->end)
34
+                            )
35
+                            <tr data-id="{{ $outcome->id }}">
36
+                                <td contenteditable="true" class="name col-md-4" >{{ $outcome->name }}</td>
37
+                                <td contenteditable="true" data-type="textarea" class="definition col-md-6" >{{ $outcome->definition }}</td>
38
+                                <td contenteditable="true" class="expected-outcome col-md-1" >{{ $outcome->expected_outcome }}</td>
39
+                                <td contenteditable="true" class="activation-date col-md-2" >{{ $outcome->activation_date }}</td>
40
+                                <td contenteditable="true" class="deactivation-date col-md-2" >{{ $outcome->deactivation_date }}</td>
41
+                                <td contenteditable="true" class="level col-md-1" >{{ $outcome->level }}</td>
42
+                            </tr>
43
+                      @endif
44
+                    {{-- @endforeach --}}
45
+                  @endforeach
46
+                  @foreach ($outcomes as $outcome)
47
+                    {{-- @foreach ($semesters as $semester) --}}
48
+                      {{-- display an outcome only if it is part of a currently selected semester --}}
49
+                      @if ((($outcome->deactivation_date != '0000-00-00') and ($outcome->deactivation_date != ''))
50
+                            // and ($outcome->deactivation_date != '0000-00-00') and ($outcome->deactivation_date != '')
51
+                            )
52
+                            <tr data-id="{{ $outcome->id }}">
53
+                                <td contenteditable="true" class="name col-md-4" >{{ $outcome->name }}</td>
54
+                                <td contenteditable="true" data-type="textarea" class="definition col-md-6" >{{ $outcome->definition }}</td>
55
+                                <td contenteditable="true" class="expected-outcome col-md-1" >{{ $outcome->expected_outcome }}</td>
56
+                                <td contenteditable="true" class="activation-date col-md-2" >{{ $outcome->activation_date }}</td>
57
+                                <td contenteditable="true" class="deactivation-date col-md-2" >{{ $outcome->deactivation_date }}</td>
58
+                                <td contenteditable="true" class="level col-md-1" >{{ $outcome->level }}</td>
59
+                            </tr>
60
+                      @endif
61
+                    {{-- @endforeach --}}
62
+                  @endforeach
33 63
                 </tbody>
34 64
             </table>
35 65
         </div>
36 66
     </div>
37 67
     <div class="row">
38
-        <div class="col-md-12"><button class="btn btn-lg btn-primary center-block">Save</button></div>
68
+      <div class="col-md-6"><button class="btn btn-lg btn-secondary center-block" id='show'>New Outcome</button></div>
69
+      <div class="col-md-6"><button class="btn btn-lg btn-primary center-block" id='save'>Save</button></div>
39 70
     </div>
71
+
72
+  <div class="" id='new_outcome_form'>
73
+    <h2>Add a new Learning Outcomes</h2>
74
+    {{-- For for adding a new outcome --}}
75
+    {{ Form::open(array('action' => 'OutcomesController@create')) }}
76
+      <div class="form-group">
77
+          {{ Form::label('name', 'Name') }}
78
+          {{ Form::text('name', '', array('class' => 'form-control', 'id'=>'outcome_name')) }}
79
+      </div>
80
+      <div class="form-group">
81
+          {{ Form::label('definition', 'Definition') }}
82
+          {{ Form::textarea('definition', 'At least 10 characters long', array('class' => 'form-control', 'id'=>'outcome_definition')) }}
83
+      </div>
84
+      Due to technical limitationss, the following must be edited after adding the new Outcome:
85
+      {{-- the technical limitation is: the Outcome Model has to be edited --}}
86
+      <ul>
87
+       <li>Expected Outcome</li>
88
+       <li>Activation Date</li>
89
+       <li>Deactivation Date</li>
90
+       <li>Level</li>
91
+      </ul>
92
+
93
+      <div class="row">
94
+        <div class="col-md-6"><button type="reset" class="btn btn-lg btn-secondary center-block" id='hide'>Hide Form</button></div>
95
+        <div class="col-md-6"><button type="submit" class="btn btn-lg btn-primary center-block">Submit New Outcome</button></div>
96
+      </div>
97
+      {{ Form::close() }}
98
+
99
+    <hr>
100
+  </div>
40 101
 @stop
41 102
 
42 103
 @section('javascript')
43 104
 
44
-        $('button').on('click', function(e)
105
+        $('#new_outcome_form').hide();
106
+
107
+        //show form
108
+        $('#show').on('click', function(e)
109
+        {
110
+          $('#new_outcome_form').show();
111
+          $('#show').hide();
112
+        });
113
+
114
+        //hide form
115
+        $('#hide').on('click', function(e)
116
+        {
117
+          $('#new_outcome_form').hide();
118
+          $('#show').show();
119
+        });
120
+
121
+        $('#save').on('click', function(e)
45 122
         {
46 123
             e.preventDefault();
47 124
 
@@ -56,6 +133,9 @@
56 133
                 outcomeObject.name= $(this).children('.name').text();
57 134
                 outcomeObject.definition= $(this).children('.definition').text();
58 135
                 outcomeObject.expected_outcome= $(this).children('.expected-outcome').text();
136
+                outcomeObject.activation_date= $(this).children('.activation-date').text();
137
+                outcomeObject.deactivation_date= $(this).children('.deactivation-date').text();
138
+                outcomeObject.level= $(this).children('.level').text();
59 139
 
60 140
                 if($(this).find('.glyphicon-eye-close').length>0)
61 141
                 {
@@ -70,7 +150,7 @@
70 150
             });
71 151
 
72 152
             $.post(
73
-                "{{ URL::action('OutcomesController@update') }}",
153
+                "{{ URL::action('OutcomesController@updateMore') }}",
74 154
                 { outcomeArray: JSON.stringify(outcomeArray)},
75 155
                 function(data)
76 156
                 {