Skip to content

Commit f3d1c4e

Browse files
author
cairisuser
committed
Persona characteristic create/update/delete now works in web app
1 parent 227649f commit f3d1c4e

File tree

4 files changed

+213
-62
lines changed

4 files changed

+213
-62
lines changed

cairis/data/PersonaCharacteristicDAO.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def add_persona_characteristic(self, pc):
7575
cDesc=pc.theCharacteristic,
7676
pcGrounds=pc.theGrounds,
7777
pcWarrant=pc.theWarrant,
78-
pcBacking=pc.theBacking,
78+
pcBacking=[],
7979
pcRebuttal=pc.theRebuttal)
8080
try:
8181
self.db_proxy.addPersonaCharacteristic(pcParams)
@@ -93,7 +93,7 @@ def update_persona_characteristic(self,pc,name):
9393
cDesc=pc.theCharacteristic,
9494
pcGrounds=pc.theGrounds,
9595
pcWarrant=pc.theWarrant,
96-
pcBacking=pc.theBacking,
96+
pcBacking=[],
9797
pcRebuttal=pc.theRebuttal)
9898
pcParams.setId(found_pc.theId)
9999
try:

cairis/tools/ModelDefinitions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,8 +1017,7 @@ class PersonaCharacteristicModel(object):
10171017
"theCharacteristic": fields.String,
10181018
"theGrounds": fields.List(fields.Nested(PersonaCharacteristicReference.resource_fields)),
10191019
"theWarrant": fields.List(fields.Nested(PersonaCharacteristicReference.resource_fields)),
1020-
"theRebuttal": fields.List(fields.Nested(PersonaCharacteristicReference.resource_fields)),
1021-
"theBacking": fields.List(fields.String)
1020+
"theRebuttal": fields.List(fields.Nested(PersonaCharacteristicReference.resource_fields))
10221021
}
10231022
required = resource_fields.keys()
10241023
required.remove(obj_id_field)

cairis/web/dist/js/cairis/personacharacteristics.js

Lines changed: 190 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function createPersonaCharacteristicsTable(){
7373
debugLogger(String(this.url));
7474
debugLogger("error: " + xhr.responseText + ", textstatus: " + textStatus + ", thrown: " + errorThrown);
7575
}
76-
})
76+
});
7777
}
7878

7979
$(document).on('click', "td.personacharacteristic-rows", function () {
@@ -90,30 +90,51 @@ $(document).on('click', "td.personacharacteristic-rows", function () {
9090
url: serverIP + "/api/persona_characteristics/name/" + encodeURIComponent(name),
9191
success: function (data) {
9292
fillOptionMenu("fastTemplates/editPersonaCharacteristicOptions.html", "#objectViewer", null, true, true, function () {
93-
$("#editPersonaCharacteristicOptionsForm").validator();
94-
$("#UpdatePersonaCharacteristic").text("Update");
95-
$.session.set("PersonaCharacteristic", JSON.stringify(data));
96-
97-
$("#theModQual").val(data.theModQual);
98-
$("#theCharacteristic").val(data.theCharacteristic);
93+
$.ajax({
94+
type: "GET",
95+
dataType: "json",
96+
accept: "application/json",
97+
data: {
98+
session_id: String($.session.get('sessionID'))
99+
},
100+
crossDomain: true,
101+
url: serverIP + "/api/dimensions/table/persona",
102+
success: function (pNames) {
103+
var personaSelect = $('#thePersonaName');
104+
$.each(pNames, function (index,pName) {
105+
personaSelect.append($("<option></option>").attr("value",pName).text(pName));
106+
});
107+
$("#editPersonaCharacteristicOptionsForm").validator();
108+
$("#UpdatePersonaCharacteristic").text("Update");
109+
$.session.set("PersonaCharacteristic", JSON.stringify(data));
110+
personaSelect.val(data.thePersonaName);
111+
$("#theVariable").val(data.theVariable);
112+
$("#theModQual").val(data.theModQual);
113+
$("#theCharacteristic").val(data.theCharacteristic);
99114

100-
$("#theGrounds").find("tbody").empty();
101-
$.each(data.theGrounds,function(idx,item) {
102-
appendGWR("#theGrounds",'ground',item);
103-
});
104-
105-
$("#theWarrant").find("tbody").empty();
106-
$.each(data.theWarrant,function(idx,item) {
107-
appendGWR("#theWarrant",'warrant',item);
108-
});
109-
$("#theRebuttal").find("tbody").empty();
110-
$.each(data.theRebuttal,function(idx,item) {
111-
appendGWR("#theRebuttal",'rebuttal',item);
115+
$("#theGrounds").find("tbody").empty();
116+
$.each(data.theGrounds,function(idx,item) {
117+
appendGWR("#theGrounds",'ground',item);
118+
});
119+
120+
$("#theWarrant").find("tbody").empty();
121+
$.each(data.theWarrant,function(idx,item) {
122+
appendGWR("#theWarrant",'warrant',item);
123+
});
124+
$("#theRebuttal").find("tbody").empty();
125+
$.each(data.theRebuttal,function(idx,item) {
126+
appendGWR("#theRebuttal",'rebuttal',item);
127+
});
128+
$("#theBacking").find("tbody").empty();
129+
$.each(data.theBacking,function(idx,item) {
130+
appendBacking(item);
131+
});
132+
},
133+
error: function (xhr, textStatus, errorThrown) {
134+
debugLogger(String(this.url));
135+
debugLogger("error: " + xhr.responseText + ", textstatus: " + textStatus + ", thrown: " + errorThrown);
136+
}
112137
});
113-
$("#theBacking").find("tbody").empty();
114-
$.each(data.theBacking,function(idx,item) {
115-
appendBacking(item);
116-
});
117138
});
118139
},
119140
error: function (xhr, textStatus, errorThrown) {
@@ -128,6 +149,10 @@ mainContent.on('click', '#UpdatePersonaCharacteristic', function (e) {
128149
e.preventDefault();
129150
var pc = JSON.parse($.session.get("PersonaCharacteristic"));
130151
var oldName = pc.theCharacteristic;
152+
pc.thePersonaName = $("#thePersonaName").val();
153+
pc.theVariable = $("#theVariable").val();
154+
pc.theModQual = $("#theModQual").val();
155+
pc.theCharacteristic = $("#theCharacteristic").val();
131156

132157
if($("#editPersonaCharacteristicOptionsForm").hasClass("new")){
133158
postPersonaCharacteristic(pc, function () {
@@ -142,25 +167,46 @@ mainContent.on('click', '#UpdatePersonaCharacteristic', function (e) {
142167
}
143168
});
144169

145-
$(document).on('click', 'td.deletePersonaCharacteristicsButton', function (e) {
170+
$(document).on('click', 'td.deletePersonaCharacteristicButton', function (e) {
146171
e.preventDefault();
147-
deletePersonaCharacteristic($(this).find('i').attr("value"), function () {
172+
var pName = $(this).closest('tr').find('td:eq(3)').text();
173+
deletePersonaCharacteristic(pName, function () {
148174
createPersonaCharacteristicsTable();
149175
});
150176
});
151177

152178
$(document).on("click", "#addNewPersonaCharacteristic", function () {
153179
activeElement("objectViewer");
154180
fillOptionMenu("fastTemplates/editPersonaCharacteristicOptions.html", "#objectViewer", null, true, true, function () {
155-
$("#editPersonaCharacteristicOptionsForm").validator();
156-
$("#UpdatePersonaCharacteristic").text("Create");
157-
$("#editPersonaCharacteristicOptionsForm").addClass("new");
158-
$.session.set("PersonaCharacteristic", JSON.stringify(jQuery.extend(true, {},personaCharacteristicDefault )));
181+
$.ajax({
182+
type: "GET",
183+
dataType: "json",
184+
accept: "application/json",
185+
data: {
186+
session_id: String($.session.get('sessionID'))
187+
},
188+
crossDomain: true,
189+
url: serverIP + "/api/dimensions/table/persona",
190+
success: function (data) {
191+
var personaSelect = $('#thePersonaName');
192+
$.each(data, function (index,pName) {
193+
personaSelect.append($("<option></option>").attr("value",pName).text(pName));
194+
});
195+
$("#editPersonaCharacteristicOptionsForm").validator();
196+
$("#UpdatePersonaCharacteristic").text("Create");
197+
$("#editPersonaCharacteristicOptionsForm").addClass("new");
198+
$.session.set("PersonaCharacteristic", JSON.stringify(jQuery.extend(true, {},personaCharacteristicDefault )));
199+
},
200+
error: function (xhr, textStatus, errorThrown) {
201+
debugLogger(String(this.url));
202+
debugLogger("error: " + xhr.responseText + ", textstatus: " + textStatus + ", thrown: " + errorThrown);
203+
}
204+
});
159205
});
160206
});
161207

162208

163-
function putPersonaCharacteristic(pc, oldName, usePopup, callback){
209+
function putPersonaCharacteristic(pc, oldName, callback){
164210
var output = {};
165211
output.object = pc;
166212
output.session_id = $.session.get('sessionID');
@@ -178,18 +224,14 @@ function putPersonaCharacteristic(pc, oldName, usePopup, callback){
178224
data: output,
179225
url: serverIP + "/api/persona_characteristics/name/" + encodeURIComponent(oldName) + "?session_id=" + $.session.get('sessionID'),
180226
success: function (data) {
181-
if(usePopup) {
182-
showPopup(true);
183-
}
227+
showPopup(true);
184228
if(jQuery.isFunction(callback)){
185229
callback();
186230
}
187231
},
188232
error: function (xhr, textStatus, errorThrown) {
189-
if(usePopup) {
190-
var error = JSON.parse(xhr.responseText);
191-
showPopup(false, String(error.message));
192-
}
233+
var error = JSON.parse(xhr.responseText);
234+
showPopup(false, String(error.message));
193235
debugLogger(String(this.url));
194236
debugLogger("error: " + xhr.responseText + ", textstatus: " + textStatus + ", thrown: " + errorThrown);
195237
}
@@ -281,6 +323,9 @@ function loadCharacteristicReference() {
281323
$.each(data, function(key, item) {
282324
$("#theReferenceName").append("<option>" + item + "</option>");
283325
});
326+
var cr = JSON.parse($("#editCharacteristicReference").data("currentcr"));
327+
$("#theReferenceName").val(cr.name);
328+
$("#theDescription").val(cr.description);
284329
},
285330
error: function (xhr, textStatus, errorThrown) {
286331
debugLogger(String(this.url));
@@ -290,23 +335,95 @@ function loadCharacteristicReference() {
290335
};
291336

292337
function addCharacteristicReference() {
338+
var cr = JSON.parse($("#editCharacteristicReference").data("crtype"));
293339
var item = {};
294340
item.theReferenceName = $("#theReferenceName").val();
295341
item.theReferenceDescription = $("#theDescription").val();
296-
appendGWR("#theGrounds",'ground',item);
342+
appendGWR(cr.tableId,cr.classId,item);
343+
item.theDimensionName = 'document';
344+
var pc = JSON.parse($.session.get("PersonaCharacteristic"));
345+
if (cr.tableId == '#theGrounds') {
346+
item.theCharacteristicType = 'grounds';
347+
pc.theGrounds.push(item);
348+
}
349+
else if (cr.tableId == '#theWarrant') {
350+
item.theCharacteristicType = 'warrant';
351+
pc.theWarrant.push(item);
352+
}
353+
else {
354+
item.theCharacteristicType = 'rebuttal';
355+
pc.theRebuttal.push(item);
356+
}
357+
$.session.set("PersonaCharacteristic", JSON.stringify(pc));
297358
$("#editCharacteristicReference").modal('hide');
298359
}
299360

300-
function loadCharacteristicReference() {
301-
var currentCr = $("#editCharacteristicReference").data('currentcr');
302-
$("#theReferenceName").val(currentCr.theReferenceName);
303-
$("#theDescription").val(currentCr.theReferenceDescription);
361+
function updateReferenceList() {
362+
var cr = JSON.parse($("#editCharacteristicReference").data("currentcr"));
363+
var item = {};
364+
item.theReferenceName = $("#theReferenceName").val();
365+
item.theReferenceDescription = $("#theDescription").val();
366+
$(cr.tableId).find("tbody").find('tr:eq(' + cr.index + ')').find('td:eq(1)').text(item.theReferenceName);
367+
$(cr.tableId).find("tbody").find('tr:eq(' + cr.index + ')').find('td:eq(2)').text(item.theReferenceDescription);
368+
item.theDimensionName = 'document';
369+
var pc = JSON.parse($.session.get("PersonaCharacteristic"));
370+
371+
if (cr.tableId == '#theGrounds') {
372+
item.theCharacteristicType = 'grounds';
373+
$.each(pc.theGrounds,function(idx,g) {
374+
if (idx == cr.index) {
375+
pc.theGrounds[idx] = item;
376+
}
377+
});
378+
}
379+
else if (cr.tableId == '#theWarrant') {
380+
item.theCharacteristicType = 'warrant';
381+
$.each(pc.theWarrant,function(idx,w) {
382+
if (idx == cr.index) {
383+
pc.theWarrant[idx] = item;
384+
}
385+
});
386+
}
387+
else {
388+
item.theCharacteristicType = 'rebuttal';
389+
$.each(pc.theRebuttal,function(idx,r) {
390+
if (idx == cr.index) {
391+
pc.theRebuttal[idx] = item;
392+
}
393+
});
394+
}
395+
$.session.set("PersonaCharacteristic", JSON.stringify(pc));
396+
$("#editCharacteristicReference").modal('hide');
304397
}
305398

306399

307400
mainContent.on("click", "#addGrounds", function(){
401+
var crt = {};
402+
crt.tableId = "#theGrounds";
403+
crt.classId = 'ground';
308404
$("#editCharacteristicReference").data('loadcr',loadCharacteristicReference);
309405
$("#editCharacteristicReference").data("savecr",addCharacteristicReference);
406+
$("#editCharacteristicReference").data("crtype",JSON.stringify(crt));
407+
$("#editCharacteristicReference").modal('show');
408+
});
409+
410+
mainContent.on("click", "#addWarrant", function(){
411+
var crt = {};
412+
crt.tableId = "#theWarrant";
413+
crt.classId = 'warrant';
414+
$("#editCharacteristicReference").data('loadcr',loadCharacteristicReference);
415+
$("#editCharacteristicReference").data("savecr",addCharacteristicReference);
416+
$("#editCharacteristicReference").data("crtype",JSON.stringify(crt));
417+
$("#editCharacteristicReference").modal('show');
418+
});
419+
420+
mainContent.on("click", "#addRebuttal", function(){
421+
var crt = {};
422+
crt.tableId = "#theRebuttal";
423+
crt.classId = 'rebuttal';
424+
$("#editCharacteristicReference").data('loadcr',loadCharacteristicReference);
425+
$("#editCharacteristicReference").data("savecr",addCharacteristicReference);
426+
$("#editCharacteristicReference").data("crtype",JSON.stringify(crt));
310427
$("#editCharacteristicReference").modal('show');
311428
});
312429

@@ -322,12 +439,37 @@ $("#editCharacteristicReference").on('click', '#saveCharacteristicReference',fun
322439

323440
mainContent.on("click",".ground", function () {
324441
var propRow = $(this).closest("tr");
325-
var selectedCr = {};
326-
selectedCr.reference = propRow.find("td:eq(1)").text();
327-
selectedCr.description = propRow.find("td:eq(2)").text();
328-
442+
var cr = {};
443+
cr.name = propRow.find("td:eq(1)").text();
444+
cr.description = propRow.find("td:eq(2)").text();
445+
cr.index = propRow.index();
446+
cr.tableId = "#theGrounds";
447+
$("#editCharacteristicReference").data("currentcr",JSON.stringify(cr));
448+
$("#editCharacteristicReference").data('loadcr',loadCharacteristicReference);
449+
$("#editCharacteristicReference").data("savecr",updateReferenceList);
450+
$("#editCharacteristicReference").modal('show');
451+
});
452+
mainContent.on("click",".warrant", function () {
453+
var propRow = $(this).closest("tr");
454+
var cr = {};
455+
cr.name = propRow.find("td:eq(1)").text();
456+
cr.description = propRow.find("td:eq(2)").text();
457+
cr.index = propRow.index();
458+
cr.tableId = "#theWarrant";
459+
$("#editCharacteristicReference").data("currentcr",JSON.stringify(cr));
460+
$("#editCharacteristicReference").data('loadcr',loadCharacteristicReference);
461+
$("#editCharacteristicReference").data("savecr",updateReferenceList);
462+
$("#editCharacteristicReference").modal('show');
463+
});
464+
mainContent.on("click",".rebuttal", function () {
465+
var propRow = $(this).closest("tr");
466+
var cr = {};
467+
cr.name = propRow.find("td:eq(1)").text();
468+
cr.description = propRow.find("td:eq(2)").text();
469+
cr.index = propRow.index();
470+
cr.tableId = "#theRebuttal";
471+
$("#editCharacteristicReference").data("currentcr",JSON.stringify(cr));
329472
$("#editCharacteristicReference").data('loadcr',loadCharacteristicReference);
330-
$("#editCharacteristicReference").data("savecr",updateCharacteristicReference);
331-
$("#editCharacteristicReference").data("currentcr",JSON.stringify(selectedCr));
473+
$("#editCharacteristicReference").data("savecr",updateReferenceList);
332474
$("#editCharacteristicReference").modal('show');
333475
});

cairis/web/fastTemplates/editPersonaCharacteristicOptions.html

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,29 @@
44
<li><a href="#general">General</a></li>
55
<li><a href="#grounds">Grounds</a></li>
66
<li><a href="#warrant">Warrant</a></li>
7-
<li><a href="#backing">Backing</a></li>
87
<li><a href="#rebuttal">Rebuttal</a></li>
98
</ul>
109
<div id="general">
10+
<div class="form-group">
11+
<label for="thePersonaName" class="control-label">Persona</label>
12+
<select class="form-control" id="thePersonaName" data-error="Persona is required" required>
13+
</select>
14+
<div class="help-block with-errors"></div>
15+
</div>
16+
<div class="form-group">
17+
<label for="theVariable" class="control-label">Variable</label>
18+
<select class="form-control" id="theVariable" data-error="Variable is required" required>
19+
<option value="Activities">Activities</option>
20+
<option value="Attitudes">Attitudes</option>
21+
<option value="Aptitudes">Aptitudes</option>
22+
<option value="Motivations">Motivations</option>
23+
<option value="Skills">Skills</option>
24+
<option value="Environment Narrative">Environment Narrative</option>
25+
<option value="Intrinsic">Intrinsic</option>
26+
<option value="Contextual">Contextual</option>
27+
</select>
28+
<div class="help-block with-errors"></div>
29+
</div>
1130
<div class="form-group">
1231
<label for="theModQual" class="control-label">Modal Qualifier</label>
1332
<input class="optionsInput personaCharacteristicUpdate form-control" type="text" name="theModQual" id="theModQual" style="width: 75%;" data-error="Modal Qualifier is required" required>
@@ -37,15 +56,6 @@
3756
</tbody>
3857
</table>
3958
</div>
40-
<div id="backing">
41-
<table class="clickable-table" id="theBacking">
42-
<thead>
43-
<tr><th>Document</th></tr>
44-
</thead>
45-
<tbody>
46-
</tbody>
47-
</table>
48-
</div>
4959
<div id="rebuttal">
5060
<table class="clickable-table" id="theRebuttal">
5161
<thead>

0 commit comments

Comments
 (0)