summaryrefslogtreecommitdiffstats
path: root/static/js/angular-ui-router-uib-modal.js
blob: 912dd31362bb2f8a4d7a8ec9f00597089aed2605 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
 * AngularJS module that adds support for ui-bootstrap modal states when using ui-router.
 *
 * @link https://github.com/nonplus/angular-ui-router-uib-modal
 *
 * @license angular-ui-router-uib-modal v0.0.11
 * (c) Copyright Stepan Riha <github@nonplus.net>
 * License MIT
 */

(function(angular) {

"use strict";
angular.module("ui.router.modal", ["ui.router"])
    .config(["$stateProvider", function ($stateProvider) {
        var stateProviderState = $stateProvider.state;
        $stateProvider["state"] = state;
        function state(name, config) {
            var stateName;
            var options;
            // check for $stateProvider.state({name: "state", ...}) usage
            if (angular.isObject(name)) {
                options = name;
                stateName = options.name;
            }
            else {
                options = config;
                stateName = name;
            }
            if (options.modal) {
                if (options.onEnter) {
                    throw new Error("Invalid modal state definition: The onEnter setting may not be specified.");
                }
                if (options.onExit) {
                    throw new Error("Invalid modal state definition: The onExit setting may not be specified.");
                }
                var openModal_1;
                // Get modal.resolve keys from state.modal or state.resolve
                var resolve_1 = (Array.isArray(options.modal) ? options.modal : []).concat(Object.keys(options.resolve || {}));
                var inject_1 = ["$uibModal", "$state"];
                options.onEnter = function ($uibModal, $state) {
                    // Add resolved values to modal options
                    if (resolve_1.length) {
                        options.resolve = {};
                        for (var i = 0; i < resolve_1.length; i++) {
                            options.resolve[resolve_1[i]] = injectedConstant(arguments[inject_1.length + i]);
                        }
                    }
                    var thisModal = openModal_1 = $uibModal.open(options);
                    openModal_1.result['finally'](function () {
                        if (thisModal === openModal_1) {
                            // Dialog was closed via $uibModalInstance.close/dismiss, go to our parent state
                            $state.go($state.get("^", stateName).name);
                        }
                    });
                };
                // Make sure that onEnter receives state.resolve configuration
                options.onEnter["$inject"] = inject_1.concat(resolve_1);
                options.onExit = function () {
                    if (openModal_1) {
                        // State has changed while dialog was open
                        openModal_1.close();
                        openModal_1 = null;
                    }
                };
            }
            return stateProviderState.call($stateProvider, stateName, options);
        }
    }]);
function injectedConstant(val) {
    return [function () { return val; }];
}


})(window.angular);
OpenPOWER on IntegriCloud