@@ 4036-4186 (lines=151) @@ | ||
4033 | return $modalStack; |
|
4034 | }]) |
|
4035 | ||
4036 | .provider('$uibModal', function() { |
|
4037 | var $modalProvider = { |
|
4038 | options: { |
|
4039 | animation: true, |
|
4040 | backdrop: true, //can also be false or 'static' |
|
4041 | keyboard: true |
|
4042 | }, |
|
4043 | $get: ['$rootScope', '$q', '$document', '$templateRequest', '$controller', '$uibResolve', '$uibModalStack', |
|
4044 | function ($rootScope, $q, $document, $templateRequest, $controller, $uibResolve, $modalStack) { |
|
4045 | var $modal = {}; |
|
4046 | ||
4047 | function getTemplatePromise(options) { |
|
4048 | return options.template ? $q.when(options.template) : |
|
4049 | $templateRequest(angular.isFunction(options.templateUrl) ? |
|
4050 | options.templateUrl() : options.templateUrl); |
|
4051 | } |
|
4052 | ||
4053 | var promiseChain = null; |
|
4054 | $modal.getPromiseChain = function() { |
|
4055 | return promiseChain; |
|
4056 | }; |
|
4057 | ||
4058 | $modal.open = function(modalOptions) { |
|
4059 | var modalResultDeferred = $q.defer(); |
|
4060 | var modalOpenedDeferred = $q.defer(); |
|
4061 | var modalClosedDeferred = $q.defer(); |
|
4062 | var modalRenderDeferred = $q.defer(); |
|
4063 | ||
4064 | //prepare an instance of a modal to be injected into controllers and returned to a caller |
|
4065 | var modalInstance = { |
|
4066 | result: modalResultDeferred.promise, |
|
4067 | opened: modalOpenedDeferred.promise, |
|
4068 | closed: modalClosedDeferred.promise, |
|
4069 | rendered: modalRenderDeferred.promise, |
|
4070 | close: function (result) { |
|
4071 | return $modalStack.close(modalInstance, result); |
|
4072 | }, |
|
4073 | dismiss: function (reason) { |
|
4074 | return $modalStack.dismiss(modalInstance, reason); |
|
4075 | } |
|
4076 | }; |
|
4077 | ||
4078 | //merge and clean up options |
|
4079 | modalOptions = angular.extend({}, $modalProvider.options, modalOptions); |
|
4080 | modalOptions.resolve = modalOptions.resolve || {}; |
|
4081 | modalOptions.appendTo = modalOptions.appendTo || $document.find('body').eq(0); |
|
4082 | ||
4083 | //verify options |
|
4084 | if (!modalOptions.template && !modalOptions.templateUrl) { |
|
4085 | throw new Error('One of template or templateUrl options is required.'); |
|
4086 | } |
|
4087 | ||
4088 | var templateAndResolvePromise = |
|
4089 | $q.all([getTemplatePromise(modalOptions), $uibResolve.resolve(modalOptions.resolve, {}, null, null)]); |
|
4090 | ||
4091 | function resolveWithTemplate() { |
|
4092 | return templateAndResolvePromise; |
|
4093 | } |
|
4094 | ||
4095 | // Wait for the resolution of the existing promise chain. |
|
4096 | // Then switch to our own combined promise dependency (regardless of how the previous modal fared). |
|
4097 | // Then add to $modalStack and resolve opened. |
|
4098 | // Finally clean up the chain variable if no subsequent modal has overwritten it. |
|
4099 | var samePromise; |
|
4100 | samePromise = promiseChain = $q.all([promiseChain]) |
|
4101 | .then(resolveWithTemplate, resolveWithTemplate) |
|
4102 | .then(function resolveSuccess(tplAndVars) { |
|
4103 | var providedScope = modalOptions.scope || $rootScope; |
|
4104 | ||
4105 | var modalScope = providedScope.$new(); |
|
4106 | modalScope.$close = modalInstance.close; |
|
4107 | modalScope.$dismiss = modalInstance.dismiss; |
|
4108 | ||
4109 | modalScope.$on('$destroy', function() { |
|
4110 | if (!modalScope.$$uibDestructionScheduled) { |
|
4111 | modalScope.$dismiss('$uibUnscheduledDestruction'); |
|
4112 | } |
|
4113 | }); |
|
4114 | ||
4115 | var ctrlInstance, ctrlInstantiate, ctrlLocals = {}; |
|
4116 | ||
4117 | //controllers |
|
4118 | if (modalOptions.controller) { |
|
4119 | ctrlLocals.$scope = modalScope; |
|
4120 | ctrlLocals.$uibModalInstance = modalInstance; |
|
4121 | angular.forEach(tplAndVars[1], function(value, key) { |
|
4122 | ctrlLocals[key] = value; |
|
4123 | }); |
|
4124 | ||
4125 | // the third param will make the controller instantiate later,private api |
|
4126 | // @see https://github.com/angular/angular.js/blob/master/src/ng/controller.js#L126 |
|
4127 | ctrlInstantiate = $controller(modalOptions.controller, ctrlLocals, true); |
|
4128 | if (modalOptions.controllerAs) { |
|
4129 | ctrlInstance = ctrlInstantiate.instance; |
|
4130 | ||
4131 | if (modalOptions.bindToController) { |
|
4132 | ctrlInstance.$close = modalScope.$close; |
|
4133 | ctrlInstance.$dismiss = modalScope.$dismiss; |
|
4134 | angular.extend(ctrlInstance, providedScope); |
|
4135 | } |
|
4136 | ||
4137 | ctrlInstance = ctrlInstantiate(); |
|
4138 | ||
4139 | modalScope[modalOptions.controllerAs] = ctrlInstance; |
|
4140 | } else { |
|
4141 | ctrlInstance = ctrlInstantiate(); |
|
4142 | } |
|
4143 | ||
4144 | if (angular.isFunction(ctrlInstance.$onInit)) { |
|
4145 | ctrlInstance.$onInit(); |
|
4146 | } |
|
4147 | } |
|
4148 | ||
4149 | $modalStack.open(modalInstance, { |
|
4150 | scope: modalScope, |
|
4151 | deferred: modalResultDeferred, |
|
4152 | renderDeferred: modalRenderDeferred, |
|
4153 | closedDeferred: modalClosedDeferred, |
|
4154 | content: tplAndVars[0], |
|
4155 | animation: modalOptions.animation, |
|
4156 | backdrop: modalOptions.backdrop, |
|
4157 | keyboard: modalOptions.keyboard, |
|
4158 | backdropClass: modalOptions.backdropClass, |
|
4159 | windowTopClass: modalOptions.windowTopClass, |
|
4160 | windowClass: modalOptions.windowClass, |
|
4161 | windowTemplateUrl: modalOptions.windowTemplateUrl, |
|
4162 | size: modalOptions.size, |
|
4163 | openedClass: modalOptions.openedClass, |
|
4164 | appendTo: modalOptions.appendTo |
|
4165 | }); |
|
4166 | modalOpenedDeferred.resolve(true); |
|
4167 | ||
4168 | }, function resolveError(reason) { |
|
4169 | modalOpenedDeferred.reject(reason); |
|
4170 | modalResultDeferred.reject(reason); |
|
4171 | })['finally'](function() { |
|
4172 | if (promiseChain === samePromise) { |
|
4173 | promiseChain = null; |
|
4174 | } |
|
4175 | }); |
|
4176 | ||
4177 | return modalInstance; |
|
4178 | }; |
|
4179 | ||
4180 | return $modal; |
|
4181 | } |
|
4182 | ] |
|
4183 | }; |
|
4184 | ||
4185 | return $modalProvider; |
|
4186 | }); |
|
4187 | ||
4188 | angular.module('ui.bootstrap.paging', []) |
|
4189 | /** |
@@ 4035-4185 (lines=151) @@ | ||
4032 | return $modalStack; |
|
4033 | }]) |
|
4034 | ||
4035 | .provider('$uibModal', function() { |
|
4036 | var $modalProvider = { |
|
4037 | options: { |
|
4038 | animation: true, |
|
4039 | backdrop: true, //can also be false or 'static' |
|
4040 | keyboard: true |
|
4041 | }, |
|
4042 | $get: ['$rootScope', '$q', '$document', '$templateRequest', '$controller', '$uibResolve', '$uibModalStack', |
|
4043 | function ($rootScope, $q, $document, $templateRequest, $controller, $uibResolve, $modalStack) { |
|
4044 | var $modal = {}; |
|
4045 | ||
4046 | function getTemplatePromise(options) { |
|
4047 | return options.template ? $q.when(options.template) : |
|
4048 | $templateRequest(angular.isFunction(options.templateUrl) ? |
|
4049 | options.templateUrl() : options.templateUrl); |
|
4050 | } |
|
4051 | ||
4052 | var promiseChain = null; |
|
4053 | $modal.getPromiseChain = function() { |
|
4054 | return promiseChain; |
|
4055 | }; |
|
4056 | ||
4057 | $modal.open = function(modalOptions) { |
|
4058 | var modalResultDeferred = $q.defer(); |
|
4059 | var modalOpenedDeferred = $q.defer(); |
|
4060 | var modalClosedDeferred = $q.defer(); |
|
4061 | var modalRenderDeferred = $q.defer(); |
|
4062 | ||
4063 | //prepare an instance of a modal to be injected into controllers and returned to a caller |
|
4064 | var modalInstance = { |
|
4065 | result: modalResultDeferred.promise, |
|
4066 | opened: modalOpenedDeferred.promise, |
|
4067 | closed: modalClosedDeferred.promise, |
|
4068 | rendered: modalRenderDeferred.promise, |
|
4069 | close: function (result) { |
|
4070 | return $modalStack.close(modalInstance, result); |
|
4071 | }, |
|
4072 | dismiss: function (reason) { |
|
4073 | return $modalStack.dismiss(modalInstance, reason); |
|
4074 | } |
|
4075 | }; |
|
4076 | ||
4077 | //merge and clean up options |
|
4078 | modalOptions = angular.extend({}, $modalProvider.options, modalOptions); |
|
4079 | modalOptions.resolve = modalOptions.resolve || {}; |
|
4080 | modalOptions.appendTo = modalOptions.appendTo || $document.find('body').eq(0); |
|
4081 | ||
4082 | //verify options |
|
4083 | if (!modalOptions.template && !modalOptions.templateUrl) { |
|
4084 | throw new Error('One of template or templateUrl options is required.'); |
|
4085 | } |
|
4086 | ||
4087 | var templateAndResolvePromise = |
|
4088 | $q.all([getTemplatePromise(modalOptions), $uibResolve.resolve(modalOptions.resolve, {}, null, null)]); |
|
4089 | ||
4090 | function resolveWithTemplate() { |
|
4091 | return templateAndResolvePromise; |
|
4092 | } |
|
4093 | ||
4094 | // Wait for the resolution of the existing promise chain. |
|
4095 | // Then switch to our own combined promise dependency (regardless of how the previous modal fared). |
|
4096 | // Then add to $modalStack and resolve opened. |
|
4097 | // Finally clean up the chain variable if no subsequent modal has overwritten it. |
|
4098 | var samePromise; |
|
4099 | samePromise = promiseChain = $q.all([promiseChain]) |
|
4100 | .then(resolveWithTemplate, resolveWithTemplate) |
|
4101 | .then(function resolveSuccess(tplAndVars) { |
|
4102 | var providedScope = modalOptions.scope || $rootScope; |
|
4103 | ||
4104 | var modalScope = providedScope.$new(); |
|
4105 | modalScope.$close = modalInstance.close; |
|
4106 | modalScope.$dismiss = modalInstance.dismiss; |
|
4107 | ||
4108 | modalScope.$on('$destroy', function() { |
|
4109 | if (!modalScope.$$uibDestructionScheduled) { |
|
4110 | modalScope.$dismiss('$uibUnscheduledDestruction'); |
|
4111 | } |
|
4112 | }); |
|
4113 | ||
4114 | var ctrlInstance, ctrlInstantiate, ctrlLocals = {}; |
|
4115 | ||
4116 | //controllers |
|
4117 | if (modalOptions.controller) { |
|
4118 | ctrlLocals.$scope = modalScope; |
|
4119 | ctrlLocals.$uibModalInstance = modalInstance; |
|
4120 | angular.forEach(tplAndVars[1], function(value, key) { |
|
4121 | ctrlLocals[key] = value; |
|
4122 | }); |
|
4123 | ||
4124 | // the third param will make the controller instantiate later,private api |
|
4125 | // @see https://github.com/angular/angular.js/blob/master/src/ng/controller.js#L126 |
|
4126 | ctrlInstantiate = $controller(modalOptions.controller, ctrlLocals, true); |
|
4127 | if (modalOptions.controllerAs) { |
|
4128 | ctrlInstance = ctrlInstantiate.instance; |
|
4129 | ||
4130 | if (modalOptions.bindToController) { |
|
4131 | ctrlInstance.$close = modalScope.$close; |
|
4132 | ctrlInstance.$dismiss = modalScope.$dismiss; |
|
4133 | angular.extend(ctrlInstance, providedScope); |
|
4134 | } |
|
4135 | ||
4136 | ctrlInstance = ctrlInstantiate(); |
|
4137 | ||
4138 | modalScope[modalOptions.controllerAs] = ctrlInstance; |
|
4139 | } else { |
|
4140 | ctrlInstance = ctrlInstantiate(); |
|
4141 | } |
|
4142 | ||
4143 | if (angular.isFunction(ctrlInstance.$onInit)) { |
|
4144 | ctrlInstance.$onInit(); |
|
4145 | } |
|
4146 | } |
|
4147 | ||
4148 | $modalStack.open(modalInstance, { |
|
4149 | scope: modalScope, |
|
4150 | deferred: modalResultDeferred, |
|
4151 | renderDeferred: modalRenderDeferred, |
|
4152 | closedDeferred: modalClosedDeferred, |
|
4153 | content: tplAndVars[0], |
|
4154 | animation: modalOptions.animation, |
|
4155 | backdrop: modalOptions.backdrop, |
|
4156 | keyboard: modalOptions.keyboard, |
|
4157 | backdropClass: modalOptions.backdropClass, |
|
4158 | windowTopClass: modalOptions.windowTopClass, |
|
4159 | windowClass: modalOptions.windowClass, |
|
4160 | windowTemplateUrl: modalOptions.windowTemplateUrl, |
|
4161 | size: modalOptions.size, |
|
4162 | openedClass: modalOptions.openedClass, |
|
4163 | appendTo: modalOptions.appendTo |
|
4164 | }); |
|
4165 | modalOpenedDeferred.resolve(true); |
|
4166 | ||
4167 | }, function resolveError(reason) { |
|
4168 | modalOpenedDeferred.reject(reason); |
|
4169 | modalResultDeferred.reject(reason); |
|
4170 | })['finally'](function() { |
|
4171 | if (promiseChain === samePromise) { |
|
4172 | promiseChain = null; |
|
4173 | } |
|
4174 | }); |
|
4175 | ||
4176 | return modalInstance; |
|
4177 | }; |
|
4178 | ||
4179 | return $modal; |
|
4180 | } |
|
4181 | ] |
|
4182 | }; |
|
4183 | ||
4184 | return $modalProvider; |
|
4185 | }); |
|
4186 | ||
4187 | angular.module('ui.bootstrap.paging', []) |
|
4188 | /** |