diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0bbb5e4..bf06d0e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -98,7 +98,7 @@ jobs: - name: Run grunt continue-on-error: true # This step will show errors but will not fail if: ${{ always() }} - run: moodle-plugin-ci grunt + run: moodle-plugin-ci grunt --max-lint-warnings=0 - name: Run phpdoc continue-on-error: true # This step will show errors but will not fail diff --git a/amd/build/postmessage.min.js b/amd/build/postmessage.min.js index c4d79c5..a61b137 100644 --- a/amd/build/postmessage.min.js +++ b/amd/build/postmessage.min.js @@ -1,3 +1,3 @@ -define("mod_collabora/postmessage",["exports","jquery","core/fragment","core/templates","core/ajax","core/notification","core/log"],(function(_exports,_jquery,_fragment,_templates,_ajax,_notification,_log){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_jquery=_interopRequireDefault(_jquery),_fragment=_interopRequireDefault(_fragment),_templates=_interopRequireDefault(_templates),_ajax=_interopRequireDefault(_ajax),_notification=_interopRequireDefault(_notification),_log=_interopRequireDefault(_log);class postMessageHandler{constructor(opts){_defineProperty(this,"asPopup",void 0),_defineProperty(this,"collaboraUrl",void 0),_defineProperty(this,"component",void 0),_defineProperty(this,"contextid",void 0),_defineProperty(this,"courseURL",void 0),_defineProperty(this,"id",void 0),_defineProperty(this,"iframeid",void 0),_defineProperty(this,"imgBackUrl",void 0),_defineProperty(this,"isSaving",void 0),_defineProperty(this,"newVersion",void 0),_defineProperty(this,"originCollabora",void 0),_defineProperty(this,"originMoodle",void 0),_defineProperty(this,"strBack",void 0),_defineProperty(this,"uiMode",void 0),_defineProperty(this,"version",void 0),_defineProperty(this,"versionManager",void 0),_defineProperty(this,"versionViewer",void 0),_defineProperty(this,"spinner",void 0),this.courseURL=opts.courseurl,this.collaboraUrl=opts.collaboraurl,this.component="component"in opts?opts.component:"mod_collabora",this.originCollabora=opts.origincollabora,this.originMoodle=opts.originmoodle,this.asPopup=opts.aspopup,this.iframeid=opts.iframeid,this.id=opts.id,this.contextid=opts.contextid,this.strBack=opts.strback,this.imgBackUrl=opts.imgbackurl,this.uiMode=opts.uimode,this.versionManager=opts.versionmanager,this.isSaving=!1,this.version=0,this.newVersion=0,this.versionViewer=document.querySelector("#"+opts.versionviewerid),this.spinner=document.querySelector("#collabora-spinner-"+this.id)}init(){const _this=this;_this.setFrameData(),_this.initModal(),window.addEventListener("message",function(e){_this.receiveMessage(e)}.bind(_this))}receiveMessage(event){var msg;const _this=this;if(_log.default.debug("ReceiveMessage from "+event.origin+": "+event.data),event.origin==_this.originCollabora||event.origin==_this.originMoodle){if(("string"==typeof event.data||event.data instanceof String)&&(msg=JSON.parse(event.data)))switch(msg.MessageId){case"UI_Close":_this.closeDocument();break;case"App_LoadingStatus":_this.tellPostmessageReady(msg);break;case"UI_FileVersions":_this.showVersionView();break;case"UI_Save":_this.invokeSave();break;case"Doc_ModifiedStatus":_this.checkSaved(msg);break;case"Clicked_Button":_this.handleCustomButton(msg);break;case"App_VersionRestore":_this.restoreVersion(msg);break;case"SET_VERSION":_this.version=msg.Values.version,_this.setFrameData(),_this.showVersionView();break;case"RESTORE_VERSION":_this.prepareRestoreVersion(msg.Values.version);break;case"DELETE_VERSION":_this.deleteVersion(msg.Values.version)}}else _log.default.debug('!!!!Received Message from wrong origin "'+event.origin+'"')}closeDocument(){const _this=this;_this.asPopup?window.close():window.location.href=_this.courseURL}showSpinner(show){const _this=this;var iframe=document.querySelector("#"+_this.iframeid);show?(_this.spinner.classList.remove("d-none"),iframe.style.opacity=.1):(_this.spinner.classList.add("d-none"),iframe.style.opacity=1)}showVersionView(){this.loadVersionView(),(0,_jquery.default)("#"+this.versionViewer.id).collapse("show")}loadVersionView(){const _this=this;if(!_this.versionManager)return;const serviceparams={function:"version_viewer_content",id:_this.id,version:_this.version};_fragment.default.loadFragment(_this.component,"get_html",_this.contextid,serviceparams).then(function(html,js){document.querySelector("#"+_this.versionViewer.id+" .card-body").innerHTML=html,js&&_templates.default.runTemplateJS(js)}.bind(_this)).fail(_notification.default.exception)}invokeSave(){this.isSaving=!0;this.postMessage({MessageId:"Action_Save",Values:{DontTerminateEdit:!0,DontSaveIfUnmodified:!0}})}checkSaved(msg){const _this=this;_this.isSaving=!0,0==msg.Values.Modified&&_this.isSaving&&_this.loadVersionView()}tellPostmessageReady(msg){const _this=this;if(msg.Values&&"Document_Loaded"==msg.Values.Status){var postObject;if(postObject={MessageId:"Host_PostmessageReady"},_this.postMessage(postObject),0!=_this.newVersion)return postObject={MessageId:"Host_VersionRestore",Values:{Status:"Pre_Restore"}},void _this.postMessage(postObject);postObject={MessageId:"Disable_Default_UIAction",Values:{action:"UI_Save",disable:!0}},_this.postMessage(postObject),0!=_this.uiMode&&(postObject={MessageId:"Action_ChangeUIMode",Values:{Mode:_this.uiMode}},_this.postMessage(postObject)),_this.showSpinner(!1),_this.version>0&&_this.addBackButton()}}handleCustomButton(msg){const _this=this;msg.Values&&"moodle_go_back"==msg.Values.Id&&(_this.version=0,_this.setFrameData())}addBackButton(){var postObject={MessageId:"Insert_Button",Values:{id:"moodle_go_back",imgurl:this.imgBackUrl,label:this.strBack,hint:this.strBack}};this.postMessage(postObject)}postMessage(postObject){const _this=this;postObject.SendTime=Date.now();var message=JSON.stringify(postObject);_log.default.debug("Post message to collabora: "+message);var iframe=document.querySelector("#"+_this.iframeid);null!==iframe&&null!=iframe?(iframe=iframe.contentWindow||iframe.contentDocument.document||iframe.contentDocument).postMessage(message,_this.originCollabora):_log.default.debug('The iframe "'+_this.iframeid+'" has vanished')}initModal(){const _this=this,inlineelement=document.querySelector("#collabora-inline_"+_this.id),modalelement=document.querySelector("#collaboramodal-body_"+_this.id),iframecontainer=document.querySelector("#iframe-container_"+_this.id);(0,_jquery.default)("#collaboramodal_"+_this.id).on("show.bs.modal",function(){modalelement.append(iframecontainer),(0,_jquery.default)("body").addClass("modal-open"),_this.setFrameData()}.bind(_this)),(0,_jquery.default)("#collaboramodal_"+_this.id).on("hide.bs.modal",function(){inlineelement.append(iframecontainer),(0,_jquery.default)("body").removeClass("modal-open"),_this.setFrameData()}.bind(_this))}setFrameData(){const _this=this;_log.default.debug("Set iframe source: "+_this.collaboraUrl);var iframe=document.querySelector("#"+_this.iframeid);if(null!==iframe&&null!=iframe){var serviceparams={function:"wopi_src",id:_this.id,version:_this.version};_fragment.default.loadFragment(_this.component,"get_html",_this.contextid,serviceparams).then(function(strparams){var params=JSON.parse(strparams),form=document.createElement("form");form.method="get",form.action=_this.collaboraUrl,form.target=_this.iframeid;for(const[key,value]of Object.entries(params)){var element=document.createElement("input");element.type="hidden",element.name=key,element.value=value,form.appendChild(element),_log.default.debug("Add element "+key+": "+value)}document.body.appendChild(form),form.submit()}.bind(_this)).fail(_notification.default.exception)}else _log.default.debug('The iframe "'+_this.iframeid+'" has vanished')}prepareRestoreVersion(version){this.showSpinner(!0),this.version=0,this.newVersion=version,this.setFrameData()}restoreVersion(msg){const _this=this;_this.versionManager?"Pre_Restore_Ack"==msg.Values.Status&&_ajax.default.call([{methodname:_this.component+"_restore_version",args:{id:_this.id,version:_this.newVersion}}])[0].done(function(data){1==data.success?(_this.version=0,_this.newVersion=0,_this.setFrameData(),_this.showVersionView()):_notification.default.exception({message:data.failuremsg})}.bind(_this)).fail(_notification.default.exception):_this.showSpinner(!0)}deleteVersion(version){const _this=this;_this.versionManager&&_ajax.default.call([{methodname:_this.component+"_delete_version",args:{id:_this.id,version:version}}])[0].done(function(data){1==data.success?(version==_this.version&&(_this.version=0,_this.setFrameData()),_this.showVersionView()):_notification.default.exception({message:data.failuremsg})}.bind(_this)).fail(_notification.default.exception)}}_exports.init=opts=>{new postMessageHandler(opts).init()}})); +define("mod_collabora/postmessage",["exports","jquery","core/fragment","core/templates","core/ajax","core/notification","core/log"],(function(_exports,_jquery,_fragment,_templates,_ajax,_notification,_log){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_jquery=_interopRequireDefault(_jquery),_fragment=_interopRequireDefault(_fragment),_templates=_interopRequireDefault(_templates),_ajax=_interopRequireDefault(_ajax),_notification=_interopRequireDefault(_notification),_log=_interopRequireDefault(_log);class PostMessageHandler{constructor(opts){_defineProperty(this,"asPopup",void 0),_defineProperty(this,"collaboraUrl",void 0),_defineProperty(this,"component",void 0),_defineProperty(this,"contextid",void 0),_defineProperty(this,"courseURL",void 0),_defineProperty(this,"id",void 0),_defineProperty(this,"iframeid",void 0),_defineProperty(this,"imgBackUrl",void 0),_defineProperty(this,"isSaving",void 0),_defineProperty(this,"newVersion",void 0),_defineProperty(this,"originCollabora",void 0),_defineProperty(this,"originMoodle",void 0),_defineProperty(this,"strBack",void 0),_defineProperty(this,"uiMode",void 0),_defineProperty(this,"version",void 0),_defineProperty(this,"versionManager",void 0),_defineProperty(this,"versionViewer",void 0),_defineProperty(this,"spinner",void 0),this.courseURL=opts.courseurl,this.collaboraUrl=opts.collaboraurl,this.component="component"in opts?opts.component:"mod_collabora",this.originCollabora=opts.origincollabora,this.originMoodle=opts.originmoodle,this.asPopup=opts.aspopup,this.iframeid=opts.iframeid,this.id=opts.id,this.contextid=opts.contextid,this.strBack=opts.strback,this.imgBackUrl=opts.imgbackurl,this.uiMode=opts.uimode,this.versionManager=opts.versionmanager,this.isSaving=!1,this.version=0,this.newVersion=0,this.versionViewer=document.querySelector("#"+opts.versionviewerid),this.spinner=document.querySelector("#collabora-spinner-"+this.id)}init(){const _this=this;_this.setFrameData(),_this.initModal(),window.addEventListener("message",(function(e){_this.receiveMessage(e)}))}receiveMessage(event){var msg;const _this=this;if(_log.default.debug("ReceiveMessage from "+event.origin+": "+event.data),event.origin==_this.originCollabora||event.origin==_this.originMoodle){if(("string"==typeof event.data||event.data instanceof String)&&(msg=JSON.parse(event.data)))switch(msg.MessageId){case"UI_Close":_this.closeDocument();break;case"App_LoadingStatus":_this.tellPostmessageReady(msg);break;case"UI_FileVersions":_this.showVersionView();break;case"UI_Save":_this.invokeSave();break;case"Doc_ModifiedStatus":_this.checkSaved(msg);break;case"Clicked_Button":_this.handleCustomButton(msg);break;case"App_VersionRestore":_this.restoreVersion(msg);break;case"SET_VERSION":_this.version=msg.Values.version,_this.setFrameData(),_this.showVersionView();break;case"RESTORE_VERSION":_this.prepareRestoreVersion(msg.Values.version);break;case"DELETE_VERSION":_this.deleteVersion(msg.Values.version)}}else _log.default.debug('!!!!Received Message from wrong origin "'+event.origin+'"')}closeDocument(){const _this=this;_this.asPopup?window.close():window.location.href=_this.courseURL}showSpinner(show){const _this=this;var iframe=document.querySelector("#"+_this.iframeid);show?(_this.spinner.classList.remove("d-none"),iframe.style.opacity=.1):(_this.spinner.classList.add("d-none"),iframe.style.opacity=1)}showVersionView(){this.loadVersionView(),(0,_jquery.default)("#"+this.versionViewer.id).collapse("show")}loadVersionView(){const _this=this;if(!_this.versionManager)return;const serviceparams={function:"version_viewer_content",id:_this.id,version:_this.version};_fragment.default.loadFragment(_this.component,"get_html",_this.contextid,serviceparams).then((function(html,js){document.querySelector("#"+_this.versionViewer.id+" .card-body").innerHTML=html,js&&_templates.default.runTemplateJS(js)})).fail(_notification.default.exception)}invokeSave(){this.isSaving=!0;this.postMessage({MessageId:"Action_Save",Values:{DontTerminateEdit:!0,DontSaveIfUnmodified:!0}})}checkSaved(msg){const _this=this;_this.isSaving=!0,0==msg.Values.Modified&&_this.isSaving&&_this.loadVersionView()}tellPostmessageReady(msg){const _this=this;if(msg.Values&&"Document_Loaded"==msg.Values.Status){var postObject;if(postObject={MessageId:"Host_PostmessageReady"},_this.postMessage(postObject),0!=_this.newVersion)return postObject={MessageId:"Host_VersionRestore",Values:{Status:"Pre_Restore"}},void _this.postMessage(postObject);postObject={MessageId:"Disable_Default_UIAction",Values:{action:"UI_Save",disable:!0}},_this.postMessage(postObject),0!=_this.uiMode&&(postObject={MessageId:"Action_ChangeUIMode",Values:{Mode:_this.uiMode}},_this.postMessage(postObject)),_this.showSpinner(!1),_this.version>0&&_this.addBackButton()}}handleCustomButton(msg){const _this=this;msg.Values&&"moodle_go_back"==msg.Values.Id&&(_this.version=0,_this.setFrameData())}addBackButton(){var postObject={MessageId:"Insert_Button",Values:{id:"moodle_go_back",imgurl:this.imgBackUrl,label:this.strBack,hint:this.strBack}};this.postMessage(postObject)}postMessage(postObject){const _this=this;postObject.SendTime=Date.now();var message=JSON.stringify(postObject);_log.default.debug("Post message to collabora: "+message);var iframe=document.querySelector("#"+_this.iframeid);null!==iframe&&null!=iframe?(iframe=iframe.contentWindow||iframe.contentDocument.document||iframe.contentDocument).postMessage(message,_this.originCollabora):_log.default.debug('The iframe "'+_this.iframeid+'" has vanished')}initModal(){const _this=this,inlineelement=document.querySelector("#collabora-inline_"+_this.id),modalelement=document.querySelector("#collaboramodal-body_"+_this.id),iframecontainer=document.querySelector("#iframe-container_"+_this.id);(0,_jquery.default)("#collaboramodal_"+_this.id).on("show.bs.modal",(function(){modalelement.append(iframecontainer),(0,_jquery.default)("body").addClass("modal-open"),_this.setFrameData()})),(0,_jquery.default)("#collaboramodal_"+_this.id).on("hide.bs.modal",(function(){inlineelement.append(iframecontainer),(0,_jquery.default)("body").removeClass("modal-open"),_this.setFrameData()}))}setFrameData(){const _this=this;_log.default.debug("Set iframe source: "+_this.collaboraUrl);var iframe=document.querySelector("#"+_this.iframeid);if(null!==iframe&&null!=iframe){var serviceparams={function:"wopi_src",id:_this.id,version:_this.version};_fragment.default.loadFragment(_this.component,"get_html",_this.contextid,serviceparams).then((function(strparams){var params=JSON.parse(strparams),form=document.createElement("form");form.method="get",form.action=_this.collaboraUrl,form.target=_this.iframeid;for(const[key,value]of Object.entries(params)){var element=document.createElement("input");element.type="hidden",element.name=key,element.value=value,form.appendChild(element),_log.default.debug("Add element "+key+": "+value)}document.body.appendChild(form),form.submit()})).fail(_notification.default.exception)}else _log.default.debug('The iframe "'+_this.iframeid+'" has vanished')}prepareRestoreVersion(version){this.showSpinner(!0),this.version=0,this.newVersion=version,this.setFrameData()}restoreVersion(msg){const _this=this;_this.versionManager?"Pre_Restore_Ack"==msg.Values.Status&&_ajax.default.call([{methodname:_this.component+"_restore_version",args:{id:_this.id,version:_this.newVersion}}])[0].done((function(data){1==data.success?(_this.version=0,_this.newVersion=0,_this.setFrameData(),_this.showVersionView()):_notification.default.exception({message:data.failuremsg})})).fail(_notification.default.exception):_this.showSpinner(!0)}deleteVersion(version){const _this=this;_this.versionManager&&_ajax.default.call([{methodname:_this.component+"_delete_version",args:{id:_this.id,version:version}}])[0].done((function(data){1==data.success?(version==_this.version&&(_this.version=0,_this.setFrameData()),_this.showVersionView()):_notification.default.exception({message:data.failuremsg})})).fail(_notification.default.exception)}}_exports.init=opts=>{new PostMessageHandler(opts).init()}})); //# sourceMappingURL=postmessage.min.js.map \ No newline at end of file diff --git a/amd/build/postmessage.min.js.map b/amd/build/postmessage.min.js.map index a6ef2a7..1dfa486 100644 --- a/amd/build/postmessage.min.js.map +++ b/amd/build/postmessage.min.js.map @@ -1 +1 @@ -{"version":3,"file":"postmessage.min.js","sources":["../src/postmessage.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Closes the collabora window.\n *\n * @module mod_collabora/monitorclose\n * @author Andreas Grabs \n * @copyright 2019 Humboldt-Universität zu Berlin \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport $ from 'jquery';\nimport fragment from 'core/fragment';\nimport templates from 'core/templates';\nimport ajax from 'core/ajax';\nimport notification from 'core/notification';\nimport log from 'core/log';\n\nclass postMessageHandler {\n asPopup;\n collaboraUrl;\n component;\n contextid;\n courseURL;\n id;\n iframeid;\n imgBackUrl;\n isSaving;\n newVersion;\n originCollabora;\n originMoodle;\n strBack;\n uiMode;\n version;\n versionManager;\n versionViewer;\n spinner;\n\n constructor(opts) {\n this.courseURL = opts.courseurl;\n this.collaboraUrl = opts.collaboraurl;\n if ('component' in opts) {\n this.component = opts.component;\n } else {\n this.component = 'mod_collabora';\n }\n this.originCollabora = opts.origincollabora;\n this.originMoodle = opts.originmoodle;\n this.asPopup = opts.aspopup;\n this.iframeid = opts.iframeid;\n this.id = opts.id;\n this.contextid = opts.contextid;\n this.strBack = opts.strback;\n this.imgBackUrl = opts.imgbackurl;\n this.uiMode = opts.uimode;\n this.versionManager = opts.versionmanager;\n this.isSaving = false;\n\n // The version is \"0\" by default.\n this.version = 0;\n this.newVersion = 0;\n\n this.versionViewer = document.querySelector('#' + opts.versionviewerid);\n this.spinner = document.querySelector('#collabora-spinner-' + this.id);\n }\n\n init() {\n const _this = this;\n\n _this.setFrameData();\n _this.initModal();\n // window.addEventListener('message', _this.receiveMessage, true);\n window.addEventListener('message', function(e) {\n _this.receiveMessage(e);\n }.bind(_this));\n }\n\n /**\n * Listener for the event 'message'\n * @param {Event} event\n */\n receiveMessage(event) {\n var msg, msgId;\n const _this = this;\n\n log.debug('ReceiveMessage from ' + event.origin + ': ' + event.data);\n // We only handle messages from Moodle or Collabora!\n if (event.origin != _this.originCollabora && event.origin != _this.originMoodle) {\n log.debug('!!!!Received Message from wrong origin \"' + event.origin + '\"');\n return;\n }\n if (typeof event.data !== 'string' && !(event.data instanceof String)) {\n return;\n }\n\n msg = JSON.parse(event.data);\n if (!msg) {\n return;\n }\n\n msgId = msg.MessageId;\n\n switch (msgId) {\n // Messages sent by collabora editor.\n case 'UI_Close':\n _this.closeDocument();\n break;\n case 'App_LoadingStatus':\n _this.tellPostmessageReady(msg);\n break;\n case 'UI_FileVersions':\n _this.showVersionView();\n break;\n case 'UI_Save':\n _this.invokeSave();\n break;\n case 'Doc_ModifiedStatus':\n _this.checkSaved(msg);\n break;\n case 'Clicked_Button':\n _this.handleCustomButton(msg);\n break;\n case 'App_VersionRestore':\n _this.restoreVersion(msg);\n break;\n\n // Messages sent by version viewer.\n case 'SET_VERSION':\n _this.version = msg.Values.version;\n _this.setFrameData();\n _this.showVersionView();\n break;\n case 'RESTORE_VERSION':\n _this.prepareRestoreVersion(msg.Values.version);\n break;\n case 'DELETE_VERSION':\n _this.deleteVersion(msg.Values.version);\n break;\n }\n }\n\n /**\n * Close the document or go back to the course page, depending on the current view.\n */\n closeDocument() {\n const _this = this;\n\n if (_this.asPopup) {\n window.close();\n } else {\n window.location.href = _this.courseURL;\n }\n }\n\n /**\n * Show or hide an overlay spinner.\n *\n * @param {boolean} show\n */\n showSpinner(show) {\n const _this = this;\n\n var iframe = document.querySelector('#' + _this.iframeid);\n if (show) {\n _this.spinner.classList.remove('d-none');\n iframe.style.opacity = 0.1;\n\n } else {\n _this.spinner.classList.add('d-none');\n iframe.style.opacity = 1;\n }\n }\n\n /**\n * Show the version_view page with all current versions.\n */\n showVersionView() {\n const _this = this;\n\n _this.loadVersionView();\n $('#' + _this.versionViewer.id).collapse('show');\n }\n\n /**\n * Load the content for the version viewer.\n */\n loadVersionView() {\n const _this = this;\n\n if (!_this.versionManager) {\n return;\n }\n\n const serviceparams = {\n 'function' : 'version_viewer_content',\n 'id': _this.id,\n 'version': _this.version\n };\n\n fragment.loadFragment(_this.component, 'get_html', _this.contextid, serviceparams).then(\n function(html, js) {\n let contentcontainer = document.querySelector('#' + _this.versionViewer.id + ' .card-body');\n contentcontainer.innerHTML = html;\n if (js) {\n templates.runTemplateJS(js);\n }\n }.bind(_this)\n ).fail(notification.exception);\n }\n\n /**\n * Invoke the save command.\n * This is different to the default save action because we can prevent saving of unmodified documents\n * which prevents creating new versions of the same document.\n */\n invokeSave() {\n const _this = this;\n\n _this.isSaving = true;\n\n const postObject = {\n 'MessageId': 'Action_Save',\n 'Values': {\n 'DontTerminateEdit': true,\n 'DontSaveIfUnmodified': true\n }\n };\n _this.postMessage(postObject);\n }\n\n /**\n * Check saving has finished and reload version view if open.\n * @param {object} msg The received message object from the collabora editor.\n */\n checkSaved(msg) {\n const _this = this;\n\n _this.isSaving = true;\n\n if (msg.Values.Modified == false) {\n if (_this.isSaving) {\n _this.loadVersionView();\n }\n }\n }\n\n /**\n * Post the first message to collabora when the document is ready.\n * @param {object} msg The received message object from the collabora editor.\n */\n tellPostmessageReady(msg) {\n const _this = this;\n\n if (msg.Values) {\n if (msg.Values.Status == 'Document_Loaded') {\n var postObject;\n // Send the Host_PostMessageReady before other posts (Mandatory)\n postObject = {\n 'MessageId': 'Host_PostmessageReady'\n };\n _this.postMessage(postObject);\n\n // If newVersion is set, we have to tell the editor we want to restore to it.\n if (_this.newVersion != 0) {\n postObject = {\n 'MessageId': 'Host_VersionRestore',\n 'Values': {\n 'Status': 'Pre_Restore'\n }\n };\n _this.postMessage(postObject);\n return;\n }\n\n // Disable the default save command to activate our own.\n postObject = {\n 'MessageId': 'Disable_Default_UIAction',\n 'Values': {\n 'action': 'UI_Save',\n 'disable': true\n }\n };\n _this.postMessage(postObject);\n\n // Set the ui mode (notebook or classic).\n if (_this.uiMode != 0) {\n postObject = {\n 'MessageId': 'Action_ChangeUIMode',\n 'Values': {\n 'Mode': _this.uiMode\n }\n };\n _this.postMessage(postObject);\n }\n // _this.spinner.classList.add('d-none');\n _this.showSpinner(false);\n if (_this.version > 0) {\n _this.addBackButton();\n }\n }\n }\n }\n\n handleCustomButton(msg) {\n const _this = this;\n\n if (msg.Values) {\n if (msg.Values.Id == 'moodle_go_back') {\n _this.version = 0;\n _this.setFrameData();\n }\n }\n\n }\n\n addBackButton() {\n const _this = this;\n\n var postObject = {\n 'MessageId': 'Insert_Button',\n 'Values': {\n 'id': 'moodle_go_back',\n 'imgurl': _this.imgBackUrl,\n 'label': _this.strBack,\n 'hint': _this.strBack\n }\n };\n _this.postMessage(postObject);\n }\n\n /**\n * Send a message to the collabora editor\n * @param {object} postObject The object we want to post.\n */\n postMessage(postObject) {\n const _this = this;\n\n postObject.SendTime = Date.now();\n var message = JSON.stringify(postObject);\n log.debug('Post message to collabora: ' + message);\n\n var iframe = document.querySelector('#' + _this.iframeid);\n if (iframe === null || iframe == undefined) {\n log.debug('The iframe \"' + _this.iframeid + '\" has vanished');\n return;\n }\n iframe = iframe.contentWindow || (iframe.contentDocument.document || iframe.contentDocument);\n\n iframe.postMessage(message, _this.originCollabora);\n }\n\n /**\n * Prepare the modal feature to set the frameData while showing or hiding the modal.\n */\n initModal() {\n const _this = this;\n\n // Get the elements between which the iframe is moved back and forth.\n const inlineelement = document.querySelector('#collabora-inline_' + _this.id);\n const modalelement = document.querySelector('#collaboramodal-body_' + _this.id);\n // Get the iframe container we move to one of the above defined elements.\n const iframecontainer = document.querySelector('#iframe-container_' + _this.id);\n\n // Move the iframe to the modal element.\n $(\"#collaboramodal_\" + _this.id).on(\"show.bs.modal\", function() {\n modalelement.append(iframecontainer);\n $(\"body\").addClass(\"modal-open\");\n\n _this.setFrameData();\n }.bind(_this));\n\n // Move the iframe to the inline element.\n $(\"#collaboramodal_\" + _this.id).on(\"hide.bs.modal\", function() {\n inlineelement.append(iframecontainer);\n $(\"body\").removeClass(\"modal-open\");\n _this.setFrameData();\n }.bind(_this));\n\n }\n\n /**\n * Set the Frame content by posting a temporary form to the iframe.\n */\n setFrameData() {\n const _this = this;\n\n log.debug('Set iframe source: ' + _this.collaboraUrl);\n\n // Check whether there is an iframe we can post the form to.\n var iframe = document.querySelector('#' + _this.iframeid);\n if (iframe === null || iframe == undefined) {\n log.debug('The iframe \"' + _this.iframeid + '\" has vanished');\n return;\n }\n\n // Load the wopi_src params.\n var serviceparams = {\n 'function' : 'wopi_src',\n 'id': _this.id,\n 'version': _this.version\n };\n fragment.loadFragment(_this.component, 'get_html', _this.contextid, serviceparams).then(\n function(strparams) {\n var params = JSON.parse(strparams);\n\n var form = document.createElement(\"form\");\n form.method = \"get\";\n form.action = _this.collaboraUrl;\n form.target = _this.iframeid;\n for (const [key, value] of Object.entries(params)) {\n var element = document.createElement(\"input\");\n element.type = \"hidden\";\n element.name = key;\n element.value = value;\n form.appendChild(element);\n log.debug('Add element ' + key + ': ' + value);\n }\n document.body.appendChild(form);\n\n form.submit();\n // form.remove(); // Remove the form because it's only temporary used.\n }.bind(_this)\n ).fail(notification.exception);\n\n return;\n }\n\n prepareRestoreVersion(version) {\n const _this = this;\n\n // _this.spinner.classList.remove('d-none');\n _this.showSpinner(true);\n\n _this.version = 0; // Set version to the current document, so we can tell other users using this document.\n _this.newVersion = version;\n _this.setFrameData();\n }\n\n restoreVersion(msg) {\n const _this = this;\n\n if (!_this.versionManager) {\n _this.showSpinner(true);\n return;\n }\n if (msg.Values.Status == 'Pre_Restore_Ack') {\n // Now we call the webservice with \"ajax.call\" and get an array of promises.\n // Because we call only one service we only get one promise inside this array.\n var myPromises = ajax.call([{ // Note: there is a Square bracket!\n // The parameter methodname is the webservice we want to call.\n methodname: _this.component + '_restore_version',\n // The second one is a json object with all in the webservice defined parameters.\n // The submitaction is needed to set the right action url in the mform.\n args:{ id: _this.id, version: _this.newVersion }\n }]);\n\n // We only have one promise because we call only one webservice. More would be possible.\n // So we just use promises[0].\n myPromises[0].done(function(data) {\n if (data.success == 1) {\n _this.version = 0;\n _this.newVersion = 0;\n _this.setFrameData();\n\n _this.showVersionView();\n\n } else {\n notification.exception({message: data.failuremsg});\n }\n }.bind(_this)).fail(notification.exception); // If any went wrong we let the user know.\n }\n }\n\n deleteVersion(version) {\n const _this = this;\n\n if (!_this.versionManager) {\n return;\n }\n\n // Now we call the webservice with \"ajax.call\" and get an array of promises.\n // Because we call only one service we only get one promise inside this array.\n var myPromises = ajax.call([{ // Note: there is a Square bracket!\n // The parameter methodname is the webservice we want to call.\n methodname: _this.component + '_delete_version',\n // The second one is a json object with all in the webservice defined parameters.\n // The submitaction is needed to set the right action url in the mform.\n args:{ id: _this.id, version: version }\n }]);\n\n // We only have one promise because we call only one webservice. More would be possible.\n // So we just use promises[0].\n myPromises[0].done(function(data) {\n if (data.success == 1) {\n if (version == _this.version) {\n _this.version = 0; // If the deleted version is in the editor, we set it to the default version.\n _this.setFrameData();\n }\n _this.showVersionView();\n } else {\n notification.exception({message: data.failuremsg});\n }\n }.bind(_this)).fail(notification.exception); // If any went wrong we let the user know.\n }\n}\n\nexport const init = (opts) => {\n const pm = new postMessageHandler(opts);\n pm.init();\n};\n"],"names":["postMessageHandler","constructor","opts","courseURL","courseurl","collaboraUrl","collaboraurl","component","originCollabora","origincollabora","originMoodle","originmoodle","asPopup","aspopup","iframeid","id","contextid","strBack","strback","imgBackUrl","imgbackurl","uiMode","uimode","versionManager","versionmanager","isSaving","version","newVersion","versionViewer","document","querySelector","versionviewerid","spinner","this","init","_this","setFrameData","initModal","window","addEventListener","e","receiveMessage","bind","event","msg","debug","origin","data","String","JSON","parse","MessageId","closeDocument","tellPostmessageReady","showVersionView","invokeSave","checkSaved","handleCustomButton","restoreVersion","Values","prepareRestoreVersion","deleteVersion","close","location","href","showSpinner","show","iframe","classList","remove","style","opacity","add","loadVersionView","collapse","serviceparams","loadFragment","then","html","js","innerHTML","runTemplateJS","fail","notification","exception","postMessage","Modified","Status","postObject","addBackButton","Id","SendTime","Date","now","message","stringify","undefined","contentWindow","contentDocument","inlineelement","modalelement","iframecontainer","on","append","addClass","removeClass","strparams","params","form","createElement","method","action","target","key","value","Object","entries","element","type","name","appendChild","body","submit","ajax","call","methodname","args","done","success","failuremsg"],"mappings":"mxBA+BMA,mBAoBFC,YAAYC,gvBACHC,UAAYD,KAAKE,eACjBC,aAAeH,KAAKI,kBAEhBC,UADL,cAAeL,KACEA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S,MAAMC,gBAEVD,MAAMmB,yCAEO8B,UAAU,CAACU,QAAS/C,KAAKkF,cAE5CvF,KAAKP,QAAQ+C,KAAKC,sBAAaC,0BAIpBlF,OACN,IAAIF,mBAAmBE,MAC/BgC"} \ No newline at end of file +{"version":3,"file":"postmessage.min.js","sources":["../src/postmessage.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Closes the collabora window.\n *\n * @module mod_collabora/monitorclose\n * @author Andreas Grabs \n * @copyright 2019 Humboldt-Universität zu Berlin \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport $ from 'jquery';\nimport fragment from 'core/fragment';\nimport templates from 'core/templates';\nimport ajax from 'core/ajax';\nimport notification from 'core/notification';\nimport log from 'core/log';\n\nclass PostMessageHandler {\n asPopup;\n collaboraUrl;\n component;\n contextid;\n courseURL;\n id;\n iframeid;\n imgBackUrl;\n isSaving;\n newVersion;\n originCollabora;\n originMoodle;\n strBack;\n uiMode;\n version;\n versionManager;\n versionViewer;\n spinner;\n\n constructor(opts) {\n this.courseURL = opts.courseurl;\n this.collaboraUrl = opts.collaboraurl;\n if ('component' in opts) {\n this.component = opts.component;\n } else {\n this.component = 'mod_collabora';\n }\n this.originCollabora = opts.origincollabora;\n this.originMoodle = opts.originmoodle;\n this.asPopup = opts.aspopup;\n this.iframeid = opts.iframeid;\n this.id = opts.id;\n this.contextid = opts.contextid;\n this.strBack = opts.strback;\n this.imgBackUrl = opts.imgbackurl;\n this.uiMode = opts.uimode;\n this.versionManager = opts.versionmanager;\n this.isSaving = false;\n\n // The version is \"0\" by default.\n this.version = 0;\n this.newVersion = 0;\n\n this.versionViewer = document.querySelector('#' + opts.versionviewerid);\n this.spinner = document.querySelector('#collabora-spinner-' + this.id);\n }\n\n init() {\n const _this = this;\n\n _this.setFrameData();\n _this.initModal();\n window.addEventListener('message', function(e) {\n _this.receiveMessage(e);\n });\n }\n\n /**\n * Listener for the event 'message'\n * @param {Event} event\n */\n receiveMessage(event) {\n var msg, msgId;\n const _this = this;\n\n log.debug('ReceiveMessage from ' + event.origin + ': ' + event.data);\n // We only handle messages from Moodle or Collabora!\n if (event.origin != _this.originCollabora && event.origin != _this.originMoodle) {\n log.debug('!!!!Received Message from wrong origin \"' + event.origin + '\"');\n return;\n }\n if (typeof event.data !== 'string' && !(event.data instanceof String)) {\n return;\n }\n\n msg = JSON.parse(event.data);\n if (!msg) {\n return;\n }\n\n msgId = msg.MessageId;\n\n switch (msgId) {\n // Messages sent by collabora editor.\n case 'UI_Close':\n _this.closeDocument();\n break;\n case 'App_LoadingStatus':\n _this.tellPostmessageReady(msg);\n break;\n case 'UI_FileVersions':\n _this.showVersionView();\n break;\n case 'UI_Save':\n _this.invokeSave();\n break;\n case 'Doc_ModifiedStatus':\n _this.checkSaved(msg);\n break;\n case 'Clicked_Button':\n _this.handleCustomButton(msg);\n break;\n case 'App_VersionRestore':\n _this.restoreVersion(msg);\n break;\n\n // Messages sent by version viewer.\n case 'SET_VERSION':\n _this.version = msg.Values.version;\n _this.setFrameData();\n _this.showVersionView();\n break;\n case 'RESTORE_VERSION':\n _this.prepareRestoreVersion(msg.Values.version);\n break;\n case 'DELETE_VERSION':\n _this.deleteVersion(msg.Values.version);\n break;\n }\n }\n\n /**\n * Close the document or go back to the course page, depending on the current view.\n */\n closeDocument() {\n const _this = this;\n\n if (_this.asPopup) {\n window.close();\n } else {\n window.location.href = _this.courseURL;\n }\n }\n\n /**\n * Show or hide an overlay spinner.\n *\n * @param {boolean} show\n */\n showSpinner(show) {\n const _this = this;\n\n var iframe = document.querySelector('#' + _this.iframeid);\n if (show) {\n _this.spinner.classList.remove('d-none');\n iframe.style.opacity = 0.1;\n\n } else {\n _this.spinner.classList.add('d-none');\n iframe.style.opacity = 1;\n }\n }\n\n /**\n * Show the version_view page with all current versions.\n */\n showVersionView() {\n const _this = this;\n\n _this.loadVersionView();\n $('#' + _this.versionViewer.id).collapse('show');\n }\n\n /**\n * Load the content for the version viewer.\n */\n loadVersionView() {\n const _this = this;\n\n if (!_this.versionManager) {\n return;\n }\n\n const serviceparams = {\n 'function': 'version_viewer_content',\n 'id': _this.id,\n 'version': _this.version\n };\n\n fragment.loadFragment(_this.component, 'get_html', _this.contextid, serviceparams).then(\n function(html, js) {\n let contentcontainer = document.querySelector('#' + _this.versionViewer.id + ' .card-body');\n contentcontainer.innerHTML = html;\n if (js) {\n templates.runTemplateJS(js);\n }\n return;\n }\n ).fail(notification.exception);\n }\n\n /**\n * Invoke the save command.\n * This is different to the default save action because we can prevent saving of unmodified documents\n * which prevents creating new versions of the same document.\n */\n invokeSave() {\n const _this = this;\n\n _this.isSaving = true;\n\n const postObject = {\n 'MessageId': 'Action_Save',\n 'Values': {\n 'DontTerminateEdit': true,\n 'DontSaveIfUnmodified': true\n }\n };\n _this.postMessage(postObject);\n }\n\n /**\n * Check saving has finished and reload version view if open.\n * @param {object} msg The received message object from the collabora editor.\n */\n checkSaved(msg) {\n const _this = this;\n\n _this.isSaving = true;\n\n if (msg.Values.Modified == false) {\n if (_this.isSaving) {\n _this.loadVersionView();\n }\n }\n }\n\n /**\n * Post the first message to collabora when the document is ready.\n * @param {object} msg The received message object from the collabora editor.\n */\n tellPostmessageReady(msg) {\n const _this = this;\n\n if (msg.Values) {\n if (msg.Values.Status == 'Document_Loaded') {\n var postObject;\n // Send the Host_PostMessageReady before other posts (Mandatory)\n postObject = {\n 'MessageId': 'Host_PostmessageReady'\n };\n _this.postMessage(postObject);\n\n // If newVersion is set, we have to tell the editor we want to restore to it.\n if (_this.newVersion != 0) {\n postObject = {\n 'MessageId': 'Host_VersionRestore',\n 'Values': {\n 'Status': 'Pre_Restore'\n }\n };\n _this.postMessage(postObject);\n return;\n }\n\n // Disable the default save command to activate our own.\n postObject = {\n 'MessageId': 'Disable_Default_UIAction',\n 'Values': {\n 'action': 'UI_Save',\n 'disable': true\n }\n };\n _this.postMessage(postObject);\n\n // Set the ui mode (notebook or classic).\n if (_this.uiMode != 0) {\n postObject = {\n 'MessageId': 'Action_ChangeUIMode',\n 'Values': {\n 'Mode': _this.uiMode\n }\n };\n _this.postMessage(postObject);\n }\n // _this.spinner.classList.add('d-none');\n _this.showSpinner(false);\n if (_this.version > 0) {\n _this.addBackButton();\n }\n }\n }\n }\n\n handleCustomButton(msg) {\n const _this = this;\n\n if (msg.Values) {\n if (msg.Values.Id == 'moodle_go_back') {\n _this.version = 0;\n _this.setFrameData();\n }\n }\n\n }\n\n addBackButton() {\n const _this = this;\n\n var postObject = {\n 'MessageId': 'Insert_Button',\n 'Values': {\n 'id': 'moodle_go_back',\n 'imgurl': _this.imgBackUrl,\n 'label': _this.strBack,\n 'hint': _this.strBack\n }\n };\n _this.postMessage(postObject);\n }\n\n /**\n * Send a message to the collabora editor\n * @param {object} postObject The object we want to post.\n */\n postMessage(postObject) {\n const _this = this;\n\n postObject.SendTime = Date.now();\n var message = JSON.stringify(postObject);\n log.debug('Post message to collabora: ' + message);\n\n var iframe = document.querySelector('#' + _this.iframeid);\n if (iframe === null || iframe == undefined) {\n log.debug('The iframe \"' + _this.iframeid + '\" has vanished');\n return;\n }\n iframe = iframe.contentWindow || (iframe.contentDocument.document || iframe.contentDocument);\n\n iframe.postMessage(message, _this.originCollabora);\n }\n\n /**\n * Prepare the modal feature to set the frameData while showing or hiding the modal.\n */\n initModal() {\n const _this = this;\n\n // Get the elements between which the iframe is moved back and forth.\n const inlineelement = document.querySelector('#collabora-inline_' + _this.id);\n const modalelement = document.querySelector('#collaboramodal-body_' + _this.id);\n // Get the iframe container we move to one of the above defined elements.\n const iframecontainer = document.querySelector('#iframe-container_' + _this.id);\n\n // Move the iframe to the modal element.\n $(\"#collaboramodal_\" + _this.id).on(\"show.bs.modal\", function() {\n modalelement.append(iframecontainer);\n $(\"body\").addClass(\"modal-open\");\n\n _this.setFrameData();\n });\n\n // Move the iframe to the inline element.\n $(\"#collaboramodal_\" + _this.id).on(\"hide.bs.modal\", function() {\n inlineelement.append(iframecontainer);\n $(\"body\").removeClass(\"modal-open\");\n _this.setFrameData();\n });\n\n }\n\n /**\n * Set the Frame content by posting a temporary form to the iframe.\n */\n setFrameData() {\n const _this = this;\n\n log.debug('Set iframe source: ' + _this.collaboraUrl);\n\n // Check whether there is an iframe we can post the form to.\n var iframe = document.querySelector('#' + _this.iframeid);\n if (iframe === null || iframe == undefined) {\n log.debug('The iframe \"' + _this.iframeid + '\" has vanished');\n return;\n }\n\n // Load the wopi_src params.\n var serviceparams = {\n 'function': 'wopi_src',\n 'id': _this.id,\n 'version': _this.version\n };\n fragment.loadFragment(_this.component, 'get_html', _this.contextid, serviceparams).then(\n function(strparams) {\n var params = JSON.parse(strparams);\n\n var form = document.createElement(\"form\");\n form.method = \"get\";\n form.action = _this.collaboraUrl;\n form.target = _this.iframeid;\n for (const [key, value] of Object.entries(params)) {\n var element = document.createElement(\"input\");\n element.type = \"hidden\";\n element.name = key;\n element.value = value;\n form.appendChild(element);\n log.debug('Add element ' + key + ': ' + value);\n }\n document.body.appendChild(form);\n\n form.submit();\n return;\n }\n ).fail(notification.exception);\n\n return;\n }\n\n prepareRestoreVersion(version) {\n const _this = this;\n\n // _this.spinner.classList.remove('d-none');\n _this.showSpinner(true);\n\n _this.version = 0; // Set version to the current document, so we can tell other users using this document.\n _this.newVersion = version;\n _this.setFrameData();\n }\n\n restoreVersion(msg) {\n const _this = this;\n\n if (!_this.versionManager) {\n _this.showSpinner(true);\n return;\n }\n if (msg.Values.Status == 'Pre_Restore_Ack') {\n // Now we call the webservice with \"ajax.call\" and get an array of promises.\n // Because we call only one service we only get one promise inside this array.\n var myPromises = ajax.call([{ // Note: there is a Square bracket!\n // The parameter methodname is the webservice we want to call.\n methodname: _this.component + '_restore_version',\n // The second one is a json object with all in the webservice defined parameters.\n // The submitaction is needed to set the right action url in the mform.\n args: {id: _this.id, version: _this.newVersion}\n }]);\n\n // We only have one promise because we call only one webservice. More would be possible.\n // So we just use promises[0].\n myPromises[0].done(function(data) {\n if (data.success == 1) {\n _this.version = 0;\n _this.newVersion = 0;\n _this.setFrameData();\n\n _this.showVersionView();\n\n } else {\n notification.exception({message: data.failuremsg});\n }\n }).fail(notification.exception); // If any went wrong we let the user know.\n }\n }\n\n deleteVersion(version) {\n const _this = this;\n\n if (!_this.versionManager) {\n return;\n }\n\n // Now we call the webservice with \"ajax.call\" and get an array of promises.\n // Because we call only one service we only get one promise inside this array.\n var myPromises = ajax.call([{ // Note: there is a Square bracket!\n // The parameter methodname is the webservice we want to call.\n methodname: _this.component + '_delete_version',\n // The second one is a json object with all in the webservice defined parameters.\n // The submitaction is needed to set the right action url in the mform.\n args: {id: _this.id, version: version}\n }]);\n\n // We only have one promise because we call only one webservice. More would be possible.\n // So we just use promises[0].\n myPromises[0].done(function(data) {\n if (data.success == 1) {\n if (version == _this.version) {\n _this.version = 0; // If the deleted version is in the editor, we set it to the default version.\n _this.setFrameData();\n }\n _this.showVersionView();\n } else {\n notification.exception({message: data.failuremsg});\n }\n }).fail(notification.exception); // If any went wrong we let the user know.\n }\n}\n\nexport const init = (opts) => {\n const pm = new PostMessageHandler(opts);\n pm.init();\n};\n"],"names":["PostMessageHandler","constructor","opts","courseURL","courseurl","collaboraUrl","collaboraurl","component","originCollabora","origincollabora","originMoodle","originmoodle","asPopup","aspopup","iframeid","id","contextid","strBack","strback","imgBackUrl","imgbackurl","uiMode","uimode","versionManager","versionmanager","isSaving","version","newVersion","versionViewer","document","querySelector","versionviewerid","spinner","this","init","_this","setFrameData","initModal","window","addEventListener","e","receiveMessage","event","msg","debug","origin","data","String","JSON","parse","MessageId","closeDocument","tellPostmessageReady","showVersionView","invokeSave","checkSaved","handleCustomButton","restoreVersion","Values","prepareRestoreVersion","deleteVersion","close","location","href","showSpinner","show","iframe","classList","remove","style","opacity","add","loadVersionView","collapse","serviceparams","loadFragment","then","html","js","innerHTML","runTemplateJS","fail","notification","exception","postMessage","Modified","Status","postObject","addBackButton","Id","SendTime","Date","now","message","stringify","undefined","contentWindow","contentDocument","inlineelement","modalelement","iframecontainer","on","append","addClass","removeClass","strparams","params","form","createElement","method","action","target","key","value","Object","entries","element","type","name","appendChild","body","submit","ajax","call","methodname","args","done","success","failuremsg"],"mappings":"mxBA+BMA,mBAoBFC,YAAYC,gvBACHC,UAAYD,KAAKE,eACjBC,aAAeH,KAAKI,kBAEhBC,UADL,cAAeL,KACEA,KAAKK,UAEL,qBAEhBC,gBAAkBN,KAAKO,qBACvBC,aAAeR,KAAKS,kBACpBC,QAAUV,KAAKW,aACfC,SAAWZ,KAAKY,cAChBC,GAAKb,KAAKa,QACVC,UAAYd,KAAKc,eACjBC,QAAUf,KAAKgB,aACfC,WAAajB,KAAKkB,gBAClBC,OAASnB,KAAKoB,YACdC,eAAiBrB,KAAKsB,oBACtBC,UAAW,OAGXC,QAAU,OACVC,WAAa,OAEbC,cAAgBC,SAASC,cAAc,IAAM5B,KAAK6B,sBAClDC,QAAUH,SAASC,cAAc,sBAAwBG,KAAKlB,IAGvEmB,aACUC,MAAQF,KAEdE,MAAMC,eACND,MAAME,YACNC,OAAOC,iBAAiB,WAAW,SAASC,GACxCL,MAAMM,eAAeD,MAQ7BC,eAAeC,WACPC,UACER,MAAQF,qBAEVW,MAAM,uBAAyBF,MAAMG,OAAS,KAAOH,MAAMI,MAE3DJ,MAAMG,QAAUV,MAAM3B,iBAAmBkC,MAAMG,QAAUV,MAAMzB,kBAIzC,iBAAfgC,MAAMI,MAAuBJ,MAAMI,gBAAgBC,UAI9DJ,IAAMK,KAAKC,MAAMP,MAAMI,cAKfH,IAAIO,eAIH,WACDf,MAAMgB,0B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BS,MAAMR,WAAa,EACnBQ,MAAMC,eAEND,MAAMkB,yCAGO8B,UAAU,CAACU,QAAS/C,KAAKkF,gBAE3C/C,KAAKC,sBAAaC,WA3BrBhD,MAAM6B,aAAY,GA+B1BJ,cAAclC,eACJS,MAAQF,KAETE,MAAMZ,gBAMMmG,cAAKC,KAAK,CAAC,CAExBC,WAAYzF,MAAM5B,UAAY,kBAG9BsH,KAAM,CAAC9G,GAAIoB,MAAMpB,GAAIW,QAASA,YAKvB,GAAGoG,MAAK,SAAShF,MACJ,GAAhBA,KAAKiF,SACDrG,SAAWS,MAAMT,UACjBS,MAAMT,QAAU,EAChBS,MAAMC,gBAEVD,MAAMkB,yCAEO8B,UAAU,CAACU,QAAS/C,KAAKkF,gBAE3C/C,KAAKC,sBAAaC,0BAIRjF,OACN,IAAIF,mBAAmBE,MAC/BgC"} \ No newline at end of file diff --git a/amd/build/versionmanager.min.js b/amd/build/versionmanager.min.js index 7c46553..889e81d 100644 --- a/amd/build/versionmanager.min.js +++ b/amd/build/versionmanager.min.js @@ -6,6 +6,6 @@ define("mod_collabora/versionmanager",["exports","core/log"],(function(_exports, * @author Andreas Grabs * @copyright 2019 Humboldt-Universität zu Berlin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_log=(obj=_log)&&obj.__esModule?obj:{default:obj};_exports.init=id=>{function postMessage(postObject){postObject.SendTime=Date.now();var message=JSON.stringify(postObject);_log.default.debug("Post message to myself: "+message),window.postMessage(message,"*")}document.querySelector("#version_viewer_table-"+id).addEventListener("click",(event=>{const target=event.target,version=target.dataset.version;target.classList.contains("collabora-preview-button")&&(event.preventDefault(),event.stopPropagation(),postMessage({MessageId:"SET_VERSION",Values:{version:version}}));target.classList.contains("collabora-restore-button")&&(event.preventDefault(),event.stopPropagation(),postMessage({MessageId:"RESTORE_VERSION",Values:{version:version}}));target.classList.contains("collabora-deleteversion-button")&&(event.preventDefault(),event.stopPropagation(),postMessage({MessageId:"DELETE_VERSION",Values:{version:version}}))}))}})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_log=(obj=_log)&&obj.__esModule?obj:{default:obj};_exports.init=id=>{function postMessage(postObject){postObject.SendTime=Date.now();var message=JSON.stringify(postObject);_log.default.debug("Post message to myself: "+message),window.postMessage(message,"*")}document.querySelector("#version_viewer_table-"+id).addEventListener("click",(event=>{const target=event.target,version=target.dataset.version;target.classList.contains("collabora-preview-button")&&(event.preventDefault(),event.stopPropagation(),postMessage({MessageId:"SET_VERSION",Values:{version:version}})),target.classList.contains("collabora-restore-button")&&(event.preventDefault(),event.stopPropagation(),postMessage({MessageId:"RESTORE_VERSION",Values:{version:version}})),target.classList.contains("collabora-deleteversion-button")&&(event.preventDefault(),event.stopPropagation(),postMessage({MessageId:"DELETE_VERSION",Values:{version:version}}))}))}})); //# sourceMappingURL=versionmanager.min.js.map \ No newline at end of file diff --git a/amd/build/versionmanager.min.js.map b/amd/build/versionmanager.min.js.map index f8d78e1..3df1f1d 100644 --- a/amd/build/versionmanager.min.js.map +++ b/amd/build/versionmanager.min.js.map @@ -1 +1 @@ -{"version":3,"file":"versionmanager.min.js","sources":["../src/versionmanager.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Change the iframe size relative to the window size.\n *\n * @module mod_collabora/resizeiframe\n * @author Andreas Grabs \n * @copyright 2019 Humboldt-Universität zu Berlin \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport log from 'core/log';\n\nexport const init = (id) => {\n const table = document.querySelector(\"#version_viewer_table-\" + id);\n table.addEventListener(\"click\", (event) => {\n const target = event.target;\n const version = target.dataset.version;\n if (target.classList.contains(\"collabora-preview-button\")) {\n event.preventDefault();\n event.stopPropagation();\n var postObject = {\n 'MessageId': 'SET_VERSION',\n 'Values': {\n 'version': version\n }\n };\n postMessage(postObject);\n }\n if (target.classList.contains(\"collabora-restore-button\")) {\n event.preventDefault();\n event.stopPropagation();\n var postObject = {\n 'MessageId': 'RESTORE_VERSION',\n 'Values': {\n 'version': version\n }\n };\n postMessage(postObject);\n }\n if (target.classList.contains(\"collabora-deleteversion-button\")) {\n event.preventDefault();\n event.stopPropagation();\n var postObject = {\n 'MessageId': 'DELETE_VERSION',\n 'Values': {\n 'version': version\n }\n };\n postMessage(postObject);\n }\n });\n\n /**\n * Send a message to the collabora editor\n * @param {object} postObject The object we want to post.\n */\n function postMessage(postObject) {\n postObject.SendTime = Date.now();\n var message = JSON.stringify(postObject);\n log.debug('Post message to myself: ' + message);\n\n window.postMessage(message, '*');\n }\n\n};\n"],"names":["id","postMessage","postObject","SendTime","Date","now","message","JSON","stringify","debug","window","document","querySelector","addEventListener","event","target","version","dataset","classList","contains","preventDefault","stopPropagation"],"mappings":";;;;;;;;kJA0BqBA,cA4CRC,YAAYC,YACjBA,WAAWC,SAAWC,KAAKC,UACvBC,QAAUC,KAAKC,UAAUN,yBACzBO,MAAM,2BAA6BH,SAEvCI,OAAOT,YAAYK,QAAS,KAhDlBK,SAASC,cAAc,yBAA2BZ,IAC1Da,iBAAiB,SAAUC,cACvBC,OAASD,MAAMC,OACfC,QAAUD,OAAOE,QAAQD,QAC3BD,OAAOG,UAAUC,SAAS,8BAC1BL,MAAMM,iBACNN,MAAMO,kBAONpB,YANiB,WACA,qBACH,SACKe,YAKnBD,OAAOG,UAAUC,SAAS,8BAC1BL,MAAMM,iBACNN,MAAMO,kBAONpB,YANiB,WACA,yBACH,SACKe,YAKnBD,OAAOG,UAAUC,SAAS,oCAC1BL,MAAMM,iBACNN,MAAMO,kBAONpB,YANiB,WACA,wBACH,SACKe"} \ No newline at end of file +{"version":3,"file":"versionmanager.min.js","sources":["../src/versionmanager.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Change the iframe size relative to the window size.\n *\n * @module mod_collabora/resizeiframe\n * @author Andreas Grabs \n * @copyright 2019 Humboldt-Universität zu Berlin \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport log from 'core/log';\n\nexport const init = (id) => {\n const table = document.querySelector(\"#version_viewer_table-\" + id);\n table.addEventListener(\"click\", (event) => {\n const target = event.target;\n const version = target.dataset.version;\n if (target.classList.contains(\"collabora-preview-button\")) {\n event.preventDefault();\n event.stopPropagation();\n postMessage({\n 'MessageId': 'SET_VERSION',\n 'Values': {\n 'version': version\n }\n });\n }\n if (target.classList.contains(\"collabora-restore-button\")) {\n event.preventDefault();\n event.stopPropagation();\n postMessage({\n 'MessageId': 'RESTORE_VERSION',\n 'Values': {\n 'version': version\n }\n });\n }\n if (target.classList.contains(\"collabora-deleteversion-button\")) {\n event.preventDefault();\n event.stopPropagation();\n postMessage({\n 'MessageId': 'DELETE_VERSION',\n 'Values': {\n 'version': version\n }\n });\n }\n });\n\n /**\n * Send a message to the collabora editor\n * @param {object} postObject The object we want to post.\n */\n function postMessage(postObject) {\n postObject.SendTime = Date.now();\n var message = JSON.stringify(postObject);\n log.debug('Post message to myself: ' + message);\n\n window.postMessage(message, '*');\n }\n\n};\n"],"names":["id","postMessage","postObject","SendTime","Date","now","message","JSON","stringify","debug","window","document","querySelector","addEventListener","event","target","version","dataset","classList","contains","preventDefault","stopPropagation"],"mappings":";;;;;;;;kJA0BqBA,cAyCRC,YAAYC,YACjBA,WAAWC,SAAWC,KAAKC,UACvBC,QAAUC,KAAKC,UAAUN,yBACzBO,MAAM,2BAA6BH,SAEvCI,OAAOT,YAAYK,QAAS,KA7ClBK,SAASC,cAAc,yBAA2BZ,IAC1Da,iBAAiB,SAAUC,cACvBC,OAASD,MAAMC,OACfC,QAAUD,OAAOE,QAAQD,QAC3BD,OAAOG,UAAUC,SAAS,8BAC1BL,MAAMM,iBACNN,MAAMO,kBACNpB,YAAY,WACK,qBACH,SACKe,YAInBD,OAAOG,UAAUC,SAAS,8BAC1BL,MAAMM,iBACNN,MAAMO,kBACNpB,YAAY,WACK,yBACH,SACKe,YAInBD,OAAOG,UAAUC,SAAS,oCAC1BL,MAAMM,iBACNN,MAAMO,kBACNpB,YAAY,WACK,wBACH,SACKe"} \ No newline at end of file diff --git a/amd/src/postmessage.js b/amd/src/postmessage.js index 26c68d1..14d9fa7 100644 --- a/amd/src/postmessage.js +++ b/amd/src/postmessage.js @@ -29,7 +29,7 @@ import ajax from 'core/ajax'; import notification from 'core/notification'; import log from 'core/log'; -class postMessageHandler { +class PostMessageHandler { asPopup; collaboraUrl; component; @@ -82,10 +82,9 @@ class postMessageHandler { _this.setFrameData(); _this.initModal(); - // window.addEventListener('message', _this.receiveMessage, true); window.addEventListener('message', function(e) { _this.receiveMessage(e); - }.bind(_this)); + }); } /** @@ -205,7 +204,7 @@ class postMessageHandler { } const serviceparams = { - 'function' : 'version_viewer_content', + 'function': 'version_viewer_content', 'id': _this.id, 'version': _this.version }; @@ -217,7 +216,8 @@ class postMessageHandler { if (js) { templates.runTemplateJS(js); } - }.bind(_this) + return; + } ).fail(notification.exception); } @@ -380,14 +380,14 @@ class postMessageHandler { $("body").addClass("modal-open"); _this.setFrameData(); - }.bind(_this)); + }); // Move the iframe to the inline element. $("#collaboramodal_" + _this.id).on("hide.bs.modal", function() { inlineelement.append(iframecontainer); $("body").removeClass("modal-open"); _this.setFrameData(); - }.bind(_this)); + }); } @@ -408,7 +408,7 @@ class postMessageHandler { // Load the wopi_src params. var serviceparams = { - 'function' : 'wopi_src', + 'function': 'wopi_src', 'id': _this.id, 'version': _this.version }; @@ -431,8 +431,8 @@ class postMessageHandler { document.body.appendChild(form); form.submit(); - // form.remove(); // Remove the form because it's only temporary used. - }.bind(_this) + return; + } ).fail(notification.exception); return; @@ -464,7 +464,7 @@ class postMessageHandler { methodname: _this.component + '_restore_version', // The second one is a json object with all in the webservice defined parameters. // The submitaction is needed to set the right action url in the mform. - args:{ id: _this.id, version: _this.newVersion } + args: {id: _this.id, version: _this.newVersion} }]); // We only have one promise because we call only one webservice. More would be possible. @@ -480,7 +480,7 @@ class postMessageHandler { } else { notification.exception({message: data.failuremsg}); } - }.bind(_this)).fail(notification.exception); // If any went wrong we let the user know. + }).fail(notification.exception); // If any went wrong we let the user know. } } @@ -498,7 +498,7 @@ class postMessageHandler { methodname: _this.component + '_delete_version', // The second one is a json object with all in the webservice defined parameters. // The submitaction is needed to set the right action url in the mform. - args:{ id: _this.id, version: version } + args: {id: _this.id, version: version} }]); // We only have one promise because we call only one webservice. More would be possible. @@ -513,11 +513,11 @@ class postMessageHandler { } else { notification.exception({message: data.failuremsg}); } - }.bind(_this)).fail(notification.exception); // If any went wrong we let the user know. + }).fail(notification.exception); // If any went wrong we let the user know. } } export const init = (opts) => { - const pm = new postMessageHandler(opts); + const pm = new PostMessageHandler(opts); pm.init(); }; diff --git a/amd/src/versionmanager.js b/amd/src/versionmanager.js index 6b1fec4..d803fba 100644 --- a/amd/src/versionmanager.js +++ b/amd/src/versionmanager.js @@ -32,42 +32,39 @@ export const init = (id) => { if (target.classList.contains("collabora-preview-button")) { event.preventDefault(); event.stopPropagation(); - var postObject = { + postMessage({ 'MessageId': 'SET_VERSION', 'Values': { 'version': version } - }; - postMessage(postObject); + }); } if (target.classList.contains("collabora-restore-button")) { event.preventDefault(); event.stopPropagation(); - var postObject = { + postMessage({ 'MessageId': 'RESTORE_VERSION', 'Values': { 'version': version } - }; - postMessage(postObject); + }); } if (target.classList.contains("collabora-deleteversion-button")) { event.preventDefault(); event.stopPropagation(); - var postObject = { + postMessage({ 'MessageId': 'DELETE_VERSION', 'Values': { 'version': version } - }; - postMessage(postObject); + }); } }); /** - * Send a message to the collabora editor - * @param {object} postObject The object we want to post. - */ + * Send a message to the collabora editor + * @param {object} postObject The object we want to post. + */ function postMessage(postObject) { postObject.SendTime = Date.now(); var message = JSON.stringify(postObject);