// so the user can click or type to find values.
preloadLinkedValues?: boolean;
+ // Additional search conditions to include when constructing
+ // the query for a linked field's combobox
+ linkedSearchConditions?: {[field: string]: string};
+
// Directly override the required state of the field.
// This only has an affect if the value is true.
isRequired?: boolean;
}
if (fieldOptions.preloadLinkedValues || !selector) {
- return this.pcrud.retrieveAll(field.class, {}, {atomic : true})
+ const search = {};
+ const orderBy = {order_by: {}};
+ if (selector) {
+ orderBy.order_by[field.class] = selector;
+ }
+ const idField = this.idl.classes[field.class].pkey || 'id';
+ search[idField] = {'!=' : null};
+ if (fieldOptions.linkedSearchConditions) {
+ const conditions = {};
+ Object.keys(fieldOptions.linkedSearchConditions).forEach(key => {
+ conditions[key] = fieldOptions.linkedSearchConditions[key];
+ });
+ // ensure that the current value, if present, is included
+ // in case it doesn't otherwise meet the conditions
+ const linkedValue = this.record[field.name]();
+ if (linkedValue !== null && linkedValue !== undefined) {
+ search['-or'] = [];
+ const retrieveRec = {};
+ retrieveRec[idField] = linkedValue;
+ search['-or'].push(retrieveRec);
+ search['-or'].push(conditions);
+ } else {
+ // just tack on the conditions
+ Object.keys(conditions).forEach(key => {
+ search[key] = conditions[key];
+ });
+ }
+ }
+ return this.pcrud.search(field.class, search, orderBy, {atomic : true})
.toPromise().then(list => {
field.linkedValues =
this.flattenLinkedValues(field, list);
const idField = this.idl.classes[field.class].pkey || 'id';
search[selector] = {'ilike': `%${term}%`};
+ if (fieldOptions.linkedSearchConditions) {
+ Object.keys(fieldOptions.linkedSearchConditions).forEach(key => {
+ search[key] = fieldOptions.linkedSearchConditions[key];
+ });
+ }
orderBy.order_by[field.class] = selector;
return this.pcrud.search(field.class, search, orderBy)
<eg-grid-column [sortable]="true" path="create_date"></eg-grid-column>
</eg-grid>
-<eg-fm-record-editor #acpEditDialog idlClass="acp" hiddenFields="call_number,creator,create_date,editor,edit_time,loan_duration,fine_level,dummy_author,dummy_isbn,ref,floating,holdable,circ_as_type,active_date,mint_condition,cost,deleted,deposit,deposit_amount,circulate,status_changed_time,copy_number">
+<eg-fm-record-editor #acpEditDialog idlClass="acp" hiddenFields="call_number,creator,create_date,editor,edit_time,loan_duration,fine_level,dummy_author,dummy_isbn,ref,floating,holdable,circ_as_type,active_date,mint_condition,cost,deleted,deposit,deposit_amount,circulate,status_changed_time,copy_number"
+ [fieldOptions]="{status:{linkedSearchConditions:{'is_available':'t'},preloadLinkedValues:true}}">
</eg-fm-record-editor>
<eg-string #successString text="Updated succeeded!" i18n-text></eg-string>
<eg-string #updateFailedString text="Updated failed!" i18n-text></eg-string>