@@ -19,8 +19,33 @@ $(document).on('o:prepare-value', function (e, type, value, valueObj) {
1919 renderedLink = repeatProperty . find ( '.items' ) ;
2020 }
2121
22- const cloneItem = ( ) => {
23- container . append ( container . find ( '.nested-data-type_repeat_property' ) . last ( ) . clone ( ) ) ;
22+ const cloneItem = ( idx ) => {
23+ let item = `
24+ <div class="nested-data-type_repeat_property">
25+ <div class="nested-data-type_repeat_property_list">
26+ <input class="nested-data-type-dropwdown nested-data-type_property_dropdown" list="property-dropdown" data-value-key="property-label-${ idx } " placeholder="Select a property" />
27+ <button class="nested-data-type_button o-icon-add nested-data-type_add_class"></button>
28+ </div>
29+ <div class="nested-data-type_repeat_class hidden">
30+ <input class="nested-data-type-dropwdown inner-class" list="class-dropdown" data-value-key="inner-class-${ idx } " placeholder="Select a class" />
31+ <input class="nested-data-type-dropwdown inner-property" list="property-dropdown" data-value-key="inner-property-${ idx } " placeholder="Select a property" />
32+ </div>
33+ <div class="input">
34+ <label class="value">
35+ <textarea class="property-value" name="property-value" data-value-key="property-value-${ idx } "></textarea>
36+ </label>
37+ </div>
38+ <div class="input hidden">
39+ <label class="value-uri">
40+ <textarea class="property-uri" name="property-uri" data-value-key="property-uri-${ idx } "></textarea>
41+ </label>
42+ </div>
43+ <input type="hidden" class="nested-data-type_is-hidden" data-value-key="is-hidden-${ idx } " />
44+ <button class="nested-data-type_button o-icon-public nested-data-type_hide_property"></button>
45+ <button class="nested-data-type_button o-icon-delete nested-data-type_remove_property"></button>
46+ </div>` ;
47+
48+ container . append ( container . append ( item ) ) ;
2449 }
2550
2651 const structureField = ( obj , type , insertVal = '' ) => {
@@ -36,22 +61,14 @@ $(document).on('o:prepare-value', function (e, type, value, valueObj) {
3661 addBtn . on ( 'click' , function ( e ) {
3762 e . preventDefault ( ) ;
3863 const num = container . find ( '.nested-data-type_repeat_property' ) . length ;
39- cloneItem ( ) ;
64+ cloneItem ( num + 1 ) ;
4065 findItems ( ) ;
4166
4267 if ( renderedLink ) {
4368 renderedLink . remove ( ) ;
4469 textareaValue . parent ( ) . parent ( ) . css ( 'display' , 'block' ) ;
45- // textareaUri.parent().parent().css('display', 'block')
4670 }
4771
48- structureField ( isHidden , `is-hidden-${ num + 1 } ` ) ;
49- structureField ( select , `property-label-${ num + 1 } ` ) ;
50- structureField ( textareaValue , `property-value-${ num + 1 } ` ) ;
51- structureField ( textareaUri , `property-uri-${ num + 1 } ` ) ;
52- structureField ( innerClass , `inner-class-${ num + 1 } ` ) ;
53- structureField ( innerProperty , `inner-property-${ num + 1 } ` ) ;
54-
5572 container . find ( '.nested-data-type_repeat_property' )
5673 . last ( )
5774 . find ( '.o-icon-private' )
@@ -107,6 +124,7 @@ $(document).on('o:prepare-value', function (e, type, value, valueObj) {
107124 try {
108125 const properties = valueObj . properties ;
109126 const keys = Object . keys ( properties [ 0 ] ) ;
127+
110128 keys . forEach ( ( element , idx ) => {
111129 let item = properties [ 0 ] [ element ] ;
112130
@@ -135,24 +153,18 @@ $(document).on('o:prepare-value', function (e, type, value, valueObj) {
135153 }
136154
137155 else if ( idx > 1 ) {
138- cloneItem ( ) ;
156+ cloneItem ( idx ) ;
139157 findItems ( ) ;
140158
141159 container . find ( '.nested-data-type_hide_property' ) . last ( ) . removeClass ( 'o-icon-private' ) . addClass ( 'o-icon-public' ) ;
142160
143161 if ( renderedLink ) {
144162 renderedLink . remove ( ) ;
145163 textareaValue . parent ( ) . parent ( ) . css ( 'display' , 'block' ) ;
146- // textareaUri.parent().parent().css('display', 'block')
147164 }
148165
149- structureField ( isHidden , `is-hidden-${ idx } ` ) ;
150- structureField ( textareaValue , `property-value-${ idx } ` ) ;
151- structureField ( textareaUri , `property-uri-${ idx } ` ) ;
152166 structureField ( select , `property-label-${ idx } ` , insertVal = element ) ;
153- structureField ( innerClass , `inner-class-${ idx } ` ) ;
154167 innerClass . parent ( ) . css ( 'display' , 'none' ) ;
155- structureField ( innerProperty , `inner-property-${ idx } ` ) ;
156168
157169 if ( val [ 'is_hidden' ] ) {
158170 structureField ( isHidden , `is-hidden-${ idx } ` , insertVal = 'true' ) ;
@@ -200,12 +212,10 @@ $(document).on('o:prepare-value', function (e, type, value, valueObj) {
200212 . last ( )
201213 . find ( '.input' )
202214 . css ( 'display' , 'none' ) ;
203-
204- structureInnerLinks ( val [ key ] [ 'label' ] , val [ '@id' ] . replace ( '/api/items/' , '/admin/item/' ) ) ;
215+ structureInnerLinks ( val [ key ] [ 'label' ] , val [ key ] [ '@id' ] . replace ( '/api/items/' , '/admin/item/' ) ) ;
205216 }
206217 }
207218 else if ( idx > 1 && key != "is_hidden" ) {
208-
209219 structureField ( innerProperty , `inner-property-${ idx } ` , insertVal = key ) ;
210220 if ( key == '@type' ) { structureField ( innerClass , `inner-class-${ idx } ` , insertVal = value ) ; } ;
211221 if ( val [ key ] [ '@value' ] ) { structureField ( textareaValue , `property-value-${ idx } ` , insertVal = val [ key ] [ '@value' ] ) ; }
@@ -245,21 +255,16 @@ $(document).on('o:prepare-value', function (e, type, value, valueObj) {
245255 if ( thisValue . is ( '.selecting-resource' ) ) {
246256 const num = container . find ( '.nested-data-type_repeat_property' ) . length ;
247257
248- cloneItem ( ) ;
258+ cloneItem ( num + 1 ) ;
249259 findItems ( ) ;
250260
251261 if ( renderedLink ) {
252262 renderedLink . remove ( ) ;
253263 textareaValue . parent ( ) . parent ( ) . css ( 'display' , 'block' ) ;
254- // textareaUri.parent().parent().css('display', 'block')
255264 }
256265
257- structureField ( isHidden , `is-hidden-${ num + 1 } ` ) ;
258- structureField ( select , `property-label-${ num + 1 } ` ) ;
259266 structureField ( textareaValue , `property-value-${ num + 1 } ` , insertVal = label ) ;
260267 structureField ( textareaUri , `property-uri-${ num + 1 } ` , insertVal = id ) ;
261- structureField ( innerClass , `inner-class-${ num + 1 } ` ) ;
262- structureField ( innerProperty , `inner-property-${ num + 1 } ` ) ;
263268
264269 container . find ( '.nested-data-type_repeat_property' )
265270 . last ( )
0 commit comments