@afeefa/vue-app 0.0.67 → 0.0.68

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.
@@ -1 +1 @@
1
- 0.0.67
1
+ 0.0.68
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afeefa/vue-app",
3
- "version": "0.0.67",
3
+ "version": "0.0.68",
4
4
  "description": "",
5
5
  "author": "Afeefa Kollektiv <kollektiv@afeefa.de>",
6
6
  "license": "MIT",
@@ -1,3 +1,6 @@
1
+ import { AlertEvent } from '@a-vue/events'
2
+ import { eventBus } from '@a-vue/plugins/event-bus/EventBus'
3
+
1
4
  import { ApiAction } from './ApiAction'
2
5
 
3
6
  export class SaveAction extends ApiAction {
@@ -12,4 +15,12 @@ export class SaveAction extends ApiAction {
12
15
 
13
16
  this.alert('Die Daten wurden gespeichert.')
14
17
  }
18
+
19
+ processError (result) {
20
+ eventBus.dispatch(new AlertEvent(AlertEvent.ERROR, {
21
+ headline: 'Die Daten konntent nicht gespeichert werden.',
22
+ message: result.message,
23
+ detail: result.detail
24
+ }))
25
+ }
15
26
  }
@@ -20,7 +20,7 @@ import { debounce } from '@a-vue/utils/debounce'
20
20
  import { ComponentWidthMixin } from './mixins/ComponentWidthMixin'
21
21
 
22
22
  @Component({
23
- props: ['focus', 'debounce', 'validator', 'password']
23
+ props: ['focus', 'debounce', 'validator', {password: false, number: false}]
24
24
  })
25
25
  export default class ATextField extends Mixins(ComponentWidthMixin) {
26
26
  showPassword = false
@@ -58,21 +58,21 @@ export default class ATextField extends Mixins(ComponentWidthMixin) {
58
58
  }
59
59
 
60
60
  get type () {
61
- if (this.password !== undefined && !this.showPassword) {
61
+ if (this.password && !this.showPassword) {
62
62
  return 'password'
63
63
  }
64
64
  return 'text'
65
65
  }
66
66
 
67
67
  get appendIcon () {
68
- if (this.password !== undefined) {
68
+ if (this.password) {
69
69
  return this.showPassword ? '$eyeIcon' : '$eyeOffIcon'
70
70
  }
71
71
  return null
72
72
  }
73
73
 
74
74
  get autocomplete () {
75
- if (this.password !== undefined) {
75
+ if (this.password) {
76
76
  return 'new-password'
77
77
  }
78
78
  return null
@@ -87,7 +87,8 @@ export default class ATextField extends Mixins(ComponentWidthMixin) {
87
87
  if (!this.validator) {
88
88
  return false
89
89
  }
90
- return this.validator.getParams().max || false
90
+
91
+ return (!this.number && this.validator.getParams().max) || false
91
92
  }
92
93
  }
93
94
  </script>
@@ -1,9 +1,11 @@
1
1
  <template>
2
2
  <a-text-field
3
- v-model="model[name]"
3
+ :value="internalValue"
4
4
  :label="label || name"
5
5
  :validator="validator"
6
6
  v-bind="$attrs"
7
+ @input="textFieldValueChanged"
8
+ @blur="onBlur"
7
9
  />
8
10
  </template>
9
11
 
@@ -11,7 +13,70 @@
11
13
  import { Component, Mixins } from '@a-vue'
12
14
  import { FormFieldMixin } from '../FormFieldMixin'
13
15
 
14
- @Component
16
+ @Component({
17
+ props: [{emptyNull: false}]
18
+ })
15
19
  export default class FormFieldText extends Mixins(FormFieldMixin) {
20
+ internalValue = ''
21
+
22
+ created () {
23
+ this.setInternalValue(this.model[this.name])
24
+ this.$watch(() => this.model[this.name], value => {
25
+ this.setInternalValue(value)
26
+ })
27
+ }
28
+
29
+ onBlur () {
30
+ this.setInternalValue(this.model[this.name], true)
31
+ }
32
+
33
+ textFieldValueChanged (value) {
34
+ this.internalValue = value
35
+
36
+ // cast to number
37
+ if (this.isNumber) {
38
+ value = Number(value)
39
+ if (isNaN(value)) {
40
+ return // do not set anything to the model
41
+ }
42
+ }
43
+
44
+ // set model value to null if empty
45
+ if (this.emptyNull) {
46
+ if (this.isNumber) {
47
+ if (value === 0) {
48
+ value = null
49
+ }
50
+ } else {
51
+ if (!value) {
52
+ value = null
53
+ }
54
+ }
55
+ }
56
+
57
+ this.model[this.name] = value
58
+ }
59
+
60
+ setInternalValue (value, reset = false) {
61
+ if (this.isNumber) {
62
+ // reset text field if value is null but keep leading 0 (allows for copy and paste)
63
+ if (value === null) {
64
+ if (!reset && this.internalValue === '0') {
65
+ value = '0'
66
+ } else {
67
+ value = ''
68
+ }
69
+ }
70
+ } else { // null string should be ''
71
+ if (!value) {
72
+ value = ''
73
+ }
74
+ }
75
+ this.internalValue = value
76
+ }
77
+
78
+ get isNumber () {
79
+ return this.$attrs.number === ''
80
+ }
16
81
  }
17
82
  </script>