diff --git a/corehq/apps/cloudcare/static/cloudcare/js/form_entry/const.js b/corehq/apps/cloudcare/static/cloudcare/js/form_entry/const.js index 30d614caa073..dfcac5edf452 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/form_entry/const.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/form_entry/const.js @@ -1,9 +1,7 @@ 'use strict'; hqDefine("cloudcare/js/form_entry/const", [], function () { return { - ADD_GROUP_TYPE: 'add-group', GROUP_TYPE: 'sub-group', - REPEAT_TYPE: 'repeat-juncture', QUESTION_TYPE: 'question', GROUPED_ELEMENT_TILE_ROW_TYPE: 'grouped-element-tile-row', diff --git a/corehq/apps/cloudcare/static/cloudcare/js/form_entry/form_ui.js b/corehq/apps/cloudcare/static/cloudcare/js/form_entry/form_ui.js index 1f214574dc1c..8be1924c3821 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/form_entry/form_ui.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/form_entry/form_ui.js @@ -182,7 +182,7 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ for (let groupChild of json.children) { // Detects configured repeat groups within the form. If a repeat group has a 'repeat-count' configured, // the Formplayer response designates the key 'type' as 'sub-group' and 'repeatable' as 'true'. - if ((groupChild.type === constants.GROUP_TYPE && groupChild.repeatable === "true") || groupChild.type === constants.REPEAT_TYPE) { + if ((groupChild.type === constants.GROUP_TYPE && groupChild.repeatable === "true")) { if (_.has(groupChild, 'style') && groupChild.style && groupChild.style.raw) { groupChild.style.raw = groupChild.style.raw.concat(" ", elementNPerRowStyle); } else { @@ -250,12 +250,8 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ return new GroupedElementTileRow(options.data, self); } else if (options.data.type === constants.QUESTION_TYPE) { return new Question(options.data, self); - } else if (options.data.type === constants.GROUP_TYPE && options.data.exists === "false") { - return new AddGroup(options.data, self); } else if (options.data.type === constants.GROUP_TYPE) { return new Group(options.data, self); - } else if (options.data.type === constants.REPEAT_TYPE) { - return new Repeat(options.data, self); } else { console.error('Could not find question type of ' + options.data.type); } @@ -292,7 +288,18 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ return options.target; }, key: function (data) { - return ko.utils.unwrapObservable(data.uuid) || ko.utils.unwrapObservable(data.ix); + const uuid = ko.utils.unwrapObservable(data.uuid); + if (uuid) { + return uuid; + } + const exists = ko.utils.unwrapObservable(data.exists); + const ix = ko.utils.unwrapObservable(data.ix); + if (exists && exists === 'false') { + // this is a add group button. replace last part with d + const lastIdx = ix.lastIndexOf('_'); + return lastIdx === -1 ? ix : ix.slice(0, lastIdx) + '_d'; + } + return ix; }, }, }; @@ -310,8 +317,7 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ let currentNode = this; let nestedDepthCount = 0; while (currentNode.parent) { - let isCollapsibleGroup = currentNode.type() === constants.GROUP_TYPE && currentNode.collapsible; - if (isCollapsibleGroup || currentNode.type() === constants.REPEAT_TYPE) { + if (currentNode.type() === constants.GROUP_TYPE && currentNode.collapsible) { nestedDepthCount += 1; } currentNode = currentNode.parent; @@ -375,7 +381,7 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ } for (let child of json.children) { - if (child.type === constants.QUESTION_TYPE || child.type === constants.GROUP_TYPE || child.type === constants.REPEAT_TYPE) { + if (child.type === constants.QUESTION_TYPE || child.type === constants.GROUP_TYPE) { const elementTileWidth = GroupedElementTileRow.calculateElementWidth(child.style); usedWidth += elementTileWidth; if (usedWidth > constants.GRID_COLUMNS) { @@ -383,7 +389,7 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ usedWidth += elementTileWidth; } - if (child.type === constants.GROUP_TYPE || child.type === constants.REPEAT_TYPE) { + if (child.type === constants.GROUP_TYPE) { child = Container.groupElements(child); } @@ -633,7 +639,7 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ }; $.unsubscribe('session'); - $.subscribe('session.reconcile', function (e, response, element, deletedGroup) { + $.subscribe('session.reconcile', function (e, response, element, options) { // TODO where does response status parsing belong? if (response.status === 'validation-error') { if (response.type === 'required') { @@ -646,18 +652,22 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ const allChildren = response.tree; delete response.tree; - if (deletedGroup) { + if (options) { // deletedGroup is only set for responses from delete-repeat. // because ko.mapping does not like reassigning keys we need to remove all repeat group siblings and // add them back in to force proper refresh. Setting response.children to [] would also work but was // quite slow for larger forms. // self.fromJS makes changes to the response. So create a copy first. response.children = JSON.parse(JSON.stringify(allChildren)); - removeSiblingsOfRepeatGroup(response, deletedGroup); + if (options.deletedGroup) { + removeSiblingsOfRepeatGroup(response, options.deletedGroup); + } self.fromJS(response); } - if (element.serverError) { element.serverError(null); } + if (element.serverError) { + element.serverError(null); + } response.children = allChildren; self.fromJS(response); @@ -682,14 +692,15 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ self.parent = parent; Container.call(self, json); + self.isDummy = ko.observable(self.exists() === "false"); + self.addChoice = ko.observable(json['add-choice']); + self.groupId = groupNum++; - self.rel_ix = ko.observable(relativeIndex(self.ix())); - // USH-4332: after FP deploy isRepetition can be removed - self.isRepetition = parent.parent instanceof Repeat; + self.rel_ix = ko.pureComputed(() => relativeIndex(self.ix())); if (Object.hasOwn(self, 'delete')) { self.showDelete = self.delete(); } else { - self.showDelete = self.isRepetition; + self.showDelete = false; } let parentForm = getParentForm(self); let oneQuestionPerScreen = parentForm.displayOptions.oneQuestionPerScreen !== undefined && parentForm.displayOptions.oneQuestionPerScreen(); @@ -699,13 +710,7 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ }); // Header and captions - self.showHeader = oneQuestionPerScreen || self.isRepetition || ko.utils.unwrapObservable(self.caption) || ko.utils.unwrapObservable(self.caption_markdown); - if (self.showHeader) { - if (!oneQuestionPerScreen && self.isRepetition) { - self.caption(null); - self.hideCaption = true; - } - } + self.showHeader = oneQuestionPerScreen || ko.utils.unwrapObservable(self.caption) || ko.utils.unwrapObservable(self.caption_markdown); if (_.has(json, 'domain_meta') && _.has(json, 'style')) { self.domain_meta = parseMeta(json.datatype, json.style); @@ -749,13 +754,11 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ }); }); - if (self.isRepetition) { - // If the group is part of a repetition the index can change if the user adds or deletes - // repeat groups. - self.ix.subscribe(function () { - self.rel_ix(relativeIndex(self.ix())); - }); - } + self.newRepeat = function () { + $.publish('formplayer.' + constants.NEW_REPEAT, self); + $.publish('formplayer.dirty'); + $('.add').trigger('blur'); + }; self.deleteRepeat = function () { $.publish('formplayer.' + constants.DELETE_REPEAT, self); @@ -763,7 +766,7 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ }; self.hasAnyNestedQuestions = function () { - return _.any(self.children(), function (d) { + return self.isDummy() || _.any(self.children(), function (d) { if (d.type() === constants.GROUPED_ELEMENT_TILE_ROW_TYPE) { return d.hasAnyNestedQuestions(); } @@ -785,7 +788,7 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ }; self.headerBackgroundColor = function () { - if (self.isRepetition || !self.collapsible) { + if (!self.collapsible) { return ''; } return Container.prototype.headerBackgroundColor.call(self); @@ -798,41 +801,6 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ Group.prototype = Object.create(Container.prototype); Group.prototype.constructor = Container; - /** - * Represents a repeat group. A repeat only has Group objects as children, which are contained - * within a GroupedElementTileRow. Each child Group contains GroupedElementTileRow - * objects which contains the child questions to be rendered - * @param {Object} json - The JSON returned from touchforms to represent a Form - * @param {Object} parent - The object's parent. Either a Form, Group, or Repeat. - */ - function Repeat(json, parent) { - var self = this; - self.parent = parent; - - Container.call(self, json); - - self.rel_ix = ko.observable(relativeIndex(self.ix())); - if (_.has(json, 'domain_meta') && _.has(json, 'style')) { - self.domain_meta = parseMeta(json.datatype, json.style); - } - self.templateType = 'repeat'; - self.ixInfo = function (o) { - var fullIx = getIx(o); - return o.rel_ix + (o.isRepetition ? '(' + o.uuid + ')' : '') + (o.rel_ix !== fullIx ? ' :: ' + fullIx : ''); - }; - - self.newRepeat = function () { - $.publish('formplayer.' + constants.NEW_REPEAT, self); - $.publish('formplayer.dirty'); - $('.add').trigger('blur'); - }; - - const columnWidth = GroupedElementTileRow.calculateElementWidth(this.style); - this.elementTile = `col-sm-${columnWidth}`; - } - Repeat.prototype = Object.create(Container.prototype); - Repeat.prototype.constructor = Container; - /** * Represents a group of Questions, Group, or Repeat. Elements are grouped such that all elements are * contained in the same row. @@ -857,7 +825,7 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ self.hasAnyNestedQuestions = function () { return _.any(self.children(), function (d) { - if (d.type() === constants.QUESTION_TYPE || d.type() === constants.REPEAT_TYPE || d.type() === constants.ADD_GROUP_TYPE) { + if (d.type() === constants.QUESTION_TYPE) { return true; } else if (d.type() === constants.GROUP_TYPE) { return d.hasAnyNestedQuestions(); @@ -889,24 +857,6 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ return itemsPerRow !== null ? Math.round(constants.GRID_COLUMNS / itemsPerRow) : constants.GRID_COLUMNS; }; - function AddGroup(json, parent) { - var self = this; - self.parent = parent; - self.hasError = ko.observable(false); - self.children = ko.observable([]); - self.newRepeat = function () { - $.publish('formplayer.' + constants.NEW_REPEAT, self); - $.publish('formplayer.dirty'); - $('.add').trigger('blur'); - }; - self.entryTemplate = "add-group-entry-ko-template"; - self.addChoice = ko.observable(json['add-choice']); - self.type = ko.observable("add-group"); - self.rel_ix = ko.observable(relativeIndex(json.ix)); - self.required = ko.observable(json.required); - self.hasError = ko.observable(json.hasError); - } - /** * Represents a Question. A Question contains an Entry which is the widget that is displayed for that question * type. @@ -978,7 +928,7 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ self.ixInfo = function (o) { var fullIx = getIx(o); - return o.rel_ix + (o.isRepetition ? '(' + o.uuid + ')' : '') + (o.rel_ix !== fullIx ? ' :: ' + fullIx : ''); + return o.rel_ix + (o.rel_ix !== fullIx ? ' :: ' + fullIx : ''); }; self.triggerAnswer = function () { @@ -1102,7 +1052,6 @@ hqDefine("cloudcare/js/form_entry/form_ui", [ Question: function (json, parent) { return new Question(json, parent); }, - Repeat: Repeat, removeSiblingsOfRepeatGroup: removeSiblingsOfRepeatGroup, }; }); diff --git a/corehq/apps/cloudcare/static/cloudcare/js/form_entry/spec/fixtures.js b/corehq/apps/cloudcare/static/cloudcare/js/form_entry/spec/fixtures.js index b2b952def540..103c9ba9ca4d 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/form_entry/spec/fixtures.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/form_entry/spec/fixtures.js @@ -92,66 +92,15 @@ hqDefine("cloudcare/js/form_entry/spec/fixtures", [ "add-choice": null, })), - repeatJSON: (options = {}) => (_.defaults(options, { - "caption_audio": null, - "caption": "Repeater", - "caption_image": null, - "type": "repeat-juncture", - "caption_markdown": null, - "ix": "0J", - "relevant": 1, - "main-header": "Repeater", - "children": [], - "add-choice": "None - Add Repeater", - "caption_video": null, - })), - - repeatNestJSON: () => ({ - "caption_audio": null, - "caption": "Repeat Simple", - "caption_image": null, - "type": "repeat-juncture", - "caption_markdown": null, - "ix": "0J", - "relevant": 1, - "children": [{ - "caption": "Repeat Simple 1/1", - "type": "sub-group", - "uuid": "ed3f01b37034", - "ix": "0:0", - "children": [{ - "caption_audio": null, - "caption": "Text_Question", - "binding": "/data/repeat/Text_Question", - "caption_image": null, - "type": "question", - "caption_markdown": null, - "required": 0, - "ix": "0:0,0", - "relevant": 1, - "help": null, - "help_image": null, - "help_audio": null, - "help_video": null, - "answer": null, - "datatype": "str", - "style": {}, - "caption_video": null, - }], - "repeatable": 1, - }], - "add-choice": "Add another Repeat Simple", - "header": "Repeat Simple", - "caption_video": null, - }), - groupJSON: (options = {}) => (_.defaults(options, { "type": "sub-group", "ix": "1", + "exists": true, "caption": "Group", "children": [ { "type": "sub-group", + "exists": true, "ix": "1,2", "children": [ { @@ -176,10 +125,12 @@ hqDefine("cloudcare/js/form_entry/spec/fixtures", [ noQuestionGroupJSON: () => ({ "type": "sub-group", "ix": "2", + "exists": true, "children": [ { "type": "sub-group", "ix": "2,2", + "exists": true, "children": [], }, ], diff --git a/corehq/apps/cloudcare/static/cloudcare/js/form_entry/spec/form_ui_spec.js b/corehq/apps/cloudcare/static/cloudcare/js/form_entry/spec/form_ui_spec.js index 3192769d03ae..ac19e46f9f5e 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/form_entry/spec/form_ui_spec.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/form_entry/spec/form_ui_spec.js @@ -21,9 +21,7 @@ hqDefine("cloudcare/js/form_entry/spec/form_ui_spec", [ groupJSON, noQuestionGroupJSON, nestedGroupJSON, - spy, - repeatJSON, - repeatNestJSON; + spy; before(function () { initialPageData.register( @@ -42,10 +40,6 @@ hqDefine("cloudcare/js/form_entry/spec/form_ui_spec", [ beforeEach(function () { questionJSON = fixtures.selectJSON(); - repeatJSON = fixtures.repeatJSON(); - - repeatNestJSON = fixtures.repeatNestJSON(); - groupJSON = fixtures.groupJSON(); noQuestionGroupJSON = fixtures.noQuestionGroupJSON(); @@ -53,13 +47,14 @@ hqDefine("cloudcare/js/form_entry/spec/form_ui_spec", [ nestedGroupJSON = { tree: [groupJSON, noQuestionGroupJSON], seq_id: 1, + exists: true, session_id: '123', title: 'My title', langs: ['en'], }; formJSON = { - tree: [questionJSON, repeatJSON], + tree: [questionJSON, groupJSON], seq_id: 1, session_id: '123', title: 'My title', @@ -87,25 +82,6 @@ hqDefine("cloudcare/js/form_entry/spec/form_ui_spec", [ assert.equal(form.children().length, 1); }); - it('Should render a repeater question', function () { - formJSON.tree = [repeatJSON]; - var form = formUI.Form(formJSON); - assert.equal(form.children().length, 1); - assert.equal(form.children()[0].children()[0].children().length, 0); - - // Add new repeat - form.fromJS({ children: [repeatNestJSON] }); - assert.equal(form.children().length, 1); - // Each repeat is a group with questions - assert.equal(form.children()[0].children()[0].type(), constants.REPEAT_TYPE); - assert.equal(form.children()[0].children()[0].children().length, 1); - assert.equal(form.children()[0].children()[0].children()[0].type(), constants.GROUPED_ELEMENT_TILE_ROW_TYPE); - assert.equal(form.children()[0].children()[0].children()[0].children()[0].type(), constants.GROUP_TYPE); - assert.isTrue(form.children()[0].children()[0].children()[0].children()[0].isRepetition); - assert.equal(form.children()[0].children()[0].children()[0].children()[0].children()[0].type(), constants.GROUPED_ELEMENT_TILE_ROW_TYPE); - assert.equal(form.children()[0].children()[0].children()[0].children()[0].children()[0].children()[0].type(), constants.QUESTION_TYPE); - }); - it('Should render questions grouped by row', function () { let styleObj = {raw: '2-per-row'}; let q0 = fixtures.textJSON({ @@ -195,56 +171,6 @@ hqDefine("cloudcare/js/form_entry/spec/form_ui_spec", [ assert.equal(form.children()[0].children()[1].children()[0].children()[0].children()[1].children().length, 1); // [q] }); - it('Should add n-per-row style to Repeat that are direct children of n-per-row-repeat Group and group the Repeat', function () { - let styleObj = {raw: '2-per-row-repeat'}, - fakeStyleObj = {raw: "fake-style"}; - - let g0 = fixtures.groupJSON({ - style: styleObj, - ix: "0", - }), - r0 = fixtures.repeatJSON({ - style: fakeStyleObj, - }), - r1 = fixtures.repeatJSON(), - r2 = fixtures.repeatJSON(); - - r1.ix = "1J"; - r2.ix = "2J"; - g0.children.push(r0, r1, r2); - formJSON.tree = [g0]; - let form = formUI.Form(formJSON); - - /* -Group-Element-Tile-Row - -Group0 - -Group-Element-Tile-Row - -Group1 - -Group-Element-Tile-Row - -Question - -Group-Element-Tile-Row - -Question - -Group-Element-Tile-Row - -Repeat0 - -Repeat1 - -Group-Element-Tile-Row - -Repeat2 - */ - - // Expected structure (where ge signifies type "grouped-element-tile-row") - let group0 = form.children()[0].children()[0], - group1 = group0.children()[0].children()[0], - repeat0 = group0.children()[1].children()[0], - repeat1 = group0.children()[1].children()[1], - repeat2 = group0.children()[2].children()[0]; - assert.equal(form.children()[0].children().length, 1); // [group0] - assert.equal(group0.children().length, 3); // [ge, ge, ge] - assert.equal(group1.style, null); // [group] - assert.equal(group0.children()[1].children().length, 2); // [repeat0, repeat1] - assert.equal(repeat0.style.raw(), "fake-style 2-per-row"); - assert.equal(repeat1.style.raw(), "2-per-row"); - assert.equal(repeat2.style.raw(), "2-per-row"); - }); - it('Should calculate nested background header color', function () { let styleObj = {raw: 'group-collapse'}; let g0 = fixtures.groupJSON({ @@ -253,10 +179,12 @@ hqDefine("cloudcare/js/form_entry/spec/form_ui_spec", [ let g1 = fixtures.groupJSON({ style: styleObj, }); - let r1 = fixtures.repeatNestJSON(); + let g2 = fixtures.groupJSON({ + style: styleObj, + }); g1.children[0].style = styleObj; - r1.children[0].children[0].style = styleObj; - g1.children[0].children.push(r1); + g2.children[0].children[0].style = styleObj; + g1.children[0].children.push(g2); g0.children[0].children.push(g1); /* Group (collapsible) [g0] @@ -275,12 +203,12 @@ hqDefine("cloudcare/js/form_entry/spec/form_ui_spec", [ -Group-Element-Tile-Row -Question -Group-Element-Tile-Row - -Repeat [r1] + -Group (collapsible) [g2-0] -Group-Element-Tile-Row - - Group (collapsible) [r1-0] - -Group-Element-Tile-Row - -Question - */ + -Question + -Group-Element-Tile-Row + -Question + */ formJSON.tree = [g0]; let form = formUI.Form(formJSON); @@ -410,7 +338,7 @@ hqDefine("cloudcare/js/form_entry/spec/form_ui_spec", [ assert.isTrue(form.children()[0].children()[0].hasAnyNestedQuestions()); assert.isFalse(form.children()[1].children()[0].hasAnyNestedQuestions()); - groupJSON.children = [repeatJSON]; + groupJSON.children = [questionJSON]; formJSON.tree = [groupJSON]; let form2 = formUI.Form(formJSON); assert.isTrue(form2.children()[0].hasAnyNestedQuestions()); diff --git a/corehq/apps/cloudcare/static/cloudcare/js/form_entry/spec/utils_spec.js b/corehq/apps/cloudcare/static/cloudcare/js/form_entry/spec/utils_spec.js index 77824b60d1b6..2327d69f8ea7 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/form_entry/spec/utils_spec.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/form_entry/spec/utils_spec.js @@ -38,33 +38,30 @@ hqDefine("cloudcare/js/form_entry/spec/utils_spec", [ * grouped-element-tile-row * textInGroup * grouped-element-tile-row - * repeat + * repeat group * grouped-element-tile-row - * groupInRepeat - * grouped-element-tile-row - * textInRepeat + * textInRepeat */ initialPageData.register("toggles_dict", { WEB_APPS_ANCHORED_SUBMIT: false }); var text = fixtures.textJSON({ix: "0"}), textInGroup = fixtures.textJSON({ix: "1,0"}), group = fixtures.groupJSON({ix: "1", children: [textInGroup]}), - textInRepeat = fixtures.textJSON({ix: "2_0,0"}), - groupInRepeat = fixtures.groupJSON({ix: "2_0", children: [textInRepeat]}), - repeat = fixtures.repeatJSON({ix: "2", children: [groupInRepeat]}), + textInRepeatGroup = fixtures.textJSON({ix: "2,0"}), + repeatGroup = fixtures.groupJSON({ix: "2", children: [textInRepeatGroup], repeatable: "true"}), form = formUI.Form({ - tree: [text, group, repeat], + tree: [text, group, repeatGroup], }); - [text, group, repeat] = form.children().map(child => child.children()[0]); - [groupInRepeat] = repeat.children()[0].children(); - [textInRepeat] = groupInRepeat.children()[0].children(); - assert.equal(groupInRepeat.caption(), null); + [text, group, repeatGroup] = form.children().map(child => child.children()[0]); + [textInGroup] = group.children()[0].children(); + [textInRepeatGroup] = repeatGroup.children()[0].children(); assert.equal(utils.getRootForm(text), form); - assert.equal(utils.getRootForm(groupInRepeat), form); - assert.equal(utils.getRootForm(textInRepeat), form); + assert.equal(utils.getRootForm(group), form); + assert.equal(utils.getRootForm(textInGroup), form); assert.equal(utils.getBroadcastContainer(text), form); - assert.equal(utils.getBroadcastContainer(textInRepeat), groupInRepeat); + assert.equal(utils.getBroadcastContainer(textInGroup), form); + assert.equal(utils.getBroadcastContainer(textInRepeatGroup), repeatGroup); initialPageData.unregister("toggles_dict"); }); diff --git a/corehq/apps/cloudcare/static/cloudcare/js/form_entry/utils.js b/corehq/apps/cloudcare/static/cloudcare/js/form_entry/utils.js index 219f806c4b95..a47e8d31dc3e 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/form_entry/utils.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/form_entry/utils.js @@ -238,8 +238,14 @@ hqDefine("cloudcare/js/form_entry/utils", [ module.getBroadcastContainer = (question) => { return getRoot(question, function (container) { // Return first containing repeat group, or form if there are no ancestor repeats - var parent = container.parent.parent; - return parent && parent.type && parent.type() === formEntryConst.REPEAT_TYPE; + if (container) { + const pType = ko.utils.unwrapObservable(container.type); + const repeatable = ko.utils.unwrapObservable(container.repeatable); + return container && pType && pType === formEntryConst.GROUP_TYPE + && repeatable && repeatable === 'true'; + } + return false; + }); }; diff --git a/corehq/apps/cloudcare/static/cloudcare/js/form_entry/web_form_session.js b/corehq/apps/cloudcare/static/cloudcare/js/form_entry/web_form_session.js index f85d3cec8258..af3273a4bb6f 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/form_entry/web_form_session.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/form_entry/web_form_session.js @@ -456,32 +456,19 @@ hqDefine("cloudcare/js/form_entry/web_form_session", [ }; self.deleteRepeat = function (repetition) { - // USH-4332: after FP deploy keep only else clause - if (repetition.parent.parent instanceof formUI.Repeat) { - var juncture = formUI.getIx(repetition.parent.parent); - var repIx = +(repetition.rel_ix().replace(/_/g, ':').split(":").slice(-1)[0]); - this.serverRequest( - { - 'action': constants.DELETE_REPEAT, - 'ix': repIx, - 'form_ix': juncture, - }, - function (resp) { - $.publish('session.reconcile', [resp, repetition]); - }, - constants.BLOCK_ALL); - } else { - const juncture = formUI.getIx(repetition); - this.serverRequest( - { - 'action': constants.DELETE_REPEAT, - 'ix': juncture, - }, - function (resp) { - $.publish('session.reconcile', [resp, repetition, juncture]); - }, - constants.BLOCK_ALL); - } + const juncture = formUI.getIx(repetition); + const options = { + deletedGroup: juncture, + }; + this.serverRequest( + { + 'action': constants.DELETE_REPEAT, + 'ix': juncture, + }, + function (resp) { + $.publish('session.reconcile', [resp, repetition, options]); + }, + constants.BLOCK_ALL); }; self.changeLang = function (lang) { diff --git a/corehq/apps/cloudcare/templates/cloudcare/partials/bootstrap3/all_templates.html b/corehq/apps/cloudcare/templates/cloudcare/partials/bootstrap3/all_templates.html index 6da8b8b468d1..eb957163cf84 100644 --- a/corehq/apps/cloudcare/templates/cloudcare/partials/bootstrap3/all_templates.html +++ b/corehq/apps/cloudcare/templates/cloudcare/partials/bootstrap3/all_templates.html @@ -11,7 +11,6 @@ {% include 'cloudcare/partials/bootstrap3/debugger.html' %} -{% include 'cloudcare/partials/form_entry/bootstrap3/add_group.html' %} {% include 'cloudcare/partials/form_entry/entry_address.html' %} {% include 'cloudcare/partials/form_entry/entry_blank.html' %} {% include 'cloudcare/partials/form_entry/bootstrap3/entry_button.html' %} @@ -36,7 +35,6 @@ {% include 'cloudcare/partials/form_entry/bootstrap3/help_multimedia.html' %} {% include 'cloudcare/partials/form_entry/bootstrap3/multimedia.html' %} {% include 'cloudcare/partials/form_entry/bootstrap3/question.html' %} -{% include 'cloudcare/partials/form_entry/bootstrap3/repeat_juncture.html' %} {% include 'cloudcare/partials/form_entry/bootstrap3/sub_group.html' %} {% include 'cloudcare/partials/grid_view/bootstrap3/grid.html' %} diff --git a/corehq/apps/cloudcare/templates/cloudcare/partials/bootstrap5/all_templates.html b/corehq/apps/cloudcare/templates/cloudcare/partials/bootstrap5/all_templates.html index 5c7867a6329a..9ea031609179 100644 --- a/corehq/apps/cloudcare/templates/cloudcare/partials/bootstrap5/all_templates.html +++ b/corehq/apps/cloudcare/templates/cloudcare/partials/bootstrap5/all_templates.html @@ -11,7 +11,6 @@ {% include 'cloudcare/partials/bootstrap5/debugger.html' %} -{% include 'cloudcare/partials/form_entry/bootstrap5/add_group.html' %} {% include 'cloudcare/partials/form_entry/entry_address.html' %} {% include 'cloudcare/partials/form_entry/entry_blank.html' %} {% include 'cloudcare/partials/form_entry/bootstrap5/entry_button.html' %} @@ -36,7 +35,6 @@ {% include 'cloudcare/partials/form_entry/bootstrap5/help_multimedia.html' %} {% include 'cloudcare/partials/form_entry/bootstrap5/multimedia.html' %} {% include 'cloudcare/partials/form_entry/bootstrap5/question.html' %} -{% include 'cloudcare/partials/form_entry/bootstrap5/repeat_juncture.html' %} {% include 'cloudcare/partials/form_entry/bootstrap5/sub_group.html' %} {% include 'cloudcare/partials/grid_view/bootstrap5/grid.html' %} diff --git a/corehq/apps/cloudcare/templates/cloudcare/partials/form_entry/bootstrap3/add_group.html b/corehq/apps/cloudcare/templates/cloudcare/partials/form_entry/bootstrap3/add_group.html deleted file mode 100644 index bd865c5ffc94..000000000000 --- a/corehq/apps/cloudcare/templates/cloudcare/partials/form_entry/bootstrap3/add_group.html +++ /dev/null @@ -1,11 +0,0 @@ -{% load hq_shared_tags %} - - diff --git a/corehq/apps/cloudcare/templates/cloudcare/partials/form_entry/bootstrap3/repeat_juncture.html b/corehq/apps/cloudcare/templates/cloudcare/partials/form_entry/bootstrap3/repeat_juncture.html deleted file mode 100644 index d93c5f82f94d..000000000000 --- a/corehq/apps/cloudcare/templates/cloudcare/partials/form_entry/bootstrap3/repeat_juncture.html +++ /dev/null @@ -1,30 +0,0 @@ -{% load i18n %} -{% load hq_shared_tags %} - - diff --git a/corehq/apps/cloudcare/templates/cloudcare/partials/form_entry/bootstrap3/sub_group.html b/corehq/apps/cloudcare/templates/cloudcare/partials/form_entry/bootstrap3/sub_group.html index 1921862a72cb..0b20a0621aa8 100644 --- a/corehq/apps/cloudcare/templates/cloudcare/partials/form_entry/bootstrap3/sub_group.html +++ b/corehq/apps/cloudcare/templates/cloudcare/partials/form_entry/bootstrap3/sub_group.html @@ -2,13 +2,22 @@ {% load hq_shared_tags %} diff --git a/corehq/apps/cloudcare/templates/cloudcare/partials/form_entry/bootstrap5/add_group.html b/corehq/apps/cloudcare/templates/cloudcare/partials/form_entry/bootstrap5/add_group.html deleted file mode 100644 index b92e4fb4ba9d..000000000000 --- a/corehq/apps/cloudcare/templates/cloudcare/partials/form_entry/bootstrap5/add_group.html +++ /dev/null @@ -1,11 +0,0 @@ -{% load hq_shared_tags %} - - diff --git a/corehq/apps/cloudcare/templates/cloudcare/partials/form_entry/bootstrap5/repeat_juncture.html b/corehq/apps/cloudcare/templates/cloudcare/partials/form_entry/bootstrap5/repeat_juncture.html deleted file mode 100644 index ce9304fa68b6..000000000000 --- a/corehq/apps/cloudcare/templates/cloudcare/partials/form_entry/bootstrap5/repeat_juncture.html +++ /dev/null @@ -1,30 +0,0 @@ -{% load i18n %} -{% load hq_shared_tags %} - - diff --git a/corehq/apps/cloudcare/templates/cloudcare/partials/form_entry/bootstrap5/sub_group.html b/corehq/apps/cloudcare/templates/cloudcare/partials/form_entry/bootstrap5/sub_group.html index ef9b8e0bab83..5f5731248c1b 100644 --- a/corehq/apps/cloudcare/templates/cloudcare/partials/form_entry/bootstrap5/sub_group.html +++ b/corehq/apps/cloudcare/templates/cloudcare/partials/form_entry/bootstrap5/sub_group.html @@ -2,13 +2,22 @@ {% load hq_shared_tags %} diff --git a/corehq/apps/hqwebapp/tests/data/bootstrap5_diffs/cloudcare/partials/all_templates.html.diff.txt b/corehq/apps/hqwebapp/tests/data/bootstrap5_diffs/cloudcare/partials/all_templates.html.diff.txt index b2147549caa3..1264dfdac8b3 100644 --- a/corehq/apps/hqwebapp/tests/data/bootstrap5_diffs/cloudcare/partials/all_templates.html.diff.txt +++ b/corehq/apps/hqwebapp/tests/data/bootstrap5_diffs/cloudcare/partials/all_templates.html.diff.txt @@ -1,6 +1,6 @@ --- +++ -@@ -1,70 +1,70 @@ +@@ -1,68 +1,68 @@ -{% include 'cloudcare/partials/bootstrap3/case_detail.html' %} +{% include 'cloudcare/partials/bootstrap5/case_detail.html' %} @@ -20,8 +20,6 @@ -{% include 'cloudcare/partials/bootstrap3/debugger.html' %} +{% include 'cloudcare/partials/bootstrap5/debugger.html' %} --{% include 'cloudcare/partials/form_entry/bootstrap3/add_group.html' %} -+{% include 'cloudcare/partials/form_entry/bootstrap5/add_group.html' %} {% include 'cloudcare/partials/form_entry/entry_address.html' %} {% include 'cloudcare/partials/form_entry/entry_blank.html' %} -{% include 'cloudcare/partials/form_entry/bootstrap3/entry_button.html' %} @@ -63,13 +61,11 @@ -{% include 'cloudcare/partials/form_entry/bootstrap3/help_multimedia.html' %} -{% include 'cloudcare/partials/form_entry/bootstrap3/multimedia.html' %} -{% include 'cloudcare/partials/form_entry/bootstrap3/question.html' %} --{% include 'cloudcare/partials/form_entry/bootstrap3/repeat_juncture.html' %} -{% include 'cloudcare/partials/form_entry/bootstrap3/sub_group.html' %} +{% include 'cloudcare/partials/form_entry/bootstrap5/grouped_element_tile_row.html' %} +{% include 'cloudcare/partials/form_entry/bootstrap5/help_multimedia.html' %} +{% include 'cloudcare/partials/form_entry/bootstrap5/multimedia.html' %} +{% include 'cloudcare/partials/form_entry/bootstrap5/question.html' %} -+{% include 'cloudcare/partials/form_entry/bootstrap5/repeat_juncture.html' %} +{% include 'cloudcare/partials/form_entry/bootstrap5/sub_group.html' %} -{% include 'cloudcare/partials/grid_view/bootstrap3/grid.html' %} diff --git a/corehq/apps/hqwebapp/tests/data/bootstrap5_diffs/cloudcare/partials/form_entry/add_group.html.diff.txt b/corehq/apps/hqwebapp/tests/data/bootstrap5_diffs/cloudcare/partials/form_entry/add_group.html.diff.txt deleted file mode 100644 index 6e0d0855d200..000000000000 --- a/corehq/apps/hqwebapp/tests/data/bootstrap5_diffs/cloudcare/partials/form_entry/add_group.html.diff.txt +++ /dev/null @@ -1,13 +0,0 @@ ---- -+++ -@@ -1,8 +1,8 @@ - {% load hq_shared_tags %} - -