1

I am trying to set a dialog to busy using setBusy() but its not working in my controller. I use setBusy() in chrome develper tools console and it works fine. I also get an error when I try clicking the dialog twice. This is the error message:

XMLTemplateProcessor-dbg.js:98 Uncaught Error: Error: adding element with duplicate id 'inactivedialog'
    at onDuplicate (Element-dbg.js:169)
    at f.register (ManagedObjectRegistry-dbg.js:44)
    at ManagedObject-dbg.js:528
    at f.constructor (ManagedObject-dbg.js:558)
    at f.constructor (Element-dbg.js:151)
    at f.constructor (Control-dbg.js:172)
    at new f (Metadata-dbg.js:463)
    at a1 (XMLTemplateProcessor-dbg.js:1063)
    at XMLTemplateProcessor-dbg.js:1070
    at SyncPromise-dbg.js:308

Here is my code in controller.

var oView = this.getView();
Fragment.load({
        name: "ariba.so.kaakbatransfer.view.InactiveEmployee",
        controller: this
  }).then(function (oDialog) {
        oView.addDependent(oDialog);
        oDialog.open();
  }.bind(this));
var inactiveDialog = sap.ui.getCore().byId("inactivedialog");
inactiveDialog.setBusy(true);
$.ajax({
    url: "private",
    type: "GET",
    contentType: "application/json",
    success: function (data) {
        this.setModel(new JSONModel(data), "inactiveemployee");
    }.bind(this),
    error: function (e) {
        var bCompact = 
        !!this.getView().$().closest(".sapUiSizeCompact").length;
        MessageBox.error(
            "Data error. Please correct and try again. Refresh the page, if needed.", {
            styleClass: bCompact ? "sapUiSizeCompact" : ""}
         );
     } 
});
inactiveDialog.setBusy(false);

Here is my code for the fragment.

<core:FragmentDefinition id="inactivefragment" xmlns="sap.m" xmlns:core="sap.ui.core">
    <SelectDialog id = "inactivedialog" noDataText="No Employees Found" title="Select Employee" search="handleSearch" confirm="InactiveEmployeeClose"
        cancel="InactiveEmployeeClose" showClearButton="false"
        items="{path :'private', sorter:{ path : 'name', descending : false }}">
        <StandardListItem title="{private}" info="{private}" type="Active"/>
    </SelectDialog>
</core:FragmentDefinition>

The inactivedialog should be busy while the ajax call runs. I should be able to do this in the controller.

kingofjong
  • 175
  • 2
  • 14

1 Answers1

0

For the error with the duplicat ID:

When you first click the button it adds the Fragement (with its ID which should be unique) to the view. When you click the button again it tries to do it again, but the ID already exists. To prevent this check if your Fragment does already exist:

   onBtnPress: function (oEvent) {
       var oEventSource = oEvent.getSource();
       if (!this._oPopover) {
            // Fragment does not yet exist, load and then open it
            Fragment.load({
                name: "com.namespace.view.CancelPopover",
                controller: this
            }).then(function (oPopover) {
                // Persist reference to the fragment
                this._oPopover = oPopover;
                this.getView().addDependent(this._oPopover);
                this._oPopover.openBy(oEventSource);
            }.bind(this));
        } else {
            // Fragment does already exist, open it
            this._oPopover.openBy(oEventSource);
        }
   }

For busy not working:

You are using

var inactiveDialog = sap.ui.getCore().byId("inactivedialog");

wich is not working, look here.

Lumpenstein
  • 1,250
  • 1
  • 10
  • 27