Search code examples
aureliaaurelia-dialog

Determine if opened as dialog in prompt


I am developing an aurelia app. I have a component (which is a full-page component and is navigable) and also in another page, I want to use this component as a prompt to let user choose from that page. So I have written the code below to open it as intended:

selectTaskFromTree(callbackOrSuccess, failure) {
    const dialog = this.dialogService
      .open({ viewModel: PLATFORM.moduleName('features/view/tree/tree'), model: {}, lock: false });

    if (callbackOrSuccess) {
      if (failure) {
        dialog.whenClosed(response => {
          if (!response.wasCancelled) {
            callbackOrSuccess(response.output);
          } else {
            failure(response);
          }
        });
      }
      else{
        dialog.whenClosed(callbackOrSuccess);
      }
      return;
    }
    else{
      return dialog;
    }
  }

So the component Tree is now successfully loaded and shown. The problem is now how to determine if the TreeComponent is opened as a dialog or not.

The way I am thinking about is to pass an arbitrary param to it and if the param is true, the status is dialog and otherwise not dialog:

  const dialog = this.dialogService
      .open({ viewModel: PLATFORM.moduleName('features/view/tree/tree'), model: {isDialog: true}, lock: false });

But I think maybe there is also a better way to do this. For example to ask from DialogService if I am a dialog or not. So what are the other solutions and which one is better?


Solution

  • I have thought about different solutions and I was seeking for keeping coupling low and preventing define of new param. So I wrote the below code where I want to know if this component is opened as a dialog or not:

      attached() {
        this._isDialog = Boolean(this.dialogController.settings);
      }