@signal24/vue-foundation 3.2.0 → 3.3.4
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.
- package/.eslintrc.js +16 -0
- package/.prettierrc.json +7 -0
- package/CHANGES.md +6 -3
- package/package.json +26 -13
- package/postcss.config.js +1 -1
- package/src/app.js +2 -2
- package/src/components/ajax-select.vue +10 -6
- package/src/components/alert.vue +29 -29
- package/src/components/index.js +6 -11
- package/src/components/modal.vue +18 -10
- package/src/components/smart-select.vue +9 -6
- package/src/config.js +1 -1
- package/src/directives/autofocus.js +4 -3
- package/src/directives/confirm-button.js +2 -2
- package/src/directives/date-input.js +7 -9
- package/src/directives/datetime.js +11 -9
- package/src/directives/disabled.js +4 -5
- package/src/directives/duration.js +7 -8
- package/src/directives/index.js +1 -1
- package/src/directives/infinite-scroll.js +1 -1
- package/src/directives/readonly.js +5 -6
- package/src/directives/tooltip.js +58 -61
- package/src/directives/user-text.js +1 -1
- package/src/filters/index.js +9 -6
- package/src/helpers/array.js +21 -22
- package/src/helpers/context-menu.js +16 -18
- package/src/helpers/delay.js +3 -0
- package/src/helpers/error.js +12 -9
- package/src/helpers/http.js +27 -25
- package/src/helpers/index.js +2 -1
- package/src/helpers/mask.js +27 -20
- package/src/helpers/number.js +2 -2
- package/src/helpers/string.js +17 -17
- package/src/helpers/vue.js +2 -2
- package/src/index.js +5 -5
- package/src/plugins/index.js +6 -6
- package/src/plugins/infinite-scroll/hook.js +2 -2
- package/src/plugins/infinite-scroll.js +20 -10
- package/src/plugins/resize-watcher.js +2 -4
|
@@ -1,48 +1,43 @@
|
|
|
1
|
-
import app from '../app';
|
|
2
1
|
import $ from 'jquery';
|
|
3
2
|
|
|
3
|
+
import app from '../app';
|
|
4
|
+
|
|
4
5
|
app.directive('tip', {
|
|
5
6
|
mounted: createTip,
|
|
6
7
|
updated: createTip,
|
|
7
8
|
unmounted: destroyTip
|
|
8
9
|
});
|
|
9
10
|
|
|
10
|
-
function createTip(el, binding
|
|
11
|
+
function createTip(el, binding) {
|
|
11
12
|
let tipText = el.attributes.tip ? el.attributes.tip.value : binding.value;
|
|
12
|
-
if (binding.value === false)
|
|
13
|
-
tipText = null;
|
|
13
|
+
if (binding.value === false) tipText = null;
|
|
14
14
|
if (tipText) {
|
|
15
15
|
let config = {};
|
|
16
16
|
config[binding.modifiers.html ? 'html' : 'text'] = tipText;
|
|
17
|
-
if (el.attributes['tip-class'])
|
|
18
|
-
config.class = el.attributes['tip-class'].value;
|
|
17
|
+
if (el.attributes['tip-class']) config.class = el.attributes['tip-class'].value;
|
|
19
18
|
$(el).vfTooltip(config);
|
|
20
|
-
}
|
|
21
|
-
else
|
|
22
|
-
$(el).vfTooltip('destroy');
|
|
19
|
+
} else $(el).vfTooltip('destroy');
|
|
23
20
|
}
|
|
24
21
|
|
|
25
22
|
function destroyTip(el) {
|
|
26
23
|
$(el).vfTooltip('destroy');
|
|
27
24
|
}
|
|
28
25
|
|
|
29
|
-
$.fn.vfTooltip = function(option) {
|
|
30
|
-
return this.each(function(index, el) {
|
|
26
|
+
$.fn.vfTooltip = function (option) {
|
|
27
|
+
return this.each(function (index, el) {
|
|
31
28
|
var tooltip = $(el).data('vf-tooltip');
|
|
32
29
|
|
|
33
|
-
if (typeof
|
|
30
|
+
if (typeof option == 'string') {
|
|
34
31
|
if (!tooltip) return;
|
|
35
32
|
tooltip[option]();
|
|
36
|
-
}
|
|
37
|
-
else if (tooltip) {
|
|
33
|
+
} else if (tooltip) {
|
|
38
34
|
tooltip.configure(option);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
$(el).data('vf-tooltip', tooltip);
|
|
35
|
+
} else {
|
|
36
|
+
var vfTooltip = new VfTooltip(el, option);
|
|
37
|
+
$(el).data('vf-tooltip', vfTooltip);
|
|
43
38
|
}
|
|
44
39
|
});
|
|
45
|
-
}
|
|
40
|
+
};
|
|
46
41
|
|
|
47
42
|
function VfTooltip(el, configIn) {
|
|
48
43
|
// exports
|
|
@@ -50,7 +45,11 @@ function VfTooltip(el, configIn) {
|
|
|
50
45
|
this.destroy = _destroy;
|
|
51
46
|
|
|
52
47
|
// state
|
|
53
|
-
var $tip,
|
|
48
|
+
var $tip,
|
|
49
|
+
config,
|
|
50
|
+
lastMoveEvt,
|
|
51
|
+
checkInterval,
|
|
52
|
+
shouldShow = false;
|
|
54
53
|
|
|
55
54
|
// apply config
|
|
56
55
|
this.configure(configIn);
|
|
@@ -62,9 +61,12 @@ function VfTooltip(el, configIn) {
|
|
|
62
61
|
config.now && _handleTargetMouseEnter(config.now);
|
|
63
62
|
|
|
64
63
|
function _configure(configIn) {
|
|
65
|
-
config = $.extend(
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
config = $.extend(
|
|
65
|
+
{
|
|
66
|
+
delay: 0
|
|
67
|
+
},
|
|
68
|
+
configIn
|
|
69
|
+
);
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
function _handleTargetMouseEnter(e) {
|
|
@@ -72,61 +74,54 @@ function VfTooltip(el, configIn) {
|
|
|
72
74
|
|
|
73
75
|
shouldShow = true;
|
|
74
76
|
|
|
75
|
-
setTimeout(function() {
|
|
77
|
+
setTimeout(function () {
|
|
76
78
|
if (!shouldShow) return;
|
|
77
79
|
|
|
78
80
|
_renderTooltip();
|
|
79
81
|
|
|
80
|
-
if (config.static)
|
|
81
|
-
|
|
82
|
-
else
|
|
83
|
-
_handleMouseMove(e);
|
|
82
|
+
if (config.static) _placeStaticTooltip();
|
|
83
|
+
else _handleMouseMove(e);
|
|
84
84
|
|
|
85
85
|
$tip.show();
|
|
86
86
|
}, config.delay);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
function _handleTargetMouseLeave(
|
|
89
|
+
function _handleTargetMouseLeave() {
|
|
90
90
|
shouldShow = false;
|
|
91
91
|
_deferredRemoveTooltip();
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
function _renderTooltip() {
|
|
95
|
-
if (!$tip)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
95
|
+
if (!$tip) config.static || $(window).on('mousemove', _handleMouseMove);
|
|
96
|
+
else $tip.remove();
|
|
97
|
+
|
|
98
|
+
$tip = $('<div class="vf-tooltip">')
|
|
99
|
+
.css('position', 'absolute')
|
|
100
|
+
.css('z-index', '1000000')
|
|
101
|
+
.addClass(config.class)
|
|
102
|
+
.appendTo(document.body);
|
|
101
103
|
config.title && $('<div class="title">').text(config.title).appendTo($tip);
|
|
102
104
|
var $content = $('<div class="content">').appendTo($tip);
|
|
103
105
|
|
|
104
|
-
if (config.callback)
|
|
105
|
-
|
|
106
|
-
else if (config.
|
|
107
|
-
$content.text(config.text).html($content.html().replace(/\n/g, '<br>'));
|
|
108
|
-
else if (config.html)
|
|
109
|
-
$content.html(config.html);
|
|
106
|
+
if (config.callback) config.callback($content[0]);
|
|
107
|
+
else if (config.text) $content.text(config.text).html($content.html().replace(/\n/g, '<br>'));
|
|
108
|
+
else if (config.html) $content.html(config.html);
|
|
110
109
|
|
|
111
110
|
if (config.static) {
|
|
112
|
-
$tip.mouseover(function() {
|
|
111
|
+
$tip.mouseover(function () {
|
|
113
112
|
shouldShow = true;
|
|
114
|
-
}).mouseout(function() {
|
|
113
|
+
}).mouseout(function () {
|
|
115
114
|
shouldShow = false;
|
|
116
115
|
_deferredRemoveTooltip();
|
|
117
116
|
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
else {
|
|
117
|
+
} else {
|
|
121
118
|
checkInterval = setInterval(_checkMoveEvent, 250);
|
|
122
119
|
}
|
|
123
120
|
}
|
|
124
121
|
|
|
125
122
|
function _deferredRemoveTooltip() {
|
|
126
|
-
if (config.static)
|
|
127
|
-
|
|
128
|
-
else
|
|
129
|
-
_removeTooltip();
|
|
123
|
+
if (config.static) setTimeout(_removeTooltip, 50);
|
|
124
|
+
else _removeTooltip();
|
|
130
125
|
}
|
|
131
126
|
|
|
132
127
|
function _removeTooltip() {
|
|
@@ -148,25 +143,27 @@ function VfTooltip(el, configIn) {
|
|
|
148
143
|
var tipX = targetPosition.left;
|
|
149
144
|
var tipY = targetPosition.top - tipHeight - 1;
|
|
150
145
|
if (tipY - 2 < 0) tipY = targetPosition.top + $target.outerHeight(true) + 1;
|
|
151
|
-
$tip.css('min-width', tipW + 'px')
|
|
146
|
+
$tip.css('min-width', tipW + 'px')
|
|
147
|
+
.css('left', tipX + 'px')
|
|
148
|
+
.css('top', tipY + 'px');
|
|
152
149
|
}
|
|
153
150
|
|
|
154
151
|
function _handleMouseMove(e) {
|
|
155
|
-
var tipWidth = $tip.outerWidth(),
|
|
156
|
-
|
|
157
|
-
var
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
152
|
+
var tipWidth = $tip.outerWidth(),
|
|
153
|
+
tipHeight = $tip.outerHeight();
|
|
154
|
+
var viewWidth = window.innerWidth,
|
|
155
|
+
viewHeight = window.innerHeight;
|
|
156
|
+
var tipX = e.pageX + 10,
|
|
157
|
+
tipY = e.pageY + 20;
|
|
158
|
+
if (tipX + tipWidth > viewWidth) tipX = e.pageX - 5 - tipWidth;
|
|
159
|
+
if (tipY + tipHeight > viewHeight) tipY = e.pageY - 5 - tipHeight;
|
|
162
160
|
$tip.css('left', tipX + 'px').css('top', tipY + 'px');
|
|
163
161
|
lastMoveEvt = e;
|
|
164
162
|
}
|
|
165
163
|
|
|
166
164
|
function _checkMoveEvent() {
|
|
167
165
|
if (!lastMoveEvt) return;
|
|
168
|
-
if (el != lastMoveEvt.target && !$.contains(el, lastMoveEvt.target))
|
|
169
|
-
_handleTargetMouseLeave();
|
|
166
|
+
if (el != lastMoveEvt.target && !$.contains(el, lastMoveEvt.target)) _handleTargetMouseLeave();
|
|
170
167
|
}
|
|
171
168
|
|
|
172
169
|
function _destroy() {
|
|
@@ -178,4 +175,4 @@ function VfTooltip(el, configIn) {
|
|
|
178
175
|
$target.off('mouseleave', _handleTargetMouseLeave);
|
|
179
176
|
$target.removeData('vf-tooltip');
|
|
180
177
|
}
|
|
181
|
-
}
|
|
178
|
+
}
|
package/src/filters/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import app from '../app';
|
|
|
2
2
|
|
|
3
3
|
const filterFns = {
|
|
4
4
|
bytes(value) {
|
|
5
|
-
var i = Math.floor(
|
|
5
|
+
var i = Math.floor(Math.log(value) / Math.log(1024));
|
|
6
6
|
return (value / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'KB', 'MB', 'GB', 'TB'][i];
|
|
7
7
|
},
|
|
8
8
|
|
|
@@ -51,7 +51,13 @@ const filterFns = {
|
|
|
51
51
|
},
|
|
52
52
|
|
|
53
53
|
usCurrency(value) {
|
|
54
|
-
return
|
|
54
|
+
return (
|
|
55
|
+
'$' +
|
|
56
|
+
Number(value)
|
|
57
|
+
.toFixed(3)
|
|
58
|
+
.replace(/0$/, '')
|
|
59
|
+
.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
|
60
|
+
);
|
|
55
61
|
}
|
|
56
62
|
};
|
|
57
63
|
|
|
@@ -73,7 +79,4 @@ app.config.globalProperties.$filter = (value, ...filters) => {
|
|
|
73
79
|
return value;
|
|
74
80
|
};
|
|
75
81
|
|
|
76
|
-
export {
|
|
77
|
-
registerFilter,
|
|
78
|
-
registerFilters
|
|
79
|
-
};
|
|
82
|
+
export { registerFilter, registerFilters };
|
package/src/helpers/array.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Object.defineProperty(Array.prototype, 'diff', {
|
|
2
2
|
enumerable: false,
|
|
3
|
-
value: function(...args) {
|
|
3
|
+
value: function (...args) {
|
|
4
4
|
return this.filter(val => {
|
|
5
5
|
for (let i = 0; i < args.length; i++) {
|
|
6
6
|
if (args[i].includes(val)) {
|
|
7
7
|
return false;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
return true;
|
|
12
12
|
});
|
|
13
13
|
}
|
|
@@ -15,36 +15,29 @@ Object.defineProperty(Array.prototype, 'diff', {
|
|
|
15
15
|
|
|
16
16
|
Object.defineProperty(Array.prototype, 'first', {
|
|
17
17
|
enumerable: false,
|
|
18
|
-
value: function() {
|
|
18
|
+
value: function () {
|
|
19
19
|
return this[0] || undefined;
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
Object.defineProperty(Array.prototype, 'intersect', {
|
|
24
24
|
enumerable: false,
|
|
25
|
-
value: function(...args) {
|
|
25
|
+
value: function (...args) {
|
|
26
26
|
return this.filter(val => {
|
|
27
27
|
for (let i = 0; i < args.length; i++) {
|
|
28
28
|
if (args[i].includes(val)) {
|
|
29
29
|
return true;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
return false;
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
-
Object.defineProperty(Array.prototype, 'unique', {
|
|
39
|
-
enumerable: false,
|
|
40
|
-
value: function() {
|
|
41
|
-
return [...new Set(this)]
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
38
|
Object.defineProperty(Array.prototype, 'keyBy', {
|
|
46
39
|
enumerable: false,
|
|
47
|
-
value: function(keyProp) {
|
|
40
|
+
value: function (keyProp) {
|
|
48
41
|
let result = {};
|
|
49
42
|
this.forEach(elem => {
|
|
50
43
|
result[elem[keyProp]] = elem;
|
|
@@ -55,16 +48,15 @@ Object.defineProperty(Array.prototype, 'keyBy', {
|
|
|
55
48
|
|
|
56
49
|
Object.defineProperty(Array.prototype, 'last', {
|
|
57
50
|
enumerable: false,
|
|
58
|
-
value: function() {
|
|
51
|
+
value: function () {
|
|
59
52
|
return this.length ? this[this.length - 1] : undefined;
|
|
60
53
|
}
|
|
61
54
|
});
|
|
62
55
|
|
|
63
56
|
Object.defineProperty(Array.prototype, 'pluck', {
|
|
64
57
|
enumerable: false,
|
|
65
|
-
value: function(prop, keyProp) {
|
|
66
|
-
if (typeof keyProp === 'undefined')
|
|
67
|
-
return this.map(elem => elem[prop]);
|
|
58
|
+
value: function (prop, keyProp) {
|
|
59
|
+
if (typeof keyProp === 'undefined') return this.map(elem => elem[prop]);
|
|
68
60
|
|
|
69
61
|
let result = {};
|
|
70
62
|
this.forEach(elem => {
|
|
@@ -76,25 +68,32 @@ Object.defineProperty(Array.prototype, 'pluck', {
|
|
|
76
68
|
|
|
77
69
|
Object.defineProperty(Array.prototype, 'remove', {
|
|
78
70
|
enumerable: false,
|
|
79
|
-
value: function(element) {
|
|
80
|
-
|
|
71
|
+
value: function (element) {
|
|
72
|
+
const index = this.indexOf(element);
|
|
81
73
|
index > -1 && this.splice(index, 1);
|
|
82
74
|
}
|
|
83
75
|
});
|
|
84
76
|
|
|
85
77
|
Object.defineProperty(Array.prototype, 'replace', {
|
|
86
78
|
enumerable: false,
|
|
87
|
-
value: function(element, replacement) {
|
|
88
|
-
|
|
79
|
+
value: function (element, replacement) {
|
|
80
|
+
const index = this.indexOf(element);
|
|
89
81
|
index > -1 && this.splice(index, 1, replacement);
|
|
90
82
|
}
|
|
91
83
|
});
|
|
92
84
|
|
|
93
85
|
Object.defineProperty(Array.prototype, 'sortBy', {
|
|
94
86
|
enumerable: false,
|
|
95
|
-
value: function(key) {
|
|
87
|
+
value: function (key) {
|
|
96
88
|
this.sort((a, b) => {
|
|
97
89
|
return String(a[key]).toLowerCase().localeCompare(String(b[key]).toLowerCase());
|
|
98
90
|
});
|
|
99
91
|
}
|
|
100
92
|
});
|
|
93
|
+
|
|
94
|
+
Object.defineProperty(Array.prototype, 'unique', {
|
|
95
|
+
enumerable: false,
|
|
96
|
+
value: function () {
|
|
97
|
+
return [...new Set(this)];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import $ from 'jquery';
|
|
2
|
+
|
|
1
3
|
import app from '../app';
|
|
2
|
-
import $ from 'jquery'
|
|
3
4
|
|
|
4
|
-
app.config.globalProperties.$contextMenu = function(e, config) {
|
|
5
|
+
app.config.globalProperties.$contextMenu = function (e, config) {
|
|
5
6
|
var $wrapper = $('<div class="vf-overlay">').click(_closeMenu).appendTo(document.body);
|
|
6
7
|
var $menu = $('<div class="vf-context-menu">').css('position', 'absolute').appendTo($wrapper);
|
|
7
8
|
|
|
@@ -13,16 +14,14 @@ app.config.globalProperties.$contextMenu = function(e, config) {
|
|
|
13
14
|
config.targetClass && $target.addClass(config.targetClass);
|
|
14
15
|
config.class && $menu.addClass(config.class);
|
|
15
16
|
|
|
16
|
-
config.items &&
|
|
17
|
-
|
|
18
|
-
return $('<div class="separator">').appendTo($menu);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
$item.click(item.handler);
|
|
25
|
-
});
|
|
17
|
+
config.items &&
|
|
18
|
+
config.items.forEach(item => {
|
|
19
|
+
if (item == '-') return $('<div class="separator">').appendTo($menu);
|
|
20
|
+
var $item = $('<div class="item">').css('user-select', 'none').text(item.title).appendTo($menu);
|
|
21
|
+
item.class && $item.addClass(item.class);
|
|
22
|
+
if (item.shouldConfirm) $item.data('handler', item.handler).click(_confirmAction);
|
|
23
|
+
else if (item.handler) $item.click(item.handler);
|
|
24
|
+
});
|
|
26
25
|
|
|
27
26
|
const dx = window.innerWidth - e.clientX;
|
|
28
27
|
const dy = window.innerHeight - e.clientY;
|
|
@@ -32,7 +31,7 @@ app.config.globalProperties.$contextMenu = function(e, config) {
|
|
|
32
31
|
const left = dx < menuWidth ? e.clientX - menuWidth - 1 : e.clientX + 1;
|
|
33
32
|
const top = dy < menuHeight ? e.clientY - menuHeight - 1 : e.clientY + 1;
|
|
34
33
|
|
|
35
|
-
$menu.css('left', left + 'px')
|
|
34
|
+
$menu.css('left', left + 'px');
|
|
36
35
|
$menu.css('top', top + 'px');
|
|
37
36
|
|
|
38
37
|
config.onCreate && config.onCreate($menu[0]);
|
|
@@ -53,16 +52,15 @@ app.config.globalProperties.$contextMenu = function(e, config) {
|
|
|
53
52
|
if ($item.hasClass('pending-confirm')) {
|
|
54
53
|
var handler = $item.data('handler');
|
|
55
54
|
handler && handler();
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
55
|
+
} else {
|
|
58
56
|
var originalContent = $item.html();
|
|
59
57
|
$item.addClass('pending-confirm').text('Confirm');
|
|
60
|
-
$item.one('mouseleave', function() {
|
|
58
|
+
$item.one('mouseleave', function () {
|
|
61
59
|
$item.removeClass('pending-confirm').html(originalContent);
|
|
62
60
|
});
|
|
63
61
|
e.stopPropagation();
|
|
64
62
|
}
|
|
65
63
|
}
|
|
66
|
-
}
|
|
64
|
+
};
|
|
67
65
|
|
|
68
|
-
// TODO: actually de-select text rather than just using CSS to hide its selection
|
|
66
|
+
// TODO: actually de-select text rather than just using CSS to hide its selection
|
package/src/helpers/error.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import app from '../app';
|
|
2
|
-
import vfConfig from '../config'
|
|
2
|
+
import vfConfig from '../config';
|
|
3
3
|
|
|
4
4
|
app.config.globalProperties.$reportError = err => {
|
|
5
5
|
if (!(err instanceof Error)) {
|
|
@@ -8,26 +8,29 @@ app.config.globalProperties.$reportError = err => {
|
|
|
8
8
|
|
|
9
9
|
if (vfConfig.reportErrorHandler) {
|
|
10
10
|
vfConfig.reportErrorHandler(err);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
else {
|
|
11
|
+
} else {
|
|
14
12
|
console.error(err);
|
|
15
13
|
}
|
|
16
|
-
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
app.config.globalProperties.$throwUserError = msg => {
|
|
17
|
+
let err = new Error(msg);
|
|
18
|
+
err.code = 'USERERR';
|
|
19
|
+
throw err;
|
|
20
|
+
};
|
|
17
21
|
|
|
18
22
|
Object.defineProperty(Error.prototype, 'userMessage', {
|
|
19
23
|
get() {
|
|
20
|
-
if (this.code == 'USERERR')
|
|
21
|
-
return this.message;
|
|
24
|
+
if (this.code == 'USERERR') return this.message;
|
|
22
25
|
else
|
|
23
26
|
return `An application error has occurred:\n\n${this.message}\n\nPlease refresh the page and try again. If this error persists, ${vfConfig.unhandledErrorSupportText}.`;
|
|
24
27
|
}
|
|
25
28
|
});
|
|
26
29
|
|
|
27
|
-
Error.prototype.handle = function() {
|
|
30
|
+
Error.prototype.handle = function () {
|
|
28
31
|
if (this.code != 'USERERR') {
|
|
29
32
|
app.config.globalProperties.$reportError(this);
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
return this;
|
|
33
|
-
};
|
|
36
|
+
};
|
package/src/helpers/http.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import app from '../app';
|
|
2
|
-
|
|
3
1
|
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
import app from '../app';
|
|
4
4
|
app.config.globalProperties.$http = axios;
|
|
5
5
|
|
|
6
6
|
axios.postOrPut = (baseUrl, id, ...args) => {
|
|
@@ -11,32 +11,34 @@ axios.postOrPut = (baseUrl, id, ...args) => {
|
|
|
11
11
|
|
|
12
12
|
import vfConfig from '../config';
|
|
13
13
|
|
|
14
|
-
axios.interceptors.response.use(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
axios.interceptors.response.use(
|
|
15
|
+
response => {
|
|
16
|
+
// TODO: will Axios auto-reject non-JSON?
|
|
17
|
+
if (response.data && typeof response.data != 'object') {
|
|
18
|
+
throw new Error('response was not JSON');
|
|
19
|
+
}
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
},
|
|
21
|
+
return response;
|
|
22
|
+
},
|
|
22
23
|
|
|
23
|
-
err => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
err => {
|
|
25
|
+
if (err.response && err.response.status == 401) {
|
|
26
|
+
if (vfConfig.unauthorizedHttpResponseHandler) {
|
|
27
|
+
const result = vfConfig.unauthorizedHttpResponseHandler(err.response);
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
// if the handler said "ok, handled", then we're going to
|
|
30
|
+
// return a promise that never resolves to prevent the userland code
|
|
31
|
+
// from ever proceeding
|
|
32
|
+
if (result) return new Promise(() => {});
|
|
33
|
+
}
|
|
32
34
|
}
|
|
33
|
-
}
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
if (err.response && err.response.data && err.response.data.error) {
|
|
37
|
+
err.code = err.response.status == 422 ? 'USERERR' : 'APIERR';
|
|
38
|
+
err.message = err.response.data.error;
|
|
39
|
+
err.field = err.response.data.errorField;
|
|
40
|
+
}
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
}
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
);
|
package/src/helpers/index.js
CHANGED
package/src/helpers/mask.js
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
|
+
import $ from 'jquery';
|
|
2
|
+
|
|
1
3
|
import app from '../app';
|
|
2
|
-
import $ from 'jquery'
|
|
3
4
|
|
|
4
5
|
/*///////////////////////////////////////////////
|
|
5
6
|
Masking
|
|
6
7
|
//////////////////////////////////////////////*/
|
|
7
|
-
app.config.globalProperties.$mask = function(message) {
|
|
8
|
+
app.config.globalProperties.$mask = function (message) {
|
|
8
9
|
let $el = $(this.$el);
|
|
9
10
|
this.$maskEl($el.hasClass('vf-overlay') ? $el.find('.vf-modal')[0] : this.$el, message);
|
|
10
|
-
}
|
|
11
|
+
};
|
|
11
12
|
|
|
12
|
-
app.config.globalProperties.$maskEl = function(el, message) {
|
|
13
|
+
app.config.globalProperties.$maskEl = function (el, message) {
|
|
13
14
|
if (this._currentMask) return;
|
|
14
|
-
this._currentMask = $('<div class="mask">')
|
|
15
|
-
|
|
15
|
+
this._currentMask = $('<div class="mask">')
|
|
16
|
+
.text(message || 'Please wait...')
|
|
17
|
+
.appendTo(el);
|
|
18
|
+
};
|
|
16
19
|
|
|
17
|
-
app.config.globalProperties.$unmask = function() {
|
|
20
|
+
app.config.globalProperties.$unmask = function () {
|
|
18
21
|
if (!this._currentMask) return;
|
|
19
22
|
$(this._currentMask).remove();
|
|
20
23
|
delete this._currentMask;
|
|
21
|
-
}
|
|
24
|
+
};
|
|
22
25
|
|
|
23
|
-
app.config.globalProperties.$maskForm = function(waitButton, waitText) {
|
|
26
|
+
app.config.globalProperties.$maskForm = function (waitButton, waitText) {
|
|
24
27
|
let el = this.$el;
|
|
25
28
|
|
|
26
29
|
if (waitButton !== undefined && waitButton.tagName == 'FORM') {
|
|
@@ -43,9 +46,9 @@ app.config.globalProperties.$maskForm = function(waitButton, waitText) {
|
|
|
43
46
|
$waitButton.disable(waitText || 'Please wait...');
|
|
44
47
|
$form.data('vf-masked-wait-btn', $waitButton);
|
|
45
48
|
}
|
|
46
|
-
}
|
|
49
|
+
};
|
|
47
50
|
|
|
48
|
-
app.config.globalProperties.$unmaskForm = function() {
|
|
51
|
+
app.config.globalProperties.$unmaskForm = function () {
|
|
49
52
|
let $form = this.$el.tagName == 'FORM' ? $(this.$el) : $(this.$el).find('form.masked');
|
|
50
53
|
if (!$form.length) return;
|
|
51
54
|
let $inputs = $form.data('vf-masked-inputs');
|
|
@@ -57,27 +60,31 @@ app.config.globalProperties.$unmaskForm = function() {
|
|
|
57
60
|
$waitButton.enable();
|
|
58
61
|
}
|
|
59
62
|
$form.removeClass('masked');
|
|
60
|
-
}
|
|
63
|
+
};
|
|
61
64
|
|
|
62
65
|
/*///////////////////////////////////////////////
|
|
63
66
|
Button Enable/Disable
|
|
64
67
|
//////////////////////////////////////////////*/
|
|
65
|
-
$.fn.disable = function(newText) {
|
|
66
|
-
this.each(function(index, item) {
|
|
68
|
+
$.fn.disable = function (newText) {
|
|
69
|
+
this.each(function (index, item) {
|
|
67
70
|
var $item = $(item);
|
|
68
71
|
var isInput = item.tagName == 'INPUT';
|
|
69
|
-
newText &&
|
|
72
|
+
newText &&
|
|
73
|
+
$item.data('originalValue', isInput ? $item.val() : $item.html()) &&
|
|
74
|
+
$item[isInput ? 'val' : 'text'](newText);
|
|
70
75
|
$item.attr('disabled', 'disabled');
|
|
71
76
|
});
|
|
72
77
|
return this;
|
|
73
|
-
}
|
|
78
|
+
};
|
|
74
79
|
|
|
75
|
-
$.fn.enable = function() {
|
|
76
|
-
this.each(function(index, item) {
|
|
80
|
+
$.fn.enable = function () {
|
|
81
|
+
this.each(function (index, item) {
|
|
77
82
|
var $item = $(item);
|
|
78
83
|
$item.removeAttr('disabled');
|
|
79
84
|
var originalValue = $item.data('originalValue');
|
|
80
|
-
originalValue != undefined &&
|
|
85
|
+
originalValue != undefined &&
|
|
86
|
+
$item[item.tagName == 'INPUT' ? 'val' : 'html'](originalValue) &&
|
|
87
|
+
$item.removeData('originalValue');
|
|
81
88
|
});
|
|
82
89
|
return this;
|
|
83
|
-
}
|
|
90
|
+
};
|
package/src/helpers/number.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*///////////////////////////////////////////////
|
|
2
2
|
Number Prototype Functions
|
|
3
3
|
///////////////////////////////////////////////*/
|
|
4
|
-
Number.prototype.format = function() {
|
|
4
|
+
Number.prototype.format = function () {
|
|
5
5
|
return this.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
6
|
-
}
|
|
6
|
+
};
|