Skip to content

Commit

Permalink
Merge branch 'bmb/remove-unused-datatables-extensions' of github.com:…
Browse files Browse the repository at this point in the history
…dimagi/commcare-hq into bmb/b5-styleguide
  • Loading branch information
biyeun committed Nov 21, 2023
2 parents e7e32c0 + de5e7cb commit 92c1579
Show file tree
Hide file tree
Showing 19 changed files with 307 additions and 181 deletions.
61 changes: 1 addition & 60 deletions corehq/apps/cloudcare/static/cloudcare/js/form_entry/entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,6 @@ hqDefine("cloudcare/js/form_entry/entries", function () {
return null;
};

self.helpText = function () {
if (isPassword) {
return gettext('Password');
}
switch (self.datatype) {
case constants.BARCODE:
return gettext('Barcode');
default:
return gettext('Free response');
}
};
self.enableReceiver(question, options);
}
FreeTextEntry.prototype = Object.create(EntrySingleAnswer.prototype);
Expand Down Expand Up @@ -302,7 +291,7 @@ hqDefine("cloudcare/js/form_entry/entries", function () {
divId: self.entryId,
itemCallback: self.geocoderItemCallback,
clearCallBack: self.geocoderOnClearCallback,
inputOnKeyDown: self._inputOnKeyDown
inputOnKeyDown: self._inputOnKeyDown,
});
};

Expand Down Expand Up @@ -338,10 +327,6 @@ hqDefine("cloudcare/js/form_entry/entries", function () {
return null;
};

self.helpText = function () {
return gettext('Number');
};

self.enableReceiver(question, options);
}
IntEntry.prototype = Object.create(FreeTextEntry.prototype);
Expand Down Expand Up @@ -370,10 +355,6 @@ hqDefine("cloudcare/js/form_entry/entries", function () {
return (!(/^[+-]?\d*(\.\d+)?$/.test(rawAnswer)) ? "This does not appear to be a valid phone/numeric number" : null);
};

this.helpText = function () {
return gettext('Phone number or Numeric ID');
};

this.enableReceiver(question, options);
}
PhoneEntry.prototype = Object.create(FreeTextEntry.prototype);
Expand All @@ -398,10 +379,6 @@ hqDefine("cloudcare/js/form_entry/entries", function () {
}
return null;
};

this.helpText = function () {
return gettext('Decimal');
};
}
FloatEntry.prototype = Object.create(IntEntry.prototype);
FloatEntry.prototype.constructor = IntEntry;
Expand Down Expand Up @@ -459,10 +436,6 @@ hqDefine("cloudcare/js/form_entry/entries", function () {
self.templateType = 'multidropdown';
self.placeholderText = gettext('Please choose an item');

self.helpText = function () {
return "";
};

self.afterRender = function () {
select2ify(self, {});
};
Expand Down Expand Up @@ -569,10 +542,6 @@ hqDefine("cloudcare/js/form_entry/entries", function () {
self.templateType = 'dropdown';
self.placeholderText = gettext('Please choose an item');

self.helpText = function () {
return "";
};

self.options = ko.computed(function () {
return [{text: "", id: undefined}].concat(_.map(question.choices(), function (choice, idx) {
return {
Expand Down Expand Up @@ -618,10 +587,6 @@ hqDefine("cloudcare/js/form_entry/entries", function () {
// Specifies the type of matching we will do when a user types a query
self.matchType = options.matchType;

self.helpText = function () {
return gettext('Combobox');
};

self.additionalSelect2Options = function () {
return {
matcher: function (params, option) {
Expand Down Expand Up @@ -791,16 +756,11 @@ hqDefine("cloudcare/js/form_entry/entries", function () {

function TimeEntry(question, options) {
this.templateType = 'time';
let is12Hour = false;
if (question.style) {
if (question.stylesContains(constants.TIME_12_HOUR)) {
this.clientFormat = 'h:mm a';
is12Hour = true;
}
}
this.helpText = function () {
return is12Hour ? gettext("12-hour clock") : gettext("24-hour clock");
};
DateTimeEntryBase.call(this, question, options);
}
TimeEntry.prototype = Object.create(DateTimeEntryBase.prototype);
Expand Down Expand Up @@ -965,11 +925,6 @@ hqDefine("cloudcare/js/form_entry/entries", function () {
var self = this;
FileEntry.call(this, question, options);
self.accept = "image/*,.pdf";

self.helpText = function () {
return gettext("Upload image");
};

}
ImageEntry.prototype = Object.create(FileEntry.prototype);
ImageEntry.prototype.constructor = FileEntry;
Expand All @@ -981,11 +936,6 @@ hqDefine("cloudcare/js/form_entry/entries", function () {
var self = this;
FileEntry.call(this, question, options);
self.accept = "audio/*";

self.helpText = function () {
return gettext("Upload audio file");
};

}
AudioEntry.prototype = Object.create(FileEntry.prototype);
AudioEntry.prototype.constructor = FileEntry;
Expand All @@ -997,11 +947,6 @@ hqDefine("cloudcare/js/form_entry/entries", function () {
var self = this;
FileEntry.call(this, question, options);
self.accept = "video/*";

self.helpText = function () {
return gettext("Upload video file");
};

}
VideoEntry.prototype = Object.create(FileEntry.prototype);
VideoEntry.prototype.constructor = FileEntry;
Expand Down Expand Up @@ -1052,10 +997,6 @@ hqDefine("cloudcare/js/form_entry/entries", function () {
self.$canvas[0].width = width;
self.$canvas[0].height = width / aspectRatio;
};

self.helpText = function () {
return gettext("Draw signature");
};
}
SignatureEntry.prototype = Object.create(FileEntry.prototype);
SignatureEntry.prototype.constructor = FileEntry;
Expand Down
37 changes: 37 additions & 0 deletions corehq/apps/cloudcare/static/cloudcare/js/form_entry/form_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,36 @@ hqDefine("cloudcare/js/form_entry/form_ui", function () {
ko.mapping.fromJS(json, mapping, self);
};

/**
* Calculates background color for nested Group and Repeat headers.
* Recursively determines nesting level (considering only Group and Repeat),
* starting at 0 for the Form level and cycling colors for each level.
*
* @returns {string} - Background color for the header's nesting level.
*/
Container.prototype.headerBackgroundColor = function () {
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) {
nestedDepthCount += 1;
}
currentNode = currentNode.parent;
}

// Colors are ordered from lightest to darkest with the lightest color for the highest level.
// Colors are based on Bootstrap provided tint/shades of #5D70D2 (CommCare Cornflower Blue)
// tint(#5D70D2, 20%): #7d8ddb
// shade(#5D70D2, 20%): #4a5aa8
// shade(#5D70D2, 40%): #38437e
const repeatColor = ["#7d8ddb", "#4a5aa8", "#38437e"];
const repeatColorCount = repeatColor.length;
const index = (nestedDepthCount - 1) % repeatColorCount;

return repeatColor[index];
};

/**
* Recursively groups sequential "question" items in a nested JSON structure.
*
Expand Down Expand Up @@ -602,6 +632,13 @@ hqDefine("cloudcare/js/form_entry/form_ui", function () {
const hasLabel = !!ko.utils.unwrapObservable(self.caption_markdown) || !!self.caption();
return hasChildren && hasLabel;
};

self.headerBackgroundColor = function () {
if (self.isRepetition || !self.collapsible) {
return '';
}
return Container.prototype.headerBackgroundColor.call(self);
};
}
Group.prototype = Object.create(Container.prototype);
Group.prototype.constructor = Container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,43 @@ hqDefine("cloudcare/js/form_entry/spec/form_ui_spec", function () {
assert.equal(form.children()[3].children().length, 1); // [q3]
});

it('Should calculate nested background header color', function () {
let styleObj = {raw: 'group-collapse'};
let g0 = fixtures.groupJSON({
style: styleObj,
});
let g1 = fixtures.groupJSON({
style: styleObj,
});
let r1 = fixtures.repeatNestJSON();
g1.children[0].style = styleObj;
r1.children[0].style = styleObj;
g1.children[0].children.push(r1);
g0.children[0].children.push(g1);

/* Group (collapsible) [g0]
-Group [g0-0]
-Question
-Question
-Group (collapsible) [g1]
-Group (collapsible) [g1-0]
-Question
-Question
-Repeat [r1]
- Group (collapsible) [r1-0]
-Question
*/
formJSON.tree = [g0];
let form = formUI.Form(formJSON);

assert.equal(form.children()[0].headerBackgroundColor(), '#7d8ddb'); //[g0]
assert.equal(form.children()[0].children()[0].headerBackgroundColor(), ''); //[g0-0]
assert.equal(form.children()[0].children()[0].children()[2].headerBackgroundColor(), '#4a5aa8'); //[g1]
assert.equal(form.children()[0].children()[0].children()[2].children()[0].headerBackgroundColor(), '#38437e'); //[g1-0]
assert.equal(form.children()[0].children()[0].children()[2].children()[0].children()[2].headerBackgroundColor(), '#7d8ddb'); //[r1]
assert.equal(form.children()[0].children()[0].children()[2].children()[0].children()[2].children()[0].headerBackgroundColor(), ''); //[r1-0]
});

it('Should reconcile question choices', function () {
formJSON.tree = [questionJSON];
var form = formUI.Form(formJSON),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,12 +535,14 @@ hqDefine("cloudcare/js/formplayer/menus/views", function () {
casesPerPageLimit: '.per-page-limit',
searchMoreButton: '#search-more',
scrollToBottomButton: '#scroll-to-bottom',
mapShowHideButton: '#hide-map-button',
};
};

const CaseListViewEvents = function () {
return {
'click @ui.actionButton': 'caseListAction',
'click @ui.mapShowHideButton': 'showHideMap',
'click @ui.searchButton': 'caseListSearch',
'click @ui.paginators': 'paginateAction',
'click @ui.paginationGoButton': 'paginationGoAction',
Expand Down Expand Up @@ -701,6 +703,24 @@ hqDefine("cloudcare/js/formplayer/menus/views", function () {
}
},

showHideMap: function (e) {
const mapDiv = $('#module-case-list-map');
const moduleCaseList = $('#module-case-list');
const hideButton = $('#hide-map-button');
if (!mapDiv.hasClass('hide')) {
mapDiv.addClass('hide');
moduleCaseList.removeClass('col-md-7 col-md-pull-5').addClass('col-md');
hideButton.text(gettext('Show Map'));
$(e.target).attr('aria-expanded', 'false');
} else {
mapDiv.removeClass('hide');
moduleCaseList.addClass('col-md-7 col-md-pull-5').removeClass('col-md');
hideButton.text(gettext('Hide Map'));
$(e.target).attr('aria-expanded', 'true');
}

},

_allCaseIds: function () {
const caseIds = [];
this.children.each(function (childView) {
Expand Down
Loading

0 comments on commit 92c1579

Please sign in to comment.