Skip to content

Commit

Permalink
Fix EMLParty to serialize parties with multiple roles correctly
Browse files Browse the repository at this point in the history
Made an error in the last commit where in the case that no role is assigned in the EMLParty model, the default "Associated Party" role would have raised an error

Relates to issue #994
  • Loading branch information
robyngit committed Jul 25, 2019
1 parent 45ccece commit 8707135
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/js/models/metadata/eml211/EMLParty.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ define(['jquery', 'underscore', 'backbone', 'models/DataONEObject'],
fax: [],
email: [],
onlineUrl: [],
role: [],
roles: [],
references: null,
userId: [],
xmlID: null,
Expand Down Expand Up @@ -106,7 +106,7 @@ define(['jquery', 'underscore', 'backbone', 'models/DataONEObject'],
//Set the text fields
modelJSON.organizationName = $(objectDOM).children("organizationname, organizationName").text() || null;
modelJSON.positionName = $(objectDOM).children("positionname, positionName").text() || null;
modelJSON.role = $(objectDOM).find("role").each(function(i,r){
modelJSON.roles = $(objectDOM).find("role").each(function(i,r){
$(r).text()
});

Expand Down Expand Up @@ -572,24 +572,26 @@ define(['jquery', 'underscore', 'backbone', 'models/DataONEObject'],
}
//Otherwise, change the value of the role element
else {
//If for some reason there is no role, create a default role
if( !this.get("role") )
var roles = ["Associated Party"];
else
var roles = this.get("role");
// If for some reason there is no role, create a default role
if( !this.get("roles") ){
var roles = ["Associated Party"];
} else {
var roles = [];
this.get("roles").each(function(i, role){
roles.push($(role).text());
});
}

roles.each(function(i, role){
var roleText = $(role).text();
_.each(roles, function(role, i){
var roleSerialized = $(objectDOM).find("role");
if(roleSerialized.length){
$(roleSerialized[i]).text(roleText)
$(roleSerialized[i]).text(role)
} else {
this.getEMLPosition(objectDOM, "role").after( $(document.createElement("role")).text(roleText) );
roleSerialized = $(document.createElement("role")).text(role);
this.getEMLPosition(objectDOM, "role").after( roleSerialized );
}
});



}

//XML id attribute
Expand Down

0 comments on commit 8707135

Please sign in to comment.