blob: 912dd31362bb2f8a4d7a8ec9f00597089aed2605 [file] [log] [blame]
Ed Tanous4758d5b2017-06-06 15:28:13 -07001/**
2 * AngularJS module that adds support for ui-bootstrap modal states when using ui-router.
3 *
4 * @link https://github.com/nonplus/angular-ui-router-uib-modal
5 *
6 * @license angular-ui-router-uib-modal v0.0.11
7 * (c) Copyright Stepan Riha <github@nonplus.net>
8 * License MIT
9 */
10
11(function(angular) {
12
13"use strict";
14angular.module("ui.router.modal", ["ui.router"])
15 .config(["$stateProvider", function ($stateProvider) {
16 var stateProviderState = $stateProvider.state;
17 $stateProvider["state"] = state;
18 function state(name, config) {
19 var stateName;
20 var options;
21 // check for $stateProvider.state({name: "state", ...}) usage
22 if (angular.isObject(name)) {
23 options = name;
24 stateName = options.name;
25 }
26 else {
27 options = config;
28 stateName = name;
29 }
30 if (options.modal) {
31 if (options.onEnter) {
32 throw new Error("Invalid modal state definition: The onEnter setting may not be specified.");
33 }
34 if (options.onExit) {
35 throw new Error("Invalid modal state definition: The onExit setting may not be specified.");
36 }
37 var openModal_1;
38 // Get modal.resolve keys from state.modal or state.resolve
39 var resolve_1 = (Array.isArray(options.modal) ? options.modal : []).concat(Object.keys(options.resolve || {}));
40 var inject_1 = ["$uibModal", "$state"];
41 options.onEnter = function ($uibModal, $state) {
42 // Add resolved values to modal options
43 if (resolve_1.length) {
44 options.resolve = {};
45 for (var i = 0; i < resolve_1.length; i++) {
46 options.resolve[resolve_1[i]] = injectedConstant(arguments[inject_1.length + i]);
47 }
48 }
49 var thisModal = openModal_1 = $uibModal.open(options);
50 openModal_1.result['finally'](function () {
51 if (thisModal === openModal_1) {
52 // Dialog was closed via $uibModalInstance.close/dismiss, go to our parent state
53 $state.go($state.get("^", stateName).name);
54 }
55 });
56 };
57 // Make sure that onEnter receives state.resolve configuration
58 options.onEnter["$inject"] = inject_1.concat(resolve_1);
59 options.onExit = function () {
60 if (openModal_1) {
61 // State has changed while dialog was open
62 openModal_1.close();
63 openModal_1 = null;
64 }
65 };
66 }
67 return stateProviderState.call($stateProvider, stateName, options);
68 }
69 }]);
70function injectedConstant(val) {
71 return [function () { return val; }];
72}
73
74
75})(window.angular);