mirror of
				https://github.com/fspc/BikeShed-1.git
				synced 2025-10-31 00:45:35 -04:00 
			
		
		
		
	Added submit js to bikes/new view
* Added displayFormErrors utility * Added 4th option to bike styles “OTHER”
This commit is contained in:
		
							parent
							
								
									e694dfbddd
								
							
						
					
					
						commit
						2d09aba26a
					
				| @ -13,3 +13,4 @@ | ||||
| //= require jquery
 | ||||
| //= require jquery_ujs
 | ||||
| //= require twitter/bootstrap/bootstrap-button
 | ||||
| //= require utils
 | ||||
|  | ||||
| @ -1 +1,30 @@ | ||||
| $('.btn').button(); | ||||
| 
 | ||||
| $("#add_bike_submit").click(function(){ | ||||
| 
 | ||||
|   json_data = { bike: { | ||||
|       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:   parseInt($("#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_data, | ||||
|     dataType: "json", | ||||
|     success: function(data, status, xhr){ | ||||
|       //window.location = "";
 | ||||
|     }, | ||||
|     error: function(data, status ){ | ||||
|       displayFormErrors(data.responseJSON); | ||||
|     } | ||||
|   }); | ||||
| 
 | ||||
| }); | ||||
|  | ||||
							
								
								
									
										8
									
								
								app/assets/javascripts/utils.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								app/assets/javascripts/utils.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,8 @@ | ||||
| function displayFormErrors(data){ | ||||
|   if( data.errors != undefined ){ | ||||
|     $.each( data.errors, function( field, errorMsg) { | ||||
|       $("#"+field).parents(".control-group").addClass("error"); | ||||
|       $("#"+field).siblings(".help-block").html(errorMsg); | ||||
|     }); | ||||
|   } | ||||
| } | ||||
| @ -1,39 +1,56 @@ | ||||
| %h2 Add Bike | ||||
| 
 | ||||
| %p | ||||
|   %p | ||||
|     %input{id: "bike_shop_id", placeholder: "Shop ID", type: "number", min:0, class: "input-lg" } | ||||
|   %p | ||||
|     = select_tag(:bike_brand_id, options_for_select(@brands)) | ||||
|   %p | ||||
|     %input{id: "bike_model", placeholder: "Model", type: "text", class: "input-lg" } | ||||
|   .control-group | ||||
|     .controls | ||||
|       %input{id: "shop_id", placeholder: "Shop ID", type: "number", min:0, class: "input-lg" } | ||||
|       .help-block | ||||
|   .control-group | ||||
|     .controls | ||||
|       = select_tag(:bike_brand_id, options_for_select(@brands)) | ||||
|       .help-block | ||||
|   .control-group | ||||
|     .controls | ||||
|       %input{id: "model", placeholder: "Model", type: "text", class: "input-lg" } | ||||
|       .help-block | ||||
|   .control-group | ||||
|     .controls | ||||
|       %input{id: "serial_number", placeholder: "Serial Number", type: "text", class: "input-lg" } | ||||
|       .help-block | ||||
|   %p | ||||
|     .btn-group{ "data-toggle" => "buttons-radio"} | ||||
|       %label{ class: "btn btn-default"} | ||||
|         %input{ type: "radio", name: "options"} RD | ||||
|         %input{ type: "radio", name: "bike_style", value: 3} RD | ||||
|       %label{ class: "btn btn-default"} | ||||
|         %input{ type: "radio", name: "options"} MTN | ||||
|         %input{ type: "radio", name: "bike_style", value: 1} MTN | ||||
|       %label{ class: "btn btn-default"} | ||||
|         %input{ type: "radio", name: "options"} HYB | ||||
|         %input{ type: "radio", name: "bike_style", value: 2} HYB | ||||
|       %label{ class: "btn btn-default"} | ||||
|         %input{ type: "radio", name: "options"} OTHER | ||||
|   %p | ||||
|     = select_tag(:bike_wheel_size, options_for_select(@wheel_sizes)) | ||||
|         %input{ type: "radio", name: "bike_style", value: 4} OTHER | ||||
|       .help-block | ||||
|   .control-group | ||||
|     .controls | ||||
|       = select_tag(:bike_wheel_size, options_for_select(@wheel_sizes), id: :bike_wheel_size_id) | ||||
|       .help-block | ||||
|   %p | ||||
|     .btn-group{ "data-toggle" => "buttons-radio"} | ||||
|       %label{ class: "btn btn-default"} | ||||
|         %input{ type: "radio", name: "options"} Poor | ||||
|         %input{ type: "radio", name: "bike_condition", value: 2} Poor | ||||
|       %label{ class: "btn btn-default"} | ||||
|         %input{ type: "radio", name: "options"} Fair | ||||
|         %input{ type: "radio", name: "bike_condition", value: 3} Fair | ||||
|       %label{ class: "btn btn-default"} | ||||
|         %input{ type: "radio", name: "options"} Good | ||||
|         %input{ type: "radio", name: "bike_condition", value: 4} Good | ||||
|       %label{ class: "btn btn-default"} | ||||
|         %input{ type: "radio", name: "options"} Excellent | ||||
|   %p | ||||
|     %input{id: "bike_seat_tube", placeholder: "Seat Tube (cm)", type: "number", min: 0, max: 100, class: "input-lg" } | ||||
|         %input{ type: "radio", name: "bike_condition", value: 5} Excellent | ||||
|       .help-block | ||||
|   .control-group | ||||
|     .controls | ||||
|       %input{id: "seat_tube_height", placeholder: "Seat Tube (cm)", type: "number", min: 0, max: 100, class: "input-lg" } | ||||
|       .help-block | ||||
|   -# Commenting this out until description is added to Bike | ||||
|     %p | ||||
|       %input{id: "bike_description", placeholder: "Short description", type: "text", class: "input-lg" } | ||||
|   %p | ||||
|     %input{id: "index_logout", value: "Add Bike", type: "button", class: "btn btn-lg btn-block btn-primary", "data-url" => "api_add_bike_path"} | ||||
|   .control-group | ||||
|     .controls | ||||
|       %input{id: "add_bike_submit", value: "Add Bike", type: "button", class: "btn btn-lg btn-block btn-primary", "data-url" => "#{api_create_bike_path}"} | ||||
| 
 | ||||
|  | ||||
| @ -7,3 +7,6 @@ hybrid: | ||||
| road: | ||||
|   id: 3 | ||||
|   style: ROAD | ||||
| road: | ||||
|   id: 4 | ||||
|   style: OTHER | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user