parent
							
								
									d131bcede6
								
							
						
					
					
						commit
						00a2d6f070
					
				| @ -0,0 +1,67 @@ | |||||||
|  | function new_location_entry() { | ||||||
|  | 	$('#location-name-input').text(''); | ||||||
|  | 	$('#location-name-input').show(); | ||||||
|  | 	$('#mapfile-input').show(); | ||||||
|  | 	init_Location_edit(-1); | ||||||
|  | 	overlay_in(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function init_Location_edit(locationID) { | ||||||
|  | 
 | ||||||
|  | 	$('table#details tr#datasheet td input').show(); | ||||||
|  | 
 | ||||||
|  | 	var newButton = '<div class="round-button-left"><a href="#" onclick="saveLocation(' + locationID + ')"><i class="fa fa-check" aria-hidden="true"></i></a></div>'; | ||||||
|  | 	$('.round-button-left').replaceWith(newButton); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function update_clickable_map() { | ||||||
|  | 	var selected_map_file = $('#mapfile-input').val(); | ||||||
|  | 	$('#clickablemap').attr('src', 'map/' + selected_map_file); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | function saveLocation(locationID) { | ||||||
|  | 	var map_v = $('#clickablemap').attr('src').substring(4); | ||||||
|  | 	var name_v = $('#location-name-input').val(); | ||||||
|  | 
 | ||||||
|  | 	if(name_v.length > 100) { | ||||||
|  | 		alert('Name too long (max 100 characters).') | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 	var data = new FormData(); | ||||||
|  | 
 | ||||||
|  | 	data.append('map', map_v); | ||||||
|  | 	data.append('name', name_v) | ||||||
|  | 
 | ||||||
|  | 	$.ajax({ | ||||||
|  | 	    url: rootURL + 'alterLocation/' + locationID, | ||||||
|  | 	    type: 'POST', | ||||||
|  |       data: data, | ||||||
|  |       cache: false, | ||||||
|  |       contentType: false, | ||||||
|  |       processData: false, | ||||||
|  | 			success: function(data) { | ||||||
|  | 				alert("k."); | ||||||
|  | 			}, | ||||||
|  | 			error: function() { | ||||||
|  | 				alert("Couldn't update the part information. Please retry."); | ||||||
|  | 			} | ||||||
|  | 	  }); | ||||||
|  | 
 | ||||||
|  | 	end_edit(); | ||||||
|  | 	$('#edit-button').click(function() { | ||||||
|  | 		init_edit(partID); | ||||||
|  | 	}); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function placeMarker(locationID){ | ||||||
|  | 	var $img = $('#clickablemap'); | ||||||
|  | 	var currentClickPosX = event.pageX - $img.offset().left; | ||||||
|  | 	var currentClickPosY = event.pageY - $img.offset().top; | ||||||
|  | 
 | ||||||
|  |     var correctX = (($img.prop('naturalWidth') / $img.width()) * currentClickPosX).toFixed(0); | ||||||
|  |     var correctY = (($img.prop('naturalHeight') / $img.height()) * currentClickPosY).toFixed(0); | ||||||
|  | 
 | ||||||
|  |     // $("#mapURL").html("elab.png?x=" + correctX + "&y=" + correctY);
 | ||||||
|  |     $("#clickablemap").attr("src", "map/" + $("#mapfile-input").val() + "?x=" + correctX + "&y=" + correctY); | ||||||
|  | } | ||||||
| @ -0,0 +1,60 @@ | |||||||
|  | <!DOCTYPE html> | ||||||
|  | <html> | ||||||
|  |   <head> | ||||||
|  |     <meta charset="utf-8"> | ||||||
|  |     <title>ELAB Part Search Engine</title> | ||||||
|  |     <script | ||||||
|  |   src="https://code.jquery.com/jquery-3.2.1.min.js" | ||||||
|  |   integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" | ||||||
|  |   crossorigin="anonymous"></script> | ||||||
|  |     <link href="https://fonts.googleapis.com/css?family=Roboto:300,400" rel="stylesheet"> | ||||||
|  |     <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}"> | ||||||
|  |     <script src="https://use.fontawesome.com/2fef7be393.js"></script> | ||||||
|  |     <script type="text/javascript" src="{{ url_for('static', filename='common.js') }}"></script> | ||||||
|  |     <script type="text/javascript" src="{{ url_for('static', filename='locationEditorScript.js') }}"></script> | ||||||
|  |   </head> | ||||||
|  |   <body> | ||||||
|  |     <h1>ELAB Part Search Engine - LOCATION EDITOR</h1> | ||||||
|  |     <p>Looking for a place to store your obsolete ICs discontinued years ago? Just toss them anywhere and mark that location here!</p> | ||||||
|  |     <table id="results"> | ||||||
|  |       <tr> | ||||||
|  |         <th id="id">ID</th> | ||||||
|  |         <th id="location">Location name</th> | ||||||
|  |         <th id="mapURL">Map URL</th> | ||||||
|  |       </tr> | ||||||
|  |       {% for location in locations %} | ||||||
|  |         <tr> | ||||||
|  |           <td>{{location['id']}}</td> | ||||||
|  |           <td>{{location['name']}}</td> | ||||||
|  |           <td>{{location['map']}}</td> | ||||||
|  |         </tr> | ||||||
|  |       {% endfor %} | ||||||
|  |     </table> | ||||||
|  |     <div class="bottom-spacer"></div> | ||||||
|  | 
 | ||||||
|  |   	<div class="overlay"> | ||||||
|  |       <h2>Part Details</h2> | ||||||
|  |       <table id="details"> | ||||||
|  |         <tr><td>Name</td></tr> | ||||||
|  |         <tr><td><p></p><input type="text" name="location-name-input" id="location-name-input" placeholder="Location name" class="pinfo-input"/></td></tr> | ||||||
|  |         | ||||||
|  |         <tr><td>MAP</td></tr> | ||||||
|  |         <tr><td> | ||||||
|  |           <select class="pinfo-input" onchange="update_clickable_map()" name="mapfile-input" id="mapfile-input"> | ||||||
|  |             {% for mapfile in mapfiles %} | ||||||
|  |             <option value="{{mapfile}}" {% if mapfile==defaultMapfile %}selected="true"{% endif %}>{{mapfile}}</option> | ||||||
|  |             {% endfor %} | ||||||
|  |           </select> | ||||||
|  |         </td></tr> | ||||||
|  | 
 | ||||||
|  |         <tr><td>And click on the map to place the marker</td></tr> | ||||||
|  |          | ||||||
|  |       </table> | ||||||
|  |       <img src="map/{{defaultMapfile}}" id="clickablemap" class="map" onclick="placeMarker()"/> | ||||||
|  |       <div class="round-button-left"><a href="#" id="edit-button"><i class="fa fa-pencil" aria-hidden="true"></i></a></div> | ||||||
|  |       <div class="round-button"><a href="#" id="delete-button"><i class="fa fa-trash" aria-hidden="true"></i></a></div> | ||||||
|  |       <div class="small-square-button"><a href="#" onclick="overlay_out()"><i class="fa fa-times" aria-hidden="true"></i></a></div> | ||||||
|  |   	</div> | ||||||
|  |     <div class="round-floating-button"><a href="#" onclick="new_location_entry()"><i class="fa fa-plus" aria-hidden="true"></i></a></div> | ||||||
|  |   </body> | ||||||
|  | </html> | ||||||
					Loading…
					
					
				
		Reference in new issue