Skip to content

Instantly share code, notes, and snippets.

@blemaire
Created October 20, 2015 07:42
Show Gist options
  • Select an option

  • Save blemaire/f28d87ef4eed9c0a46d5 to your computer and use it in GitHub Desktop.

Select an option

Save blemaire/f28d87ef4eed9c0a46d5 to your computer and use it in GitHub Desktop.
function makeTreeView() {
var officesWithNegs = [];
var officeCodesWithNegCodes = UserEnvironment.lookups.officeNegotiators;
var office;
for (var key in officeCodesWithNegCodes) {
// Initialise this office
office = {
negs: buildOfficeNegotiators()
};
// Extra data when possible
if (officeCodesWithNegCodes.hasOwnProperty(key)) {
office.code = key;
office.selected = false;
office.name = negPickerModal.offices[key];
}
// Push onto main array
officesWithNegs.push(office);
}
// This builds an array of negs, the implementation is concealed here as the
// calling function does not need to know how to do this.
function buildOfficeNegotiators() {
var previouslySelectedNeg = false;
return officeCodesWithNegCodes[key].reduce(formatNeg, []);
function formatNeg(negArray, neg) {
var newNeg = {
code: neg,
name: negPickerModal.negs[neg],
officeCode: office.code,
selected: false
};
if (!previouslySelectedNeg && negPickerModal.defaultCodes.indexOf(neg) >= 0) {
newNeg.selected = true;
selectedNegs[newNeg.code] = newNeg;
// limit selected neg to one
if (negPickerModal.single) {
previouslySelectedNeg = newNeg;
}
}
negArray.negs.push(newNeg);
}
}
return officesWithNegs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment