Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions src/caseManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ function autoAssignName(vellum) {
vellum.ensureCurrentMugIsSaved(() => {
const form = vellum.data.core.form;
let mug = form.findFirstMatchingChild(null, () => true);
if (!mug || mug.p.caseProperty || mug.spec.caseProperty?.presence !== 'optional') {
if (!mug || mug.p.caseProperty || !mug.spec.caseProperty ||
mug.getPresence("caseProperty") !== 'optional') {
mug = vellum.addQuestion('DataBindOnly', 'first');
mug.p.nodeID = form.generate_question_id('case-name');
mug.p.calculateAttr = 'uuid()';
Expand Down Expand Up @@ -458,6 +459,19 @@ $.vellum.plugin('caseManagement', {}, {
initAutoAssignName(this);
},

postInit: function() {
this.__callOld();
const types = this.data.core.mugTypes.normalTypes;
const exclude = {'Trigger': true, 'SaveToCase': true};
_(types).each((type, name) => {
if (Object.hasOwn(exclude, name) ||
type.dataType === 'binary' || // multimedia: Audio, Image, ...
type.tagName === 'group') {
type.spec.caseProperty = { presence: 'notallowed' };
}
});
},

loadXML: function () {
this.__callOld();
const _this = this;
Expand Down Expand Up @@ -506,19 +520,6 @@ $.vellum.plugin('caseManagement', {}, {
}
},

getMugTypes: function () {
const types = this.__callOld();
const excludedTypes = [
types.normal.Trigger,
types.normal.Group,
types.normal.Repeat,
types.normal.FieldList
];
excludedTypes.forEach(excludedType => excludedType.spec.caseProperty = { presence: 'notallowed' });

return types;
},

getSections: function (mug) {
const sections = this.__callOld(mug);
sections.splice(1, 0, {
Expand All @@ -545,6 +546,13 @@ $.vellum.plugin('caseManagement', {}, {
if (options.slug !== 'caseManagement') {
return $sec;
}
let parent = mug.parentMug;
while (parent) {
if (parent.__className === "Repeat") {
return $(); // hide section if in repeat group
}
parent = parent.parentMug;
}
const data = this.data.caseManagement;
if (data.is_registration_form && !data.caseMappings?.name?.length) {
const $nudge = $(nudgeName({format: util.format}));
Expand Down
55 changes: 40 additions & 15 deletions tests/caseManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ describe("The Case Management plugin", function () {
assert.notExists(getCaseManagementSection()[0]);
});

it("should hide the case management section for questions in repeat groups", function () {
util.loadXML("");
const repeat = util.addQuestion("Repeat", "repeat_group");
const group = util.addQuestion("Group", "group");
const text = util.addQuestion("Text", "text");
util.clickQuestion(text);

assert.equal(text.parentMug, group);
assert.equal(group.parentMug, repeat);
assert.notExists(getCaseManagementSection()[0]);
});

it("should hide the case management section for question lists", function () {
util.loadXML("");
util.addQuestion("FieldList", "question_list");
Expand Down Expand Up @@ -717,21 +729,34 @@ describe("The Case Management plugin", function () {
save.popover("show");
});

it("new mug when first mug is a group", function (done) {
util.loadXML("");
const group = util.addQuestion("Group", "test");
const save = call("getData").core.saveButton.ui;
function test() {
save.off('shown.bs.popover.test');
$(".fd-auto-assign-case-name").trigger("click");
const name = call("getMugByPath", "/data/case-name");
assert.equal(name.p.nodeID, 'case-name');
assert.equal(name.p.caseProperty, 'name');
assert.equal(group.p.caseProperty, undefined);
done();
}
save.on('shown.bs.popover.test', test);
save.popover("show");
describe("new mug when first mug is a", function () {
([
"Trigger",
"Group",
"Repeat",
"SaveToCase",
"Audio",
"Image",
"Video",
"Document",
]).forEach(type => {
it(type, function (done) {
util.loadXML("");
const mug = util.addQuestion(type, "test");
const save = call("getData").core.saveButton.ui;
function test() {
save.off('shown.bs.popover.test');
$(".fd-auto-assign-case-name").trigger("click");
const name = call("getMugByPath", "/data/case-name");
assert.isUndefined(mug.p.caseProperty, type + " caseProperty should be undefined");
assert.equal(name.p.nodeID, 'case-name');
assert.equal(name.p.caseProperty, 'name');
done();
}
save.on('shown.bs.popover.test', test);
save.popover("show");
});
});
});

it("new mug with unique node ID", function (done) {
Expand Down
Loading