From 44b7cf3f8f5a24d0991391558ecb1ff1ebadb10b Mon Sep 17 00:00:00 2001 From: Helena Jank <jank@uni-potsdam.de> Date: Thu, 19 Nov 2015 18:24:21 +0100 Subject: [PATCH] + added connectionModel script tag to HTML # replaced unit DOM element IDs "stateX" with UUIDs # further merged, simplified, and corrected code (matching new data models) --- index.html | 1 + .../controllers/authorSystemController.js | 6 +- js/authoring/controllers/canvasController.js | 6 +- js/authoring/controllers/menuController.js | 54 +++--- .../deleteUnitModalWindowController.js | 41 ++-- js/authoring/controllers/navBarController.js | 32 +-- .../controllers/tabs/generalTabController.js | 17 +- .../tabs/propertiesTabController.js | 2 +- js/authoring/controllers/unitController.js | 183 ++++++++---------- .../models/authorSystemContentModel.js | 4 +- js/authoring/models/contextInfoModel.js | 14 +- js/authoring/models/scenarioModel.js | 28 +-- 12 files changed, 176 insertions(+), 212 deletions(-) diff --git a/index.html b/index.html index 0367209..5a094f8 100644 --- a/index.html +++ b/index.html @@ -35,6 +35,7 @@ <script type="text/javascript" src="js/authoring/models/contextInfoListModel.js"></script> <script type="text/javascript" src="js/authoring/models/scenarioModel.js"></script> <script type="text/javascript" src="js/authoring/models/unitModel.js"></script> + <script type="text/javascript" src="js/authoring/models/connectionModel.js"></script> <!-- controllers --> <script type="text/javascript" src="js/authoring/controllers/authorSystemController.js"></script> diff --git a/js/authoring/controllers/authorSystemController.js b/js/authoring/controllers/authorSystemController.js index 887a92a..94e06b2 100644 --- a/js/authoring/controllers/authorSystemController.js +++ b/js/authoring/controllers/authorSystemController.js @@ -131,10 +131,12 @@ function loadScenario(data) { jsPlumb.setContainer($("#stm")); // load units from scenario - for (var j=0; j<data["units"].length; j++) { - var unit = loadUnit(data["units"][j], (j+1).toString()); + var unitsList = data.getUnits(); + for (var j in unitsList) { + var unit = loadUnit(unitsList[j], (j+1).toString()); // set event listeners + // TODO: activateFunctionalities expects a DOM element as parameter! activateFunctionalities(unit); } diff --git a/js/authoring/controllers/canvasController.js b/js/authoring/controllers/canvasController.js index 44f8b60..eba2ef6 100644 --- a/js/authoring/controllers/canvasController.js +++ b/js/authoring/controllers/canvasController.js @@ -292,11 +292,11 @@ function deleteSelectedUnitsFromDOM() { for (var i=0; i<list_deleteableUnits.length; i++) { // get unit id var unitID = list_deleteableUnits[i].id; - + var uuidSelector = "[uuid="+unitID+"]"; // delete all connections - inst.detachAllConnections($("#" + unitID)); + inst.detachAllConnections($(uuidSelector)); // delete unit in canvas - $("#" + unitID).remove(); + $(uuidSelector).remove(); } } \ No newline at end of file diff --git a/js/authoring/controllers/menuController.js b/js/authoring/controllers/menuController.js index 8b5fc37..c481765 100644 --- a/js/authoring/controllers/menuController.js +++ b/js/authoring/controllers/menuController.js @@ -1,6 +1,6 @@ $(function() { - $('#cssmenu li.has-sub>a').on('click', function(){ + $('#cssmenu li.has-sub>a').on('click', function(){ $(this).removeAttr('href'); var element = $(this).parent('li'); if (element.hasClass('open')) { @@ -42,24 +42,24 @@ $(function() { })(); function rgbToHsl(r, g, b) { - r /= 255, g /= 255, b /= 255; - var max = Math.max(r, g, b), min = Math.min(r, g, b); - var h, s, l = (max + min) / 2; - - if(max == min){ - h = s = 0; - } - else { - var d = max - min; - s = l > 0.5 ? d / (2 - max - min) : d / (max + min); - switch(max){ - case r: h = (g - b) / d + (g < b ? 6 : 0); break; - case g: h = (b - r) / d + 2; break; - case b: h = (r - g) / d + 4; break; - } - h /= 6; - } - return l; + r /= 255, g /= 255, b /= 255; + var max = Math.max(r, g, b), min = Math.min(r, g, b); + var h, s, l = (max + min) / 2; + + if(max == min){ + h = s = 0; + } + else { + var d = max - min; + s = l > 0.5 ? d / (2 - max - min) : d / (max + min); + switch(max){ + case r: h = (g - b) / d + (g < b ? 6 : 0); break; + case g: h = (b - r) / d + 2; break; + case b: h = (r - g) / d + 4; break; + } + h /= 6; + } + return l; } }); @@ -151,15 +151,25 @@ function addUnitToMenu(nameCurrentScenario) { function removeUnitFromMenu(scenarioName, unitName) { // needed to find scenario in menu bar var liCurrentScenario; - $("#menuScenarios").children("li").children("a").children("span.title").each(function() { - if ( $(this)[0].innerHTML == scenarioName ) { + $("#menuScenarios").children("li").children("a").children("span.title").each(function () { + if ($(this)[0].innerHTML == scenarioName) { liCurrentScenario = $(this).parent("a").parent("li"); } }); // delete unit in menu bar - liCurrentScenario.children("ul").children("li").each(function() { + liCurrentScenario.children("ul").children("li").each(function () { if ($(this).children("a").children("span")[0].innerHTML == unitName) { $(this).remove(); } }); + + // delete holder in scenario in menu bar + if (liCurrentScenario.children("ul").children("li").length == 0 && + liCurrentScenario.hasClass("has-sub")) { + liCurrentScenario.removeClass("has-sub"); + liCurrentScenario.children("a").children("span.holder").remove(); + liCurrentScenario.children("ul").remove(); + + liCurrentScenario.addClass("last"); + } } \ No newline at end of file diff --git a/js/authoring/controllers/modalWindows/deleteUnitModalWindowController.js b/js/authoring/controllers/modalWindows/deleteUnitModalWindowController.js index 2da444a..689f22e 100644 --- a/js/authoring/controllers/modalWindows/deleteUnitModalWindowController.js +++ b/js/authoring/controllers/modalWindows/deleteUnitModalWindowController.js @@ -17,7 +17,7 @@ $(function() { // for button: delete unit = NO $("btnDeleteUnitsNot").on("click", deleteUnitsNot); - // set the trigger for the delete scenarios modal window + // set the trigger for the delete units modal window $("#deleteLearnUnit").on("click", showDeleteUnits); // set the trigger for opening a new modal window to confirm the unit deletion @@ -30,13 +30,13 @@ $(function() { * Sets event listeners to the selection and multi selection bar. * */ function showDeleteUnits() { - var selectScenarioDeleteUnitElement = $("#selectScenarioDeleteUnit"); + var selectMultiDeleteUnitsElement = $("#selectMultiDeleteUnits"); showModalWindow($("#modal-delete-units")); // set deletion button label var list_units = []; - $("#btnDeleteUnits").text("L�schen (" + list_units.length.toString() + ")"); + $("#btnDeleteUnits").text("Löschen (" + list_units.length.toString() + ")"); // delete scenarios and put them and new scenarios in selection bar again $("#selectScenarioDeleteUnit").empty(); @@ -48,14 +48,14 @@ function showDeleteUnits() { } // clean multi selection bar and fill it again - selectScenarioDeleteUnitElement.empty(); - selectScenarioDeleteUnitElement.select2("data", null); + selectMultiDeleteUnitsElement.empty(); + selectMultiDeleteUnitsElement.select2("data", null); // triggered if an scenario was selected $("#selectScenarioDeleteUnit").on("select2-selecting", function(e) { // clean multi selection bar - selectScenarioDeleteUnitElement.empty(); + selectMultiDeleteUnitsElement.empty(); list_units = []; $("#btnDeleteUnits").text("Löschen (" + 0 + ")"); @@ -68,11 +68,9 @@ function showDeleteUnits() { option.attr('value', units[i].getUUID()); // set option name and append in multi selection bar option.html(units[i].getName()); - selectScenarioDeleteUnitElement.append(option); + selectMultiDeleteUnitsElement.append(option); } -// TODO: Unit deletion currently depends on units' names fetched from select in modal window (see below). -// TODO: This must be changed toward using UUIDs. /* for (var j=0; j<myAuthorSystem.length; j++) { // find right scenario if (myAuthorSystem[j]["name"] == e.choice.text) { @@ -98,7 +96,7 @@ function showDeleteUnits() { } */ // select unit which should be deleted - selectScenarioDeleteUnitElement.select2().on("select2-selecting", function(e) { + selectMultiDeleteUnitsElement.select2().on("select2-selecting", function(e) { // test if unit is already in the list var isContained = false; @@ -113,19 +111,19 @@ function showDeleteUnits() { } // set label - $("#btnDeleteUnits").text("L�schen (" + list_units.length.toString() + ")"); + $("#btnDeleteUnits").text("Löschen (" + list_units.length.toString() + ")"); }); // triggered if a unit was deleted - selectScenarioDeleteUnitElement.select2().on("select2-removed", function(e) { + selectMultiDeleteUnitsElement.select2().on("select2-removed", function(e) { // remove unit from list for (var j=0; j<list_units.length; j++) { - if (list_units[j].text == e.choice.text) { + if (list_units[j].id == e.val) { list_units.splice(j, 1); } } // set label - $("#btnDeleteUnits").text("L�schen (" + list_units.length.toString() + ")"); + $("#btnDeleteUnits").text("Löschen (" + list_units.length.toString() + ")"); }); }); } @@ -148,7 +146,7 @@ function showDeleteUnitsConfirm() { */ function deleteUnits(){ // get units which should be deleted - var list_deleteableUnits = $("#selectMultiDeleteUnits").select2("data"); + var list_deletableUnits = $("#selectMultiDeleteUnits").select2("data"); // get right scenario name var currentScenario = $("#selectScenarioDeleteUnit").select2("data")["text"]; @@ -163,8 +161,8 @@ function deleteUnits(){ // update gui and JSON structure var selectedScenario = authorSystemContent.getScenario(currentScenario); - for (var i in list_deleteableUnits) { - var unitName = list_deleteableUnits[i].text; + for (var i in list_deletableUnits) { + var unitName = list_deletableUnits[i].text; var deletableUnit = selectedScenario.getUnitByName(unitName); selectedScenario.removeUnit(deletableUnit); removeUnitFromMenu(currentScenario, unitName); @@ -200,15 +198,6 @@ function deleteUnits(){ } } }*/ - // delete holder in scenario in menu bar - /*if (liCurrentScenario.children("ul").children("li").length == 0 && - liCurrentScenario.hasClass("has-sub")) { - liCurrentScenario.removeClass("has-sub"); - liCurrentScenario.children("a").children("span.holder").remove(); - liCurrentScenario.children("ul").remove(); - - liCurrentScenario.addClass("last"); - }*/ // all tab content invisible $(".tabContents").hide(); diff --git a/js/authoring/controllers/navBarController.js b/js/authoring/controllers/navBarController.js index 4aec246..f6903f1 100644 --- a/js/authoring/controllers/navBarController.js +++ b/js/authoring/controllers/navBarController.js @@ -70,27 +70,27 @@ $(function() { $(this).hide(); // create input field - var inputName = $("<input>").addClass("form-control"); + var inputNameField = $("<input>").addClass("form-control"); var scenarioName = $("#lname")[0].innerHTML; - inputName.attr("value", scenarioName); + inputNameField.attr("value", scenarioName); //$(inputName).css("height", "100%"); - $(inputName).css("height", "30"); - $(inputName).css("width", "200"); - $(inputName).css("display", "inherit"); + $(inputNameField).css("height", "30"); + $(inputNameField).css("width", "200"); + $(inputNameField).css("display", "inherit"); // place it in parent DOM and set focus on last position - $(this).parent().append(inputName); - inputName.focus(); - $(inputName)[0].setSelectionRange(scenarioName.length, scenarioName.length); + $(this).parent().append(inputNameField); + inputNameField.focus(); + $(inputNameField)[0].setSelectionRange(scenarioName.length, scenarioName.length); e.stopPropagation(); // triggered if enter was clicked in input field - $(inputName).keyup(function(e) { + $(inputNameField).keyup(function(e) { if (e.keyCode === 13) { // save name in JSON structure and in GUI - saveScenarioName(inputName, scenarioName); + saveScenarioName(inputNameField, scenarioName); } }); @@ -98,10 +98,10 @@ $(function() { $("body").on("click", function() { // only save scenario name if input field is visible - if ($(inputName).css("display") != "none" && $(inputName).css("display") != "inherit") { + if ($(inputNameField).css("display") != "none" && $(inputNameField).css("display") != "inherit") { // save name in JSON structure and in GUI - saveScenarioName(inputName, scenarioName); + saveScenarioName(inputNameField, scenarioName); } }); }); @@ -114,8 +114,8 @@ $(function() { * @param inputName * @param scenarioName */ -function saveScenarioName(inputName, scenarioName) { - var newName = $(inputName).val(); +function saveScenarioName(inputNameField, scenarioName) { + var newName = $(inputNameField).val(); // get new name in label $("#lname").html(newName); @@ -124,11 +124,11 @@ function saveScenarioName(inputName, scenarioName) { $("#lname").show(); // remove input field - $(inputName).remove(); + $(inputNameField).remove(); // change name in menu bar changeScenarioNameInMenu(scenarioName, newName); // update name JSON structure - changeScenarioName(scenarioName, newName); + authorSystemContent.getScenario(scenarioName).setName(newName); } \ No newline at end of file diff --git a/js/authoring/controllers/tabs/generalTabController.js b/js/authoring/controllers/tabs/generalTabController.js index c362bb4..51080f7 100644 --- a/js/authoring/controllers/tabs/generalTabController.js +++ b/js/authoring/controllers/tabs/generalTabController.js @@ -85,7 +85,7 @@ function activateFunctionalities(newState) { current_unit = getCurrentUnitDataModel(); // set description field - $("#inputUnitDescription")[0].value = current_unit["description"]; + $("#inputUnitDescription")[0].value = current_unit.getDescription(); /* tab "Kontextinformation" */ loadContextTabForUnit(unit); @@ -122,7 +122,7 @@ function activateFunctionalities(newState) { unitSatisfiesAllContextInfos = false; // change sat information in current unit - current_unit["sat"] = "one"; + current_unit.setSat("one"); } // decides that all of the group of selected context information has to be satisfied (0 == "Alle") if (e.val == 0) { @@ -142,7 +142,7 @@ function activateFunctionalities(newState) { unitSatisfiesAllContextInfos = true; // change sat information in current unit - current_unit["sat"] = "all"; + current_unit.setSat("all"); } }); @@ -172,7 +172,7 @@ function activateFunctionalities(newState) { } // update JSON structure - current_unit["name"] = global_currentInputUnitName; + current_unit.setName(global_currentInputUnitName); // necessary to redraw endpoints inst.repaintEverything(); @@ -182,7 +182,7 @@ function activateFunctionalities(newState) { // triggered if string is changed in description field in tab "Eigenschaften" $("#inputUnitDescription").bind("input", function() { // update JSON structure with current input field value - current_unit["description"] = $(this).val(); + current_unit.setDescription($(this).val()); }); // triggered if an operator was selected in tab "Kontextinformation" @@ -236,9 +236,10 @@ function activateFunctionalities(newState) { } // update JSON structure - for (var i=0; i<current_unit["contextInformations"].length; i++) { - if (current_unit["contextInformations"][i].name == e.choice.text) { - current_unit["contextInformations"].splice(i, 1); + var currentUnitContextList = current_unit.getContextData(); + for (var i in currentUnitContextList) { + if (currentUnitContextList[i].name == e.choice.text) { + currentUnitContextList.splice(i, 1); break; } } diff --git a/js/authoring/controllers/tabs/propertiesTabController.js b/js/authoring/controllers/tabs/propertiesTabController.js index 06116be..b58a78d 100644 --- a/js/authoring/controllers/tabs/propertiesTabController.js +++ b/js/authoring/controllers/tabs/propertiesTabController.js @@ -24,5 +24,5 @@ function showDeleteUnitConfirm() { // get unit name and show the unit specific text var unitName = $("#inputUnitName")[0].value; - $("#tabTextUnitDeletion").html('Wollen Sie die Lerneinheit "' + unitName + '" wirklich l�schen?'); + $("#tabTextUnitDeletion").html('Wollen Sie die Lerneinheit "' + unitName + '" wirklich löschen?'); } \ No newline at end of file diff --git a/js/authoring/controllers/unitController.js b/js/authoring/controllers/unitController.js index b72b28e..3483e83 100644 --- a/js/authoring/controllers/unitController.js +++ b/js/authoring/controllers/unitController.js @@ -3,52 +3,14 @@ */ -var counter_multiSelectionMetaData = 0; - function createUnit() { /* if loaded sceanrio */ - // get last id number - var max = 0; - $("#stm").children("div.w").each(function() { - var id = parseInt($(this)[0].getAttribute("id").slice(-1)); - if (id > max) { - max = id; - } - }); - // prevent that two unit have the same id - max = max + 1; - // generate a UUID for this new unit. This will also serve as its A-box identifier. - // TODO: Maybe replace "state"+max by uuid... var uuid = uuid4(); - - // build unit DOM - var newState = $('<div>') - .attr('id', 'state' + max) - .attr("uuid", uuid) - .addClass('w'); - var title = $('<div>').addClass('title').css("padding", "0px 7px"); - var stateName = $('<input>').attr('type', 'text').css("color", "#34495e"); - title.append(stateName); - - // add div for context information icons - var divContextIcons = $("<div>").addClass("unit-icons"); - - // create connection point - var ep = $('<div>').addClass('ep'); - - window.jsp = inst; - var windows = jsPlumb.getSelector("#stm .w"); - - // add elements to unit DOM - newState.append(divContextIcons); - newState.append(title); - newState.append(ep); - - // add unit DOM to state machine - $('#stm').append(newState); + // get new unit DOM + var newState = buildUnitDOM(uuid, stateName); var nameSet = false; @@ -74,8 +36,12 @@ function createUnit() { // add learning unit in menu bar addUnitToMenu(nameCurrentScenario); + // update JSON structure: get new unit in its scenario - addUnitToScenarioModel(nameCurrentScenario, uuid); + var newUnit = new Unit(); + newUnit.setUUID(uuid); + newUnit.setName(global_currentInputUnitName); + authorSystemContent.getScenario(nameCurrentScenario).addUnit(newUnit); // hide tabs because all units will be unmarked $(".tabContents").hide(); @@ -85,7 +51,7 @@ function createUnit() { // to set the source and target points, it is necessary to wait until the name was entered // --> prevent the wrong placement of the dots if (nameSet) { - plumbUnit(newState, ep); + plumbUnit(newState); nameSet = false; } }); @@ -98,42 +64,26 @@ function createUnit() { * Hint: The website will be new loaded. * @param {Object} unit Contains all information about the unit * @param {String} j Contains the running ID number - * @return {Object} Contains the unit DOM element * */ function loadUnit(unit, j) { - window.jsp = inst; - - // build unit DOM - var newState = $('<div>').attr('id', 'state' + j).addClass('w'); - var title = $('<div>').addClass('title').css("padding", "0px 7px"); - title.html(unit.name); - var ep = $('<div>').addClass('ep'); - - // add div for context information icons - var divContextIcons = $("<div>").addClass("unit-icons"); - - // add elements to unit DOM - newState.append(divContextIcons); - newState.append(title); - newState.append(ep); - - // add unit to state machine - $('#stm').append(newState); + var newState = buildUnitDOM(unit.getUID(), unit.getName()); + var divContextIcons = newState.children(".unit-icons")[0]; // get all context information - for (var k= 0; k<unit["contextInformations"].length; k++) { + var unitContextInfoList = unit.getContextData(); + for (var k in unitContextInfoList) { var divContextIcon = $("<div>") .addClass("unit-icon") - .attr("id", unit["contextInformations"][k]["name"] + k + "icon"); - var icon = unit["contextInformations"][k]["icon"]; + .attr("id", unitContextInfoList[k]["name"] + k + "icon"); + var icon = unitContextInfoList[k]["icon"]; // add icon und div to unit divContextIcon.append(icon); divContextIcons.append(divContextIcon); // get state of satisfiability - if (unit["sat"] == "all") { + if (unit.getSat() == "all") { divContextIcons.css("border", "2px solid #adadad"); divContextIcons.attr("ci", "all"); } else { @@ -149,11 +99,14 @@ function loadUnit(unit, j) { } // get all meta data - for (var l= 0; l<unit["metaData"].length; l++) { - var divMetaIcon = $("<div>").addClass("unit-meta-icons").attr("id", unit["name"] + l + "metaIcon"); + var unitMetaData = unit.getMetaData(); + for (var l in unitMetaData) { + var divMetaIcon = $("<div>") + .addClass("unit-meta-icons") + .attr("id", unit.getName() + l + "metaIcon"); - var metaIcon = chooseMetaIcon(unit["metaData"][l]["name"]); - divMetaIcon.attr("title", unit["metaData"][l]["name"]); + var metaIcon = chooseMetaIcon(unitMetaData[l]["name"]); + divMetaIcon.attr("title", unitMetaData[l]["name"]); // add meta icon to unit DOM var bMetaIcon = $("<b>").addClass(metaIcon); @@ -165,17 +118,19 @@ function loadUnit(unit, j) { } // place unit in state machine - $(newState).css("top", unit.posY + "px"); - $(newState).css("left", unit.posX + "px"); + $(newState).css("top", unit.getPosY() + "px"); + $(newState).css("left", unit.getPosX() + "px"); - plumbUnit(newState, ep); + plumbUnit(newState); return newState; } // set properties for newly created unit in jsPlumb instance -function plumbUnit(newState, ep) { +function plumbUnit(newState) { + var ep = newState.children(".ep")[0]; + // make the unit draggable inst.draggable(newState, { //containment: 'parent' @@ -229,8 +184,17 @@ function chooseMetaIcon(metaDataName) { * */ function addMetaDataToUnit(metaDatum, unit) { + // update JSON structure + var current_unit = getCurrentUnitDataModel(); + current_unit.addMetaInfo({ + name : metaDatum, + icon : metaIcon + }); + // create meta data DOM - var divMetaIcon = $("<div>").addClass("unit-meta-icons").attr("id", counter_multiSelectionMetaData + "metaIcon"); + var divMetaIcon = $("<div>") + .addClass("unit-meta-icons") + .attr("id", current_unit.getName() + current_unit.getMetaData().length + "metaIcon"); // choose icon symbol and add it to meta data DOM var metaIcon = chooseMetaIcon(metaDatum); @@ -246,14 +210,6 @@ function addMetaDataToUnit(metaDatum, unit) { // change size of learning unit $(unit).css("padding-bottom", "5px"); - counter_multiSelectionMetaData++; - - // update JSON structure - var current_unit = getCurrentUnitDataModel(); - current_unit["metaData"].push({ - name : metaDatum, - icon : metaIcon - }); // set endpoints on the right place inst.repaintEverything(); @@ -266,30 +222,27 @@ function addMetaDataToUnit(metaDatum, unit) { * */ function removeMetaDataFromUnit(metaDatum, unit) { - // find the right meta icon - $(unit).find("div.unit-meta-icons").each(function() { - - // get icon title name - var icon = $(this)[0].title; + // update JSON structure + var current_unit = getCurrentUnitDataModel(); + var currentUnitMetaData = current_unit.getMetaData(); + for (var j in currentUnitMetaData) { + if (currentUnitMetaData[j].name == metaDatum) { + currentUnitMetaData.splice(j, 1); + } + } + // find the right meta icon + var metaDataIcons = $(unit).find("div.unit-meta-icons"); + metaDataIcons.each(function() { // remove the right icon from unit - if (icon == metaDatum) { + if ($(this)[0].title == metaDatum) { this.remove(); - - // if no more meta icons in unit go back to old unit design - if (counter_multiSelectionMetaData == 0) { - $(unit).css("padding-bottom", ""); - } + return false; } }); - var current_unit = getCurrentUnitDataModel(); - // update JSON structure - for (var j=0; j<current_unit["metaData"].length; j++) { - if (current_unit["metaData"][j].name == metaDatum) { - current_unit["metaData"].splice(j, 1); - } - } + if (metaDataIcons.length == 0) + $(unit).css("padding-bottom", ""); // set endpoints on the right place inst.repaintEverything(); @@ -319,4 +272,34 @@ function getCurrentUnitDataModel() { } } }*/ +} + + +// build unit DOM +function buildUnitDOM(uuid, name) { + + var newState = $('<div>') + .attr("id", uuid) + .addClass('w'); + + var title = $('<div>').addClass('title').css("padding", "0px 7px"); + title.append(name); + + // add div for context information icons + var divContextIcons = $("<div>").addClass("unit-icons"); + // create connection point + var ep = $('<div>').addClass('ep'); + + window.jsp = inst; + //var windows = jsPlumb.getSelector("#stm .w"); + + // add elements to unit DOM + newState.append(divContextIcons); + newState.append(title); + newState.append(ep); + + // add unit DOM to state machine + $('#stm').append(newState); + + return newState; } \ No newline at end of file diff --git a/js/authoring/models/authorSystemContentModel.js b/js/authoring/models/authorSystemContentModel.js index 979c7a9..d28a683 100644 --- a/js/authoring/models/authorSystemContentModel.js +++ b/js/authoring/models/authorSystemContentModel.js @@ -39,7 +39,7 @@ AuthorSystemContent.prototype.getScenarios = function() { AuthorSystemContent.prototype.getScenario = function(scenarioName) { for (var i in this._scenarioList) { var scenario = this._scenarioList[i]; - if (scenario.name == scenarioName) + if (scenario.getName() == scenarioName) return scenario; } }; @@ -51,7 +51,7 @@ AuthorSystemContent.prototype.addScenario = function (scenario) { AuthorSystemContent.prototype.removeScenario = function(scenarioName) { for (var i in this._scenarioList) { var scenario = this._scenarioList[i]; - if (scenario.name == scenarioName) + if (scenario.getName() == scenarioName) this._scenarioList.splice(i, 1); } }; \ No newline at end of file diff --git a/js/authoring/models/contextInfoModel.js b/js/authoring/models/contextInfoModel.js index b21493a..fb03d80 100644 --- a/js/authoring/models/contextInfoModel.js +++ b/js/authoring/models/contextInfoModel.js @@ -7,9 +7,9 @@ // the list of all available context information data types function ContextInformation() { - this.name = ""; - this.classes = []; - this.value = { + this._name = ""; + this._classes = []; + this._value = { attributes:{ type:"", min:"", @@ -19,16 +19,16 @@ function ContextInformation() { operators:[], enums:[] }; - this.parameters = []; + this._parameters = []; return this; } function Parameter() { - this.id = ""; - this.type = ""; - this.values = []; + this._id = ""; + this._type = ""; + this._values = []; return this; } \ No newline at end of file diff --git a/js/authoring/models/scenarioModel.js b/js/authoring/models/scenarioModel.js index 0b6f6ad..4ee233f 100644 --- a/js/authoring/models/scenarioModel.js +++ b/js/authoring/models/scenarioModel.js @@ -24,7 +24,7 @@ Scenario.prototype.getUnits = function() { Scenario.prototype.getUnitByName = function(unitName) { for (var i in this._units) { var unit = this._units[i]; - if (unit.name == unitName) + if (unit.getName() == unitName) return unit; } }; @@ -32,7 +32,7 @@ Scenario.prototype.getUnitByName = function(unitName) { Scenario.prototype.getUnitByUUID = function(uuid) { for (var i in this._units) { var unit = this._units[i]; - if (unit.uuid == uuid) + if (unit.getUUID() == uuid) return unit; } }; @@ -67,26 +67,4 @@ Scenario.prototype.removeConnection = function(conn) { var index = this._connections.indexOf(conn); if (index > -1) this._connections.splice(index, 1); -}; - - -// TODO: Incorporate the following two functions into scenario model. - -function changeScenarioName(oldName, newName) { - authorSystemContent.getScenario(oldName).setName(newName); -} - -// TODO: Use unit model for this. -function addUnitToScenarioModel(scenarioName, uuid) { - authorSystemContent.getScenario(scenarioName).addUnit({ - uuid: uuid, // a (hopefully truly) unique id for this unit - name:global_currentInputUnitName, // displayed name - description:"", // description of the unit - sat:"all", // how much context information have to be satisfied - contextInformations:[], // list of containing context information - metaData:[], // list of containing meta data - //connections:[], // list of connections with other units - posX:0, // absolute X position in the displayed container - posY:0 // absolute Y position in the displayed container - }); -} \ No newline at end of file +}; \ No newline at end of file -- GitLab