1
1
import { html , TemplateResult } from 'lit-element' ;
2
- import { nothing } from " lit-html" ;
2
+ import { nothing } from ' lit-html' ;
3
3
import { get } from 'lit-translate' ;
4
- import { DaiValidationTypes , getCustomField } from '../editors/ied/foundation/foundation.js' ;
4
+
5
+ import { DaiFieldTypes , getCustomField } from './foundation/dai-field-type.js' ;
5
6
6
7
import '../../src/wizard-textfield.js' ;
7
8
8
9
import {
9
10
ComplexAction ,
10
11
EditorAction ,
11
- getValue ,
12
12
Wizard ,
13
13
WizardActor ,
14
14
WizardInputElement ,
15
15
} from '../foundation.js' ;
16
- import { SCL_NAMESPACE } from " ../schemas.js" ;
16
+ import { SCL_NAMESPACE } from ' ../schemas.js' ;
17
17
18
- export function updateValue ( instanceElement : Element ) : WizardActor {
18
+ export function updateValue (
19
+ element : Element ,
20
+ instanceElement : Element
21
+ ) : WizardActor {
19
22
return ( inputs : WizardInputElement [ ] ) : EditorAction [ ] => {
20
- const newValue = getValue ( inputs . find ( i => i . value ) ! ) ! ;
21
- const name = instanceElement . getAttribute ( 'name' ) ;
23
+ const bType = element . getAttribute ( 'bType' ) ! ;
24
+ const newValue = getCustomField ( ) [ < DaiFieldTypes > bType ] . value ( inputs ) ;
22
25
26
+ const name = instanceElement . getAttribute ( 'name' ) ;
23
27
const complexAction : ComplexAction = {
24
28
actions : [ ] ,
25
- title : get ( 'dai.action.updatedai' , { daiName : name ! } ) ,
29
+ title : get ( 'dai.action.updatedai' , { daiName : name ! } ) ,
26
30
} ;
27
31
28
32
const oldVal = instanceElement . querySelector ( 'Val' ) ;
29
33
if ( oldVal ) {
30
34
const newVal = < Element > oldVal . cloneNode ( false ) ;
31
35
newVal . textContent = newValue ;
32
- complexAction . actions . push ( { old : { element : oldVal } , new : { element : newVal } } ) ;
36
+ complexAction . actions . push ( {
37
+ old : { element : oldVal } ,
38
+ new : { element : newVal } ,
39
+ } ) ;
33
40
} else {
34
- const newVal = instanceElement . ownerDocument . createElementNS ( SCL_NAMESPACE , 'Val' ) ;
41
+ const newVal = instanceElement . ownerDocument . createElementNS (
42
+ SCL_NAMESPACE ,
43
+ 'Val'
44
+ ) ;
35
45
newVal . textContent = newValue ;
36
- complexAction . actions . push ( { new : { parent : instanceElement , element : newVal } } ) ;
46
+ complexAction . actions . push ( {
47
+ new : { parent : instanceElement , element : newVal } ,
48
+ } ) ;
37
49
}
38
50
return [ complexAction ] ;
39
51
} ;
40
52
}
41
53
42
- export function createValue ( parent : Element , newElement : Element , instanceElement : Element ) : WizardActor {
54
+ export function createValue (
55
+ parent : Element ,
56
+ element : Element ,
57
+ newElement : Element ,
58
+ instanceElement : Element
59
+ ) : WizardActor {
43
60
return ( inputs : WizardInputElement [ ] ) : EditorAction [ ] => {
44
- const newValue = getValue ( inputs . find ( i => i . value ) ! ) ! ;
45
- const name = instanceElement . getAttribute ( 'name' ) ;
46
-
47
- const complexAction : ComplexAction = {
48
- actions : [ ] ,
49
- title : get ( 'dai.action.createdai' , { daiName : name ! } ) ,
50
- } ;
61
+ const bType = element . getAttribute ( 'bType' ) ! ;
62
+ const newValue = getCustomField ( ) [ < DaiFieldTypes > bType ] . value ( inputs ) ;
51
63
52
64
let valElement = instanceElement . querySelector ( 'Val' ) ;
53
65
if ( ! valElement ) {
54
66
valElement = parent . ownerDocument . createElementNS ( SCL_NAMESPACE , 'Val' ) ;
55
67
instanceElement . append ( valElement ) ;
56
68
}
57
69
valElement . textContent = newValue ;
58
- complexAction . actions . push ( { new : { parent, element : newElement } } ) ;
70
+
71
+ const name = instanceElement . getAttribute ( 'name' ) ;
72
+ const complexAction : ComplexAction = {
73
+ actions : [ { new : { parent, element : newElement } } ] ,
74
+ title : get ( 'dai.action.createdai' , { daiName : name ! } ) ,
75
+ } ;
59
76
return [ complexAction ] ;
60
77
} ;
61
78
}
@@ -68,49 +85,64 @@ export function renderDAIWizard(
68
85
const daValue = element . querySelector ( 'Val' ) ?. textContent ?. trim ( ) ?? '' ;
69
86
70
87
return [
71
- html `
72
- ${ getCustomField ( ) [ < DaiValidationTypes > bType ] . render ( element , instanceElement ) }
73
- ${ daValue
74
- ? html `< wizard-textfield label ="DA Template Value "
75
- .maybeValue =${ daValue }
76
- readonly
77
- disabled >
78
- </ wizard-textfield > `
79
- : nothing } `,
88
+ html ` ${ getCustomField ( ) [ < DaiFieldTypes > bType ] . render (
89
+ element ,
90
+ instanceElement
91
+ ) }
92
+ ${ daValue
93
+ ? html `< wizard-textfield
94
+ id ="daVal "
95
+ label ="DA Template Value "
96
+ .maybeValue =${ daValue }
97
+ readonly
98
+ disabled
99
+ >
100
+ </ wizard-textfield > `
101
+ : nothing } `,
80
102
] ;
81
103
}
82
104
83
- export function createDAIWizard ( parent : Element , newElement : Element , element : Element ) : Wizard {
105
+ export function createDAIWizard (
106
+ parent : Element ,
107
+ newElement : Element ,
108
+ element : Element
109
+ ) : Wizard {
84
110
// Retrieve the created DAI, can be the new element or one of the child elements below.
85
- const instanceElement = ( newElement . tagName === 'DAI' ) ? newElement : newElement . querySelector ( 'DAI' ) ! ;
111
+ const instanceElement =
112
+ newElement . tagName === 'DAI'
113
+ ? newElement
114
+ : newElement . querySelector ( 'DAI' ) ! ;
86
115
87
116
return [
88
117
{
89
118
title : get ( 'dai.wizard.title.create' , {
90
- daiName : instanceElement ?. getAttribute ( 'name' ) ?? ''
119
+ daiName : instanceElement ?. getAttribute ( 'name' ) ?? '' ,
91
120
} ) ,
92
121
element : instanceElement ,
93
122
primary : {
94
123
icon : 'edit' ,
95
124
label : get ( 'save' ) ,
96
- action : createValue ( parent , newElement , instanceElement ) ,
125
+ action : createValue ( parent , element , newElement , instanceElement ) ,
97
126
} ,
98
127
content : renderDAIWizard ( element , instanceElement ) ,
99
128
} ,
100
129
] ;
101
130
}
102
131
103
- export function editDAIWizard ( element : Element , instanceElement ?: Element ) : Wizard {
132
+ export function editDAIWizard (
133
+ element : Element ,
134
+ instanceElement ?: Element
135
+ ) : Wizard {
104
136
return [
105
137
{
106
138
title : get ( 'dai.wizard.title.edit' , {
107
- daiName : instanceElement ?. getAttribute ( 'name' ) ?? ''
139
+ daiName : instanceElement ?. getAttribute ( 'name' ) ?? '' ,
108
140
} ) ,
109
141
element : instanceElement ,
110
142
primary : {
111
143
icon : 'edit' ,
112
144
label : get ( 'save' ) ,
113
- action : updateValue ( instanceElement ! ) ,
145
+ action : updateValue ( element , instanceElement ! ) ,
114
146
} ,
115
147
content : renderDAIWizard ( element , instanceElement ) ,
116
148
} ,
0 commit comments