Merge branch 'master' of git.elab.kth.se:davide/ELAB-partsearch

pull/3/head
Wilhelm Westermark 6 years ago
commit e592f300bb

@ -183,10 +183,11 @@ def getfile(filename):
def alter(partID): def alter(partID):
partID = int(partID) partID = int(partID)
s = '' s = ''
r = {}
if partID < 0: if partID < 0:
# New entry # New entry
s = 'insert into parts (partno, description, datasheet, location_id) ' s = 'insert into parts (partno, description, datasheet, location_id) '
s += 'values (:partno, :description, :datasheet, :location_id);' s += 'values (:partno, :description, :datasheet, :location_id) returning id;'
s = text(s) s = text(s)
if len(request.files) != 0: if len(request.files) != 0:
datasheet_file = request.files['datasheet-file'] datasheet_file = request.files['datasheet-file']
@ -223,17 +224,20 @@ def alter(partID):
os.remove('/srv/datasheets/' + l[0]['datasheet']) os.remove('/srv/datasheets/' + l[0]['datasheet'])
else: else:
datasheet_filename = l[0]['datasheet'] datasheet_filename = l[0]['datasheet']
s += 'where id=:id;' s += 'where id=:id returning id;'
s = text(s) s = text(s)
r = db_engine.execute(s, partno=request.form['partno'], r = db_engine.execute(s, partno=request.form['partno'],
description=request.form['description'], description=request.form['description'],
datasheet=datasheet_filename, datasheet=datasheet_filename,
location_id=request.form['location_id'], location_id=request.form['location_id'],
id=partID) id=partID)
return '{"status":"ok"}'
new_id = r.fetchone()[0]
r.close()
return '{"status":"ok", "part_id" : ' + str(new_id) + '}'
@app.route('/parts/delete/<partID>') @app.route('/parts/delete/<partID>')
@requires_auth # @requires_auth
def delete(partID): def delete(partID):
if partID < 0: if partID < 0:
abort(400) abort(400)

@ -29,12 +29,16 @@ function new_entry() {
} }
function end_edit() { function end_edit() {
$('table#details tr#location td p').text($('table#details tr#location td select option:checked').val());
$('table#details tr#location td p').show(); $('table#details tr#location td p').show();
$('table#details tr#location td select').hide(); $('table#details tr#location td select').hide();
$('table#details tr#partno td p').text($('table#details tr#partno td input').val());
$('table#details tr#partno td p').show(); $('table#details tr#partno td p').show();
$('table#details tr#partno td input').hide(); $('table#details tr#partno td input').hide();
$('table#details tr#description td p').text($('table#details tr#description td input').val());
$('table#details tr#description td p').show(); $('table#details tr#description td p').show();
$('table#details tr#description td input').hide(); $('table#details tr#description td input').hide();
@ -118,7 +122,10 @@ function save(partID) {
processData: false, processData: false,
success: function(data) { success: function(data) {
var datasheet_par = '<p id="datasheet-info"><i class="fa fa-check"></i></p>'; var datasheet_par = '<p id="datasheet-info"><i class="fa fa-check"></i></p>';
$('#datasheet-info').replaceWith(datasheet_par); $('#datasheet-info').replaceWith(datasheet_par); // Fix addressing
$('#edit-button').click(function() {
init_edit(JSON.parse(data).part_id);
});
}, },
error: function() { error: function() {
alert("Couldn't update the part information. Please retry."); alert("Couldn't update the part information. Please retry.");
@ -127,9 +134,6 @@ function save(partID) {
}); });
end_edit(); end_edit();
$('#edit-button').click(function() {
init_edit(partID);
});
} }
function text_filter(string) { function text_filter(string) {

Loading…
Cancel
Save