Skip to content

Commit

Permalink
Add support to set dialog handlers (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamPrestor authored Sep 20, 2023
1 parent 1ce7499 commit 913e6f3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions vue/dynamicforms/src/components/api_consumer/api-consumer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import RowTypes from '../table/definitions/row-types';
import { gettext } from '../util/translations-mixin';
import ComponentDisplay from './component-display';
import ConsumerLogicBase from './consumer-logic-base';
import FormConsumerBase from './form-consumer/base';
import { APIConsumer } from './namespace';
Expand All @@ -32,6 +33,7 @@ const props = defineProps<{
consumer: APIConsumer.ConsumerLogicBaseInterface | FormConsumerBase,
displayComponent: ComponentDisplay,
handlers?: IHandlers,
dialogHandlers?: IHandlers,
}>();
if (!ComponentDisplay.isDefined(props.displayComponent)) {
Expand Down Expand Up @@ -67,6 +69,10 @@ const renderComponentData = computed(() => {
const { handler } = useActionHandler();
if (props.consumer instanceof ConsumerLogicBase) {
(<APIConsumer.ConsumerLogicBaseInterface> props.consumer).setDialogHandlers(props.dialogHandlers);
}
async function actionDelete(actionData: Action, payload: FormPayload) {
const res = await dfModal.yesNo('Delete', gettext('Are you sure you want to delete this record?'));
if (res.action.name.toUpperCase() === 'YES') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class ConsumerLogicApi extends ConsumerLogicBase implements APIConsumer.Consumer
this.trailingSlash,
pk,
this.formData,
this.dialogHandlers,
);

await this.reload();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { IHandlers } from '../actions/action-handler-composable';
import FilteredActions from '../actions/filtered-actions';
import { ActionsNS } from '../actions/namespace';
import FormPayload from '../form/definitions/form-payload';
Expand Down Expand Up @@ -46,6 +47,8 @@ abstract class ConsumerLogicBase implements APIConsumer.ConsumerLogicBaseInterfa

protected titles: APIConsumer.Titles;

protected dialogHandlers?: IHandlers;

protected constructor() {
/**
* pkName specifies the primary key for the table. This field is expected to be unique and will be used to uniquely
Expand Down Expand Up @@ -99,6 +102,10 @@ abstract class ConsumerLogicBase implements APIConsumer.ConsumerLogicBaseInterfa
this.requestedPKValue : this.formData?.[this.pkName];
}

setDialogHandlers = (handlers?: IHandlers) => {
this.dialogHandlers = handlers;
};

/** @virtual */
processUXDefinition(UXDefinition: APIConsumer.TableUXDefinition): void {
/**
Expand Down
1 change: 1 addition & 0 deletions vue/dynamicforms/src/components/api_consumer/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export namespace APIConsumer {

export interface ConsumerLogicBaseInterface {
pkName: string;
setDialogHandlers(handlers?: IHandlers): void;
setOrdering(parameter: string, style: any | null, counter: number): void;
reload(filter: boolean): Promise<void>;
deleteRow(tableRow: FormPayload): Promise<void>;
Expand Down

0 comments on commit 913e6f3

Please sign in to comment.