function new _location _entry ( ) {
}
function init _Location _edit ( locationID , name , containerID ) {
$ ( '#save-button' ) . attr ( "onclick" , "saveLocation(" + locationID + ")" ) ;
$ ( '#delete-button' ) . attr ( "onclick" , "deleteLocation(" + locationID + ")" ) ;
$ ( '#location-name-input' ) . val ( name ) ;
if ( containerID > 0 ) {
$ ( "#container-input" ) . val ( containerID ) ;
update _map ( ) ;
}
overlay _in ( ) ;
}
function update _map ( ) {
var selected _map _file = $ ( '#container-input' ) . val ( ) ;
$ ( '#map' ) . attr ( 'src' , 'map/' + selected _map _file ) ;
}
function saveLocation ( locationID ) {
var container _v = $ ( '#container-input' ) . val ( ) ;
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 ( 'container' , container _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 deleteLocation ( locationID ) {
if ( locationID < 0 ) {
alert ( 'Congratulations! You found the secret UI bug easter egg! This button should not be here, yet I left it specifically because I wanted an easter egg and not because of any other reasons! Good for you!' )
return ;
}
if ( ! confirm ( 'Delete the selected location? If there are parts there, this will leave a mess in the database and Marek will be very sad.' ) ) {
return ;
}
$ . ajax ( {
url : rootURL + 'deleteLocation/' + locationID ,
type : 'GET' ,
cache : false ,
contentType : false ,
processData : false ,
success : function ( ) {
alert ( "location removed." ) ;
overlay _out ( ) ;
location . reload ( ) ;
} ,
fail : function ( ) {
console . log ( 'An error occurred while deleting the entry' ) ;
} ,
} ) ;
}
function end _edit ( ) {
//intentionally left blank
}
function show _location _info ( locationID ) {
$ . getJSON ( rootURL + 'getpartinfo/' + partID , function ( data ) {
$ ( 'table#details tr#location td p' ) . text ( text _filter ( data . location _descriptor ) ) ; // name is the location friendly name
$ ( '#location-dropdown' ) . val ( data . location _id ) ;
$ ( '#container-dropdown' ) . val ( data . container _id ) ;
$ ( 'table#details tr#partno td p' ) . text ( text _filter ( data . partno ) ) ;
$ ( 'table#details tr#partno td input' ) . val ( text _filter ( data . partno ) ) ;
$ ( 'table#details tr#description td p' ) . text ( text _filter ( data . description ) ) ;
$ ( 'table#details tr#description td input' ) . val ( text _filter ( data . description ) ) ;
container _onchange ( ) ;
if ( data . datasheet != null ) {
$ ( 'tr#datasheet-head' ) . html ( $ ( '<td>DATASHEET: <a href="parts/getfile/' + data . datasheet + '"><i class="fa fa-file-text" aria-hidden="true"></i></a></td>' ) ) ;
$ ( '#datasheet-input' ) . val ( data . datasheet ) ;
}
else
$ ( 'tr#datasheet-head td' ) . text ( 'DATASHEET: ' ) ;
$ ( '#edit-button' ) . click ( function ( ) {
init _edit ( partID ) ;
} ) ;
$ ( '#delete-button' ) . click ( function ( ) {
delete _entry ( partID ) ;
} ) ;
overlay _in ( ) ;
} ) . fail ( function ( ) {
console . log ( "Fetching part info failed" ) ;
} ) ;
}
function placeMarker ( locationID ) {
//temporarily not used
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 ) ;
}