mirror of
https://github.com/fspc/BikeShed-1.git
synced 2026-09-16 08:31:36 -04:00
Bike photo upload
This commit is contained in:
@@ -16,4 +16,5 @@
|
||||
//= require utils
|
||||
//= require moment
|
||||
//= require bootstrap-datetimepicker
|
||||
//= require jquery.form
|
||||
|
||||
|
||||
@@ -1,31 +1,11 @@
|
||||
$('.btn').button();
|
||||
|
||||
$("#add_bike_submit").click(function(){
|
||||
|
||||
json_data = { bikes: [{
|
||||
serial_number: $("#serial_number").val(),
|
||||
bike_brand_id: parseInt($("#bike_brand_id").val()),
|
||||
shop_id: parseInt($("#shop_id").val()),
|
||||
model: $("#model").val(),
|
||||
bike_style_id: parseInt($('input[name=bike_style]:checked').val()),
|
||||
seat_tube_height: parseFloat($("#seat_tube_height").val()),
|
||||
bike_condition_id: parseInt($('input[name=bike_condition]:checked').val()),
|
||||
bike_purpose_id: 1,
|
||||
bike_wheel_size_id: parseInt($("#bike_wheel_size_id").val()),
|
||||
}]};
|
||||
|
||||
$.ajax({
|
||||
url: $("#add_bike_submit").data("url"),
|
||||
type: "POST",
|
||||
data: JSON.stringify(json_data),
|
||||
contentType: 'application/json',
|
||||
$("#add_bike_form").ajaxForm({
|
||||
dataType: "json",
|
||||
success: function(data, status, xhr){
|
||||
success: function(data){
|
||||
window.location = data.bikes[0].id + "?add_bike=1";
|
||||
},
|
||||
error: function(data, status ){
|
||||
error: function(data){
|
||||
displayFormErrors(data.responseJSON);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
})
|
||||
@@ -2,7 +2,7 @@ function displayFormErrors(data){
|
||||
if(data.errors != undefined ){
|
||||
$.each(data.errors, function(field, errorMsg) {
|
||||
$("#"+field).closest(".form-group").addClass("has-error");
|
||||
$("#"+field).siblings(".help-block").html(errorMsg);
|
||||
$("#"+field).siblings(".help-block").html(errorMsg.join(", "));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user