From 968a9c2d9cf509945bca620718243e574db6587c Mon Sep 17 00:00:00 2001 From: Sebastien Curt <sebastien.curt@tetras-libre.fr> Date: Tue, 3 May 2022 14:45:58 +0200 Subject: [PATCH] Remove direct dependency from rekall to online-script.js --- capsule-prototype/js/online-rekall/Rekall.js | 43 +++++++++++++------- capsule-prototype/js/online-script.js | 7 ++++ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/capsule-prototype/js/online-rekall/Rekall.js b/capsule-prototype/js/online-rekall/Rekall.js index 67d7376..971ed99 100644 --- a/capsule-prototype/js/online-rekall/Rekall.js +++ b/capsule-prototype/js/online-rekall/Rekall.js @@ -70,6 +70,10 @@ Rekall.prototype.allowProjectDeletion = function () { this.Settings._allowProjectDeletion = arguments[0]; } +Rekall.prototype.publish = function (eventName, data){ + return window.app.rekall.Rekall('pubSub').publish(eventName, data); +} + Rekall.prototype.loadXMLFile = function () { var oldURL = window.document.location + ""; var index = 0; @@ -92,16 +96,19 @@ Rekall.prototype.loadXMLFile = function () { this.baseUrl = url; let that = this; - rouletteStart(); + this.publish('roulette.started'); $.ajax("php/file.php?r=project.xml", { type: "GET", cache: false, - data: {"rand": random()}, + data: {"rand": Math.random()}, dataType: "xml", success: function (xml) { - if ((xml == null) || (xml == undefined)) - openAlert("Your project is unreachable. Did you move the folder to an other location?", 60); - else { + if ((xml == null) || (xml == undefined)) { + that.publish('alert', { + message: "Your project is unreachable. Did you move the folder to an other location?", + buttons: 60 + }); + } else { $(xml).find('project').each(function () { //if($(this).find('document').length == 0) { // openAlert("Start by adding files to your project.", 60); @@ -112,21 +119,27 @@ Rekall.prototype.loadXMLFile = function () { //} }); } - rouletteEnd(); + that.publish('roulette.terminated', {}); }, error: function () { $.ajax("file/project.xml", { type: "GET", cache: false, - data: {"rand": random()}, + data: {"rand": Math.random()}, dataType: "xml", success: function (xml) { - if ((xml == null) || (xml == undefined)) - openAlert("Your project is unreachable. Did you move the folder to an other location?", 60); - else { + if ((xml == null) || (xml == undefined)) { + that.publish('alert', { + message: "Your project is unreachable. Did you move the folder to an other location?", + buttons: 60 + }); + } else { $(xml).find('project').each(function () { if ($(this).find('document').length == 0) { - openAlert("Start by adding files to your project.", 60); + that.publish('alert', { + message: "Start by adding files to your project.", + buttons: 60 + }); } else { if (that.project == undefined) that.project = new Project(url, that); @@ -134,13 +147,13 @@ Rekall.prototype.loadXMLFile = function () { } }); } - rouletteEnd(); + that.publish('roulette.terminated', {}); }, error: function () { - rouletteEnd(); + that.publish('roulette.terminated', {}); } }); - rouletteEnd(); + that.publish('roulette.terminated'); } }); } @@ -236,4 +249,4 @@ Rekall.prototype.ensureVideoPlayerCreated = function (url, tech) { }); return true; -} \ No newline at end of file +} diff --git a/capsule-prototype/js/online-script.js b/capsule-prototype/js/online-script.js index 3a29877..ddda241 100644 --- a/capsule-prototype/js/online-script.js +++ b/capsule-prototype/js/online-script.js @@ -12,6 +12,9 @@ window.onload = function() { pubSub.subscribe('open_paste_modal', openPasteModal); pubSub.subscribe('close_paste_modal', closePasteModal); pubSub.subscribe('updated.project.name', onUpdatedProjectName); + pubSub.subscribe('alert', openAlertWrapper); + pubSub.subscribe('roulette.terminated', rouletteEnd); + pubSub.subscribe('roulette.started', rouletteStart); }; $(document).ready(function() { @@ -655,6 +658,10 @@ function openAlert(message, buttons) { } } +function openAlertWrapper(message, data){ + openAlert(data.message, data.buttons); +} + function closeAlert() { $("#popupAlertMessage").html(""); $(".popupAlertButton").hide(); -- GitLab