diff --git a/parts/server.py b/parts/server.py index b1df0e0..0e8da1d 100644 --- a/parts/server.py +++ b/parts/server.py @@ -211,6 +211,9 @@ def alter(partID): datasheet_filename = datasheet_filename[:-4] + str(i) + '.pdf' i += 1 datasheet_file.save('/srv/datasheets/' + datasheet_filename) + datasheet_filename = 'http://elab.kth.se/parts/getfile/' + datasheet_filename + elif request.form.has_key('datasheet-url'): + datasheet_filename = request.form['datasheet-url'] else: datasheet_filename = None r = db_engine.execute(s, partno=request.form['partno'], @@ -234,8 +237,11 @@ def alter(partID): datasheet_filename = datasheet_filename[:-4] + str(i) + '.pdf' i += 1 datasheet_file.save('/srv/datasheets/' + datasheet_filename) + datasheet_filename = 'http://elab.kth.se/parts/getfile/' + datasheet_filename if l[0]['datasheet'] != None: os.remove('/srv/datasheets/' + l[0]['datasheet']) + elif request.form.has_key('datasheet-url'): + datasheet_filename = request.form['datasheet-url'] else: datasheet_filename = l[0]['datasheet'] s += 'where id=:id returning id;' diff --git a/parts/static/script.js b/parts/static/script.js index 202b4c5..d67b31c 100644 --- a/parts/static/script.js +++ b/parts/static/script.js @@ -65,6 +65,7 @@ function save(partID) { var partno_v = $('input[name=partno-input]').val(); var description_v = $('input[name=description-input]').val(); var datasheet = $('table#details tr#datasheet td input')[0].files; + var datasheet_url_v = $('input[name=datasheet-url-input]').val(); if(partno_v.length == 0){ alert('Please enter a part number.'); return; @@ -89,6 +90,8 @@ function save(partID) { return; } data.append('datasheet-file', datasheet[0]); + } else if (datasheet_url_v.length > 0) { + data.append('datasheet-url', datasheet_url_v); } data.append('partno', partno_v); data.append('location_id', location_id_v) @@ -162,8 +165,8 @@ function show_part_info(partID) { $('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); + $('tr#datasheet-head').html($('DATASHEET: ')); + $('input[name=datasheet-url-input]').val(data.datasheet); } else $('tr#datasheet-head td').text('DATASHEET: ');