mirror of
https://github.com/fspc/BikeShed-1.git
synced 2025-02-28 08:43:23 -05:00
WIP, adding JS and api time entry create
This commit is contained in:
parent
b30203b750
commit
069a11f480
@ -1,4 +1,5 @@
|
||||
$(document).ready(function(){
|
||||
|
||||
var currentdate = new Date();
|
||||
$("#date_id").datepicker().on('changeDate', function(ev){
|
||||
$("#date_id").datepicker('hide');
|
||||
@ -7,4 +8,35 @@ $(document).ready(function(){
|
||||
|
||||
$("#start_time_id").timepicker();
|
||||
$("#end_time_id").timepicker();
|
||||
|
||||
$("#add_time_entry_submit").click(function(){
|
||||
date = $("#date_id").val();
|
||||
start_date = new Date(date + " " + $("#start_time_id").val());
|
||||
end_date = new Date(date + " " + $("#end_time_id").val());
|
||||
|
||||
json_data = { time_entries: [{
|
||||
start_date: start_date.toISOString(),
|
||||
end_date: end_date.toISOString(),
|
||||
log_action_id: parseInt($('input[name=action_id]:checked').val()),
|
||||
bike_id: parseInt($("#bike_id").val()),
|
||||
description: $("#description_id").val(),
|
||||
}]};
|
||||
console.log(json_data);
|
||||
|
||||
$.ajax({
|
||||
url: $("#add_time_entry_submit").data("url"),
|
||||
type: "POST",
|
||||
data: JSON.stringify(json_data),
|
||||
contentType: 'application/json',
|
||||
dataType: "json",
|
||||
success: function(data, status, xhr){
|
||||
console.log(data);
|
||||
//window.location = data.bikes[0].id;
|
||||
},
|
||||
error: function(data, status ){
|
||||
console.log(data);
|
||||
displayFormErrors(data.responseJSON);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -40,3 +40,8 @@ body {
|
||||
.inline-block {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.control-group.error .btn-group > .btn {
|
||||
color: #b94a48;
|
||||
border-color: #b94a48;
|
||||
}
|
||||
|
30
app/controllers/api/v1/time_entries_controller.rb
Normal file
30
app/controllers/api/v1/time_entries_controller.rb
Normal file
@ -0,0 +1,30 @@
|
||||
class Api::V1::TimeEntriesController < Api::V1::BaseController
|
||||
def create
|
||||
if params[:time_entries] && time_entry = params[:time_entries].first
|
||||
puts time_entry.inspect
|
||||
time_entry_defaults = {
|
||||
loggable_type: "User",
|
||||
loggable_id: current_user.id,
|
||||
log_action_type: "ActsAsLoggable::UserAction"}
|
||||
time_entry.merge(time_entry_defaults)
|
||||
|
||||
if time_entry[:bike_id] >= 0
|
||||
copy_defaults = {
|
||||
copy_log: true,
|
||||
copy_type: 'Bike',
|
||||
copy_id: time_entry[:bike_id],
|
||||
copy_action_type: 'ActsAsLoggable::BikeAction',
|
||||
copy_action_id: 4
|
||||
}
|
||||
time_entry.merge( copy_defaults )
|
||||
end
|
||||
|
||||
@time_entry = ::ActsAsLoggable::Log.new(time_entry.except(:bike_id))
|
||||
if !@time_entry.save
|
||||
render json: { errors: @time_entry.errors }, status: 422 and return
|
||||
end
|
||||
else
|
||||
render json: { errors: [EXPECTED_TIME_ENTRY]}, status: 422 and return
|
||||
end
|
||||
end
|
||||
end
|
@ -11,11 +11,13 @@
|
||||
.controls{ class: "bootstrap-timepicker"}
|
||||
%label Start
|
||||
%input{id: "start_time_id", placeholder: "Time ID", type: "text", class: "input-small" }
|
||||
.hidden{ id: "start_date" }
|
||||
.help-block
|
||||
.control-group
|
||||
.controls
|
||||
%label End
|
||||
%input{id: "end_time_id", placeholder: "Time ID", type: "text", class: "input-small" }
|
||||
.hidden{ id: "end_date" }
|
||||
.help-block
|
||||
.control-group
|
||||
.controls
|
||||
@ -26,15 +28,15 @@
|
||||
%input{ type: "radio", name: "action_id", value: 1} Personal
|
||||
%label{ class: "btn btn-default"}
|
||||
%input{ type: "radio", name: "action_id", value: 2} Staff
|
||||
%input{ id: "bike_style_id", type: "hidden"}
|
||||
.hidden{ id: "log_action_id" }
|
||||
.help-block
|
||||
.control-group
|
||||
.controls
|
||||
%label
|
||||
= select_tag(:bike_brand_id, options_for_select(@bikes))
|
||||
= select_tag(:bike_id, options_for_select(@bikes))
|
||||
.control-group
|
||||
.controls
|
||||
%textarea{id: "work_description", placeholder: "Work description", class: "input-lg" }
|
||||
%textarea{id: "description_id", placeholder: "Work description", class: "input-lg" }
|
||||
.control-group
|
||||
.controls
|
||||
%input{id: "add_bike_submit", value: "Add Time Entry", type: "button", class: "btn btn-lg btn-block btn-primary", "data-url" => "#{api_create_bike_path}"}
|
||||
%input{id: "add_time_entry_submit", value: "Add Time Entry", type: "button", class: "btn btn-lg btn-block btn-primary", "data-url" => "#{api_create_time_entry_path}"}
|
||||
|
@ -28,6 +28,8 @@ Velocipede::Application.routes.draw do
|
||||
get 'task_lists/:id' => "task_lists#show", as: "api_task_list"
|
||||
|
||||
put 'tasks/update' => "tasks#update", as: "api_update_task"
|
||||
|
||||
post 'time_entries/create' => "time_entries#create", as: "api_create_time_entry"
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user