1+
2+
13$ ( document ) . on ( 'o:prepare-value' , function ( e , type , value , valueObj ) {
24 const thisValue = $ ( value ) ;
35 const container = thisValue . find ( '.nested-data-type_properties' ) ;
46 const addBtn = thisValue . find ( '.nested-data-type_add_property' ) ;
5- const addClass = $ ( '.nested-data-type_add_class' ) ;
6- const rmvBtn = $ ( '.nested-data-type_remove_property' ) ;
7+ const selectResource = $ ( '.nested-data-type__resource_link' ) ;
78
89 // Add a default Value to trigger the hydrate() function
910 const defaultValue = thisValue . find ( '.nested-data-type_value' ) . val ( 'value' ) ;
@@ -17,14 +18,17 @@ $(document).on('o:prepare-value', function (e, type, value, valueObj) {
1718 innerClass = container . find ( '.nested-data-type_repeat_property' ) . last ( ) . find ( '.inner-class' ) ;
1819 innerProperty = container . find ( '.nested-data-type_repeat_property' ) . last ( ) . find ( '.inner-property' ) ;
1920 }
20- const cloneItem = ( ) => container . append ( container . find ( '.nested-data-type_repeat_property' ) . last ( ) . clone ( ) ) ;
21+
22+ const cloneItem = ( ) =>
23+ container . append ( container . find ( '.nested-data-type_repeat_property' ) . last ( ) . clone ( ) ) ;
2124
2225 // Add item on click
2326 addBtn . on ( 'click' , function ( e ) {
2427 e . preventDefault ( ) ;
2528 const num = container . find ( '.nested-data-type_repeat_property' ) . length ;
2629 cloneItem ( ) ;
2730 findItems ( ) ;
31+
2832 select . attr ( { 'data-value-key' : `property-label-${ num + 1 } ` } )
2933 . val ( '' ) ;
3034 textareaValue . attr ( { 'data-value-key' : `property-value-${ num + 1 } ` } )
@@ -35,20 +39,16 @@ $(document).on('o:prepare-value', function (e, type, value, valueObj) {
3539 . val ( '' ) ;
3640 innerProperty . attr ( { 'data-value-key' : `inner-property-${ num + 1 } ` } )
3741 . val ( '' ) ;
38- container . find ( '.nested-data-type_repeat_property' )
39- . last ( )
40- . find ( '.nested-data-type_repeat_class' )
41- . css ( 'display' , 'block' ) ;
4242 } ) ;
4343
4444 // Remove Button on click
45- rmvBtn . on ( 'click' , function ( e ) {
45+ container . on ( 'click' , '.nested-data-type_remove_property ', function ( e ) {
4646 e . preventDefault ( ) ;
4747 $ ( this ) . parent ( ) . remove ( ) ;
4848 } ) ;
4949
5050 // Add Class on click
51- addClass . on ( 'click' , function ( e ) {
51+ container . on ( 'click' , '.nested-data-type_add_class ', function ( e ) {
5252 e . preventDefault ( ) ;
5353 $ ( this ) . next ( ) . children ( ) . val ( '' )
5454 $ ( this ) . next ( ) . toggle ( ) ;
@@ -65,14 +65,27 @@ $(document).on('o:prepare-value', function (e, type, value, valueObj) {
6565 keys . forEach ( ( element , idx ) => {
6666 let item = properties [ 0 ] [ element ] ;
6767 let val = item [ 0 ]
68-
6968 if ( typeof val === "object" ) {
7069 if ( idx == 1 ) {
7170 findItems ( ) ;
7271 select . val ( element ) ;
7372 if ( val [ '@value' ] ) textareaValue . val ( val [ '@value' ] ) ;
7473 if ( val [ 'label' ] ) textareaValue . val ( val [ 'label' ] ) ;
7574 if ( val [ '@id' ] ) textareaUri . val ( val [ '@id' ] ) ;
75+ if ( val [ '@id' ] && val [ '@id' ] . includes ( '/api/items/' ) ) {
76+
77+ container . find ( '.nested-data-type_repeat_property' )
78+ . last ( )
79+ . find ( '.o-title.items' )
80+ . remove ( ) ;
81+
82+ container . find ( '.nested-data-type_repeat_property' )
83+ . last ( )
84+ . find ( '.input' )
85+ . css ( 'display' , 'none' ) ;
86+ let link = `<span class="o-title items ml"><a href="${ url } "> ${ label } </a></span>`
87+ container . append ( container . find ( '.nested-data-type_repeat_property' ) . last ( ) . append ( link ) ) ;
88+ }
7689 }
7790
7891 else if ( idx > 1 ) {
@@ -88,6 +101,22 @@ $(document).on('o:prepare-value', function (e, type, value, valueObj) {
88101 if ( val [ '@value' ] ) { textareaValue . attr ( { 'data-value-key' : `property-value-${ idx } ` } ) . val ( val [ '@value' ] ) } ;
89102 if ( val [ 'label' ] ) textareaValue . attr ( { 'data-value-key' : `property-value-${ idx } ` } ) . val ( val [ 'label' ] ) ;
90103 if ( val [ '@id' ] ) textareaUri . attr ( { 'data-value-key' : `property-uri-${ idx } ` } ) . val ( val [ '@id' ] ) ;
104+
105+ if ( val [ '@id' ] && val [ '@id' ] . includes ( '/api/items/' ) ) {
106+ container . find ( '.nested-data-type_repeat_property' )
107+ . last ( )
108+ . find ( '.o-title.items' )
109+ . remove ( ) ;
110+
111+ container . find ( '.nested-data-type_repeat_property' )
112+ . last ( )
113+ . find ( '.input' )
114+ . css ( 'display' , 'none' ) ;
115+
116+ let changeLinkView = val [ '@id' ] . replace ( '/api/items/' , '/admin/item/' ) ;
117+ let link = `<span class="o-title items ml"><a href="${ changeLinkView } "> ${ val [ 'label' ] } </a></span>`
118+ container . append ( container . find ( '.nested-data-type_repeat_property' ) . last ( ) . append ( link ) ) ;
119+ }
91120 }
92121
93122 for ( const [ key , value ] of Object . entries ( val ) ) {
@@ -106,6 +135,22 @@ $(document).on('o:prepare-value', function (e, type, value, valueObj) {
106135 textareaValue . val ( val [ key ] [ '@id' ] ) ;
107136 }
108137 if ( val [ key ] [ 'label' ] ) textareaValue . val ( val [ key ] [ 'label' ] ) ;
138+
139+ if ( val [ key ] [ '@id' ] && val [ key ] [ '@id' ] . includes ( '/api/items/' ) ) {
140+ container . find ( '.nested-data-type_repeat_property' )
141+ . last ( )
142+ . find ( '.o-title.items' )
143+ . remove ( ) ;
144+
145+ container . find ( '.nested-data-type_repeat_property' )
146+ . last ( )
147+ . find ( '.input' )
148+ . css ( 'display' , 'none' ) ;
149+
150+ let changeLinkView = val [ key ] [ '@id' ] . replace ( '/api/items/' , '/admin/item/' ) ;
151+ let link = `<span class="o-title items ml"><a href="${ changeLinkView } "> ${ val [ key ] [ 'label' ] } </a></span>`
152+ container . append ( container . find ( '.nested-data-type_repeat_property' ) . last ( ) . append ( link ) ) ;
153+ }
109154 }
110155 else if ( idx > 1 ) {
111156 innerClass . attr ( { 'data-value-key' : `inner-class-${ idx } ` } ) ;
@@ -114,15 +159,79 @@ $(document).on('o:prepare-value', function (e, type, value, valueObj) {
114159 if ( val [ key ] [ '@value' ] ) {
115160 textareaValue . attr ( { 'data-value-key' : `property-value-${ idx } ` } ) . val ( val [ key ] [ '@value' ] ) ;
116161 }
117- if ( val [ key ] [ '@id' ] ) {
118- textareaValue . attr ( { 'data-value-key' : `property-value-${ idx } ` } ) . val ( val [ key ] [ '@id' ] ) ;
162+ if ( val [ key ] [ 'label' ] ) {
163+ textareaValue . attr ( { 'data-value-key' : `property-value-${ idx } ` } ) . val ( val [ key ] [ 'label' ] ) ;
164+ }
165+ if ( val [ key ] [ '@id' ] ) textareaUri . attr ( { 'data-value-key' : `property-uri-${ idx } ` } ) . val ( val [ key ] [ '@id' ] ) ;
166+
167+ if ( val [ key ] [ '@id' ] && val [ key ] [ '@id' ] . includes ( '/api/items/' ) ) {
168+ container . find ( '.nested-data-type_repeat_property' )
169+ . last ( )
170+ . find ( '.o-title.items' )
171+ . remove ( ) ;
172+
173+ container . find ( '.nested-data-type_repeat_property' )
174+ . last ( )
175+ . find ( '.input' )
176+ . css ( 'display' , 'none' ) ;
177+
178+ let changeLinkView = val [ key ] [ '@id' ] . replace ( '/api/items/' , '/admin/item/' ) ;
179+ let link = `<span class="o-title items ml"><a href="${ changeLinkView } "> ${ val [ key ] [ 'label' ] } </a></span>`
180+ container . append ( container . find ( '.nested-data-type_repeat_property' ) . last ( ) . append ( link ) ) ;
119181 }
120- if ( val [ key ] [ 'label' ] ) textareaUri . attr ( { 'data-value-key' : `property-uri-${ idx } ` } ) . val ( val [ key ] [ 'label' ] ) ;
121182 }
122183 }
123184 }
124185 } ) ;
125186 }
126187 catch ( error ) { console . error ( error ) ; }
127188 }
189+
190+ $ ( document ) . on ( 'click' , '.nested-data-type__resource_link' , function ( e ) {
191+ e . preventDefault ( ) ;
192+
193+ const resource = JSON . parse ( $ ( this . parentElement ) . attr ( 'data-resource-values' ) ) ;
194+ const id = resource [ '@id' ] ;
195+ const label = resource [ 'display_title' ] ;
196+ const url = resource [ 'url' ] ;
197+
198+ if ( thisValue . is ( '.selecting-resource' ) ) {
199+ const num = container . find ( '.nested-data-type_repeat_property' ) . length ;
200+
201+ cloneItem ( ) ;
202+ findItems ( ) ;
203+
204+ select . attr ( { 'data-value-key' : `property-label-${ num + 1 } ` } )
205+ . val ( '' ) ;
206+ textareaValue . attr ( { 'data-value-key' : `property-value-${ num + 1 } ` } )
207+ . val ( label )
208+ textareaUri . attr ( { 'data-value-key' : `property-uri-${ num + 1 } ` } )
209+ . val ( id )
210+ innerClass . attr ( { 'data-value-key' : `inner-class-${ num + 1 } ` } )
211+ . val ( '' ) ;
212+ innerProperty . attr ( { 'data-value-key' : `inner-property-${ num + 1 } ` } )
213+ . val ( '' ) ;
214+
215+ container . find ( '.nested-data-type_repeat_property' )
216+ . last ( )
217+ . find ( '.input' )
218+ . css ( 'display' , 'none' ) ;
219+
220+ container . find ( '.nested-data-type_repeat_property' )
221+ . last ( )
222+ . find ( '.o-title.items' )
223+ . remove ( ) ;
224+
225+
226+ let link = `<span class="o-title items ml"><a href="${ url } "> ${ label } </a></span>`
227+
228+ console . log ( link )
229+
230+ container . append ( container . find ( '.nested-data-type_repeat_property' ) . last ( ) . append ( link ) ) ;
231+
232+ } ;
233+ } ) ;
234+
128235} ) ;
236+
237+
0 commit comments