nice-elements 1.7.6 → 1.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -40,17 +40,17 @@ angular.module('niceElements')
40
40
  attr.multiple = angular.isDefined(attr.multiple);
41
41
 
42
42
  scope.firstTime = true;
43
- scope.checkIfFirstTime = function(){
44
- if (scope.firstTime){
43
+ scope.checkIfFirstTime = function () {
44
+ if (scope.firstTime) {
45
45
  scope.firstTime = false;
46
46
  return true;
47
- }else{
47
+ } else {
48
48
  return false;
49
49
  }
50
50
  };
51
51
 
52
52
  // If selected is not yet defined
53
- if(!angular.isDefined(scope.model)){
53
+ if (!angular.isDefined(scope.model)) {
54
54
  if (scope.multiple) {
55
55
  scope.model = [];
56
56
  }
@@ -60,7 +60,7 @@ angular.module('niceElements')
60
60
  if (scope.listIsObj) {
61
61
  scope.internalList = scope.list;
62
62
  } else {
63
- scope.internalList =_.map(scope.list, function(val) {
63
+ scope.internalList = _.map(scope.list, function (val) {
64
64
  var obj = {};
65
65
  obj[scope.objKey] = val;
66
66
  obj[scope.objValue] = val;
@@ -71,9 +71,9 @@ angular.module('niceElements')
71
71
  // Set internalSelected
72
72
  if (scope.selectedIsObj) {
73
73
  scope.internalSelected = scope.model;
74
- }else {
74
+ } else {
75
75
  if (scope.multiple) {
76
- scope.internalSelected =_.map(scope.model, function(val) {
76
+ scope.internalSelected = _.map(scope.model, function (val) {
77
77
  var obj = {};
78
78
  obj[scope.objKey] = val;
79
79
  obj[scope.objValue] = val;
@@ -85,14 +85,14 @@ angular.module('niceElements')
85
85
  obj[scope.objKey] = scope.model;
86
86
  obj[scope.objValue] = scope.model;
87
87
  scope.internalSelected = obj;
88
- }else{
88
+ } else {
89
89
  scope.internalSelected = scope.internalList[0];
90
90
  }
91
91
  }
92
92
  }
93
93
  },
94
- controller: function($rootScope, $scope) {
95
- var getFilter = function(item){
94
+ controller: function ($rootScope, $scope) {
95
+ var getFilter = function (item) {
96
96
  // Create filter for finding object by objValue with _.where()
97
97
  var filter = {};
98
98
  if (item.hasOwnProperty($scope.objKey))
@@ -102,40 +102,39 @@ angular.module('niceElements')
102
102
  return filter;
103
103
  };
104
104
 
105
- $scope.setDefault = function(){
106
- if(!$scope.multiple){
105
+ $scope.setDefault = function () {
106
+ if (!$scope.multiple) {
107
107
  $scope.internalSelected = $scope.internalList[0];
108
108
  }
109
109
  };
110
110
 
111
- $scope.isItemSelected = function(item){
111
+ $scope.isItemSelected = function (item) {
112
112
  if (!$scope.internalSelected)
113
113
  return false;
114
114
  // Which item is selected
115
115
  if ($scope.multiple) {
116
- return _.where($scope.internalSelected, getFilter(item)).length > 0;
117
- }else{
118
- return $scope.internalSelected[$scope.objKey] == item[$scope.objKey];
116
+ return _.where($scope.internalSelected, getFilter(item)).length > 0;
117
+ } else {
118
+ return $scope.internalSelected[$scope.objKey] == item[$scope.objKey];
119
119
  }
120
120
  };
121
121
 
122
- $scope.toggle = function(item) {
123
- if (!$scope.isDisabled) {
124
- $scope.formChoice.$setDirty();
122
+ $scope.toggle = function (item) {
123
+ if ($scope.isDisabled) return;
124
+ $scope.formChoice.$setDirty();
125
125
 
126
- if (!$scope.multiple) {
127
- $scope.internalSelected = item;
126
+ if (!$scope.multiple) {
127
+ $scope.internalSelected = item;
128
+ } else {
129
+ if ($scope.isItemSelected(item)) {
130
+ $scope.internalSelected = _.without($scope.internalSelected, _.findWhere($scope.internalSelected, getFilter(item)));
128
131
  } else {
129
- if($scope.isItemSelected(item)){
130
- $scope.internalSelected = _.without($scope.internalSelected, _.findWhere($scope.internalSelected, getFilter(item)));
131
- } else {
132
- $scope.internalSelected.push(item);
133
- }
132
+ $scope.internalSelected.push(item);
134
133
  }
135
134
  }
136
135
  };
137
136
 
138
- $scope.getLabel = function(item){
137
+ $scope.getLabel = function (item) {
139
138
  return item[$scope.objValue];
140
139
  };
141
140
 
@@ -143,8 +142,8 @@ angular.module('niceElements')
143
142
  // Set internalList
144
143
  if ($scope.listIsObj) {
145
144
  $scope.internalList = $scope.list;
146
- }else{
147
- $scope.internalList =_.map($scope.list, function(val) {
145
+ } else {
146
+ $scope.internalList = _.map($scope.list, function (val) {
148
147
  var obj = {};
149
148
  obj[$scope.objKey] = val;
150
149
  obj[$scope.objValue] = val;
@@ -155,11 +154,11 @@ angular.module('niceElements')
155
154
 
156
155
  $scope.$watchCollection('internalSelected', function (value_new, value_old) {
157
156
  // Update $scope.selected based on settings
158
- if (value_new && (!angular.equals(value_new, value_old) || $scope.checkIfFirstTime())){
159
- if ($scope.selectedIsObj){
157
+ if (value_new && (!angular.equals(value_new, value_old) || $scope.checkIfFirstTime())) {
158
+ if ($scope.selectedIsObj) {
160
159
  $scope.model = value_new;
161
160
  } else {
162
- if ($scope.multiple){
161
+ if ($scope.multiple) {
163
162
  $scope.model = _.map(value_new, $scope.objKey);
164
163
  } else {
165
164
  $scope.model = value_new[$scope.objKey];
@@ -171,8 +170,8 @@ angular.module('niceElements')
171
170
 
172
171
  $scope.$watchCollection('model', function (value_new, value_old) {
173
172
  if (!angular.equals(value_new, value_old)) {
174
- if (!value_new){
175
- if(!$scope.multiple)
173
+ if (!value_new) {
174
+ if (!$scope.multiple)
176
175
  $scope.internalSelected = $scope.internalList[0];
177
176
  else
178
177
  $scope.internalSelected = [];
@@ -193,7 +192,7 @@ angular.module('niceElements')
193
192
  }
194
193
  }
195
194
 
196
- if(!value_new){
195
+ if (!value_new) {
197
196
  if (!$scope.multiple) {
198
197
  $scope.internalSelected = $scope.internalList[0];
199
198
  }
@@ -14,8 +14,13 @@
14
14
 
15
15
  &:hover {
16
16
  .choice-checkbox {
17
+ cursor: not-allowed;
17
18
  border-color: $nice-border-color !important;
18
19
  }
20
+
21
+ .choice-label {
22
+ color: $nice-font-color;
23
+ }
19
24
  }
20
25
  }
21
26
 
@@ -34,32 +39,49 @@
34
39
  }
35
40
 
36
41
  li {
37
- padding: 5px 0px;
38
42
  @extend .noselect;
39
43
  cursor: pointer;
44
+ display: flex;
45
+ // align-items: center;
46
+ margin-bottom: 10px;
47
+ padding: 0 !important;
48
+
49
+ &:last-child {
50
+ margin-bottom: 0;
51
+ }
52
+
53
+ &:first-child {
54
+ margin-top: 7px;
55
+ }
40
56
 
41
57
  .choice-checkbox {
42
58
  transition: all 0.2s;
43
59
  background: $nice-choice-bg;
44
60
  color: $nice-choice-bg;
45
- width: 25px;
46
- height: 25px;
61
+ width: 20px;
62
+ height: 20px;
47
63
  border: 1px solid $nice-border-color;
48
- position: absolute;
49
64
  border-radius: $nice-border-radius;
50
65
  padding: 0;
51
66
  justify-content: center;
52
67
  align-items: center;
53
68
  display: flex;
69
+ flex-shrink: 0;
54
70
 
55
71
  nice-icon {
56
72
  display: block;
57
73
  }
58
74
 
59
75
  svg {
60
- height: 18px;
61
- width: 18px;
62
- margin-top: 1px;
76
+ height: 16px;
77
+ width: 16px;
78
+ }
79
+
80
+ .multiple-circle {
81
+ height: 8px;
82
+ width: 8px;
83
+ border-radius: 50%;
84
+ background: white;
63
85
  }
64
86
 
65
87
  &:focus {
@@ -71,6 +93,10 @@
71
93
  .choice-checkbox {
72
94
  border-color: $nice-choice-hover-border;
73
95
  }
96
+
97
+ .choice-label {
98
+ color: darken($nice-font-color, 15%);
99
+ }
74
100
  }
75
101
 
76
102
  .circle {
@@ -78,9 +104,7 @@
78
104
  }
79
105
 
80
106
  .choice-label {
81
- margin-left: 35px;
82
- line-height: 26px;
107
+ margin-left: 10px;
83
108
  }
84
-
85
109
  }
86
110
  }
@@ -1,4 +1,4 @@
1
- <div class="nice-component nice-dropdown" ng-class="{ 'margin-bottom-0': noMargin, 'nice-component-inline': isInline }">
1
+ <div class="nice-component nice-dropdown" ng-class="{ 'margin-bottom-0': noMargin, 'nice-component-inline': isInline }" ng-form="formDropdown">
2
2
  <div class="row">
3
3
  <!------------------------- Title ------------------------->
4
4
  <nice-title title="title" help="help" required="required" label-width="labelWidth"></nice-title>
@@ -54,5 +54,4 @@
54
54
  </div>
55
55
  </div>
56
56
  </div>
57
- <div ng-form="formDropdown"></div>
58
57
  </div>
@@ -6,11 +6,11 @@
6
6
  <!------------------------- Field ------------------------->
7
7
  <div class="nice-field col-xs-12" ng-class="[fieldWidth ? fieldWidth : 'col-sm-8', { 'nice-disabled': isDisabled }]">
8
8
  <div class="input-group">
9
- <button class="btn btn-default btn-left" ng-click="sub()" type="button" ng-disabled="isDisabled" tabindex="-1">
9
+ <button class="btn btn-default btn-left" ng-click="sub()" type="button" ng-disabled="model <= min || isDisabled" tabindex="-1">
10
10
  <nice-icon icon="icon-minus"></nice-icon>
11
11
  </button>
12
- <input class="value form-control" ng-model="model" type="number" ng-change="handleChange()" ng-disabled="isDisabled" />
13
- <button class="btn btn-default btn-right" ng-click="add()" type="button" ng-disabled="isDisabled" tabindex="-1">
12
+ <input class="value form-control" ng-model="model" type="number" min="{{ min }}" max="{{ max }}" ng-change="handleChange()" ng-disabled="isDisabled" />
13
+ <button class="btn btn-default btn-right" ng-click="add()" type="button" ng-disabled="model >= max || isDisabled" tabindex="-1">
14
14
  <nice-icon icon="icon-plus"></nice-icon>
15
15
  </button>
16
16
  </div>
@@ -14,7 +14,8 @@ angular.module('niceElements')
14
14
  scope: {
15
15
  title: '@',
16
16
  model: '=',
17
- max: '=',
17
+ min: '=?',
18
+ max: '=?',
18
19
  onChange: '&?',
19
20
  noMargin: '@',
20
21
  fieldWidth: '@',
@@ -24,32 +25,29 @@ angular.module('niceElements')
24
25
  help: '@',
25
26
  },
26
27
  controller: function ($scope) {
27
- if (!$scope.model) {
28
- $scope.model = 0;
29
- }
28
+ $scope.min = Number($scope.min) || 0;
29
+ $scope.max = Number($scope.max) || Infinity;
30
+ if (!$scope.model) $scope.model = Number($scope.min);
30
31
 
31
32
  $scope.add = function () {
32
- if ($scope.max) {
33
- if ($scope.max >= $scope.model + 1) {
34
- $scope.model += 1;
35
- if ($scope.onChange) $scope.onChange({ model: $scope.model });
36
- }
37
- } else {
38
- $scope.model += 1;
39
- if ($scope.onChange) $scope.onChange({ model: $scope.model });
40
- }
33
+ $scope.model += 1;
34
+ $scope.handleChange();
41
35
  };
42
36
 
43
37
  $scope.sub = function () {
44
- if ($scope.model - 1 >= 0) {
45
- $scope.model -= 1;
46
- if ($scope.onChange) $scope.onChange({ model: $scope.model });
47
- }
38
+ $scope.model -= 1;
39
+ $scope.handleChange();
48
40
  };
49
41
 
50
42
  $scope.handleChange = function () {
51
- if ($scope.model) {
43
+ if ($scope.model != undefined) {
52
44
  $scope.model = Number($scope.model);
45
+ if ($scope.model < $scope.min) $scope.model = angular.copy($scope.min);
46
+ if ($scope.model > $scope.max) $scope.model = angular.copy($scope.max);
47
+ if ($scope.onChange) $scope.onChange({ model: $scope.model });
48
+ } else {
49
+ $scope.model = angular.copy($scope.min);
50
+ $scope.handleChange();
53
51
  }
54
52
  };
55
53
  }