diff --git a/lms/static/js/edxnotes/plugins/llm_summarize.js b/lms/static/js/edxnotes/plugins/llm_summarize.js index e6c7eee0ff52..fff196fa4840 100644 --- a/lms/static/js/edxnotes/plugins/llm_summarize.js +++ b/lms/static/js/edxnotes/plugins/llm_summarize.js @@ -84,10 +84,12 @@ transform: rotate(360deg); } `; - document.head.appendChild(style); let annotator = this.annotator; + document.head.appendChild(style); this.modifyDom(this.annotator); + const summarizeButton = document.getElementById('summarizeButton'); + summarizeButton.addEventListener('click', function(ev) { annotator.editor.element[0].setAttribute('is_summarizing', true); }); @@ -96,10 +98,15 @@ }, handleSummarize: function (editor, annotation) { if (editor.element[0].getAttribute('is_summarizing') !== 'true') return; - const textAreaWrapper = editor.fields[0].element; - editor.fields[1].element.children[0].value = 'ai_summary'; - toggleLoader(editor); + function toggleLoader() { + const saveButton = document.querySelector('.annotator-controls .annotator-save'); + const loaderWrapper = document.querySelector('.summarize-loader-wrapper'); + editor.fields[0].element.children[0].classList.toggle('d-none'); + loaderWrapper.classList.toggle('d-none'); + saveButton.disabled = !saveButton.disabled; + } + const textAreaWrapper = editor.fields[0].element; const request = new Request('/pearson-core/llm-assistance/api/v0/summarize-text', { method: 'POST', headers: { @@ -110,6 +117,9 @@ text_to_summarize: annotation.quote, }), }); + + editor.fields[1].element.children[0].value = 'ai_summary'; + toggleLoader(editor); fetch(request) .then((response) => { toggleLoader(); @@ -123,24 +133,19 @@ alert(error.message); editor.hide(); }); - - function toggleLoader() { - const saveButton = document.querySelector('.annotator-controls .annotator-save'); - const loaderWrapper = document.querySelector('.summarize-loader-wrapper'); - editor.fields[0].element.children[0].classList.toggle('d-none'); - loaderWrapper.classList.toggle('d-none'); - saveButton.disabled = !saveButton.disabled; - } }, cleanupSummarize: function(editor) { const textAreaWrapper = editor.fields[0].element; + const loaderWrapper = document.querySelector('.summarize-loader-wrapper'); + textAreaWrapper.children[0].value = ''; textAreaWrapper.children[1].value = ''; editor.element[0].setAttribute('is_summarizing', 'false'); - const loaderWrapper = document.querySelector('.summarize-loader-wrapper'); loaderWrapper.classList.add('d-none'); }, modifyDom: function(annotator) { + const textAreaWrapper = annotator.editor.fields[0].element; + annotator.adder[0].children[0].id = 'annotateButton'; annotator.adder[0].children[0].innerHTML = ''; annotator.adder[0].innerHTML += ` @@ -148,7 +153,6 @@ `; - const textAreaWrapper = annotator.editor.fields[0].element; // Style is being defined here since classes styling not working // for this element. textAreaWrapper.innerHTML += `