diff --git a/parts/static/userEditorScript.js b/parts/static/userEditorScript.js new file mode 100755 index 0000000..9e4d1d8 --- /dev/null +++ b/parts/static/userEditorScript.js @@ -0,0 +1,118 @@ +function new_user_entry() { + +} + +function init_User_edit(userID, name) { + $('#save-button').attr("onclick", "saveUser(" + userID + ")"); + $('#delete-button').attr("onclick", "deleteUser(" + userID + ")"); + $('#user-name-input').val(name); + $('#user-password-input').val(''); + overlay_in(); +} + + +function saveUser(userID) { + var name_v = $('#user-name-input').val(); + var password_v = $('#user-password-input').val(); + + if(name_v.length > 100) { + alert('Name too long (max 100 characters).') + return; + } + var data = new FormData(); + + data.append('password', password_v); + data.append('name', name_v) + + $.ajax({ + url: rootURL + 'alterUser/' + userID, + type: 'POST', + data: data, + cache: false, + contentType: false, + processData: false, + success: function(data) { + alert("k."); + }, + error: function() { + alert("Couldn't update the user information. Please retry."); + } + }); + + end_edit(); + $('#edit-button').click(function() { + init_edit(userID); + }); +} + + +function deleteUser(userID) { + if (userID < 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 user? ')){ + return; + } + $.ajax({ + url: rootURL + 'deleteUser/' + userID, + type: 'GET', + cache: false, + contentType: false, + processData: false, + success: function() { + alert("User removed."); + overlay_out(); + location.reload(); + }, + fail: function() { + console.log('An error occurred while deleting the entry'); + }, + }); +} + +function end_edit(){ + //intentionally left blank +} + + +function show_user_info(userID) { + $.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($('DATASHEET: ')); + $('#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); +} diff --git a/parts/templates/userEditor.html b/parts/templates/userEditor.html new file mode 100755 index 0000000..2a9d652 --- /dev/null +++ b/parts/templates/userEditor.html @@ -0,0 +1,53 @@ + + + + + ELAB Part Search Engine - User editor + + + + + + + + +

USER EDITOR

+

Get in! Get out! Get your fresh users here! back to parts

+ + + + + + {% for user in users %} + + + + + {% endfor %} +
IDUsername
{{user['id']}}{{user['username']}}
+
+ +
+
+

User Details

+ + + + + + + + + + +
Adding a new user
Name and password for new user
Example: "noob"

+
+
+
+
+
+ +