search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Preventing move after answering cancel in the modal dialog

Asked by Naomi
5 months ago.

Hi,

I'm trying to ask a question in the modal dialog in the EventMove (I also tried in the EventMoved) and if I answer cancel, I'd like to prevent moving.

The problem is that it doesn't work. Perhaps the cancel from the modal happens too late? This is my current code - I added now preventDefault before calling the modal, but in this case my modal result will have no effect.

What can I do to resolve this problem?

if (data.masterbook > 0) {

                args.preventDefault();
                // Moving booking series should be handled differently
                const { Modal } = SW.serviceLoader;

                const confirmAction = `${Resource.getLabel(EResourceLabel.MOVE)} ${Resource.getLabel(EResourceLabel.SERIES)}`;

                const titleWarning = EResourceMessage.CONFIRM_ACTION_X_BOOKING_Y;

                const self = this;
                const modal = Modal.open({
                    scope: self.scope,
                    templateUrl: "app/templates/modals/confirmationModal",
                    controller($scope) {
                        $scope.okLabel = confirmAction;
                        $scope.cancelLabel = Resource.getLabel(EResourceLabel.CANCEL);
                        $scope.title = Resource.getMessage(titleWarning).format(confirmAction, data.booking_id);
                        $scope.message = Resource.getMessage(EResourceMessage.CONFIRM_MOVE_SERIES).format(args.newResource);
                        $scope.showSecondButton = true;
                        $scope.secondButtonLabel = Resource.getLabel(EResourceLabel.MOVE_SINGLE);
                    }
                });

                modal.result.then((type) => {
                    if (type === 1) {
                        self.logInfo("Moving Series");
                    } else {
                        self.logInfo("Moving Single");
                    }
                }, () => {
                    args.preventDefault();
                    self.logInfo("Cancel of the modal called");
                    //    self.scope.$apply();
                });
            }

Thanks in advance.

Answer posted by Naomi
5 months ago.

My colleague found a way:

if (data.masterbook > 0) {

                args.async = true;
                // Moving booking series should be handled differently
                const { Modal } = SW.serviceLoader;

                const confirmAction = `${Resource.getLabel(EResourceLabel.MOVE)} ${Resource.getLabel(EResourceLabel.SERIES)}`;

                const titleWarning = EResourceMessage.CONFIRM_ACTION_X_BOOKING_Y;

                const self = this;
                const modal = Modal.open({
                    scope: self.scope,
                    templateUrl: "app/templates/modals/confirmationModal",
                    controller($scope) {
                        $scope.okLabel = confirmAction;
                        $scope.cancelLabel = Resource.getLabel(EResourceLabel.CANCEL);
                        $scope.title = Resource.getMessage(titleWarning).format(confirmAction, data.booking_id);
                        $scope.message = Resource.getMessage(EResourceMessage.CONFIRM_MOVE_SERIES).format(self.getInstructorName(args.newResource));
                        $scope.showSecondButton = true;
                        $scope.secondButtonLabel = Resource.getLabel(EResourceLabel.MOVE_SINGLE);
                    }
                });

                modal.result.then((type) => {
                    if (type === 1) {                        
                        self.needToMoveSeries = true;
                        args.loaded();
                    } else {                        
                        self.needToMoveSeries = false;
                        args.loaded();
                    }
                }, () => {
                    args.preventDefault();
                    args.loaded();
                });
            }

E.g. using args.async = true;

and also using args.loaded;

This question is more than 3 months old and has been closed. Please create a new question if you have anything to add.