mirror of
https://github.com/fspc/BikeShed-1.git
synced 2026-09-16 08:31:36 -04:00
Merge pull request #118 from ilya-konanykhin/issue-105-106
Issue #105, #106: photo upload for User & Bike
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,50 +2,79 @@ $(document).ready(function(){
|
||||
var MIN_LEN = 3;
|
||||
var MAX_SUBMITS = 3;
|
||||
var submit_count = 0;
|
||||
$("input[name=commit]").click( function(e){
|
||||
console.log("clicked");
|
||||
submit_count += 1;
|
||||
//IDs of contact info
|
||||
var contact_info_ids = [
|
||||
"user_email",
|
||||
"user_user_profiles_attributes_0_addrStreet1",
|
||||
"user_user_profiles_attributes_0_addrCity",
|
||||
"user_user_profiles_attributes_0_addrState",
|
||||
"user_user_profiles_attributes_0_addrZip",
|
||||
"user_user_profiles_attributes_0_phone"
|
||||
];
|
||||
var contact_vals = "";
|
||||
var index = 0;
|
||||
//see if any contact info exists
|
||||
for( var index in contact_info_ids){
|
||||
contact_vals += $("#"+contact_info_ids[index]).val();
|
||||
}
|
||||
if( contact_vals.length >= MIN_LEN || submit_count > MAX_SUBMITS){
|
||||
|
||||
if( submit_count > MAX_SUBMITS ){
|
||||
alert("Fine.");
|
||||
var checkContacts = function() {
|
||||
submit_count += 1;
|
||||
//IDs of contact info
|
||||
var contact_info_ids = [
|
||||
"user_email",
|
||||
"user_user_profiles_attributes_0_addrStreet1",
|
||||
"user_user_profiles_attributes_0_addrCity",
|
||||
"user_user_profiles_attributes_0_addrState",
|
||||
"user_user_profiles_attributes_0_addrZip",
|
||||
"user_user_profiles_attributes_0_phone"
|
||||
];
|
||||
|
||||
var contact_vals = "";
|
||||
//see if any contact info exists
|
||||
for( var index in contact_info_ids){
|
||||
contact_vals += $("#"+contact_info_ids[index]).val();
|
||||
}
|
||||
return true;
|
||||
if( contact_vals.length >= MIN_LEN || submit_count > MAX_SUBMITS){
|
||||
|
||||
}else{
|
||||
if( submit_count == MAX_SUBMITS + 1 ){
|
||||
alert("Fine.");
|
||||
}
|
||||
return true;
|
||||
|
||||
switch(submit_count){
|
||||
case 1:
|
||||
alert("It appears you have not entered any contact information. " +
|
||||
"Please do.");
|
||||
break;
|
||||
case 2:
|
||||
alert("It is highly recommended that you enter at least one form of" +
|
||||
" contact information. It is in your best interest.");
|
||||
break;
|
||||
case 3:
|
||||
alert("If something happens to your bicycle, we will not be able to" +
|
||||
" notify you. Please enter at least one form of contact.");
|
||||
break;
|
||||
default:
|
||||
alert("Please enter at least one form of contact.");
|
||||
}else{
|
||||
|
||||
switch(submit_count){
|
||||
case 1:
|
||||
alert("It appears you have not entered any contact information. " +
|
||||
"Please do.");
|
||||
break;
|
||||
case 2:
|
||||
alert("It is highly recommended that you enter at least one form of" +
|
||||
" contact information. It is in your best interest.");
|
||||
break;
|
||||
case 3:
|
||||
alert("If something happens to your bicycle, we will not be able to" +
|
||||
" notify you. Please enter at least one form of contact.");
|
||||
break;
|
||||
default:
|
||||
alert("Please enter at least one form of contact.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
var checkValid = function() {
|
||||
var errors = {};
|
||||
var hasErrors = false;
|
||||
["username", "first_name", "last_name"].forEach(function(requiredField) {
|
||||
if(!$("#user_" + requiredField).val().trim()) {
|
||||
errors["user_" + requiredField] = ["can't be blank"];
|
||||
hasErrors = true;
|
||||
}
|
||||
});
|
||||
|
||||
if($("#user_password").val().length < 6) {
|
||||
errors["user_password"] = ["is too short (minimum is 6 characters)"];
|
||||
hasErrors = true;
|
||||
}
|
||||
|
||||
if($("#user_password").val() != $("#user_password_confirmation").val()) {
|
||||
errors["user_password_confirmation"] = ["confirmation doesn't match password"];
|
||||
hasErrors = true;
|
||||
}
|
||||
|
||||
displayFormErrors({errors: errors}, "#new_user");
|
||||
|
||||
return !hasErrors;
|
||||
};
|
||||
|
||||
$("input[name=commit]").click(function(e){
|
||||
return checkContacts() && checkValid();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
function displayFormErrors(data){
|
||||
function displayFormErrors(data, form){
|
||||
if(form){
|
||||
$(form).find(".form-group.has-error").removeClass("has-error").find(".help-block").html("");
|
||||
}
|
||||
if(data.errors != undefined ){
|
||||
$.each(data.errors, function(field, errorMsg) {
|
||||
$("#"+field).closest(".form-group").addClass("has-error");
|
||||
$("#"+field).siblings(".help-block").html(errorMsg);
|
||||
$("#"+field).closest(".form-group").addClass("has-error").find(".help-block").html(errorMsg.join(", "));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user