nice-elements 1.9.16 → 1.10.0

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.
Files changed (143) hide show
  1. package/.vscode/settings.json +17 -17
  2. package/CHANGELOG.md +407 -401
  3. package/LICENSE.md +21 -21
  4. package/README.md +95 -93
  5. package/bower.json +10 -10
  6. package/dist/nice.js +8073 -7930
  7. package/dist/nice.min.js +1 -1
  8. package/dist/style.css +105 -9
  9. package/dist/style.css.map +3 -1
  10. package/dist/style.min.css +8 -8
  11. package/package.json +40 -40
  12. package/src/components/nice-button/nice-button.html +4 -4
  13. package/src/components/nice-button/nice-button.js +41 -41
  14. package/src/components/nice-button/nice-button.scss +16 -16
  15. package/src/components/nice-button-toggle/nice-button-toggle.html +9 -9
  16. package/src/components/nice-button-toggle/nice-button-toggle.js +23 -23
  17. package/src/components/nice-button-toggle/nice-button-toggle.scss +2 -2
  18. package/src/components/nice-calendar/nice-calendar.html +91 -91
  19. package/src/components/nice-calendar/nice-calendar.js +334 -334
  20. package/src/components/nice-calendar/nice-calendar.scss +285 -285
  21. package/src/components/nice-checkbox/nice-checkbox.html +5 -5
  22. package/src/components/nice-checkbox/nice-checkbox.js +33 -33
  23. package/src/components/nice-checkbox/nice-checkbox.scss +91 -91
  24. package/src/components/nice-choice/nice-choice.html +18 -18
  25. package/src/components/nice-choice/nice-choice.js +210 -210
  26. package/src/components/nice-choice/nice-choice.scss +110 -110
  27. package/src/components/nice-click-outside/nice-click-outside.js +105 -105
  28. package/src/components/nice-comment/nice-comment.html +10 -10
  29. package/src/components/nice-comment/nice-comment.js +69 -69
  30. package/src/components/nice-comment/nice-comment.scss +39 -39
  31. package/src/components/nice-date/nice-date.html +74 -74
  32. package/src/components/nice-date/nice-date.js +327 -327
  33. package/src/components/nice-date/nice-date.scss +302 -302
  34. package/src/components/nice-date-input/nice-date-input.html +41 -41
  35. package/src/components/nice-date-input/nice-date-input.js +109 -109
  36. package/src/components/nice-date-input/nice-date-input.scss +45 -45
  37. package/src/components/nice-date-range/nice-date-range.html +15 -15
  38. package/src/components/nice-date-range/nice-date-range.js +76 -76
  39. package/src/components/nice-date-range/nice-date-range.scss +390 -390
  40. package/src/components/nice-datetime-picker/nice-datetime-picker.html +29 -29
  41. package/src/components/nice-datetime-picker/nice-datetime-picker.js +87 -87
  42. package/src/components/nice-datetime-picker/nice-datetime-picker.scss +428 -428
  43. package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.html +55 -55
  44. package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.js +246 -246
  45. package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.scss +73 -73
  46. package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.html +44 -44
  47. package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.js +172 -172
  48. package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.scss +127 -127
  49. package/src/components/nice-dropdown/nice-dropdown.html +60 -60
  50. package/src/components/nice-dropdown/nice-dropdown.js +489 -489
  51. package/src/components/nice-dropdown/nice-dropdown.scss +249 -249
  52. package/src/components/nice-dropdown-date/nice-dropdown-date.html +28 -28
  53. package/src/components/nice-dropdown-date/nice-dropdown-date.js +126 -126
  54. package/src/components/nice-dropdown-date/nice-dropdown-date.scss +82 -82
  55. package/src/components/nice-dropdown-old/nice-dropdown-old.html +44 -44
  56. package/src/components/nice-dropdown-old/nice-dropdown-old.js +330 -330
  57. package/src/components/nice-dropdown-old/nice-dropdown-old.scss +129 -129
  58. package/src/components/nice-dtp/nice-dtp.html +91 -91
  59. package/src/components/nice-dtp/nice-dtp.js +833 -833
  60. package/src/components/nice-help/nice-help.html +6 -6
  61. package/src/components/nice-help/nice-help.js +55 -55
  62. package/src/components/nice-help/nice-help.scss +78 -78
  63. package/src/components/nice-input/nice-input.html +48 -48
  64. package/src/components/nice-input/nice-input.js +244 -244
  65. package/src/components/nice-input/nice-input.scss +130 -130
  66. package/src/components/nice-label/nice-label.html +10 -10
  67. package/src/components/nice-label/nice-label.js +30 -30
  68. package/src/components/nice-loader/nice-loader.html +6 -6
  69. package/src/components/nice-loader/nice-loader.js +28 -28
  70. package/src/components/nice-loader/nice-loader.scss +47 -47
  71. package/src/components/nice-no-data/nice-no-data.html +4 -0
  72. package/src/components/nice-no-data/nice-no-data.js +26 -0
  73. package/src/components/nice-no-data/nice-no-data.scss +27 -0
  74. package/src/components/nice-notification/nice-notification.html +3 -3
  75. package/src/components/nice-notification/nice-notification.js +124 -124
  76. package/src/components/nice-notification/nice-notification.scss +66 -66
  77. package/src/components/nice-number/nice-number.html +40 -40
  78. package/src/components/nice-number/nice-number.js +169 -169
  79. package/src/components/nice-number/nice-number.scss +18 -18
  80. package/src/components/nice-percent/nice-percent.html +24 -24
  81. package/src/components/nice-percent/nice-percent.js +94 -94
  82. package/src/components/nice-pill/nice-pill.html +3 -3
  83. package/src/components/nice-pill/nice-pill.js +29 -29
  84. package/src/components/nice-pill/nice-pill.scss +25 -25
  85. package/src/components/nice-popup/nice-popup.html +6 -6
  86. package/src/components/nice-popup/nice-popup.js +122 -122
  87. package/src/components/nice-popup/nice-popup.scss +43 -43
  88. package/src/components/nice-progress-bar/nice-progress-bar.html +15 -15
  89. package/src/components/nice-progress-bar/nice-progress-bar.js +54 -54
  90. package/src/components/nice-progress-bar/nice-progress-bar.scss +47 -47
  91. package/src/components/nice-quantity/nice-quantity.html +22 -22
  92. package/src/components/nice-quantity/nice-quantity.js +55 -55
  93. package/src/components/nice-quantity/nice-quantity.scss +51 -51
  94. package/src/components/nice-search/nice-search.html +44 -44
  95. package/src/components/nice-search/nice-search.js +239 -239
  96. package/src/components/nice-search/nice-search.scss +90 -90
  97. package/src/components/nice-search2/nice-search2.html +32 -32
  98. package/src/components/nice-search2/nice-search2.js +264 -264
  99. package/src/components/nice-search2/nice-search2.scss +80 -80
  100. package/src/components/nice-slot/nice-slot.html +10 -10
  101. package/src/components/nice-slot/nice-slot.js +29 -29
  102. package/src/components/nice-steps/nice-steps.scss +81 -81
  103. package/src/components/nice-svgs/nice-svgs.html +1262 -1262
  104. package/src/components/nice-svgs/nice-svgs.js +16 -16
  105. package/src/components/nice-table/nice-table.html +28 -0
  106. package/src/components/nice-table/nice-table.js +40 -0
  107. package/src/components/nice-table/nice-table.scss +62 -0
  108. package/src/components/nice-time-picker/nice-time-picker.html +43 -43
  109. package/src/components/nice-time-picker/nice-time-picker.js +83 -83
  110. package/src/components/nice-time-picker/nice-time-picker.scss +37 -37
  111. package/src/components/nice-title/nice-title.html +3 -3
  112. package/src/components/nice-title/nice-title.js +21 -21
  113. package/src/components/nice-toast/nice-toast.html +2 -2
  114. package/src/components/nice-toast/nice-toast.js +56 -56
  115. package/src/components/nice-toast/nice-toast.scss +74 -74
  116. package/src/components/nice-toggle/nice-toggle.html +12 -12
  117. package/src/components/nice-toggle/nice-toggle.js +95 -95
  118. package/src/components/nice-toggle/nice-toggle.scss +74 -67
  119. package/src/components/nice-tooltip/_nice-tooltip.scss +71 -71
  120. package/src/components/nice-tooltip/nice-tooltip.js +23 -23
  121. package/src/components/nice-upload/nice-upload.html +22 -22
  122. package/src/components/nice-upload/nice-upload.js +157 -157
  123. package/src/components/nice-upload/nice-upload.scss +85 -85
  124. package/src/components/nice-wrapper/_nice-wrapper.scss +87 -87
  125. package/src/components/nice-wrapper/nice-wrapper.html +12 -12
  126. package/src/components/nice-wrapper/nice-wrapper.js +43 -43
  127. package/src/components/nice-yesno/nice-yesno.html +14 -14
  128. package/src/components/nice-yesno/nice-yesno.js +109 -109
  129. package/src/components/nice-yesno/nice-yesno.scss +95 -95
  130. package/src/filters/nice-date.js +17 -17
  131. package/src/filters/nice-highlight.js +16 -16
  132. package/src/modals/nice-multilangual-modal/nice-multilangual-modal.html +30 -30
  133. package/src/modals/nice-multilangual-modal/nice-multilangual-modal.js +67 -67
  134. package/src/modals/nice-multilangual-modal/nice-multilangual-modal.scss +19 -19
  135. package/src/nice.js +2 -2
  136. package/src/services/nice-service.js +19 -19
  137. package/src/styles/_bootstrap-variables.scss +178 -178
  138. package/src/styles/_nice-buttons.scss +403 -403
  139. package/src/styles/_nice-common.scss +471 -471
  140. package/src/styles/_nice-ngdialog.scss +85 -85
  141. package/src/styles/_nice-spacing.scss +283 -283
  142. package/src/styles/_nice.scss +67 -65
  143. package/src/styles/_variables.scss +197 -195
@@ -1,72 +1,72 @@
1
- .nice-tooltip {
2
- $nice-help-popup-color: #3e3e3e;
3
- position: relative;
4
- display: inline-block;
5
- cursor: help;
6
-
7
- &:hover{
8
- .nice-tooltip-window {
9
- display: block;
10
- }
11
-
12
- &:before {
13
- display: block;
14
- }
15
- }
16
-
17
- // &:before {
18
- // content: attr(nice-tooltip) " ";
19
- // display: none;
20
- // position: absolute;
21
- // background: $nice-help-popup-color;
22
- // color: white;
23
- // max-width: 200px;
24
- // width: max-content;
25
- // bottom: 100%;
26
- // left: 50%;
27
- // border-radius: $nice-border-radius;
28
- // font-size: 12px;
29
- // z-index: 99999;
30
- // transform: translate(-50%, -5px);
31
- // line-height: 1.3;
32
- // padding: 7px 10px;
33
- // font-weight: normal;
34
- // text-align: center;
35
- // text-transform: none;
36
- // }
37
-
38
- .nice-tooltip-window {
39
- display: none;
40
- position: absolute;
41
- background: $nice-help-popup-color;
42
- color: white;
43
- max-width: 200px;
44
- width: max-content;
45
- bottom: 100%;
46
- left: 50%;
47
- border-radius: $nice-border-radius;
48
- font-size: 12px;
49
- z-index: 99999;
50
- transform: translate(-50%, -5px);
51
- line-height: 1.3;
52
- padding: 7px 10px;
53
- font-weight: normal;
54
- text-align: center;
55
- text-transform: none;
56
-
57
- &:before {
58
- content: "";
59
- width: 0;
60
- height: 0;
61
- position: absolute;
62
- bottom: -3px;
63
- left: 50%;
64
- margin-left: -5px;
65
-
66
- border-bottom: 0px solid transparent;
67
- border-left: 5px solid transparent;
68
- border-right: 5px solid transparent;
69
- border-top: 3px solid $nice-help-popup-color;
70
- }
71
- }
1
+ .nice-tooltip {
2
+ $nice-help-popup-color: #3e3e3e;
3
+ position: relative;
4
+ display: inline-block;
5
+ cursor: help;
6
+
7
+ &:hover{
8
+ .nice-tooltip-window {
9
+ display: block;
10
+ }
11
+
12
+ &:before {
13
+ display: block;
14
+ }
15
+ }
16
+
17
+ // &:before {
18
+ // content: attr(nice-tooltip) " ";
19
+ // display: none;
20
+ // position: absolute;
21
+ // background: $nice-help-popup-color;
22
+ // color: white;
23
+ // max-width: 200px;
24
+ // width: max-content;
25
+ // bottom: 100%;
26
+ // left: 50%;
27
+ // border-radius: $nice-border-radius;
28
+ // font-size: 12px;
29
+ // z-index: 99999;
30
+ // transform: translate(-50%, -5px);
31
+ // line-height: 1.3;
32
+ // padding: 7px 10px;
33
+ // font-weight: normal;
34
+ // text-align: center;
35
+ // text-transform: none;
36
+ // }
37
+
38
+ .nice-tooltip-window {
39
+ display: none;
40
+ position: absolute;
41
+ background: $nice-help-popup-color;
42
+ color: white;
43
+ max-width: 200px;
44
+ width: max-content;
45
+ bottom: 100%;
46
+ left: 50%;
47
+ border-radius: $nice-border-radius;
48
+ font-size: 12px;
49
+ z-index: 99999;
50
+ transform: translate(-50%, -5px);
51
+ line-height: 1.3;
52
+ padding: 7px 10px;
53
+ font-weight: normal;
54
+ text-align: center;
55
+ text-transform: none;
56
+
57
+ &:before {
58
+ content: "";
59
+ width: 0;
60
+ height: 0;
61
+ position: absolute;
62
+ bottom: -3px;
63
+ left: 50%;
64
+ margin-left: -5px;
65
+
66
+ border-bottom: 0px solid transparent;
67
+ border-left: 5px solid transparent;
68
+ border-right: 5px solid transparent;
69
+ border-top: 3px solid $nice-help-popup-color;
70
+ }
71
+ }
72
72
  }
@@ -1,23 +1,23 @@
1
- 'use strict';
2
-
3
- /**
4
- * @ngdoc directive
5
- * @name niceElements.directive:niceTooltip
6
- * @description
7
- * # niceTooltip
8
- */
9
- angular.module('niceElements')
10
- .directive('niceTooltip', function () {
11
- return {
12
- restrict: 'EA',
13
- link: function (scope, element, attrs) {
14
- element.addClass("nice-tooltip");
15
-
16
- var tooltipWindow = document.createElement('span')
17
- tooltipWindow.className = 'nice-tooltip-window';
18
- tooltipWindow.innerHTML = attrs.niceTooltip;
19
-
20
- element.append(tooltipWindow);
21
- }
22
- };
23
- });
1
+ 'use strict';
2
+
3
+ /**
4
+ * @ngdoc directive
5
+ * @name niceElements.directive:niceTooltip
6
+ * @description
7
+ * # niceTooltip
8
+ */
9
+ angular.module('niceElements')
10
+ .directive('niceTooltip', function () {
11
+ return {
12
+ restrict: 'EA',
13
+ link: function (scope, element, attrs) {
14
+ element.addClass("nice-tooltip");
15
+
16
+ var tooltipWindow = document.createElement('span')
17
+ tooltipWindow.className = 'nice-tooltip-window';
18
+ tooltipWindow.innerHTML = attrs.niceTooltip;
19
+
20
+ element.append(tooltipWindow);
21
+ }
22
+ };
23
+ });
@@ -1,23 +1,23 @@
1
- <ng-form class="nice-component nice-upload" ng-class="{ 'margin-bottom-0' : noMargin, 'nice-component-inline': isInline }" name="form">
2
- <div class="row">
3
- <!------------------------- Title ------------------------->
4
- <nice-title text="title" help="help" required="required" label-width="labelWidth"></nice-title>
5
-
6
- <!------------------------- Field ------------------------->
7
- <div class="nice-field col-xs-12" ng-class="[fieldWidth ? fieldWidth : 'col-sm-8', { 'nice-disabled': isDisabled }]">
8
- <div class="nice-upload-area">
9
- <div class="input-area" ng-class="{ 'dragging': dragging || draggingGlobal }">
10
- <div class="middle-text" ng-if="!imageSource && !loading">
11
- <nice-icon icon="icon-upload"></nice-icon>
12
- <div class="text text-placeholder" ng-if="!dragging">{{ text }}</div>
13
- <div class="text text-placeholder" ng-if="dragging" translate translate-group="Nice">Drop file here</div>
14
- <div class="error" ng-if="error">{{ error }}</div>
15
- </div>
16
- <img ng-if="imageSource" data-ng-src="{{ imageSource }}" />
17
- </div>
18
- <input class="input-file" type="file" accept="{{ accept }}" ng-model="file" ng-disabled="isDisabled || loading" />
19
- <nice-loader fulldiv="true" ng-if="loading"></nice-loader>
20
- </div>
21
- </div>
22
- </div>
1
+ <ng-form class="nice-component nice-upload" ng-class="{ 'margin-bottom-0' : noMargin, 'nice-component-inline': isInline }" name="form">
2
+ <div class="row">
3
+ <!------------------------- Title ------------------------->
4
+ <nice-title text="title" help="help" required="required" label-width="labelWidth"></nice-title>
5
+
6
+ <!------------------------- Field ------------------------->
7
+ <div class="nice-field col-xs-12" ng-class="[fieldWidth ? fieldWidth : 'col-sm-8', { 'nice-disabled': isDisabled }]">
8
+ <div class="nice-upload-area">
9
+ <div class="input-area" ng-class="{ 'dragging': dragging || draggingGlobal }">
10
+ <div class="middle-text" ng-if="!imageSource && !loading">
11
+ <nice-icon icon="icon-upload"></nice-icon>
12
+ <div class="text text-placeholder" ng-if="!dragging">{{ text }}</div>
13
+ <div class="text text-placeholder" ng-if="dragging" translate translate-group="Nice">Drop file here</div>
14
+ <div class="error" ng-if="error">{{ error }}</div>
15
+ </div>
16
+ <img ng-if="imageSource" data-ng-src="{{ imageSource }}" />
17
+ </div>
18
+ <input class="input-file" type="file" accept="{{ accept }}" ng-model="file" ng-disabled="isDisabled || loading" />
19
+ <nice-loader fulldiv="true" ng-if="loading"></nice-loader>
20
+ </div>
21
+ </div>
22
+ </div>
23
23
  </ng-form>
@@ -1,157 +1,157 @@
1
- 'use strict';
2
-
3
- /**
4
- * @ngdoc directive
5
- * @name niceElements.directive:niceUpload
6
- * @description
7
- * # niceUpload
8
- */
9
- angular.module('niceElements')
10
- .directive('niceUpload', function ($timeout, gettextCatalog) {
11
- return {
12
- restrict: 'E',
13
- replace: true,
14
- transclude: true,
15
- templateUrl: 'src/components/nice-upload/nice-upload.html',
16
- scope: {
17
- model: '=',
18
- title: '@',
19
- text: '@',
20
- fieldWidth: '@',
21
- labelWidth: '@',
22
- noMargin: '@',
23
- accept: '@',
24
- uploadFunction: '=',
25
- callbackFunction: '=',
26
- callbackFile: '=',
27
- callbackUrl: '=',
28
- isDisabled: '=',
29
- isInline: '=',
30
- help: '@',
31
- maxFileSize: '@'
32
- },
33
-
34
- link: function (scope, element, attrs) {
35
- if (!attrs.title) { attrs.title = ''; }
36
- if (!attrs.text) { attrs.text = gettextCatalog.getString('Click to upload file', null, 'Nice'); }
37
- if (!attrs.fieldWidth) { attrs.fieldWidth = 'col-sm-8'; }
38
- if (!attrs.labelWidth) { attrs.labelWidth = 'col-sm-4'; }
39
- if (!attrs.maxFileSize) scope.maxFileSize = 1; // 1MB
40
- attrs.noMargin = angular.isDefined(attrs.noMargin);
41
-
42
- scope.startDragging = function () { $timeout(function () { scope.dragging = true; }); }
43
- scope.endDragging = function () { $timeout(function () { scope.dragging = false; }); }
44
- scope.startDraggingGlobal = function () { $timeout(function () { scope.draggingGlobal = true; }); }
45
- scope.endDraggingGlobal = function () { $timeout(function () { scope.dragging = false; scope.draggingGlobal = false; }); }
46
-
47
- scope.dragging = false;
48
- scope.draggingGlobal = false;
49
- var inputElement = element[0].querySelector(".input-file");
50
- // document.addEventListener("dragenter", scope.startDraggingGlobal);
51
- // document.addEventListener("drop", scope.endDraggingGlobal);
52
- // document.addEventListener("dragend", scope.endDraggingGlobal);
53
- // document.addEventListener("mouseleave", scope.endDraggingGlobal);
54
- // document.addEventListener("dragleave", scope.endDragging);
55
- inputElement.addEventListener("dragenter", scope.startDragging);
56
- inputElement.addEventListener("dragleave", scope.endDragging);
57
- inputElement.addEventListener("dragend", scope.endDraggingGlobal);
58
- inputElement.addEventListener("drop", scope.endDraggingGlobal);
59
-
60
- scope.$on('$destroy', function () {
61
- // document.removeEventListener("dragenter", scope.startDraggingGlobal);
62
- // document.removeEventListener("drop", scope.endDraggingGlobal);
63
- // document.removeEventListener("dragend", scope.endDraggingGlobal);
64
- // document.removeEventListener("mouseleave", scope.endDraggingGlobal);
65
- // document.removeEventListener("dragleave", scope.endDraggingGlobal);
66
- inputElement.removeEventListener("dragenter", scope.startDragging);
67
- inputElement.removeEventListener("dragleave", scope.endDragging);
68
- inputElement.removeEventListener("dragend", scope.endDraggingGlobal);
69
- inputElement.removeEventListener("drop", scope.endDraggingGlobal);
70
- });
71
-
72
-
73
- element.bind("change", function (changeEvent) {
74
- if (scope.callbackUrl != undefined) {
75
- scope.callbackUrl(URL.createObjectURL(changeEvent.target.files[0]));
76
- }
77
-
78
- $timeout(function () {
79
- scope.loading = true;
80
- scope.error = null;
81
- var inputObj = changeEvent.target;
82
- var reader = new FileReader();
83
-
84
- if (inputObj.files) {
85
- try {
86
- var fileSize = inputObj.files[0].size; // in bytes
87
-
88
- reader.onload = function (event) {
89
- $timeout(function () {
90
- // file size must be smaller than XMB.
91
- if (fileSize > (scope.maxFileSize * 1000000)) {
92
- scope.error = gettextCatalog.getString("File must be smaller than {{size}}MB", { size: scope.maxFileSize }, "Nice");
93
- scope.loading = false;
94
- scope.imageSource = null;
95
- return;
96
- }
97
-
98
- if (scope.callbackFunction != undefined) {
99
- scope.loading = false;
100
- scope.imageSource = null;
101
- scope.callbackFunction(event.target.result);
102
- scope.text = inputObj.files[0].name;
103
- scope.form.$setDirty();
104
- }
105
-
106
- if (scope.callbackFile != undefined) {
107
- scope.loading = false;
108
- scope.text = inputObj.files[0].name;
109
- scope.callbackFile(inputObj.files[0]);
110
- scope.form.$setDirty();
111
- }
112
-
113
- if (scope.uploadFunction != undefined) {
114
- scope.uploadFunction(inputObj.files[0]).then(function (response) {
115
- scope.loading = false;
116
- scope.imageSource = event.target.result;
117
- scope.model = response.data.url;
118
- scope.form.$setDirty();
119
- }, function (error) {
120
- // Handle upload function error
121
- scope.error = error;
122
- scope.loading = false;
123
- scope.imageSource = null;
124
- });
125
- } else {
126
- // console.error("No upload function set!");
127
- if (event.target.result.substring(0, 10) == "data:image") {
128
- scope.imageSource = event.target.result;
129
- }
130
- }
131
- });
132
- };
133
-
134
- } catch (err) {
135
- // Handle try catch
136
- scope.error = gettextCatalog.getString("Something went wrong", null, "Nice");
137
- scope.loading = false;
138
- scope.imageSource = null;
139
- }
140
-
141
- // when the file is read it triggers the onload event above.
142
- reader.readAsDataURL(inputObj.files[0]);
143
-
144
- }
145
- });
146
-
147
- });
148
- },
149
-
150
- controller: function ($scope) {
151
- $scope.$watch("model", function (value) {
152
- $scope.imageSource = angular.copy($scope.model);
153
- });
154
- }
155
-
156
- };
157
- });
1
+ 'use strict';
2
+
3
+ /**
4
+ * @ngdoc directive
5
+ * @name niceElements.directive:niceUpload
6
+ * @description
7
+ * # niceUpload
8
+ */
9
+ angular.module('niceElements')
10
+ .directive('niceUpload', function ($timeout, gettextCatalog) {
11
+ return {
12
+ restrict: 'E',
13
+ replace: true,
14
+ transclude: true,
15
+ templateUrl: 'src/components/nice-upload/nice-upload.html',
16
+ scope: {
17
+ model: '=',
18
+ title: '@',
19
+ text: '@',
20
+ fieldWidth: '@',
21
+ labelWidth: '@',
22
+ noMargin: '@',
23
+ accept: '@',
24
+ uploadFunction: '=',
25
+ callbackFunction: '=',
26
+ callbackFile: '=',
27
+ callbackUrl: '=',
28
+ isDisabled: '=',
29
+ isInline: '=',
30
+ help: '@',
31
+ maxFileSize: '@'
32
+ },
33
+
34
+ link: function (scope, element, attrs) {
35
+ if (!attrs.title) { attrs.title = ''; }
36
+ if (!attrs.text) { attrs.text = gettextCatalog.getString('Click to upload file', null, 'Nice'); }
37
+ if (!attrs.fieldWidth) { attrs.fieldWidth = 'col-sm-8'; }
38
+ if (!attrs.labelWidth) { attrs.labelWidth = 'col-sm-4'; }
39
+ if (!attrs.maxFileSize) scope.maxFileSize = 1; // 1MB
40
+ attrs.noMargin = angular.isDefined(attrs.noMargin);
41
+
42
+ scope.startDragging = function () { $timeout(function () { scope.dragging = true; }); }
43
+ scope.endDragging = function () { $timeout(function () { scope.dragging = false; }); }
44
+ scope.startDraggingGlobal = function () { $timeout(function () { scope.draggingGlobal = true; }); }
45
+ scope.endDraggingGlobal = function () { $timeout(function () { scope.dragging = false; scope.draggingGlobal = false; }); }
46
+
47
+ scope.dragging = false;
48
+ scope.draggingGlobal = false;
49
+ var inputElement = element[0].querySelector(".input-file");
50
+ // document.addEventListener("dragenter", scope.startDraggingGlobal);
51
+ // document.addEventListener("drop", scope.endDraggingGlobal);
52
+ // document.addEventListener("dragend", scope.endDraggingGlobal);
53
+ // document.addEventListener("mouseleave", scope.endDraggingGlobal);
54
+ // document.addEventListener("dragleave", scope.endDragging);
55
+ inputElement.addEventListener("dragenter", scope.startDragging);
56
+ inputElement.addEventListener("dragleave", scope.endDragging);
57
+ inputElement.addEventListener("dragend", scope.endDraggingGlobal);
58
+ inputElement.addEventListener("drop", scope.endDraggingGlobal);
59
+
60
+ scope.$on('$destroy', function () {
61
+ // document.removeEventListener("dragenter", scope.startDraggingGlobal);
62
+ // document.removeEventListener("drop", scope.endDraggingGlobal);
63
+ // document.removeEventListener("dragend", scope.endDraggingGlobal);
64
+ // document.removeEventListener("mouseleave", scope.endDraggingGlobal);
65
+ // document.removeEventListener("dragleave", scope.endDraggingGlobal);
66
+ inputElement.removeEventListener("dragenter", scope.startDragging);
67
+ inputElement.removeEventListener("dragleave", scope.endDragging);
68
+ inputElement.removeEventListener("dragend", scope.endDraggingGlobal);
69
+ inputElement.removeEventListener("drop", scope.endDraggingGlobal);
70
+ });
71
+
72
+
73
+ element.bind("change", function (changeEvent) {
74
+ if (scope.callbackUrl != undefined) {
75
+ scope.callbackUrl(URL.createObjectURL(changeEvent.target.files[0]));
76
+ }
77
+
78
+ $timeout(function () {
79
+ scope.loading = true;
80
+ scope.error = null;
81
+ var inputObj = changeEvent.target;
82
+ var reader = new FileReader();
83
+
84
+ if (inputObj.files) {
85
+ try {
86
+ var fileSize = inputObj.files[0].size; // in bytes
87
+
88
+ reader.onload = function (event) {
89
+ $timeout(function () {
90
+ // file size must be smaller than XMB.
91
+ if (fileSize > (scope.maxFileSize * 1000000)) {
92
+ scope.error = gettextCatalog.getString("File must be smaller than {{size}}MB", { size: scope.maxFileSize }, "Nice");
93
+ scope.loading = false;
94
+ scope.imageSource = null;
95
+ return;
96
+ }
97
+
98
+ if (scope.callbackFunction != undefined) {
99
+ scope.loading = false;
100
+ scope.imageSource = null;
101
+ scope.callbackFunction(event.target.result);
102
+ scope.text = inputObj.files[0].name;
103
+ scope.form.$setDirty();
104
+ }
105
+
106
+ if (scope.callbackFile != undefined) {
107
+ scope.loading = false;
108
+ scope.text = inputObj.files[0].name;
109
+ scope.callbackFile(inputObj.files[0]);
110
+ scope.form.$setDirty();
111
+ }
112
+
113
+ if (scope.uploadFunction != undefined) {
114
+ scope.uploadFunction(inputObj.files[0]).then(function (response) {
115
+ scope.loading = false;
116
+ scope.imageSource = event.target.result;
117
+ scope.model = response.data.url;
118
+ scope.form.$setDirty();
119
+ }, function (error) {
120
+ // Handle upload function error
121
+ scope.error = error;
122
+ scope.loading = false;
123
+ scope.imageSource = null;
124
+ });
125
+ } else {
126
+ // console.error("No upload function set!");
127
+ if (event.target.result.substring(0, 10) == "data:image") {
128
+ scope.imageSource = event.target.result;
129
+ }
130
+ }
131
+ });
132
+ };
133
+
134
+ } catch (err) {
135
+ // Handle try catch
136
+ scope.error = gettextCatalog.getString("Something went wrong", null, "Nice");
137
+ scope.loading = false;
138
+ scope.imageSource = null;
139
+ }
140
+
141
+ // when the file is read it triggers the onload event above.
142
+ reader.readAsDataURL(inputObj.files[0]);
143
+
144
+ }
145
+ });
146
+
147
+ });
148
+ },
149
+
150
+ controller: function ($scope) {
151
+ $scope.$watch("model", function (value) {
152
+ $scope.imageSource = angular.copy($scope.model);
153
+ });
154
+ }
155
+
156
+ };
157
+ });