1 define(['common/general/common.navigation.module'], function(common) {
4 * Helper to set CSS class to active via ng-class using $location.path()
7 common.directive('isActive', function($compile) {
18 controller: ['$scope', '$location', '$state', function ($scope, $location, $state) {
19 $scope.$state = $state;
20 $scope.$location = $location;
23 return function (scope, iElement, iAttrs, controller) {
26 var state = scope.stateActive || scope.$state.current.name.split('.')[0];
27 active = 'active: $state.includes(\'' + scope.state + '\')';
28 } else if (scope.url) {
29 active = 'active: url === $location.path()';
33 iElement.attr('ng-class', '{ ' + active + ' }'); // Adding the ngClass
34 iElement.removeAttr('is-active'); // Avoid infinite loop
35 $compile(iElement)(scope);
42 common.directive('brdAnchor', function ($compile, $rootScope) {
53 /* The idea is to support both state and url, to be able to set {active} either
54 if stateActive matches via $state.includes() or if the url matches
55 Change this into a actual href later on ? - see https://github.com/angular-ui/ui-router/issues/395
57 template: '<a href="" ng-click="doClick()">{{label}}</a>',
58 controller: ['$scope', '$rootScope', '$location', '$state', function ($scope, $rootScope, $location, $state) {
59 $scope.$location = $location;
60 $scope.$state = $state;
62 $scope.doClick = function () {
66 stateParams: $scope.stateParams,
70 $rootScope.$broadcast('event:navigation', args);
72 if (!$scope.url && $scope.state) {
73 var params = $scope.stateParams || {};
74 $state.transitionTo($scope.state, params, { location: true, inherit: true, relative: $state.$current, notify: true });
75 } else if ($scope.url) {
76 $location.path($scope.url);
84 common.directive('buttonCancel', function() {
85 // Runs during compile
93 'cancelFunc': '=function',
97 template: '<button class="btn btn-{{size}} btn-danger" ng-click="doCancel()"><i class="icon-remove-sign"></i> {{label}}</button>',
98 controller: ['$scope', '$state', function ($scope, $state) {
99 $scope.label = $scope.btnLabel || 'Cancel';
100 $scope.size = $scope.btnSize || 'md';
101 $scope.glyph = $scope.btnGlyph || 'remove-circle';
103 $scope.doCancel = function () {
104 if (angular.isFunction($scope.cancelFunc)) {
109 var params = $scope.stateParams || {};
110 $state.transitionTo($scope.state, params, { location: true, inherit: true, relative: $state.$current, notify: true });
117 common.directive('buttonSubmit', function(){
118 // Runs during compile
123 'btnLabel': '@label',
125 'btnGlyph': '@glyph',
126 'submitFunc': '=function',
130 template: '<button class="btn btn-{{size}} btn-orange" ng-click="doSubmit()" ng-disabled="submitDisabled"><i class="icon-ok-sign"></i> {{label}}</button>',
131 controller: ['$scope', function ($scope) {
132 $scope.label = $scope.btnLabel || 'Submit';
133 $scope.size = $scope.btnSize || 'md';
134 $scope.glyph = $scope.btnGlyph || 'ok-circle';
136 $scope.submitDisabled = true;
138 $scope.doSubmit = function () {
139 if ($scope.submitFunc) {
144 $scope.toggle = function (newVal) {
145 $scope.submitDisabled = newVal ? false : true;
149 // Setup a watch for form.$valid if it's passed
150 if (!$scope.validator && $scope.form) {
151 $scope.$watch('form.$valid', function (newVal, oldVal) {
152 $scope.toggle(newVal);
156 // This overrules the form watch if set - use with cauthion!
157 if ($scope.validator && angular.isFunction($scope.validator)) {
160 return $scope.validator();
162 function(newVal, oldVal) {
163 $scope.toggle(newVal);
168 // Lastly if none of the above goes we'll just enable ourselves
169 if (!$scope.form && !$scope.validator) {
170 $scope.submitDisabled = false;
177 common.directive('showSelected', function() {
178 // Runs during compile
185 template: '<span>Selected: {{data.length}}</span>'
189 common.directive('ctrlReload', function() {
190 // Runs during compile
197 template: '<button class="btn btn-primary btn-xs" ng-click="svc.getAll()"><i class="icon-refresh"></i></button>',
198 link: function ($scope, iElm, iAttrs, controller) {
199 $scope.$on('evt:refresh', function() {
206 common.directive('ctrlDelete', function($rootScope) {
207 // Runs during compile
211 template: '<button class="btn btn-danger btn-xs" ng-click="deleteSelected()" ng-disabled="gridOptions.selectedItems.length == 0"><i class="icon-remove"></i></button>',
212 link: function($scope, iElm, iAttrs, controller) {
214 var selected = $scope.gridOptions.selectedItems;
216 // Fire up a evt:refresh event once done.
217 $scope.deleteSelected = function () {
218 angular.forEach(selected, function(value, key) {
219 $scope.svc.delete(value).then(
222 if (i == selected.length) {
223 $rootScope.$broadcast('evt:refresh');