2828 </th >
2929 </tr >
3030 <template v-for =" (value , name ) in assignedIdentifiers " >
31- <tr :key =" name" v-if =" value && !isEdition " >
31+ <tr :key =" name" v-if =" value && !saveIdentifiersAsList " >
3232 <td >{{ identifierConfigsByKey[name].label }}</td >
3333 <td >{{ value }}</td >
3434 <td >
3535 <button class =" form-control" @click =" removeIdentifier(name)" >Remove</button >
3636 </td >
3737 </tr >
38- <template v-else-if =" value && isEdition " >
38+ <template v-else-if =" value && saveIdentifiersAsList " >
3939 <tr v-for =" (item, idx) in value" :key =" name + idx" >
4040 <td >{{ identifierConfigsByKey[name].label }}</td >
4141 <td >{{ item }}</td >
5252</template >
5353
5454<script >
55- import { errorDisplay , validateEditionIdentifiers } from ' ./IdentifiersInput/utils/utils.js' ;
55+ import { errorDisplay , validateIdentifiers } from ' ./IdentifiersInput/utils/utils.js' ;
5656const identifierPatterns = {
5757 wikidata: / ^ Q[1-9 ] \d * $ / i ,
5858 isni: / ^ [0] {4} ? [0-9 ] {4} ? [0-9 ] {4} ? [0-9 ] {3} [0-9 X] $ / i ,
@@ -76,7 +76,9 @@ export default {
7676 id_config_string: {
7777 type: String
7878 },
79- /** see createHiddenInputs function for usage */
79+ /** see createHiddenInputs function for usage
80+ * #hiddenEditionIdentifiers, #hiddenWorkIdentifiers
81+ */
8082 output_selector: {
8183 type: String
8284 },
@@ -108,20 +110,20 @@ export default {
108110 return {
109111 selectedIdentifier: ' ' , // Which identifier is selected in dropdown
110112 inputValue: ' ' , // What user put into input
111- assignedIdentifiers: {}, // IDs assigned to the entity Ex: {'viaf': '12632978'}
113+ assignedIdentifiers: {}, // IDs assigned to the entity Ex: {'viaf': '12632978'} or {'abaa': ['123456','789012']}
112114 }
113115 },
114116
115117 computed: {
116118 popularEditionConfigs : function () {
117- if (this .isEdition ) {
119+ if (this .edition_popular ) {
118120 const popularConfigs = JSON .parse (decodeURIComponent (this .edition_popular ));
119121 return Object .fromEntries (popularConfigs .map (e => [e .name , e]));
120122 }
121123 return {};
122124 },
123125 secondaryEditionConfigs : function () {
124- if (this .isEdition ) {
126+ if (this .secondary_identifiers ) {
125127 const secondConfigs = JSON .parse (decodeURIComponent (this .secondary_identifiers ));
126128 return Object .fromEntries (secondConfigs .map (e => [e .name , e]));
127129 }
@@ -139,6 +141,9 @@ export default {
139141 return this .admin .toLowerCase () === ' true' ;
140142 },
141143 isEdition () {
144+ return this .multiple .toLowerCase () === ' true' && this .edition_popular ;
145+ },
146+ saveIdentifiersAsList () {
142147 return this .multiple .toLowerCase () === ' true' ;
143148 },
144149 setButtonEnabled : function (){
@@ -154,10 +159,10 @@ export default {
154159 if (this .selectedIdentifier === ' isni' ) {
155160 this .inputValue = this .inputValue .replace (/ \s / g , ' ' )
156161 }
157- if (this .isEdition ) {
162+ if (this .saveIdentifiersAsList ) {
158163 // collect id values of matching type, or empty array if none present
159164 const existingIds = this .assignedIdentifiers [this .selectedIdentifier ] ?? [];
160- const validEditionId = validateEditionIdentifiers (this .selectedIdentifier , this .inputValue , existingIds);
165+ const validEditionId = validateIdentifiers (this .selectedIdentifier , this .inputValue , existingIds, this . output_selector );
161166 if (validEditionId) {
162167 if (! this .assignedIdentifiers [this .selectedIdentifier ]) {
163168 this .inputValue = [this .inputValue ];
@@ -170,18 +175,18 @@ export default {
170175 return ;
171176 }
172177 } else if (this .assignedIdentifiers [this .selectedIdentifier ]) {
173- errorDisplay (` An author identifier for ${ this .identifierConfigsByKey [this .selectedIdentifier ].label } already exists.` )
178+ errorDisplay (` An identifier for ${ this .identifierConfigsByKey [this .selectedIdentifier ].label } already exists.` , this . output_selector )
174179 return ;
175- } else { errorDisplay () }
180+ } else { errorDisplay (' ' , this . output_selector ) }
176181 // We use $set otherwise we wouldn't get the reactivity desired
177182 // See https://vuejs.org/v2/guide/reactivity.html#Change-Detection-Caveats
178183 this .$set (this .assignedIdentifiers , this .selectedIdentifier , this .inputValue );
179184 this .inputValue = ' ' ;
180185 this .selectedIdentifier = ' ' ;
181186 },
182187 /** Removes an identifier with value from memory and it will be deleted from database on save */
183- removeIdentifier: function (identifierName , idx = 0 ){
184- if (this .isEdition ) {
188+ removeIdentifier: function (identifierName , idx = 0 ) {
189+ if (this .saveIdentifiersAsList ) {
185190 this .assignedIdentifiers [identifierName].splice (idx, 1 );
186191 } else {
187192 this .$set (this .assignedIdentifiers , identifierName, ' ' );
@@ -194,7 +199,8 @@ export default {
194199 * So for now this just drops the hidden inputs into the the parent form anytime there is a change
195200 */
196201 let html = ' ' ;
197- if (this .isEdition ) {
202+ // should save a list of ids for work + edition identifiers
203+ if (this .saveIdentifiersAsList ) {
198204 let num = 0 ;
199205 for (const [key , value ] of Object .entries (this .assignedIdentifiers )) {
200206 for (const idx in value) {
@@ -227,7 +233,11 @@ export default {
227233 },
228234 created : function (){
229235 this .assignedIdentifiers = JSON .parse (decodeURIComponent (this .assigned_ids_string ));
230- if (this .isEdition ) {
236+ if (this .assignedIdentifiers .length === 0 ) {
237+ this .assignedIdentifiers = {}
238+ return ;
239+ }
240+ if (this .saveIdentifiersAsList ) {
231241 const edition_identifiers = {};
232242 this .assignedIdentifiers .forEach (entry => {
233243 if (! edition_identifiers[entry .name ]) {
0 commit comments