From ab5298f302482c0c9c8d06ed9c33f7f4c431bf86 Mon Sep 17 00:00:00 2001 From: Shamal Faily Date: Mon, 4 Dec 2017 19:20:36 -0800 Subject: [PATCH] Fix #159 --- cairis/core/MySQLDatabaseProxy.py | 2 +- cairis/sql/procs.sql | 12 +- cairis/web/dist/js/cairis/goals.js | 312 ++++++++++-------- cairis/web/dist/js/cairis/obstacles.js | 55 +-- .../web/fastTemplates/editGoalsOptions.html | 281 +++++++++------- 5 files changed, 371 insertions(+), 291 deletions(-) diff --git a/cairis/core/MySQLDatabaseProxy.py b/cairis/core/MySQLDatabaseProxy.py index ceaa20b79..51e4b4929 100644 --- a/cairis/core/MySQLDatabaseProxy.py +++ b/cairis/core/MySQLDatabaseProxy.py @@ -1990,7 +1990,7 @@ def addGoalConcernAssociations(self,goalId,environmentName,associations): self.addGoalConcernAssociation(goalId,environmentName,source,sourceMultiplicity,link,target,targetMultiplicity) def addGoalConcernAssociation(self,goalId,environmentName,source,sourceMultiplicity,link,target,targetMultiplicity): - self.updateDatabase('call addGoalConcernAssociation(:gId,:env,:src,:sMulti,:link,:trgt,:tMulti)',{'gId':goalId,'env':environmentName,'src':source,'sMulti':sourceMultiplicity,'linl':link,'trgt':target,'tMulti':targetMultiplicity},'MySQL error adding goal concern association') + self.updateDatabase('call addGoalConcernAssociation(:gId,:env,:src,:sMulti,:link,:trgt,:tMulti)',{'gId':goalId,'env':environmentName,'src':source,'sMulti':sourceMultiplicity,'link':link,'trgt':target,'tMulti':targetMultiplicity},'MySQL error adding goal concern association') def addTaskConcernAssociations(self,taskId,environmentName,associations): for source,sourceMultiplicity,link,target,targetMultiplicity in associations: diff --git a/cairis/sql/procs.sql b/cairis/sql/procs.sql index 29dd47742..1d8a6f75c 100755 --- a/cairis/sql/procs.sql +++ b/cairis/sql/procs.sql @@ -8888,7 +8888,7 @@ create procedure goalRefinements(in goalId int, in environmentId int) begin select ga.id id,e.name environment,hg.name goal_name,'goal' goal_dim,rt.name ref_type,tg.name subgoal_name,'goal' subgoal_dim,ga.alternative_id alternative_id,ga.rationale from goalgoal_goalassociation ga, environment e, goal hg, reference_type rt, goal tg where ga.environment_id = environmentId and ga.goal_id = hg.id and ga.ref_type_id = rt.id and ga.subgoal_id = goalId and ga.subgoal_id = tg.id and ga.environment_id = e.id union - select ga.id id,e.name environment,hg.name goal_name,'goal' goal_dim,rt.name ref_type,concat(a.short_code,'-',tg.label) subgoal_name,'requirement' subgoal_dim,ga.alternative_id alternative_id,ga.rationale from goalrequirement_goalassociation ga, environment e, goal hg, reference_type rt, requirement tg, asset_requirement ar, asset a where ga.environment_id = environmentId and ga.goal_id = hg.id and ga.ref_type_id = rt.id and ga.subgoal_id = goalId and ga.subgoal_id = tg.id and tg.version = (select max(i.version) from requirement i where i.id = tg.id) and ga.environment_id = e.id and tg.id = ar.requirement_id and ar.asset_id = a.id + select ga.id id,e.name environment,hg.name goal_name,'goal' goal_dim,rt.name ref_type,tg.name subgoal_name,'requirement' subgoal_dim,ga.alternative_id alternative_id,ga.rationale from goalrequirement_goalassociation ga, environment e, goal hg, reference_type rt, requirement tg, asset_requirement ar, asset a where ga.environment_id = environmentId and ga.goal_id = hg.id and ga.ref_type_id = rt.id and ga.subgoal_id = goalId and ga.subgoal_id = tg.id and tg.version = (select max(i.version) from requirement i where i.id = tg.id) and ga.environment_id = e.id and tg.id = ar.requirement_id and ar.asset_id = a.id union select ga.id id,e.name environment,hg.name goal_name,'goal' goal_dim,rt.name ref_type,tg.name subgoal_name,'task' subgoal_dim,ga.alternative_id alternative_id,ga.rationale from goaltask_goalassociation ga, environment e, goal hg, reference_type rt, task tg where ga.environment_id = environmentId and ga.goal_id = hg.id and ga.ref_type_id = rt.id and ga.subgoal_id = goalId and ga.subgoal_id = tg.id and ga.environment_id = e.id union @@ -8898,7 +8898,7 @@ begin union select ga.id id,e.name environment,hg.name goal_name,'goal' goal_dim,rt.name ref_type,tg.name subgoal_name,'usecase' subgoal_dim,ga.alternative_id alternative_id,ga.rationale from goalusecase_goalassociation ga, environment e, goal hg, reference_type rt, usecase tg where ga.environment_id = environmentId and ga.goal_id = hg.id and ga.ref_type_id = rt.id and ga.subgoal_id = goalId and ga.subgoal_id = tg.id and ga.environment_id = e.id union - select ga.id id,e.name environment,hg.name goal_name,'goal' goal_dim,rt.name ref_type,concat(a.short_code,'-',tg.label) subgoal_name,'requirement' subgoal_dim,ga.alternative_id alternative_id,ga.rationale from goalrequirement_goalassociation ga, environment e, goal hg, reference_type rt, requirement tg, environment_requirement ar, environment a where ga.environment_id = environmentId and ga.goal_id = hg.id and ga.ref_type_id = rt.id and ga.subgoal_id = goalId and ga.subgoal_id = tg.id and tg.version = (select max(i.version) from requirement i where i.id = tg.id) and ga.environment_id = e.id and tg.id = ar.requirement_id and ar.environment_id = a.id + select ga.id id,e.name environment,hg.name goal_name,'goal' goal_dim,rt.name ref_type,tg.name subgoal_name,'requirement' subgoal_dim,ga.alternative_id alternative_id,ga.rationale from goalrequirement_goalassociation ga, environment e, goal hg, reference_type rt, requirement tg, environment_requirement ar, environment a where ga.environment_id = environmentId and ga.goal_id = hg.id and ga.ref_type_id = rt.id and ga.subgoal_id = goalId and ga.subgoal_id = tg.id and tg.version = (select max(i.version) from requirement i where i.id = tg.id) and ga.environment_id = e.id and tg.id = ar.requirement_id and ar.environment_id = a.id union select ga.id id,e.name environment,hg.name goal_name,'goal' goal_dim,rt.name ref_type,tg.name subgoal_name,'domainproperty' subgoal_dim,ga.alternative_id alternative_id,ga.rationale from goaldomainproperty_goalassociation ga, environment e, goal hg, reference_type rt, domainproperty tg where ga.goal_id = hg.id and ga.ref_type_id = rt.id and ga.subgoal_id = goalId and ga.subgoal_id = tg.id and ga.environment_id = e.id and ga.environment_id = environmentId union @@ -8916,9 +8916,9 @@ begin union select ga.id id,e.name environment,hg.name goal_name,'obstacle' goal_dim,rt.name ref_type,tg.name subgoal_name,'vulnerability' subgoal_dim,ga.alternative_id alternative_id,ga.rationale from obstaclevulnerability_goalassociation ga, environment e, obstacle hg, reference_type rt, vulnerability tg where ga.goal_id = hg.id and ga.ref_type_id = rt.id and ga.subgoal_id = goalId and ga.subgoal_id = tg.id and ga.environment_id = e.id and ga.environment_id = environmentId union - select ga.id id,e.name environment,concat(a.short_code,'-',hg.label) goal_name,'requirement' subgoal_dim,rt.name ref_type,tg.name subgoal_name,'obstacle' subgoal_dim,ga.alternative_id alternative_id,ga.rationale from requirementobstacle_goalassociation ga, environment e, requirement hg, reference_type rt, obstacle tg, asset_requirement ar, asset a where ga.environment_id = environmentId and ga.goal_id = hg.id and ga.ref_type_id = rt.id and ga.subgoal_id = goalId and ga.subgoal_id = tg.id and hg.version = (select max(i.version) from requirement i where i.id = hg.id) and ga.environment_id = e.id and ga.goal_id = ar.requirement_id and ar.asset_id = a.id + select ga.id id,e.name environment,hg.name goal_name,'requirement' subgoal_dim,rt.name ref_type,tg.name subgoal_name,'obstacle' subgoal_dim,ga.alternative_id alternative_id,ga.rationale from requirementobstacle_goalassociation ga, environment e, requirement hg, reference_type rt, obstacle tg, asset_requirement ar, asset a where ga.environment_id = environmentId and ga.goal_id = hg.id and ga.ref_type_id = rt.id and ga.subgoal_id = goalId and ga.subgoal_id = tg.id and hg.version = (select max(i.version) from requirement i where i.id = hg.id) and ga.environment_id = e.id and ga.goal_id = ar.requirement_id and ar.asset_id = a.id union - select ga.id id,e.name environment,concat(a.short_code,'-',hg.label) goal_name,'requirement' subgoal_dim,rt.name ref_type,tg.name subgoal_name,'obstacle' subgoal_dim,ga.alternative_id alternative_id,ga.rationale from requirementobstacle_goalassociation ga, environment e, requirement hg, reference_type rt, obstacle tg, environment_requirement ar, environment a where ga.environment_id = environmentId and ga.goal_id = hg.id and ga.ref_type_id = rt.id and ga.subgoal_id = goalId and ga.subgoal_id = tg.id and hg.version = (select max(i.version) from requirement i where i.id = hg.id) and ga.environment_id = e.id and ga.goal_id = ar.requirement_id and ar.environment_id = a.id; + select ga.id id,e.name environment,hg.name goal_name,'requirement' subgoal_dim,rt.name ref_type,tg.name subgoal_name,'obstacle' subgoal_dim,ga.alternative_id alternative_id,ga.rationale from requirementobstacle_goalassociation ga, environment e, requirement hg, reference_type rt, obstacle tg, environment_requirement ar, environment a where ga.environment_id = environmentId and ga.goal_id = hg.id and ga.ref_type_id = rt.id and ga.subgoal_id = goalId and ga.subgoal_id = tg.id and hg.version = (select max(i.version) from requirement i where i.id = hg.id) and ga.environment_id = e.id and ga.goal_id = ar.requirement_id and ar.environment_id = a.id; end // @@ -8926,7 +8926,7 @@ create procedure subGoalRefinements(in goalId int, in environmentId int) begin select ga.id id,e.name environment,hg.name goal_name,'goal' goal_dim,rt.name ref_type,tg.name subgoal_name,'goal' subgoal_dim,ga.alternative_id alternative_id,ga.rationale from goalgoal_goalassociation ga, environment e, goal hg, reference_type rt, goal tg where ga.environment_id = environmentId and ga.goal_id = goalId and ga.goal_id = hg.id and ga.ref_type_id = rt.id and ga.subgoal_id = tg.id and ga.environment_id = e.id union - select ga.id id,e.name environment,hg.name goal_name,'goal' goal_dim,rt.name ref_type,concat(a.short_code,'-',tg.label) subgoal_name,'requirement' subgoal_dim,ga.alternative_id alternative_id,ga.rationale from goalrequirement_goalassociation ga, environment e, goal hg, reference_type rt, requirement tg, asset_requirement ar, asset a where ga.environment_id = environmentId and ga.goal_id = goalId and ga.goal_id = hg.id and ga.ref_type_id = rt.id and ga.subgoal_id = tg.id and tg.version = (select max(i.version) from requirement i where i.id = tg.id) and ga.environment_id = e.id and tg.id = ar.requirement_id and ar.asset_id = a.id + select ga.id id,e.name environment,hg.name goal_name,'goal' goal_dim,rt.name ref_type,tg.name subgoal_name,'requirement' subgoal_dim,ga.alternative_id alternative_id,ga.rationale from goalrequirement_goalassociation ga, environment e, goal hg, reference_type rt, requirement tg, asset_requirement ar, asset a where ga.environment_id = environmentId and ga.goal_id = goalId and ga.goal_id = hg.id and ga.ref_type_id = rt.id and ga.subgoal_id = tg.id and tg.version = (select max(i.version) from requirement i where i.id = tg.id) and ga.environment_id = e.id and tg.id = ar.requirement_id and ar.asset_id = a.id union select ga.id id,e.name environment,hg.name goal_name,'goal' goal_dim,rt.name ref_type,tg.name subgoal_name,'task' subgoal_dim,ga.alternative_id alternative_id,ga.rationale from goaltask_goalassociation ga, environment e, goal hg, reference_type rt, task tg where ga.environment_id = environmentId and ga.goal_id = goalId and ga.goal_id = hg.id and ga.ref_type_id = rt.id and ga.subgoal_id = tg.id and ga.environment_id = e.id union @@ -8936,7 +8936,7 @@ begin union select ga.id id,e.name environment,hg.name goal_name,'goal' goal_dim,rt.name ref_type,tg.name subgoal_name,'usecase' subgoal_dim,ga.alternative_id alternative_id,ga.rationale from goalusecase_goalassociation ga, environment e, goal hg, reference_type rt, usecase tg where ga.environment_id = environmentId and ga.goal_id = goalId and ga.goal_id = hg.id and ga.ref_type_id = rt.id and ga.subgoal_id = tg.id and ga.environment_id = e.id union - select ga.id id,e.name environment,hg.name goal_name,'goal' goal_dim,rt.name ref_type,concat(a.short_code,'-',tg.label) subgoal_name,'requirement' subgoal_dim,ga.alternative_id alternative_id,ga.rationale from goalrequirement_goalassociation ga, environment e, goal hg, reference_type rt, requirement tg, environment_requirement ar, environment a where ga.environment_id = environmentId and ga.goal_id = goalId and ga.goal_id = hg.id and ga.ref_type_id = rt.id and ga.subgoal_id = tg.id and tg.version = (select max(i.version) from requirement i where i.id = tg.id) and ga.environment_id = e.id and tg.id = ar.requirement_id and ar.environment_id = a.id + select ga.id id,e.name environment,hg.name goal_name,'goal' goal_dim,rt.name ref_type,tg.name subgoal_name,'requirement' subgoal_dim,ga.alternative_id alternative_id,ga.rationale from goalrequirement_goalassociation ga, environment e, goal hg, reference_type rt, requirement tg, environment_requirement ar, environment a where ga.environment_id = environmentId and ga.goal_id = goalId and ga.goal_id = hg.id and ga.ref_type_id = rt.id and ga.subgoal_id = tg.id and tg.version = (select max(i.version) from requirement i where i.id = tg.id) and ga.environment_id = e.id and tg.id = ar.requirement_id and ar.environment_id = a.id union select ga.id id,e.name environment,hg.name goal_name,'goal' goal_dim,rt.name ref_type,tg.name subgoal_name,'domainproperty' subgoal_dim,ga.alternative_id alternative_id,ga.rationale from goaldomainproperty_goalassociation ga, environment e, goal hg, reference_type rt, domainproperty tg where ga.goal_id = goalId and ga.goal_id = hg.id and ga.ref_type_id = rt.id and ga.subgoal_id = tg.id and ga.environment_id = e.id and ga.environment_id = environmentId union diff --git a/cairis/web/dist/js/cairis/goals.js b/cairis/web/dist/js/cairis/goals.js index 85e446ebc..7a14013eb 100644 --- a/cairis/web/dist/js/cairis/goals.js +++ b/cairis/web/dist/js/cairis/goals.js @@ -148,42 +148,37 @@ mainContent.on('click', '.deleteGoalEnvConcernAssoc', function () { }); }); -mainContent.on('click', '#updateGoalConcernAss', function () { +mainContent.on('click', '#AddGoalConcernAssociationButton', function () { + + var assoc = []; + assoc[0] = $("#theSourceSelect").val(); + assoc[1] = $("#theNSelect").val(); + assoc[2] = $("#theLink").val(); + assoc[3] = $("#theTargetSelect").val(); + assoc[4] = $("#theN2Select").val(); + var goal = JSON.parse($.session.get("Goal")); var envName = $.session.get("GoalEnvName"); - var arr = []; - arr[0] = $("#theSourceSelect").val(); - arr[1] = $("#theNSelect").val(); - arr[2] = $("#theLink").val(); - arr[3] = $("#theTargetSelect").val(); - arr[4] = $("#theN2Select").val(); - - if($("#editgoalConcernAssociations").hasClass("new")){ - $.each(goal.theEnvironmentProperties, function (index, env) { - if(env.theEnvironmentName == envName){ - env.theConcernAssociations.push(arr); + $.each(goal.theEnvironmentProperties, function (index, env) { + if(env.theEnvironmentName == envName){ + var selectedIdx = $('#goalConcernAssociationsDialog').attr('data-selectedIndex'); + if (selectedIdx != undefined) { + env.theConcernAssociations[selectedIdx] = assoc; + $.session.set("Goal", JSON.stringify(goal)); + $('#editgoalsConcernassociationsTable').find('tbody').find('tr:eq(' + selectedIdx + ')').find("td:eq(1)").text(assoc[0]); + $('#editgoalsConcernassociationsTable').find('tbody').find('tr:eq(' + selectedIdx + ')').find("td:eq(2)").text(assoc[1]); + $('#editgoalsConcernassociationsTable').find('tbody').find('tr:eq(' + selectedIdx + ')').find("td:eq(3)").text(assoc[2]); + $('#editgoalsConcernassociationsTable').find('tbody').find('tr:eq(' + selectedIdx + ')').find("td:eq(4)").text(assoc[3]); + $('#editgoalsConcernassociationsTable').find('tbody').find('tr:eq(' + selectedIdx + ')').find("td:eq(5)").text(assoc[4]); } - }); - } - else { - var oldname = $.session.get("goalAssocName"); - $.each(goal.theEnvironmentProperties, function (index, env) { - if(env.theEnvironmentName == envName){ - $.each(env.theConcernAssociations, function (index, concern) { - if(concern[0] == oldname){ - concern[0] = $("#theSourceSelect").val(); - concern[1] = $("#theNSelect").val(); - concern[2] = $("#theLink").val(); - concern[3] = $("#theTargetSelect").val(); - concern[4] = $("#theN2Select").val(); - } - }); + else { + env.theConcernAssociations.push(assoc); + $.session.set("Goal", JSON.stringify(goal)); + appendGoalConcernAssoc(assoc); } - }); - } - toggleGoalWindow("#editGoalOptionsForm"); - fillGoalOptionMenu(goal); - $.session.set("Goal", JSON.stringify(goal)); + $('#goalConcernAssociationsDialog').modal('hide'); + } + }); }); mainContent.on('click',".deleteGoalSubGoal", function () { @@ -275,33 +270,46 @@ mainContent.on('click',".deleteGoalEnvConcern", function () { }); mainContent.on('click', '#addConcernAssociationstoGoal', function () { - toggleGoalWindow("#editgoalConcernAssociations"); - $("#editgoalConcernAssociations").addClass("new"); - var envName = $.session.get("GoalEnvName"); - $("#theSourceSelect").empty(); - $("#theTargetSelect").empty(); - getAllAssetsInEnv(envName, function (data) { - $.each(data, function (index, asset) { - $("#theSourceSelect").append($("") - .attr("value",asset) - .text(asset)); - $("#theTargetSelect").append($("") - .attr("value",asset) - .text(asset)); - }) - }); + $('#AddGoalConcernAssociationButton').text('Add'); + $('#goalConcernAssociationsDialog').attr('data-selectedIndex',undefined); + refreshGoalConcernSelectors(); + $('#goalConcernAssociationsDialog').modal('show'); }); mainContent.on('click', '#addSubGoaltoGoal', function () { - $("#editgoalSubGoal").addClass("new"); - toggleGoalWindow("#editgoalSubGoal"); - fillGoalEditSubGoal(); + $("#editGoalSubGoal").attr('data-selectedIdx',undefined); + $("#editGoalSubGoal").attr('data-currentGoal',undefined); + $("#editGoalSubGoal").modal('show'); +}); + +$(document).on('shown.bs.modal','#editGoalSubGoal',function() { + var currentObject = $('#editGoalSubGoal').attr('data-currentGoal'); + if (currentObject != undefined) { + currentObject = JSON.parse(currentObject); + fillGoalEditSubGoal(currentObject.name,currentObject.type,currentObject.refinement,currentObject.target,currentObject.rationale); + } + else { + fillGoalEditSubGoal(); + } }); +$(document).on('shown.bs.modal','#editGoalGoal',function() { + var currentObject = $('#editGoalGoal').attr('data-currentGoal'); + if (currentObject != undefined) { + currentObject= JSON.parse(currentObject); + fillGoalEditGoal(currentObject.name,currentObject.type,currentObject.refinement,currentObject.target,currentObject.rationale); + } + else { + fillGoalEditGoal(); + } +}); + + + mainContent.on('click', '#addGoaltoGoal', function () { - $("#editGoalGoal").addClass("new"); - toggleGoalWindow("#editGoalGoal"); - fillGoalEditGoal(); + $("#editGoalGoal").attr('data-selectedIdx',undefined); + $("#editGoalGoal").attr('data-currentGoal',undefined); + $("#editGoalGoal").modal('show'); }); mainContent.on("click", "#addGoalEnvironment", function () { @@ -352,8 +360,8 @@ mainContent.on('click', ".deleteGoalEnv", function () { mainContent.on('click', '#updateGoalSubGoal', function () { var goal = JSON.parse($.session.get("Goal")); var envName = $.session.get("GoalEnvName"); - if($("#editgoalSubGoal").hasClass("new")){ - $("#editgoalSubGoal").removeClass("new"); + var selectedIdx = $("#editGoalSubGoal").attr('data-selectedIndex'); + if(selectedIdx == undefined) { $.each(goal.theEnvironmentProperties, function (index, env) { if(env.theEnvironmentName == envName){ var array = []; @@ -364,9 +372,11 @@ mainContent.on('click', '#updateGoalSubGoal', function () { array[4] = $("#theGoalSubGoalRationale").val(); env.theSubGoalRefinements.push(array); appendGoalSubGoal(array); + $.session.set("Goal", JSON.stringify(goal)); + $("#editGoalSubGoal").modal('hide'); } }); - } + } else { var oldName = $.session.get("oldsubGoalName"); $.each(goal.theEnvironmentProperties, function (index, env) { @@ -378,14 +388,18 @@ mainContent.on('click', '#updateGoalSubGoal', function () { arr[2] = $("#theRefinementSelect").val(); arr[3] = $("#theAlternate").val(); arr[4] = $("#theGoalSubGoalRationale").val(); + $.session.set("Goal", JSON.stringify(goal)); + $('#editgoalsSubgoalsTable').find('tbody').find('tr:eq(' + selectedIdx + ')').find("td:eq(1)").text(arr[0]); + $('#editgoalsSubgoalsTable').find('tbody').find('tr:eq(' + selectedIdx + ')').find("td:eq(2)").text(arr[1]); + $('#editgoalsSubgoalsTable').find('tbody').find('tr:eq(' + selectedIdx + ')').find("td:eq(3)").text(arr[2]); + $('#editgoalsSubgoalsTable').find('tbody').find('tr:eq(' + selectedIdx + ')').find("td:eq(4)").text(arr[3]); + $('#editgoalsSubgoalsTable').find('tbody').find('tr:eq(' + selectedIdx + ')').find("td:eq(5)").text(arr[4]); + $("#editGoalSubGoal").modal('hide'); } }); } }); } - $.session.set("Goal", JSON.stringify(goal)); - fillGoalOptionMenu(goal); - toggleGoalWindow("#editGoalOptionsForm"); }); mainContent.on('change', ".goalAutoUpdater" ,function() { @@ -453,79 +467,89 @@ function commitGoal() { } mainContent.on('click', '.editGoalSubGoalRow', function () { - toggleGoalWindow("#editgoalSubGoal"); - var name = $(this).find("td").eq(1).text(); - fillGoalEditSubGoal(name); - var type = $(this).find("td").eq(2).text(); - var refinement = $(this).find("td").eq(3).text(); - var target = $(this).find("td").eq(4).text(); - var rationale = $(this).find("td").eq(5).text(); - $.session.set("oldsubGoalName", name); - - $("#theSubgoalType").val(type); - $("#theRefinementSelect").val(refinement); - $("#theAlternate").val(target); - $("#theGoalSubGoalRationale").val(rationale); + var refRow = $(this).closest('tr'); + var currentGoal = {} + currentGoal.name = refRow.find("td").eq(1).text(); + currentGoal.type = refRow.find("td").eq(2).text(); + currentGoal.refinement = refRow.find("td").eq(3).text(); + currentGoal.target = refRow.find("td").eq(4).text(); + currentGoal.rationale = refRow.find("td").eq(5).text(); + $.session.set("oldsubGoalName", currentGoal.name); + $("#editGoalSubGoal").attr('data-currentGoal',JSON.stringify(currentGoal)); + $("#editGoalSubGoal").attr('data-selectedIndex',refRow.index()); + $("#theSubgoalType").val(currentGoal.type); + $("#theRefinementSelect").val(currentGoal.refinement); + $("#theAlternate").val(currentGoal.target); + $("#theGoalSubGoalRationale").val(currentGoal.rationale); + $("#editGoalSubGoal").modal('show'); }); mainContent.on('click', '.editGoalGoalRow', function () { - toggleGoalWindow("#editGoalGoal"); - var name = $(this).find("td").eq(1).text(); - fillGoalEditGoal(name); - - var type = $(this).find("td").eq(2).text(); - var refinement = $(this).find("td").eq(3).text(); - var target = $(this).find("td").eq(4).text(); - var rationale = $(this).find("td").eq(5).text(); - $.session.set("oldGoalName", name); - - $("#theGoalType").val(type); - $("#theGoalRefinementSelect").val(refinement); - $("#theGoalAlternate").val(target); - $("#theGoalGoalRationale").val(rationale); + var refRow = $(this).closest('tr'); + var currentGoal = {} + currentGoal.name = refRow.find("td").eq(1).text(); + currentGoal.type = refRow.find("td").eq(2).text(); + currentGoal.refinement = refRow.find("td").eq(3).text(); + currentGoal.target = refRow.find("td").eq(4).text(); + currentGoal.rationale = refRow.find("td").eq(5).text(); + $.session.set("oldGoalName", currentGoal.name); + $("#editGoalGoal").attr('data-currentGoal',JSON.stringify(currentGoal)); + $("#editGoalGoal").attr('data-selectedIndex',refRow.index()); + $("#theGoalType").val(currentGoal.type); + $("#theGoalRefinementSelect").val(currentGoal.refinement); + $("#theGoalAlternate").val(currentGoal.target); + $("#theGoalGoalRationale").val(currentGoal.rationale); + $("#editGoalGoal").modal('show'); }); -//editGoalConcernAssoc -mainContent.on('click', '.editGoalConcernAssoc', function () { +function refreshGoalConcernSelectors(name,n1,link,n2,target) { + $("#theSourceSelect").empty(); + $("#theTargetTarget").empty(); + var goal = JSON.parse($.session.get("Goal")); var envName = $.session.get("GoalEnvName"); - var tr = $(this); - getAllAssetsInEnv(envName, function (data) { - $.each(data, function (index, asset) { - $("#theSourceSelect").append($("") - .attr("value",asset) - .text(asset)); - $("#theTargetSelect").append($("") - .attr("value",asset) - .text(asset)); - }); - var name = $(tr).find(".assocName").text(); - $.session.set("goalAssocName",name); - var n1 = $(tr).find(".assocN1").text(); - var link = $(tr).find(".assocLink").text(); - var n2 = $(tr).find(".assocN2").text(); - var target = $(tr).find(".assocTarget").text(); - + $.each(goal.theEnvironmentProperties, function (index, env) { + if(env.theEnvironmentName == envName){ + $.each(env.theConcerns, function (idx2, conc) { + $("#theSourceSelect").append($("").attr('value',conc).text(conc)); + $("#theTargetSelect").append($("").attr('value',conc).text(conc)); + }); + } + }); + if (name != undefined) { $("#theSourceSelect").val(name); $("#theNSelect").val(n1); $("#theLink").val(link); $("#theTargetSelect").val(target); $("#theN2Select").val(n2); - toggleGoalWindow("#editgoalConcernAssociations"); - }); + } +} + +mainContent.on('click', '.editGoalConcernAssoc', function () { + var caRow = $(this).closest("tr"); + $('#AddGoalConcernAssociationButton').text('Edit'); + $('#goalConcernAssociationsDialog').attr('data-selectedIndex',caRow.index()); + var name = $(caRow).find(".assocName").text(); + $.session.set("goalAssocName",name); + var n1 = $(caRow).find(".assocN1").text(); + var link = $(caRow).find(".assocLink").text(); + var n2 = $(caRow).find(".assocN2").text(); + var target = $(caRow).find(".assocTarget").text(); + refreshGoalConcernSelectors(name,n1,link,n2,target); + $('#goalConcernAssociationsDialog').modal('show'); }); mainContent.on('click', '#goalCancelButton', function (e) { clearLocalStorage("goal"); $("#objectViewer").empty(); e.preventDefault(); - toggleGoalWindow("#editGoalOptionsForm"); }); mainContent.on('click',"#updateGoalGoal", function () { + var goal = JSON.parse($.session.get("Goal")); var envName = $.session.get("GoalEnvName"); - if($("#editGoalGoal").hasClass("new")) { - $("#editGoalGoal").removeClass("new"); + var selectedIdx = $("#editGoalGoal").attr('data-selectedIndex'); + if(selectedIdx == undefined) { $.each(goal.theEnvironmentProperties, function (index, env) { if(env.theEnvironmentName == envName){ var array = []; @@ -536,28 +560,34 @@ mainContent.on('click',"#updateGoalGoal", function () { array[4] = $("#theGoalGoalRationale").val(); env.theGoalRefinements.push(array); appendGoalGoal(array); + $.session.set("Goal", JSON.stringify(goal)); + $("#editGoalGoal").modal('hide'); } }); } - else{ + else { + var oldName = $.session.get("oldGoalName"); $.each(goal.theEnvironmentProperties, function (index, env) { if(env.theEnvironmentName == envName){ - var oldname = $.session.get("oldGoalName"); - $.each(env.theGoalRefinements, function (index, ref) { - if(ref[0] == oldname){ - ref[1] = $("#theGoalType").val(); - ref[0] = $("#theGoalName").val(); - ref[2] = $("#theGoalRefinementSelect").val(); - ref[3] = $("#theGoalAlternate").val(); - ref[4] = $("#theGoalGoalRationale").val(); + $.each(env.theGoalRefinements, function (index, arr) { + if(arr[0] == oldName){ + arr[1] = $("#theGoalType").val(); + arr[0] = $("#theGoalName").val(); + arr[2] = $("#theGoalRefinementSelect").val(); + arr[3] = $("#theGoalAlternate").val(); + arr[4] = $("#theGoalGoalRationale").val(); + $.session.set("Goal", JSON.stringify(goal)); + $('#editgoalsGoalsTable').find('tbody').find('tr:eq(' + selectedIdx + ')').find("td:eq(1)").text(arr[0]); + $('#editgoalsGoalsTable').find('tbody').find('tr:eq(' + selectedIdx + ')').find("td:eq(2)").text(arr[1]); + $('#editgoalsGoalsTable').find('tbody').find('tr:eq(' + selectedIdx + ')').find("td:eq(3)").text(arr[2]); + $('#editgoalsGoalsTable').find('tbody').find('tr:eq(' + selectedIdx + ')').find("td:eq(4)").text(arr[3]); + $('#editgoalsGoalsTable').find('tbody').find('tr:eq(' + selectedIdx + ')').find("td:eq(5)").text(arr[4]); + $("#editGoalGoal").modal('hide'); } }); } }); } - $.session.set("Goal", JSON.stringify(goal)); - fillGoalOptionMenu(goal); - toggleGoalWindow("#editGoalOptionsForm"); }); function viewGoal(goalName){ @@ -609,20 +639,32 @@ function fillGoalOptionMenu(data,callback){ }); } -function fillGoalEditSubGoal(theSettableValue){ - refreshDimensionSelector($('#theSubGoalName'),'goal',$.session.get("GoalEnvName"),undefined,['All']); -} - -function fillGoalEditGoal(theSettableValue) { - refreshDimensionSelector($('#theGoalName'),'goal',$.session.get("GoalEnvName"),undefined,['All']); +function fillGoalEditSubGoal(theSettableValue,theSettableType,refinement,target,rationale){ + if (theSettableType == undefined) { + theSettableType = 'goal'; + } + refreshDimensionSelector($('#theSubGoalName'),theSettableType,$.session.get("GoalEnvName"),function() { + if (theSettableValue != undefined) { + $('#theSubGoalName').val(theSettableValue); + $("#theRefinementSelect").val(refinement); + $("#theAlternate").val(target); + $("#theGoalSubGoalRationale").val(rationale); + } + },['All']); } -function toggleGoalWindow(window) { - $("#editgoalConcernAssociations").hide(); - $("#editGoalOptionsForm").hide(); - $("#editgoalSubGoal").hide(); - $("#editGoalGoal").hide(); - $(window).show(); +function fillGoalEditGoal(theSettableValue,theSettableType,refinement,target,rationale) { + if (theSettableType == undefined) { + theSettableType = 'goal'; + } + refreshDimensionSelector($('#theGoalName'),theSettableType,$.session.get("GoalEnvName"),function() { + if (theSettableValue != undefined) { + $("#theGoalName").val(theSettableValue); + $("#theGoalRefinementSelect").val(refinement); + $("#theGoalAlternate").val(target); + $("#theGoalGoalRationale").val(rationale); + } + },['All']); } function emptyGoalEnvTables(){ @@ -645,7 +687,7 @@ function appendGoalConcern(concern){ $("#editgoalsConcernTable").append(''+concern+''); } function appendGoalConcernAssoc(assoc){ - $("#editgoalsConcernassociationsTable").append(''+assoc[0]+''+assoc[1]+''+assoc[2]+''+assoc[4]+''+assoc[3]+''); + $("#editgoalsConcernassociationsTable").append(''+assoc[0]+''+assoc[1]+''+assoc[2]+''+assoc[4]+''+assoc[3]+''); } mainContent.on('click', '#goalCancelButton', function (e) { diff --git a/cairis/web/dist/js/cairis/obstacles.js b/cairis/web/dist/js/cairis/obstacles.js index 1a1417f4e..b867e293f 100644 --- a/cairis/web/dist/js/cairis/obstacles.js +++ b/cairis/web/dist/js/cairis/obstacles.js @@ -204,14 +204,13 @@ mainContent.on('click', '#obstacle_addSubGoaltoGoal', function () { }); $(document).on('shown.bs.modal','#obstacle_editGoalSubGoal',function() { - fillObstacleEditSubGoal(); - var currentObstacle = $('#obstacle_editGoalSubGoal').attr('data-currentObstacle'); - if (currentObstacle != undefined) { - currentObstacle = JSON.parse(currentObstacle); - $("#obstacle_theSubgoalType").val(currentObstacle.type); - $("#obstacle_theRefinementSelect").val(currentObstacle.refinement); - $("#obstacle_theAlternate").val(currentObstacle.target); - $("#obstacle_theGoalSubGoalRationale").val(currentObstacle.rationale); + var currentObject = $('#obstacle_editGoalSubGoal').attr('data-currentObstacle'); + if (currentObject != undefined) { + currentObject = JSON.parse(currentObject); + fillObstacleEditSubGoal(currentObject.name,currentObject.type,currentObject.refinement,currentObject.target,currentObject.rationale); + } + else { + fillObstacleEditSubGoal(); } }); @@ -222,14 +221,13 @@ mainContent.on('click', '#obstacle_addGoaltoGoal', function () { }); $(document).on('shown.bs.modal','#obstacle_editGoalGoal',function() { - fillObstacleEditGoal(); - var currentObstacle = $('#obstacle_editGoalGoal').attr('data-currentObstacle'); - if (currentObstacle != undefined) { - currentObstacle = JSON.parse(currentObstacle); - $("#obstacle_theGoalType").val(currentObstacle.type); - $("#obstacle_theGoalRefinementSelect").val(currentObstacle.refinement); - $("#obstacle_theGoalAlternate").val(currentObstacle.target); - $("#obstacle_theGoalGoalRationale").val(currentObstacle.rationale); + var currentObject = $('#obstacle_editGoalGoal').attr('data-currentObstacle'); + if (currentObject != undefined) { + currentObject= JSON.parse(currentObject); + fillObstacleEditGoal(currentObject.name,currentObject.type,currentObject.refinement,currentObject.target,currentObject.rationale); + } + else { + fillObstacleEditGoal(); } }); @@ -526,18 +524,31 @@ function fillObstacleOptionMenu(data,callback){ }); } -function fillObstacleEditSubGoal(theSettableValue){ - refreshDimensionSelector($('#obstacle_theSubGoalName'),'goal',$.session.get("ObstacleEnvName"),function() { - if (typeof theSettableValue !== "undefined"){ +function fillObstacleEditSubGoal(theSettableValue,theSettableType,refinement,target,rationale){ + if (theSettableType == undefined) { + theSettableType = 'obstacle'; + } + + refreshDimensionSelector($('#obstacle_theSubGoalName'),theSettableType,$.session.get("ObstacleEnvName"),function() { + if (theSettableValue != "undefined"){ $('#obstacle_theSubGoalName').val(theSettableValue); + $("#obstacle_theRefinementSelect").val(refinement); + $("#obstacle_theAlternate").val(target); + $("#obstacle_theGoalSubGoalRationale").val(rationale); } },['All']); } -function fillObstacleEditGoal(theSettableValue){ - refreshDimensionSelector($('#obstacle_theGoalName'),'goal',$.session.get("ObstacleEnvName"),function() { - if (typeof theSettableValue !== "undefined"){ +function fillObstacleEditGoal(theSettableValue,theSettableType,refinement,target,rationale){ + if (theSettableType == undefined) { + theSettableType = 'obstacle'; + } + refreshDimensionSelector($('#obstacle_theGoalName'),theSettableType,$.session.get("ObstacleEnvName"),function() { + if (theSettableValue != "undefined"){ $('#obstacle_theGoalName').val(theSettableValue); + $("#obstacle_theGoalRefinementSelect").val(refinement); + $("#obstacle_theGoalAlternate").val(target); + $("#obstacle_theGoalGoalRationale").val(rationale); } },['All']); } diff --git a/cairis/web/fastTemplates/editGoalsOptions.html b/cairis/web/fastTemplates/editGoalsOptions.html index 62457fd18..1c5f9babb 100644 --- a/cairis/web/fastTemplates/editGoalsOptions.html +++ b/cairis/web/fastTemplates/editGoalsOptions.html @@ -115,139 +115,166 @@ -