diff --git a/amd/build/lifecycle.min.js b/amd/build/lifecycle.min.js index c1b2e5c..d5691ff 100644 --- a/amd/build/lifecycle.min.js +++ b/amd/build/lifecycle.min.js @@ -1,3 +1,3 @@ -define("block_lifecycle/lifecycle",["exports","core/ajax","core/notification"],(function(_exports,_ajax,_notification){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_ajax=_interopRequireDefault(_ajax),_notification=_interopRequireDefault(_notification);var defaultfreezedate="",originalfreezedatevalue="";function togglefreezebutton(checked){var readonlydateinput=document.getElementById("delayfreezedate");checked?(readonlydateinput.value="",readonlydateinput.disabled=!0):readonlydateinput.disabled=!1}function togglesettings(){var content=document.getElementById("automatic-read-only-settings");document.getElementById("override-freeze-date-button").classList.toggle("active"),content.style.maxHeight?content.style.maxHeight=null:content.style.maxHeight=content.scrollHeight+"px"}function initscheduledfreezedateblock(courseid){var scheduledfreezedatecontainer=document.getElementById("scheduled-freeze-date-container");originalfreezedatevalue=document.getElementById("delayfreezedate").value,scheduledfreezedatecontainer.style.display="none",_ajax.default.call([{methodname:"block_lifecycle_get_scheduled_freeze_date",args:{courseid:courseid}}])[0].done((function(response){document.getElementById("togglefreezebutton").checked?togglefreezebutton(!0):(document.getElementById("scheduled-freeze-date").innerHTML=response.scheduledfreezedate,scheduledfreezedatecontainer.style.display="block"),"true"===response.success&&(defaultfreezedate=response.defaultfreezedate)})).fail((function(err){window.console.log(err)}))}_exports.init=function(courseid){document.getElementById("lifecycle-settings-container")&&(initscheduledfreezedateblock(courseid),document.getElementById("togglefreezebutton").addEventListener("click",(function(event){togglefreezebutton(event.target.checked)})),document.getElementById("update_auto_freezing_preferences_button").addEventListener("click",(function(){!function(courseid){var preferences={togglefreeze:document.getElementById("togglefreezebutton").checked,delayfreezedate:document.getElementById("delayfreezedate").value};(function(){var freezedateelement=document.getElementById("delayfreezedate");if(freezedateelement.value.length>0){if(""===defaultfreezedate)return _notification.default.alert("Error","Could not get the automatically suggested date, please try again later.","OK"),freezedateelement.value=originalfreezedatevalue,!1;var defaultfreezedateobj=new Date(defaultfreezedate),freezedateobj=new Date(freezedateelement.value);if(freezedateobj{document.getElementById("lifecycle-settings-container")&&(initscheduledfreezedateblock(courseid),document.getElementById("togglefreezebutton").addEventListener("click",(event=>{togglefreezebutton(event.target.checked)})),document.getElementById("update_auto_freezing_preferences_button").addEventListener("click",(()=>{!function(courseid){let preferences={togglefreeze:document.getElementById("togglefreezebutton").checked,delayfreezedate:document.getElementById("delayfreezedate").value};(function(){let freezedateelement=document.getElementById("delayfreezedate");if(freezedateelement.value.length>0){if(""===defaultfreezedate)return _notification.default.alert("Error","Could not get the automatically suggested date, please try again later.","OK"),freezedateelement.value=originalfreezedatevalue,!1;{let defaultfreezedateobj=new Date(defaultfreezedate),freezedateobj=new Date(freezedateelement.value);if(freezedateobj {\n // The course is read-only. Do nothing.\n if (!document.getElementById('lifecycle-settings-container')) {\n return;\n }\n\n initscheduledfreezedateblock(courseid);\n // On click listener for \"Disable Automatic Read-Only\" toggle.\n document.getElementById('togglefreezebutton').addEventListener('click', (event) => {\n togglefreezebutton(event.target.checked);\n });\n\n // Save button.\n document.getElementById('update_auto_freezing_preferences_button').addEventListener('click', () => {\n updatepreferences(courseid);\n });\n\n // Drop down settings button.\n document.getElementById('override-freeze-date-button').addEventListener(\"click\", function(e) {\n e.preventDefault();\n togglesettings();\n });\n};\n\n/**\n * Disable read-only date input when \"Disable Automatic Read-Only button\" is on.\n *\n * @param {boolean} checked\n */\nfunction togglefreezebutton(checked) {\n let readonlydateinput = document.getElementById('delayfreezedate');\n if (checked) {\n readonlydateinput.value = '';\n readonlydateinput.disabled = true;\n } else {\n readonlydateinput.disabled = false;\n }\n}\n\n/**\n * Toggle the automatic read only settings container.\n */\nfunction togglesettings() {\n let content = document.getElementById('automatic-read-only-settings');\n document.getElementById('override-freeze-date-button').classList.toggle('active');\n if (content.style.maxHeight) {\n content.style.maxHeight = null;\n } else {\n content.style.maxHeight = content.scrollHeight + \"px\";\n }\n}\n\n/**\n * Validate the preferences.\n * @return {boolean}\n */\nfunction validate() {\n let freezedateelement = document.getElementById('delayfreezedate');\n\n if (freezedateelement.value.length > 0) {\n // The default suggested date is not initialized, so cannot continue the checking.\n if (defaultfreezedate === '') {\n notification.alert(\n 'Error',\n 'Could not get the automatically suggested date, please try again later.',\n 'OK'\n );\n freezedateelement.value = originalfreezedatevalue;\n return false;\n } else {\n let defaultfreezedateobj = new Date(defaultfreezedate);\n let freezedateobj = new Date(freezedateelement.value);\n\n // The override freeze date should not be saved when it is earlier than the default suggested date.\n if (freezedateobj < defaultfreezedateobj || freezedateobj < new Date()) {\n notification.alert(\n 'Invalid Selection',\n 'The date for a Read-Only override must be post the automatically suggested date (' +\n defaultfreezedateobj.toLocaleDateString() +\n '), earlier dates may not be used.',\n 'OK'\n );\n freezedateelement.value = originalfreezedatevalue;\n return false;\n }\n }\n }\n\n return true;\n}\n\n/**\n * Initialize the scheduled freeze date container.\n *\n * @param {int} courseid\n */\nfunction initscheduledfreezedateblock(courseid) {\n let scheduledfreezedatecontainer = document.getElementById('scheduled-freeze-date-container');\n originalfreezedatevalue = document.getElementById('delayfreezedate').value;\n\n // Hide scheduled read-only date text at the beginning.\n scheduledfreezedatecontainer.style.display = 'none';\n\n // Get scheduled read-only dates.\n Ajax.call([{\n methodname: 'block_lifecycle_get_scheduled_freeze_date',\n args: {\n 'courseid': courseid\n },\n }])[0].done(function(response) {\n // Show scheduled date.\n if (!document.getElementById('togglefreezebutton').checked) {\n document.getElementById('scheduled-freeze-date').innerHTML = response.scheduledfreezedate;\n scheduledfreezedatecontainer.style.display = 'block';\n } else {\n // Disable read-only date input depends on freeze button status.\n togglefreezebutton(true);\n }\n // Set the default suggested date.\n if (response.success === 'true') {\n defaultfreezedate = response.defaultfreezedate;\n }\n }).fail(function(err) {\n window.console.log(err);\n });\n}\n\n/**\n * Update the auto context freezing preferences.\n * @param {int} courseid\n */\nfunction updatepreferences(courseid) {\n let preferences = {\n togglefreeze: document.getElementById('togglefreezebutton').checked,\n delayfreezedate: document.getElementById('delayfreezedate').value\n };\n\n if (validate()) {\n Ajax.call([{\n methodname: 'block_lifecycle_update_auto_freezing_preferences',\n args: {\n 'courseid': courseid,\n 'preferences': JSON.stringify(preferences)\n },\n }])[0].done(function(response) {\n notification.addNotification({\n message: response.message,\n type: response.success ? 'success' : 'error'\n });\n initscheduledfreezedateblock(courseid);\n togglesettings();\n }).fail(function(err) {\n window.console.log(err);\n });\n }\n}\n"],"names":["defaultfreezedate","originalfreezedatevalue","togglefreezebutton","checked","readonlydateinput","document","getElementById","value","disabled","togglesettings","content","classList","toggle","style","maxHeight","scrollHeight","initscheduledfreezedateblock","courseid","scheduledfreezedatecontainer","display","call","methodname","args","done","response","innerHTML","scheduledfreezedate","success","fail","err","window","console","log","addEventListener","event","target","preferences","togglefreeze","delayfreezedate","freezedateelement","length","alert","defaultfreezedateobj","Date","freezedateobj","toLocaleDateString","validate","JSON","stringify","addNotification","message","type","updatepreferences","e","preventDefault"],"mappings":"kXAIIA,kBAAoB,GAEpBC,wBAA0B,YA+BrBC,mBAAmBC,aACpBC,kBAAoBC,SAASC,eAAe,mBAC5CH,SACAC,kBAAkBG,MAAQ,GAC1BH,kBAAkBI,UAAW,GAE7BJ,kBAAkBI,UAAW,WAO5BC,qBACDC,QAAUL,SAASC,eAAe,gCACtCD,SAASC,eAAe,+BAA+BK,UAAUC,OAAO,UACpEF,QAAQG,MAAMC,UACdJ,QAAQG,MAAMC,UAAY,KAE1BJ,QAAQG,MAAMC,UAAYJ,QAAQK,aAAe,cAgDhDC,6BAA6BC,cAC9BC,6BAA+Bb,SAASC,eAAe,mCAC3DL,wBAA0BI,SAASC,eAAe,mBAAmBC,MAGrEW,6BAA6BL,MAAMM,QAAU,qBAGxCC,KAAK,CAAC,CACPC,WAAY,4CACZC,KAAM,UACUL,aAEhB,GAAGM,MAAK,SAASC,UAEZnB,SAASC,eAAe,s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.js","sources":["../src/lifecycle.js"],"sourcesContent":["import Ajax from 'core/ajax';\nimport notification from 'core/notification';\n\n// Default auto suggested read-only date.\nlet defaultfreezedate = '';\n// The datepicker original value before user make any changes.\nlet originalfreezedatevalue = '';\n\nexport const init = (courseid) => {\n // The course is read-only. Do nothing.\n if (!document.getElementById('lifecycle-settings-container')) {\n return;\n }\n\n initscheduledfreezedateblock(courseid);\n // On click listener for \"Disable Automatic Read-Only\" toggle.\n document.getElementById('togglefreezebutton').addEventListener('click', (event) => {\n togglefreezebutton(event.target.checked);\n });\n\n // Save button.\n document.getElementById('update_auto_freezing_preferences_button').addEventListener('click', () => {\n updatepreferences(courseid);\n });\n\n // Drop down settings button.\n document.getElementById('override-freeze-date-button').addEventListener(\"click\", function(e) {\n e.preventDefault();\n togglesettings();\n });\n};\n\n/**\n * Disable read-only date input when \"Disable Automatic Read-Only button\" is on.\n *\n * @param {boolean} checked\n */\nfunction togglefreezebutton(checked) {\n let readonlydateinput = document.getElementById('delayfreezedate');\n if (checked) {\n readonlydateinput.value = '';\n readonlydateinput.disabled = true;\n } else {\n readonlydateinput.disabled = false;\n }\n}\n\n/**\n * Toggle the automatic read only settings container.\n */\nfunction togglesettings() {\n let content = document.getElementById('automatic-read-only-settings');\n document.getElementById('override-freeze-date-button').classList.toggle('active');\n if (content.style.maxHeight) {\n content.style.maxHeight = null;\n } else {\n content.style.maxHeight = content.scrollHeight + \"px\";\n }\n}\n\n/**\n * Validate the preferences.\n * @return {boolean}\n */\nfunction validate() {\n let freezedateelement = document.getElementById('delayfreezedate');\n\n if (freezedateelement.value.length > 0) {\n // The default suggested date is not initialized, so cannot continue the checking.\n if (defaultfreezedate === '') {\n notification.alert(\n 'Error',\n 'Could not get the automatically suggested date, please try again later.',\n 'OK'\n );\n freezedateelement.value = originalfreezedatevalue;\n return false;\n } else {\n let defaultfreezedateobj = new Date(defaultfreezedate);\n let freezedateobj = new Date(freezedateelement.value);\n\n // The override freeze date should not be saved when it is earlier than the default suggested date.\n if (freezedateobj < defaultfreezedateobj || freezedateobj < new Date()) {\n notification.alert(\n 'Invalid Selection',\n 'The date for a Read-Only override must be post the automatically suggested date (' +\n defaultfreezedateobj.toLocaleDateString() +\n '), earlier dates may not be used.',\n 'OK'\n );\n freezedateelement.value = originalfreezedatevalue;\n return false;\n }\n }\n }\n\n return true;\n}\n\n/**\n * Initialize the scheduled freeze date container.\n *\n * @param {int} courseid\n */\nfunction initscheduledfreezedateblock(courseid) {\n let scheduledfreezedatecontainer = document.getElementById('scheduled-freeze-date-container');\n originalfreezedatevalue = document.getElementById('delayfreezedate').value;\n\n // Hide scheduled read-only date text at the beginning.\n scheduledfreezedatecontainer.style.display = 'none';\n\n // Get scheduled read-only dates.\n Ajax.call([{\n methodname: 'block_lifecycle_get_scheduled_freeze_date',\n args: {\n 'courseid': courseid\n },\n }])[0].done(function(response) {\n // Show scheduled date.\n if (!document.getElementById('togglefreezebutton').checked) {\n document.getElementById('scheduled-freeze-date').innerHTML = response.scheduledfreezedate;\n scheduledfreezedatecontainer.style.display = 'block';\n } else {\n // Disable read-only date input depends on freeze button status.\n togglefreezebutton(true);\n }\n // Set the default suggested date.\n if (response.success === 'true') {\n defaultfreezedate = response.defaultfreezedate;\n }\n }).fail(function(err) {\n window.console.log(err);\n });\n}\n\n/**\n * Update the auto context freezing preferences.\n * @param {int} courseid\n */\nfunction updatepreferences(courseid) {\n let preferences = {\n togglefreeze: document.getElementById('togglefreezebutton').checked,\n delayfreezedate: document.getElementById('delayfreezedate').value\n };\n\n if (validate()) {\n Ajax.call([{\n methodname: 'block_lifecycle_update_auto_freezing_preferences',\n args: {\n 'courseid': courseid,\n 'preferences': JSON.stringify(preferences)\n },\n }])[0].done(function(response) {\n notification.addNotification({\n message: response.message,\n type: response.success ? 'success' : 'error'\n });\n initscheduledfreezedateblock(courseid);\n togglesettings();\n }).fail(function(err) {\n window.console.log(err);\n });\n }\n}\n"],"names":["defaultfreezedate","originalfreezedatevalue","togglefreezebutton","checked","readonlydateinput","document","getElementById","value","disabled","togglesettings","content","classList","toggle","style","maxHeight","scrollHeight","initscheduledfreezedateblock","courseid","scheduledfreezedatecontainer","display","call","methodname","args","done","response","innerHTML","scheduledfreezedate","success","fail","err","window","console","log","addEventListener","event","target","preferences","togglefreeze","delayfreezedate","freezedateelement","length","alert","defaultfreezedateobj","Date","freezedateobj","toLocaleDateString","validate","JSON","stringify","addNotification","message","type","updatepreferences","e","preventDefault"],"mappings":"kXAIIA,kBAAoB,GAEpBC,wBAA0B,YA+BrBC,mBAAmBC,aACpBC,kBAAoBC,SAASC,eAAe,mBAC5CH,SACAC,kBAAkBG,MAAQ,GAC1BH,kBAAkBI,UAAW,GAE7BJ,kBAAkBI,UAAW,WAO5BC,qBACDC,QAAUL,SAASC,eAAe,gCACtCD,SAASC,eAAe,+BAA+BK,UAAUC,OAAO,UACpEF,QAAQG,MAAMC,UACdJ,QAAQG,MAAMC,UAAY,KAE1BJ,QAAQG,MAAMC,UAAYJ,QAAQK,aAAe,cAgDhDC,6BAA6BC,cAC9BC,6BAA+Bb,SAASC,eAAe,mCAC3DL,wBAA0BI,SAASC,eAAe,mBAAmBC,MAGrEW,6BAA6BL,MAAMM,QAAU,qBAGxCC,KAAK,CAAC,CACPC,WAAY,4CACZC,KAAM,UACUL,aAEhB,GAAGM,MAAK,SAASC,UAEZnB,SAASC,eAAe,sBAAsBH,QAK/CD,oBAAmB,IAJnBG,SAASC,eAAe,yBAAyBmB,UAAYD,SAASE,oBACtER,6BAA6BL,MAAMM,QAAU,SAMxB,SAArBK,SAASG,UACT3B,kBAAoBwB,SAASxB,sBAElC4B,MAAK,SAASC,KACbC,OAAOC,QAAQC,IAAIH,sBA3HNZ,WAEZZ,SAASC,eAAe,kCAI7BU,6BAA6BC,UAE7BZ,SAASC,eAAe,sBAAsB2B,iBAAiB,SAAUC,QACrEhC,mBAAmBgC,MAAMC,OAAOhC,YAIpCE,SAASC,eAAe,2CAA2C2B,iBAAiB,SAAS,eAsHtEhB,cACn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