diff --git a/materials/forms.py b/materials/forms.py index 22f0876..744e84f 100644 --- a/materials/forms.py +++ b/materials/forms.py @@ -25,8 +25,13 @@ def __init__(self, model=None, field=None, *args, **kwargs): class AddReferenceForm(forms.Form): + inputRISFile = forms.FileField( + required=False, + widget=forms.ClearableFileInput(attrs={'multiple': True, 'onchange':'handleFileSelect();' }), + help_text='Upload RIS file reference' + ) title = forms.CharField( - widget=forms.TextInput(attrs={'class': 'form-control'}), + widget=forms.TextInput(attrs={'class': 'form-control', 'id':'title'}), max_length=1000, help_text='Article title') journal = forms.CharField( diff --git a/materials/static/materials/javascript/autoupdates.js b/materials/static/materials/javascript/autoupdates.js new file mode 100644 index 0000000..c735586 --- /dev/null +++ b/materials/static/materials/javascript/autoupdates.js @@ -0,0 +1,29 @@ +function handleFileSelect() { + const fileInput = document.querySelector('[name="inputRISFile"]'); + const textInput = document.querySelector('[name="title"]'); + + if (fileInput.files.length > 0) { + const file = fileInput.files[0]; + const reader = new FileReader(); + + reader.onload = function (event) { + const fileContent = event.target.result; + const lines = fileContent.split('\n'); // Split content into lines + + // Search for lines starting with "T1 -" or "TI -" + const relevantLines = lines.filter(line => + line.trim().startsWith("TI -") || line.trim().startsWith("T1 -") + ); + + // Extract the text after "T1 -" or "T1 -" + const extractedText = relevantLines.map(line => + line.trim().replace(/^(T1|TI) -/, "") + ).join("\n"); + + // Set the extracted text to textInput.value + textInput.value = extractedText; + }; + + reader.readAsText(file); // Read the file as text + } + } \ No newline at end of file diff --git a/materials/templates/materials/add_data.html b/materials/templates/materials/add_data.html index 821b307..aaa2330 100644 --- a/materials/templates/materials/add_data.html +++ b/materials/templates/materials/add_data.html @@ -13,6 +13,10 @@

Add Data

Add new reference
+
+ + {{ reference_form.inputRISFile }} +
@@ -547,6 +551,7 @@

Add Data

{% block script %} {% load static %} +