{"version":3,"sources":["Pages/Curriculum.js"],"names":["Dialog","Form","xhr","ignoreError","CurriculumDetails","_refreshUrl","_footerUrl","_addToSpacesDialog","_addToSpacesForm","_addToSpacesButton","document","getElementById","_maxCurriculumCountSpaceCanHave","_messageDialog","_backToBrowse","addEventListener","_backToBrowserListener","bind","linkEvent","preventDefault","returnValue","referrer","includes","window","navigator","userAgent","history","go","back","refreshAvailableSpacesUrl","getAddedCurriculumFooterUrl","maximumCurriculumCount","_initializeDialog","addToSpaceDialogButton","_form","querySelector","noSpaceSelected","querySelectorAll","length","disabled","spaceLabel","createElement","className","detailsSpan","appendChild","spaceNameSpan","curriculumCountSpan","checkboxWrapper","checkbox","setAttribute","checkboxSpan","onbeforeshow","dialog","container","then","spaces","data","availableSpaces","spacesContainer","innerHTML","template","_buildSpaceNode","fragment","createDocumentFragment","i","checkboxData","item","cloneNode","innerText","label","name","id","checked","onclick","event","_ifNoSpaceSelectedDisableAddToSpaceDialogButton","curriculumCount","style","color","idField","value","itemId","labelField","curriculumCountField","div","h5","textContent","a","oncreated","done","_formSubmitted","onclosed","addedSpaces","_updateView","viewData","_updateAssociatedSpacesListing","_updateAddToSpacesButton","count","_showAddedCurriculumFooter","close","Promise","resolve","dialogScript","parser","DOMParser","dialogContent","parseFromString","dialogForm","formContainer","parentElement","removeChild","html","result","body","availableSpacesCount","classList","add","addedSpacesContainer","initiallyEmpty","span","checkCircle","associatedSpaces","associatedSpacesContainer","hasChildNodes","url","indexOf","replace","ids","push","method","JSON","stringify","setUpPopUp","remove","_redirectToSpace","e","target","nextElementSibling","tagName","location","assign","dataset","open"],"mappings":";;;;;;;;;;;;;;;AAASA,kB,uBAAAA,M;;AACAC,gB,sBAAAA,I;;AACAC,e,qBAAAA,G;AAAKC,uB,qBAAAA,W;;;;;;;;;;;;;;;;;;;;;yCAERC,iB;AACF,6CAAc;AAAA;;AACV,yBAAKC,WAAL,GAAmB,IAAnB;AACA,yBAAKC,UAAL,GAAkB,IAAlB;;AAEA,y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AAF,CAASK,OAAT,CAAiBjB,GAAxC,EADJ,KAGIrG,OAAOoH,QAAP,CAAgBC,MAAhB,CAAuBL,EAAEC,MAAF,CAASxD,KAAhC;AACP;;;gDAEWuD,C,EAAG;AACX,6BAAKhI,kBAAL,CAAwBuI,IAAxB;AACH;;;;;;yCAGI1I,iB","file":"Curriculum.js","sourcesContent":["import { Dialog } from \"../Components/Dialog.js\";\r\nimport { Form } from \"../Components/Forms.js\";\r\nimport { xhr, ignoreError } from \"../Components/Ajax.js\";\r\n\r\nclass CurriculumDetails {\r\n constructor() {\r\n this._refreshUrl = null;\r\n this._footerUrl = null;\r\n\r\n this._addToSpacesDialog = null;\r\n this._addToSpacesForm = null;\r\n\r\n this._addToSpacesButton = document.getElementById(\"add-to-space-button\");\r\n this._maxCurriculumCountSpaceCanHave = null;\r\n\r\n this._messageDialog = new Dialog('premium-curriculum-message');\r\n\r\n this._backToBrowse = document.getElementById(\"backtobrowse\");\r\n if (this._backToBrowse)\r\n this._backToBrowse.addEventListener('click', this._backToBrowserListener.bind(this), false);\r\n }\r\n\r\n _backToBrowserListener(linkEvent) {\r\n if (linkEvent.preventDefault)\r\n linkEvent.preventDefault();\r\n linkEvent.returnValue = false;\r\n if (document.referrer.includes(\"results\")) {\r\n if (window.navigator.userAgent.includes(\"Edge\"))\r\n window.history.go(-2);\r\n else\r\n window.history.back();\r\n }\r\n else {\r\n window.history.back();\r\n }\r\n }\r\n\r\n initializeAddToSpacesDialog(refreshAvailableSpacesUrl, getAddedCurriculumFooterUrl, maximumCurriculumCount) {\r\n this._refreshUrl = refreshAvailableSpacesUrl;\r\n this._footerUrl = getAddedCurriculumFooterUrl;\r\n this._maxCurriculumCountSpaceCanHave = maximumCurriculumCount;\r\n this._initializeDialog();\r\n }\r\n\r\n _ifNoSpaceSelectedDisableAddToSpaceDialogButton() {\r\n var addToSpaceDialogButton = this._addToSpacesForm._form.querySelector(\"button[type='submit']\");\r\n var noSpaceSelected = this._addToSpacesForm._form.querySelectorAll(\".spaces input:checked\").length == 0;\r\n addToSpaceDialogButton.disabled = noSpaceSelected;\r\n }\r\n\r\n _buildSpaceNode() {\r\n let spaceLabel = document.createElement(\"label\");\r\n spaceLabel.className = \"flex-row space\";\r\n\r\n let detailsSpan = document.createElement(\"span\");\r\n detailsSpan.className = \"flex-2-column\";\r\n spaceLabel.appendChild(detailsSpan);\r\n\r\n let spaceNameSpan = document.createElement(\"span\");\r\n spaceNameSpan.className = \"name space-label\";\r\n detailsSpan.appendChild(spaceNameSpan);\r\n\r\n let curriculumCountSpan = document.createElement(\"span\");\r\n curriculumCountSpan.className = \"curriculum-count space-label\";\r\n detailsSpan.appendChild(curriculumCountSpan);\r\n\r\n let checkboxWrapper = document.createElement(\"span\");\r\n checkboxWrapper.className = \"checkbox-wrapper\";\r\n spaceLabel.appendChild(checkboxWrapper);\r\n\r\n let checkbox = document.createElement(\"input\");\r\n checkbox.className = \"checkbox\";\r\n checkbox.setAttribute(\"type\", \"checkbox\");\r\n checkboxWrapper.appendChild(checkbox);\r\n\r\n let checkboxSpan = document.createElement(\"span\");\r\n checkboxSpan.className = \"pretty-checkbox\";\r\n checkboxWrapper.appendChild(checkboxSpan);\r\n\r\n return spaceLabel;\r\n }\r\n\r\n _initializeDialog() {\r\n this._addToSpacesDialog = new Dialog('add-curriculum-to-spaces-dialog');\r\n\r\n this._addToSpacesDialog.onbeforeshow = (dialog, container) => {\r\n return xhr(this._refreshUrl).then(data => {\r\n let spaces = data.availableSpaces;\r\n let spacesContainer = container.querySelector(\"#add-curriculum-to-spaces-form .spaces\");\r\n spacesContainer.innerHTML = \"\";\r\n\r\n if (spaces.length >0) {\r\n let template = this._buildSpaceNode();\r\n let fragment = document.createDocumentFragment();\r\n\r\n for (let i = 0; i < spaces.length; i++) {\r\n let checkboxData = spaces[i];\r\n\r\n let item = template.cloneNode(true);\r\n item.querySelector(\".name\").innerText = checkboxData.label;\r\n\r\n let checkbox = item.querySelector(\".checkbox\");\r\n checkbox.name = checkbox.id = `Spaces[${i}].Checked`;\r\n checkbox.checked = checkboxData.checked;\r\n checkbox.onclick = (event) => {\r\n this._ifNoSpaceSelectedDisableAddToSpaceDialogButton();\r\n }\r\n\r\n if (checkboxData.curriculumCount < this._maxCurriculumCountSpaceCanHave)\r\n {\r\n item.querySelector(\".curriculum-count\").innerText = `${checkboxData.curriculumCount} Curriculum`;\r\n }\r\n else\r\n {\r\n checkbox.disabled = true;\r\n checkbox.checked = false;\r\n item.querySelector(\".curriculum-count\").style.color = \"orange\";\r\n item.querySelector(\".curriculum-count\").innerText = `Max curriculum limit(${this._maxCurriculumCountSpaceCanHave}) reached. `;\r\n }\r\n\r\n let idField = document.createElement(\"input\");\r\n idField.setAttribute(\"type\", \"hidden\");\r\n idField.name = idField.id = `Spaces[${i}].ItemId`;\r\n idField.value = checkboxData.itemId;\r\n item.appendChild(idField);\r\n\r\n let labelField = document.createElement(\"input\");\r\n labelField.setAttribute(\"type\", \"hidden\");\r\n labelField.name = labelField.id = `Spaces[${i}].Label`;\r\n labelField.value = checkboxData.label;\r\n item.appendChild(labelField);\r\n\r\n let curriculumCountField = document.createElement(\"input\");\r\n curriculumCountField.setAttribute(\"type\", \"hidden\");\r\n curriculumCountField.name = curriculumCountField.id = `Spaces[${i}].CurriculumCount`;\r\n curriculumCountField.value = checkboxData.curriculumCount;\r\n item.appendChild(curriculumCountField);\r\n\r\n fragment.appendChild(item);\r\n }\r\n\r\n spacesContainer.appendChild(fragment);\r\n this._ifNoSpaceSelectedDisableAddToSpaceDialogButton();\r\n } else {\r\n let spaces = container.querySelector(\".spaces\")\r\n let div = document.createElement(\"div\")\r\n div.className = \"flex-coloum center-text\";\r\n let h5 = document.createElement(\"h5\");\r\n h5.textContent = \"No space to add this curriculum. Please add a space.\"\r\n div.appendChild(h5);\r\n\r\n let a = document.createElement(\"a\");\r\n a.className = \"button primary call-to-action small\";\r\n a.setAttribute(\"href\", \"/spaces?isnospace=true\");\r\n a.textContent = \"Create a Space\"\r\n div.appendChild(a)\r\n\r\n spaces.appendChild(div);\r\n container.querySelector(\"button[type='submit']\").disabled = true;\r\n }\r\n });\r\n };\r\n\r\n this._addToSpacesDialog.oncreated = (dialog, container) => {\r\n this._addToSpacesForm = new Form(container.querySelector('form'), { done: this._formSubmitted.bind(this) });\r\n return true;\r\n };\r\n\r\n this._addToSpacesDialog.onclosed = (dialog, container) => {\r\n container.querySelector(\"#add-curriculum-to-spaces-form .spaces\").innerHTML = \"\";\r\n };\r\n }\r\n\r\n _formSubmitted(addedSpaces) {\r\n xhr(this._refreshUrl)\r\n .then(viewData => this._updateView(addedSpaces, viewData));\r\n }\r\n\r\n _updateView(addedSpaces, viewData) {\r\n this._updateAssociatedSpacesListing(addedSpaces);\r\n\r\n this._updateAddToSpacesButton(viewData.count);\r\n\r\n this._showAddedCurriculumFooter(addedSpaces);\r\n\r\n this._addToSpacesDialog.close();\r\n\r\n return Promise.resolve(viewData);\r\n }\r\n\r\n _updateDialogTemplate(viewData) {\r\n // Load the dialog template\r\n let dialogScript = document.getElementById(\"add-curriculum-to-spaces-dialog\");\r\n\r\n // Parse dialog template into html\r\n let parser = new DOMParser();\r\n let dialogContent = parser.parseFromString(dialogScript.innerHTML, 'text/html');\r\n let dialogForm = dialogContent.querySelector('form');\r\n\r\n // Replace existing form with the new form\r\n let formContainer = dialogForm.parentElement;\r\n formContainer.removeChild(dialogForm);\r\n formContainer.innerHTML = viewData.html.result;\r\n\r\n dialogScript.innerHTML = dialogContent.body.innerHTML;\r\n\r\n return Promise.resolve();\r\n }\r\n\r\n _reinitializeDialog() {\r\n this._addToSpacesDialog.close();\r\n\r\n this._initializeDialog();\r\n\r\n return Promise.resolve();\r\n }\r\n\r\n _updateAddToSpacesButton(availableSpacesCount) {\r\n if (availableSpacesCount === 0) {\r\n this._addToSpacesButton.parentElement.removeChild(this._addToSpacesButton);\r\n }\r\n else {\r\n this._addToSpacesButton.classList.add(\"added\");\r\n this._addToSpacesButton.innerText = \"Added to space\";\r\n }\r\n }\r\n\r\n _updateAssociatedSpacesListing(spaces) {\r\n var addedSpacesContainer = document.getElementById(\"added-spaces\");\r\n var initiallyEmpty = document.getElementById('added-to') === null;\r\n\r\n if (spaces.length > 0) {\r\n if (initiallyEmpty) {\r\n var span = document.createElement(\"span\");\r\n\r\n var checkCircle = document.createElement(\"i\");\r\n checkCircle.classList.add(\"fa\");\r\n checkCircle.classList.add(\"fa-check-circle-o\");\r\n checkCircle.setAttribute(\"aria-hidden\", \"true\");\r\n span.appendChild(checkCircle);\r\n\r\n span.innerHTML += \"Added to \";\r\n\r\n var associatedSpaces = document.createElement(\"span\");\r\n associatedSpaces.id = \"associated-spaces\";\r\n span.appendChild(associatedSpaces);\r\n addedSpacesContainer.appendChild(span);\r\n }\r\n }\r\n\r\n var associatedSpacesContainer = document.getElementById(\"associated-spaces\");\r\n\r\n for (var i = 0; i < spaces.length; i++) {\r\n if (!associatedSpacesContainer.hasChildNodes()) {\r\n associatedSpacesContainer.innerHTML = `${spaces[i].name}`;\r\n }\r\n else {\r\n if (associatedSpacesContainer.innerHTML.indexOf(\" and <\") !== -1) {\r\n associatedSpacesContainer.innerHTML = associatedSpacesContainer.innerHTML.replace(\" and <\", \", <\");\r\n }\r\n\r\n associatedSpacesContainer.innerHTML += ` and ${spaces[i].name}`;\r\n }\r\n }\r\n }\r\n\r\n _showAddedCurriculumFooter(addedSpaces) {\r\n var ids = [];\r\n for (var i = 0; i < addedSpaces.length; i++)\r\n ids.push(addedSpaces[i].id);\r\n\r\n xhr(this._footerUrl,\r\n {\r\n method: \"POST\",\r\n data: JSON.stringify({ ids })\r\n })\r\n .then(data => {\r\n\r\n var setUpPopUp = document.getElementById(\"set-up-pop-up\");\r\n setUpPopUp.querySelector(\"section\").innerHTML = data.result;\r\n setUpPopUp.classList.remove(\"hide\");\r\n\r\n var container = document.getElementById(\"curriculum-added-footer\");\r\n\r\n if (ids.length === 1)\r\n container.querySelector(\"div:nth-last-child(2) button\").addEventListener(\"click\", this._redirectToSpace.bind(this), true);\r\n else\r\n container.querySelector(\"div:nth-last-child(2) select\").addEventListener(\"change\", this._redirectToSpace.bind(this), true);\r\n\r\n document.body.querySelector(\"#set-up-pop-up i.fa-times\").addEventListener(\r\n \"click\",\r\n function (e) {\r\n // Hide the footer\r\n e.target.parentElement.classList.add(\"hide\");\r\n\r\n // Clear the footer contents\r\n e.target.nextElementSibling.innerHTML = \"\";\r\n },\r\n true);\r\n });\r\n }\r\n\r\n _redirectToSpace(e) {\r\n if (e.target.tagName === \"BUTTON\")\r\n window.location.assign(e.target.dataset.url);\r\n else\r\n window.location.assign(e.target.value);\r\n }\r\n\r\n _openDialog(e) {\r\n this._addToSpacesDialog.open();\r\n }\r\n}\r\n\r\nexport { CurriculumDetails };\r\n"]}