moved modal into global controller scope

This commit is contained in:
2016-07-06 21:55:05 +02:00
parent 7a1a4a654c
commit d2397bf46e
2 changed files with 53 additions and 71 deletions
+40 -56
View File
@@ -1,6 +1,6 @@
var transactionControllers = angular.module('transactionControllers', ['ngResource']);
transactionControllers.controller('TransactionListCtrl', [ '$http', '$scope', '$location', '$resource', '$q', function($http, $scope, $location, $resource, $q) {
transactionControllers.controller('TransactionListCtrl', [ '$http', '$scope', '$location', '$resource', '$q', '$uibModal', '$log', function($http, $scope, $location, $resource, $q, $uibModal, $log) {
$scope.refreshList = function() {
@@ -229,11 +229,50 @@ transactionControllers.controller('TransactionListCtrl', [ '$http', '$scope', '$
});
};
$scope.items = ['item1', 'item2', 'item3'];
$scope.openDetails = function() {
var modalInstance = $uibModal.open({
templateUrl: 'detailsTemplate.html',
controller: 'DetailsModalCtrl',
resolve: {
items: function () {
return $scope.items;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};
// initialize (http://stackoverflow.com/a/25662066/3761783)
$scope.initList();
} ]);
transactionControllers.controller('DetailsModalCtrl', [ '$scope', '$uibModalInstance', 'items', function($scope, $uibModalInstance, items) {
$scope.items = items;
$scope.selected = {
item: $scope.items[0]
};
$scope.ok = function () {
$uibModalInstance.close($scope.selected.item);
};
$scope.cancel = function () {
$uibModalInstance.dismiss('cancel');
};
} ]);
transactionControllers.controller('TransactionDetailCtrl', [ '$scope', '$routeParams', '$resource', '$location', function($scope, $routeParams, $resource, $location) {
$scope.initDetails = function() {
@@ -286,8 +325,6 @@ transactionControllers.controller('TransactionDetailCtrl', [ '$scope', '$routePa
}
$scope.deleteTransaction = function(transaction) {
/*console.log(angular.toJson(transaction, false));*/
// TODO auf return code reagieren
$resource(transaction._links.self.href).remove().$promise.then(function() {
$location.path('/');
@@ -297,56 +334,3 @@ transactionControllers.controller('TransactionDetailCtrl', [ '$scope', '$routePa
$scope.initDetails();
} ]);
transactionControllers.controller('ModalDemoCtrl', function ($scope, $uibModal, $log) {
$scope.items = ['item1', 'item2', 'item3'];
$scope.animationsEnabled = true;
$scope.open = function (size) {
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
size: size,
resolve: {
items: function () {
return $scope.items;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};
$scope.toggleAnimation = function () {
$scope.animationsEnabled = !$scope.animationsEnabled;
};
});
// Please note that $uibModalInstance represents a modal window (instance) dependency.
// It is not the same as the $uibModal service used above.
transactionControllers.controller('ModalInstanceCtrl', function ($scope, $uibModalInstance, items) {
$scope.items = items;
$scope.selected = {
item: $scope.items[0]
};
$scope.ok = function () {
$uibModalInstance.close($scope.selected.item);
};
$scope.cancel = function () {
$uibModalInstance.dismiss('cancel');
};
});
@@ -102,10 +102,15 @@
<div style="margin-top: 2em; text-align: center;">
<span ng-repeat="user in accountUsers">{{user.name}} {{user.outstandings | number : 2}}&nbsp;<br/></span>
</div>
</div>
<div ng-controller="ModalDemoCtrl">
<script type="text/ng-template" id="myModalContent.html">
<button type="button" class="btn btn-default" ng-click="openDetails()">Open me!</button>
<div ng-show="selected">Selection from a modal: {{ selected }}</div>
<script type="text/ng-template" id="detailsTemplate.html">
<div class="modal-header">
<h3 class="modal-title">I'm a modal!</h3>
</div>
@@ -123,16 +128,9 @@
</div>
</script>
<button type="button" class="btn btn-default" ng-click="open()">Open me!</button>
<button type="button" class="btn btn-default" ng-click="open('lg')">Large modal</button>
<button type="button" class="btn btn-default" ng-click="open('sm')">Small modal</button>
<button type="button" class="btn btn-default" ng-click="toggleAnimation()">Toggle Animation ({{ animationsEnabled }})</button>
<div ng-show="selected">Selection from a modal: {{ selected }}</div>
</div>
<!-- div>
<pre style="font-size: 75%; color: darkgray;">{{account | json}}</pre>
</div -->
</div>
</div>
</div>
</div>