From 1cb758c32b6cdc9b0f505a0f84a68c00b4886f20 Mon Sep 17 00:00:00 2001
From: Helena Jank <jank@uni-potsdam.de>
Date: Tue, 12 Jan 2016 14:07:43 +0100
Subject: [PATCH] ! fixed check for unselected operator and error on return
 from checkInformation() in confirmContextInformation() + call
 replaceScenarioReferencesWithNames() before every console log

---
 js/authoring/controllers/contextInfoController.js     | 2 +-
 js/authoring/controllers/saveScenarioController.js    | 2 +-
 js/authoring/controllers/tabs/contextTabController.js | 4 ++++
 js/authoring/controllers/unitController.js            | 3 ++-
 4 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/js/authoring/controllers/contextInfoController.js b/js/authoring/controllers/contextInfoController.js
index eb6d2b6..096bc7d 100644
--- a/js/authoring/controllers/contextInfoController.js
+++ b/js/authoring/controllers/contextInfoController.js
@@ -37,7 +37,7 @@ function checkInformation() {
          }*/
 
         // check selection bar "Operator"
-        if ( selectedOperator == null ) {
+        if ( selectedOperator == null || selectedOperator.id == "\r") {
             // if selection bar operator is empty, concatenate it in missing_content string
             missing_content += " - Operator\n";
         } else {
diff --git a/js/authoring/controllers/saveScenarioController.js b/js/authoring/controllers/saveScenarioController.js
index 4403abe..38c41e2 100644
--- a/js/authoring/controllers/saveScenarioController.js
+++ b/js/authoring/controllers/saveScenarioController.js
@@ -27,7 +27,7 @@ function showSaveScenario() {
     replaceScenarioReferencesWithNames();
 
     // find current scenario in all scenarios
-    var json = authorSystemContent.getScenario(currentScenario);
+    var json = JSON.stringify(authorSystemContent.getScenario(currentScenario));
     //var jsonLD = JSON.stringify(json ? json.getABoxJSONLD() : {});
 
     // set blob with JSON data
diff --git a/js/authoring/controllers/tabs/contextTabController.js b/js/authoring/controllers/tabs/contextTabController.js
index eb634f0..328496a 100644
--- a/js/authoring/controllers/tabs/contextTabController.js
+++ b/js/authoring/controllers/tabs/contextTabController.js
@@ -599,6 +599,8 @@ function confirmContextInformation() {
 
     // check if all needed fields were filled with information and return selected context
     var selectedInfo = checkInformation();
+    // abort if error occurred
+    if (!selectedInfo) return false;
 
     // add the new information to the context list of the currently selected unit
     current_unit.addContextInfo(selectedInfo, unitContextIndex);
@@ -673,6 +675,8 @@ function confirmContextInformation() {
     // show main, hide detail
     showMainContextInfo();
 
+    // workaround to avoid error message due to circular structure
+    replaceScenarioReferencesWithNames();
     console.log(JSON.stringify(authorSystemContent));
 }
 
diff --git a/js/authoring/controllers/unitController.js b/js/authoring/controllers/unitController.js
index f062e4f..8731831 100644
--- a/js/authoring/controllers/unitController.js
+++ b/js/authoring/controllers/unitController.js
@@ -188,7 +188,8 @@ function initUnitClickEventHandler () {
         // prevents that underlying container is also clicked (needed for unit marking)
         event.stopPropagation();
 
-        //console.log(myAuthorSystem);
+        // workaround to avoid error message due to circular structure
+        replaceScenarioReferencesWithNames();
         console.log(JSON.stringify(authorSystemContent));
     });
 }
-- 
GitLab