<button class="btn btn-success" (click)="newAddr()" i18n>New Address</button>
+ <div class="alert alert-success p-2 m-3" i18n>Statistical Categories</div>
+
+ <div class="row pt-1 pb-1 mt-1" *ngFor="let stat of statCats">
+ <div class="col-lg-3 field-label">
+ <label for="asc-{{stat.cat.id()}}-input">{{stat.cat.name()}}</label>
+ </div>
+ <div class="col-lg-3">
+ <eg-combobox
+ domId="asc-{{stat.cat.id()}}-input"
+ name="asc-{{stat.cat.id()}}-input"
+ [entries]="stat.entries"
+ [allowFreeText]="stat.cat.allow_freetext() == 1"
+ [(ngModel)]="userStatCats[stat.cat.id()]"
+ (onChange)="userStatCatChange(stat.cat, $event)">
+ </eg-combobox>
+ </div>
+ </div>
+
+ <div class="alert alert-success p-2 m-3" i18n>Surveys</div>
+
+ <div class="row pt-1 pb-1 mt-1" *ngFor="let survey of surveys">
+ <div class="col-lg-3 field-label">
+ <label for="asv-{{survey.id()}}-input">{{survey.name()}}</label>
+ </div>
+ <div class="col-lg-3">
+ </div>
+
</div>
'UPDATE_PATRON_PRIMARY_CARD'
];
-const FLESH_PATRON_FIELDS = {
- flesh: 1,
- flesh_fields: {
- au: ['card', 'mailing_address', 'billing_address', 'addresses', 'settings']
- }
-};
-
interface StatCat {
cat: IdlObject;
entries: ComboboxEntry[];
@ViewChild('secondaryGroupsDialog')
private secondaryGroupsDialog: SecondaryGroupsDialogComponent;
+ autoId = -1;
patron: IdlObject;
changeHandlerNeeded = false;
nameTab = 'primary';
loading = false;
+ surveys: IdlObject[];
smsCarriers: ComboboxEntry[];
identTypes: ComboboxEntry[];
inetLevels: ComboboxEntry[];
orgSettings: {[name: string]: any} = {};
+ statCats: StatCat[] = [];
+ userStatCats: {[statId: number]: ComboboxEntry} = {};
userSettings: {[name: string]: any} = {};
userSettingTypes: {[name: string]: IdlObject} = {};
optInSettingTypes: {[name: string]: IdlObject} = {};
secondaryGroups: IdlObject[];
- statCats: StatCat[] = [];
expireDate: Date;
// All locations we have the specified permissions
load(): Promise<any> {
this.loading = true;
- return this.loadPatron()
+ return this.setStatCats()
+ .then(_ => this.setSurveys())
+ .then(_ => this.loadPatron())
.then(_ => this.getSecondaryGroups())
.then(_ => this.applyPerms())
.then(_ => this.setIdentTypes())
.then(_ => this.setInetLevels())
.then(_ => this.setOptInSettings())
.then(_ => this.setOrgSettings())
- .then(_ => this.setStatCats())
.then(_ => this.setSmsCarriers())
- .finally(() => this.loading = false);
+ .then(_ => this.loading = false);
+ }
+
+ setSurveys(): Promise<any> {
+ return this.patronService.getSurveys()
+ .then(surveys => this.surveys = surveys);
+ }
+
+ surveyQuestionAnswers(question: IdlObject): ComboboxEntry[] {
+ return question.answers().map(
+ a => ({id: a.id(), label: a.answer(), fm: a}));
}
setStatCats(): Promise<any> {
this.statCats = [];
return this.patronService.getStatCats().then(cats => {
cats.forEach(cat => {
- const entries = cat.entries.map(entry => {
- return {id: entry.id(), label: entry.value()};
- });
+ cat.id(Number(cat.id()));
+ cat.entries().forEach(entry => entry.id(Number(entry.id())));
+
+ const entries = cat.entries().map(entry =>
+ ({id: entry.id(), label: entry.value()}));
this.statCats.push({
cat: cat,
}
setOptInSettings(): Promise<any> {
-
const orgIds = this.org.ancestors(this.auth.user().ws_ou(), true);
const query = {
loadPatron(): Promise<any> {
if (this.patronId) {
- return this.patronService.getById(this.patronId, FLESH_PATRON_FIELDS)
+ return this.patronService.getFleshedById(this.patronId)
.then(patron => {
this.patron = patron;
this.absorbPatronData();
}
this.expireDate = new Date(this.patron.expire_date());
+
+ // stat_cat_entries() are entry maps under the covers.
+ this.patron.stat_cat_entries().forEach(map => {
+ const stat: StatCat = this.statCats.filter(
+ stat => stat.cat.id() === map.stat_cat())[0];
+ let cboxEntry: ComboboxEntry =
+ stat.entries.filter(e => e.label === map.stat_cat_entry())[0];
+
+ if (!cboxEntry) {
+ // If the applied value is not in the list of entries,
+ // create a freetext combobox entry for it.
+ cboxEntry = {
+ id: null,
+ freetext: true,
+ label: map.stat_cat_entry()
+ };
+
+ stat.entries.unshift(cboxEntry);
+ }
+
+ this.userStatCats[map.stat_cat()] = cboxEntry;
+ });
}
createNewPatron() {
return this.objectFromPath(path, index)[field]();
}
+
+ userStatCatChange(cat: IdlObject, entry: ComboboxEntry) {
+ // TODO: set dirty
+ // 2-way binding at work, no need to set the value
+ }
+
userSettingChange(name: string, value: any) {
// TODO: set dirty
this.userSettings[name] = value;
profileGroups: IdlObject[];
smsCarriers: IdlObject[];
statCats: IdlObject[];
+ surveys: IdlObject[];
constructor(
private net: NetService,
return this.pcrud.retrieve('au', id, pcrudOps).toPromise();
}
+
+ // Alternate retrieval method that uses the fleshed user API,
+ // which performs some additional data munging on the back end.
+ getFleshedById(id: number, fleshFields?: string[]): Promise<IdlObject> {
+ return this.net.request(
+ 'open-ils.actor',
+ 'open-ils.actor.user.fleshed.retrieve',
+ this.auth.token(), id, fleshFields).toPromise();
+ }
+
// Returns a name part (e.g. family_name) with preference for
// preferred name value where available.
namePart(patron: IdlObject, part: string): string {
'open-ils.circ.stat_cat.actor.retrieve.all',
this.auth.token(), this.auth.user().ws_ou()
).toPromise().then(cats => {
- cats = cats.sort((a, b) => a.name() < b.name() ? -1 : 1);
+ cats.sort((a, b) => a.name() < b.name() ? -1 : 1);
cats.forEach(cat => {
cat.entries(
cat.entries().sort((a,b) => a.value() < b.value() ? -1 : 1)
return cats;
});
}
+
+ getSurveys(): Promise<IdlObject[]> {
+ if (this.surveys) {
+ return Promise.resolve(this.surveys);
+ }
+
+ const orgIds = this.org.fullPath(this.auth.user().ws_ou(), true);
+
+ return this.pcrud.search('asv', {
+ owner: orgIds,
+ start_date: {'<=': 'now'},
+ end_date: {'>=': 'now'}
+ }, {
+ flesh: 2,
+ flesh_fields: {
+ asv: ['questions'],
+ asvq: ['answers']
+ }
+ },
+ {atomic : true}
+ ).toPromise().then(surveys => {
+ return this.surveys =
+ surveys.sort((s1, s2) => s1.name() < s2.name() ? -1 : 1);
+ });
+ }
}