working way to update your scheduled PTO
This commit is contained in:
@@ -1,7 +1,38 @@
|
|||||||
class ScheduleController < ApplicationController
|
class ScheduleController < ApplicationController
|
||||||
def create
|
def create
|
||||||
|
message = false
|
||||||
|
|
||||||
|
if params[:schedule][:event_type] == "pto"
|
||||||
|
sched = Schedule.new(params[:schedule])
|
||||||
|
sched.date_begin, sched.date_end = format_schedule_date(params[:date_range1])
|
||||||
|
sched.user_id = current_user.user_id
|
||||||
|
a = sched.date_end
|
||||||
|
if sched.save
|
||||||
|
message = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json {render :json => {:msg => "success"}}
|
format.json {render :json => {:msg => message ? "success" : "failure" }}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# Returns a two part array consisting of dates
|
||||||
|
# First value is the begin date and the second is the end date
|
||||||
|
def format_schedule_date(date_array)
|
||||||
|
begin
|
||||||
|
vals = []
|
||||||
|
return vals if date_array.empty?
|
||||||
|
date_array.split('-').each do |s|
|
||||||
|
date = Date.strptime(s.strip, '%m/%d/%Y')
|
||||||
|
vals <<(date)
|
||||||
|
end
|
||||||
|
rescue ArgumentError
|
||||||
|
return []
|
||||||
|
end
|
||||||
|
return vals
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
class Schedule < ActiveRecord::Base
|
class Schedule < ActiveRecord::Base
|
||||||
attr_accessible :date_begin, :date_end, :event_desc, :event_name, :event_type, :user_id
|
attr_accessible :date_begin, :date_end, :event_desc, :event_name, :event_type, :user_id
|
||||||
belongs_to :paid_time_off
|
belongs_to :paid_time_off
|
||||||
|
|
||||||
|
validates_presence_of :date_begin, :date_end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,29 @@
|
|||||||
<div class="dashboard-wrapper">
|
<div class="dashboard-wrapper">
|
||||||
<div class="main-container">
|
<div class="main-container">
|
||||||
|
<div class="row-fluid">
|
||||||
|
<div class="span12">
|
||||||
|
<div id="success" style="display: none;" class="alert alert-block alert-success fade in">
|
||||||
|
<h4 class="alert-heading">
|
||||||
|
Success!
|
||||||
|
</h4>
|
||||||
|
<p>
|
||||||
|
Information successfully updated.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row-fluid">
|
||||||
|
<div class="span12">
|
||||||
|
<div id="failure" style="display: none;" class="alert alert-block alert-error fade in">
|
||||||
|
<h4 class="alert-heading">
|
||||||
|
Error!
|
||||||
|
</h4>
|
||||||
|
<p>
|
||||||
|
Failed to update.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<!-- Begin DP-->
|
<!-- Begin DP-->
|
||||||
<div class="row-fluid">
|
<div class="row-fluid">
|
||||||
<!-- begin cal -->
|
<!-- begin cal -->
|
||||||
@@ -206,8 +230,11 @@ $("#cal_update_submit").click(function(event) {
|
|||||||
data: valuesToSubmit,
|
data: valuesToSubmit,
|
||||||
type: "POST",
|
type: "POST",
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
|
if (response.msg == "failure") {
|
||||||
|
$('#failure').show(500).delay(1500).fadeOut();
|
||||||
|
} else {
|
||||||
$('#success').show(500).delay(1500).fadeOut();
|
$('#success').show(500).delay(1500).fadeOut();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
error: function(event) {
|
error: function(event) {
|
||||||
$('#failure').show(500).delay(1500).fadeOut();
|
$('#failure').show(500).delay(1500).fadeOut();
|
||||||
|
|||||||
Reference in New Issue
Block a user