AngularJS $ модал с обещанием внутри - PullRequest
0 голосов
/ 11 января 2019

так что у меня есть 2 модала, первый должен создать бронирование, и внутри него есть тот второй модал, который предназначен для добавления пользователя. Я сделал два мода, и один для пользователя работает, но теперь мне нужно передать данные от пользователя, добавившего модал к родителю (модал бронирования). Проблема в том, что я использую сервис внутри одного для добавления пользователя, поэтому он выглядит так:

$modal.open({
                        animation: true,
                        backdrop: true,
                        dialogFade: false,
                        keyboard: true,
                        templateUrl: 'templates/main/modals/modalCreateCustomer.html',
                        controller: function ($scope, $modalInstance) {
                            $scope.loading = false;
                            $scope.salutations = self.getSalutations({id: 1});
                            utilsManager.getCountries(function (countries) {
                                $scope.country = {
                                    availableOptions: countries,
                                    selectedOption: countries[79]
                                };
                            });
                            $scope.inlineAlert = {
                                type: "",
                                showDismissButton: true,
                                autoDismiss: true,
                                dismissTime: 5,
                                message: ""
                            };

                            $scope.ok = function () {
                                var data = {
                                    salutation: $scope.salutations.selectedOption.id,
                                    countryId: $scope.country.selectedOption.id,
                                    email: $scope.customer.email,
                                    fullName: $scope.customer.fullName,
                                    phone: $scope.customer.phone
                                };
                                authManager.registerUser(function (response) {
                                    if (!response || !response.errors || response.errors.length) {
                                        //general error
                                        $scope.loading = false;
                                        $scope.inlineAlert.showAlert('error', $translate.instant('registration.error'));
                                    } else {
                                        //$scope.customer.id = response.data.userId;
                                        $scope.loading = false;
                                        $scope.inlineAlert.showAlert('success', $translate.instant('registration.success'));
                                        $timeout(function () {
                                            $scope.customer.email = response.data.email;
                                            $modalInstance.close();
                                        }, 1500);
                                    }
                                }, data);
                            };

                            $scope.cancel = function () {
                                $modalInstance.dismiss('cancel');
                            };
                        }
                    }).result.then(function (data) {
                        $scope.loading = true;
                    });

Это пользовательский модал, который находится внутри модема addBooking. AuthManager выглядит так:

this.registerUser = function (callback, data) {
        restManager.jsonRequest(constants.get('httpMethods.post'), constants.get('login.register'), function (response) {
            if (callback) {
                callback(response);
            }
        }, data);
    };

Я понимаю, что модал не ждет ответа, но как мне заставить его ждать? Кроме того, я чувствую, что мой код - своего рода спагетти, поэтому любые предложения о том, как его лучше организовать, приветствуются. Спасибо!

...