- Timestamp:
- 03/10/12 11:10:17 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mauRepo/MolesManager/trunk/cedaMoles/MolesManager/static/js/cedaObservation.js
r8600 r8601 1 define(['dojo', 'dojox/lang/functional', 'ceda/cedaol', 'ceda/common'], function(dojo, functional, cedaol, common){ 1 define(['dojo', 'dojox/lang/functional', 'ceda/cedaol', 'ceda/common', 2 'dojo/parser', 'dojo/_base/json', 3 'dijit/TitlePane','dojo/html'], function(dojo, functional, cedaol, common, parser){ 2 4 //console.log("loads cedaObservation.js") 3 5 // function <nameOfFunction>(parameter, parameter2..etc coming in){ … … 7 9 // } 8 10 9 function getIDs(idArray){ 10 var idDict = {}; 11 for (loopVal=0; loopVal<idArray.length; loopVal++){ 12 var innerDict = {}; 13 14 innerDict['code'] = idArray[loopVal].code; 15 16 try { 17 if (idArray[loopVal].authority.title == 'DOI'){ 18 innerDict['doiDate'] = (idArray[loopVal].authority.hasOwnProperty('date') && idArray[loopVal].authority.date.length != 0 )?idArray[loopVal].authority.date[0].year :'undefined'; 19 } 11 12 13 return { 14 doInit: function(){ 15 function getIDs(idArray){ 16 var idDict = {}; 17 for (loopVal=0; loopVal<idArray.length; loopVal++){ 18 var innerDict = {}; 19 20 innerDict['code'] = idArray[loopVal].code; 21 22 try { 23 if (idArray[loopVal].authority.title == 'DOI'){ 24 innerDict['doiDate'] = (idArray[loopVal].authority.hasOwnProperty('date') && idArray[loopVal].authority.date.length != 0 )?idArray[loopVal].authority.date[0].year :'undefined'; 25 } 26 } 27 catch(err){ 28 console.log('error on DOI') 29 } 30 try { 31 idDict[idArray[loopVal].authority.title] = innerDict; 32 } 33 catch(err){ 34 console.log('empty id field') 35 } 36 37 } 38 return idDict 39 }; 40 41 42 function docLinkObj(moles2url){ 43 var docLinkString = '<p>For further details see the following links: </p><ol><li>' ; 44 docLinkString += '<a href="' + moles2url + '"> CEDA MOLES2 Metadata Catalogue Entry</a>' + '</li></ol>'; 45 return docLinkString 46 }; 47 48 function downloadLink(result){ 49 var dltext = (result.source[0].name != null)?'<p><b>' + result.source[0].name + ':</b> ': '<p><b>Data Download Link:</b> '; 50 dltext += '<a href="'+ result.source[0].linkage + '">' + result.source[0].function + '</a>'; 51 dltext += '</p>'; 52 return dltext 53 }; 54 55 function timeLead(timeElement){ 56 if (timeElement.length == 1){ 57 timeElement = '0' + timeElement; 58 } 59 return timeElement; 60 61 }; 62 63 function publicationDetails(coObs,ids){ 64 var pubDetails = {}; 65 var typePub=(ids.hasOwnProperty('DOI'))?"Dataset is Citable <br /> additional metadata fields may be added ": coObs_old.publicationState.value; 66 67 pubDetails['pubType'] = typePub; 68 69 70 try { 71 pubDetails['pubYear'] = coObs_old.resultTime.position.dateTime8601.year; 72 pubDetails['pubMonth'] = timeLead(coObs_old.resultTime.position.dateTime8601.month); 73 pubDetails['pubDay'] = timeLead(coObs_old.resultTime.position.dateTime8601.day).timeElement; 74 } 75 catch(err){ 76 pubDetails['pubYear'] = 'undefined' 77 pubDetails['pubMonth'] = '' 78 pubDetails['pubDay'] = '' 79 } 80 pubDetails['pubString'] = '<p> Record Status: <b>'+ pubDetails['pubType'] +'</b><br /> Available: <b>' + pubDetails['pubYear'] +'-'+ pubDetails['pubMonth'] + '-' + pubDetails['pubDay']+'</b></p>'; 81 return pubDetails 82 }; 83 84 function buildTimeString(year, month, day, hour, minute, second) { 85 ret = '' 86 if (year){ 87 ret = ret + year 88 if (month){ 89 ret = ret + '-' + month 90 if (day){ 91 ret = ret + '-' + day 92 if (hour){ 93 ret = ret + ' ' + hour 94 if (minute){ 95 ret = ret + ':' + minute 96 if (second){ 97 ret = ret + ':' + second 98 } 99 } 100 } 101 } 102 } 103 } 104 return ret 105 }; 106 107 function resultTime(timeDetails){ 108 timeArray = {}; 109 if (timeDetails){ 110 if (timeDetails.hasOwnProperty('position')){ 111 idate = timeDetails.position.date8601 112 timeArray['startDate'] = buildTimeString(idate.year, idate.month, idate.day, 113 idate.hour, idate.minute, idate.second) 114 timeArray['endDate'] = null 115 } 116 117 if (timeDetails.hasOwnProperty('begin')){ 118 idate = timeDetails.begin.position.date8601 119 timeArray['startDate'] = buildTimeString(idate.year, idate.month, idate.day, 120 idate.hour, idate.minute, idate.second) 121 } 122 if (timeDetails.hasOwnProperty('end')){ 123 idate = timeDetails.begin.position.date8601 124 timeArray['endDate'] = buildTimeString(idate.year, idate.month, idate.day, 125 isdate.hour, idate.minute, idate.second) 126 } 127 } else { 128 timeArray['startDate'] = 'not defined' 129 timeArray['endDate'] = 'not defined' 130 } 131 timeArray['timeString'] = '<p>Data Start Date: <b>'+ timeArray['startDate'] 132 if (!timeArray['timeString']){ 133 timeArray['timeString'] = timeArray['timeString'] + '</b></p><p>Data End Date: <b>' + timeArray['endDate'] 134 } 135 return timeArray 136 }; 137 138 function getRelatedParties(coObs){ 139 var relatedPartyDict = {}; 140 for (loopVal=0; loopVal<coObs.relatedParty.length; loopVal++){ 141 //var names=[]; 142 143 var details = {} ; 144 if (typeof coObs.relatedParty[loopVal].role !='undefined'){ 145 146 if (typeof coObs.relatedParty[loopVal].role !='undefined' && coObs.relatedParty[loopVal].role !=null && coObs.relatedParty[loopVal].party.length > 0){ 147 for (loopInner=0; loopInner<coObs.relatedParty[loopVal].party.length; loopInner++){ 148 var innerDetails = {}; 149 innerDetails['type'] = coObs.relatedParty[loopVal].party[loopInner].__class__ 150 151 if (coObs.relatedParty[loopVal].role == 'pointofcontact'){ 152 try{ 153 innerDetails['helpEmail'] = coObs.relatedParty[loopVal].party[loopInner].contactInfo[0].address.electronicMailAddress[0]; 154 innerDetails['helpString'] = '<p>For assistance please contact <a href="mailto:' + innerDetails['helpEmail'] + '">'+ coObs.relatedParty[loopVal].party[loopInner].name +'</a>.</p>' 155 } 156 catch(err){ 157 innerDetails['helpString'] = '<p>For assistance email <a href="mailto:support@ceda.ac.uk"> CEDA Support</a>.</p>' 158 } 159 } 160 details[coObs.relatedParty[loopVal].party[loopInner].name] = innerDetails 161 162 relatedPartyDict[coObs.relatedParty[loopVal].role] = details;//names; 163 164 } 165 } 166 } 167 } 168 //innerDetails['helpString'] = '<p>For assistance email <a href="mailto:support@ceda.ac.uk"> CEDA Support</a>.</p>' 169 170 return relatedPartyDict 171 }; 172 173 174 function citeNameArrange(nameIn,type){ 175 // function to strip off additional info from the name and then to prepare the name if individual for citation, e.g. 176 // G Vaughan (University of Manchester), PI should be just "Vaughan, G" in citation. 177 178 if (type == 'CI_Organisation'){ 179 return nameIn.split(' (')[0] 180 } 181 else { 182 if (nameIn != 'unknonwn'){ 183 var nameInPartsClean = nameIn.split(',') 184 var nameInParts = nameInPartsClean[0].split(' (')[0].split(' ') 185 leadname = nameInParts[0] 186 return nameInPartsClean[0].split(' (')[0].split(leadname + ' ')[1] + ', ' + leadname 187 } 188 else {return nameIn} 189 } 190 }; 191 192 function getObjectByIndex(obj) { 193 foo = dojo.map(obj, function(item){ return item }); 194 }; 195 196 197 198 function createCitation(coObs,ids,rps,pubDetails,guid){ 199 var citationString =''; 200 authName = functional.keys(rps['author'])[0] 201 citationString += '<p>' + citeNameArrange(authName,rps['author'][authName].type); 202 if (rps.hasOwnProperty('coinvestigator')){ 203 var orgCoauth = ''; 204 var indCoauth = ''; 205 206 for (loopVal=0; loopVal<functional.keys(rps['coinvestigator']).length; loopVal++){ 207 208 var coInvName = functional.keys(rps['coinvestigator'])[loopVal]; 209 if (rps['coinvestigator'][coInvName].type == 'CI_Organisation'){ 210 orgCoauth += '; ' + citeNameArrange(coInvName,rps['coinvestigator'][coInvName].type); 211 } 212 else { 213 214 indCoauth +='; ' + citeNameArrange(coInvName,rps['coinvestigator'][coInvName].type); 215 } 216 } 217 citationString += orgCoauth; 218 citationString += indCoauth; 219 220 } 221 var dataYear=(ids.hasOwnProperty("DOI") && ids["DOI"].doiDate != pubDetails['pubYear'])?ids['DOI'].doiDate:pubDetails['pubYear']; 222 var titleString = ids['ceda_title'].code; 223 citationString += ', (' + dataYear + '): ' + titleString 224 225 if (titleString.substring(titleString.length -1, length) != '.'){ 226 citationString += '.'; 227 } 228 citationString += '[Internet]' 229 230 if (rps.hasOwnProperty('publisher')){ 231 citationString += ' ' + functional.keys(rps['publisher'])[0] +'.'; 232 } 233 else { 234 citationString += ' Centre for Environmental Data Archival.'; 235 } 236 if (ids.hasOwnProperty('DOI')){ 237 var doi = ids['DOI'].code; 238 var doiHttp = (doi.substring(0,18) != 'http://dx.doi.org/')?doiHttp = 'http://dx.doi.org/' + doi : doi; 239 citationString += ' doi:' + '<a href="' + doiHttp + '">' + doiHttp.substring(18,doiHttp.length) + '</a>'; 240 } 241 else { 242 var citeURL = 'http://www.ceda.ac.uk/datacat/' 243 citationString += ' Available from: ' + '<a href="' + citeURL + guid + '">' + citeURL + guid + '</a>'; 244 } 245 citationString += '</p>' 246 return citationString 247 }; 248 249 250 function accessLink(permission){ 251 var accessString = ''; 252 253 if (permission != null ){ 254 var split = permission.useLimitation[0].split(' http://') 255 split[1] = split[1].trim() 256 if (split[1][split[1].length] == '.'){split[1] = split[1].substring[0,split[1].length - 1]} 257 accessString = '<p>' + split[0] + ' <a href="http://' + split[1] + '">' + 'http://' +split[1] + '</a></p>' 258 259 } 260 if (accessString == '' ){ 261 accessString = '<p>These data may be open access. Please contact the data centre to enquire about access to these data.</p>' 262 } 263 264 return accessString 265 }; 266 267 function geogExtent(extents) { 268 try { 269 var box_extents = [extents[0].westBoundLongitude,extents[0].southBoundLatitude,extents[0].eastBoundLongitude,extents[0].northBoundLatitude] 270 } 271 272 catch(err){ 273 var box_extents = [-180,-90,180,90] 274 } 275 276 return box_extents 277 }; 278 279 function bboxText(box_extents){ 280 281 return '<p><b>Bounding Box:</b>:</p><p>N: ' + box_extents[3] + '<br />W: ' + box_extents[0] + ' E: ' + box_extents[2] + '<br />S: '+ box_extents[1] + '</p>' 282 }; 283 284 285 function phenomText(timeBounds){ 286 287 return '<p><b>Start time:</b>:' + timeBounds.startDate + '</p>' + '<p><b>End time:</b>:' + timeBounds.endDate + '</p>' 288 }; 289 290 291 292 function keywordsText(keywords){ 293 var keytext = ''; 294 for (var i = 0; i < keywords.length; i++) { 295 keytext = keywords[i].keyword[0] 296 } 297 return keytext 298 }; 299 300 301 var old_json = dojo.byId('old_coObs_id').value; 302 var json = dojo.byId('coObs_id').value; 303 var isChrome = /(chrome)[ \/]([\w.]+)/i.test(navigator.userAgent); 304 305 if (json == ''){ 306 var title_id = new dojo.html.set(dojo.byId("title_id"),'<h3>The required item does not exist.</h3>'); 307 common.fadeOutNode("lower_section") 308 common.fadeOutNode("upper_section") 309 return 20 310 } 21 catch(err){ 22 console.log('error on DOI') 23 } 24 try { 25 idDict[idArray[loopVal].authority.title] = innerDict; 26 } 27 catch(err){ 28 console.log('empty id field') 29 } 30 31 } 32 return idDict 33 } 311 312 var guid = dojo.byId('guid_id').value; 313 coObs = dojo.fromJson(json); 314 old_coObs = dojo.fromJson(old_json); 315 var coOobs = ' '; 316 317 if (coObs != '' && old_coObs != ''){ 318 319 if (isChrome){ 320 console.log(coObs) 321 console.log(old_coObs) 322 } 323 324 var ids = getIDs(coObs.identifier); 325 var pubDetails_old = publicationDetails(old_coObs,ids); 326 var old_rps = getRelatedParties(old_coObs); 327 328 // top left content 329 330 var pubString = '<p> Record Status: <b>'+ pubDetails_old['pubType'] +'</b><br /> Available: <b>' + coObs.resultTime.year +'-'+ timeLead(coObs.resultTime.month) + '-' + timeLead(coObs.resultTime.day) +'</b></p>'; 331 var pubDetails_id = new dojo.html.set(dojo.byId("pubDetails_id"),pubString); 332 333 // main tabbed area 34 334 35 36 function docLinkObj(moles2url){ 37 var docLinkString = '<p>For further details see the following links: </p><ol><li>' ; 38 docLinkString += '<a href="' + moles2url + '"> CEDA MOLES2 Metadata Catalogue Entry</a>' + '</li></ol>'; 39 return docLinkString 40 } 41 42 function downloadLink(result){ 43 var dltext = (result.source[0].name != null)?'<p><b>' + result.source[0].name + ':</b> ': '<p><b>Data Download Link:</b> '; 44 dltext += '<a href="'+ result.source[0].linkage + '">' + result.source[0].function + '</a>'; 45 dltext += '</p>'; 46 return dltext 47 } 48 49 function timeLead(timeElement){ 50 if (timeElement.length == 1){ 51 timeElement = '0' + timeElement; 52 } 53 return timeElement; 54 55 } 56 57 function publicationDetails(coObs,ids){ 58 var pubDetails = {}; 59 var typePub=(ids.hasOwnProperty('DOI'))?"Dataset is Citable <br /> additional metadata fields may be added ": coObs_old.publicationState.value; 60 61 pubDetails['pubType'] = typePub; 62 63 64 try { 65 pubDetails['pubYear'] = coObs_old.resultTime.position.dateTime8601.year; 66 pubDetails['pubMonth'] = timeLead(coObs_old.resultTime.position.dateTime8601.month); 67 pubDetails['pubDay'] = timeLead(coObs_old.resultTime.position.dateTime8601.day).timeElement; 68 } 69 catch(err){ 70 pubDetails['pubYear'] = 'undefined' 71 pubDetails['pubMonth'] = '' 72 pubDetails['pubDay'] = '' 73 } 74 pubDetails['pubString'] = '<p> Record Status: <b>'+ pubDetails['pubType'] +'</b><br /> Available: <b>' + pubDetails['pubYear'] +'-'+ pubDetails['pubMonth'] + '-' + pubDetails['pubDay']+'</b></p>'; 75 return pubDetails 76 } 77 78 function buildTimeString(year, month, day, hour, minute, second) { 79 ret = '' 80 if (year){ 81 ret = ret + year 82 if (month){ 83 ret = ret + '-' + month 84 if (day){ 85 ret = ret + '-' + day 86 if (hour){ 87 ret = ret + ' ' + hour 88 if (minute){ 89 ret = ret + ':' + minute 90 if (second){ 91 ret = ret + ':' + second 92 } 93 } 94 } 95 } 335 // title 336 try { 337 var title_id = new dojo.html.set(dojo.byId("title_id"),'<h3>'+ ids['ceda_title'].code+'</h3>'); 338 } 339 catch(err){ 340 console.log('no title') 341 } 342 343 // citation 344 var citation_id = new dijit.TitlePane( 345 { 346 title: 'Citation', content: createCitation(old_coObs,ids,old_rps,pubDetails_old,guid) 347 },"citation_id"); 348 citation_id.startup(); 349 350 // previous citations 351 if (ids.hasOwnProperty("moles2url")){ 352 var pastCitation_id = new dijit.TitlePane( 353 { 354 title: "Previous Identifiers Used:", content: '<a href="'+ids['moles2url'].code+'">'+ids['moles2url'].code+'</a>', open: 0 355 },"pastCitation_id"); 356 pastCitation_id.startup(); 357 } 358 359 // description 360 var description_id = new dijit.TitlePane( 361 { 362 title: 'Description', content: coObs.description, open:1 363 },"description_id"); 364 description_id.startup(); 365 366 // accordion content 367 368 // download 369 var dataLink_id = new dojo.html.set(dojo.byId("datalink_id"),downloadLink(old_coObs.result)); 370 // access 371 var access_id = new dojo.html.set(dojo.byId("access_id"),accessLink(old_coObs.permission)); 372 373 try { 374 var help_id = new dojo.html.set(dojo.byId("help_id"),old_rps['pointofcontact'][functional.keys(old_rps['pointofcontact'])[0]].helpString); 375 } 376 catch(err){ 377 console.log('no point of contact given') 378 } 379 380 // bbox 381 var bbox_id = new dijit.TitlePane( 382 { 383 title: 'Geographical Extent', content: bboxText(geogExtent(coObs.geographicExtent)), open:1 384 },"bbox_id"); 385 bbox_id.startup(); 386 387 // phenom time (users see this is the result time!) 388 var resultTime_id = new dijit.TitlePane( 389 { 390 title: 'Data Temporal Range', content: phenomText(coObs.phenomenonTime), open:1 391 392 }, "resultTime_id"); 393 resultTime_id.startup(); 394 395 // var resultTime_id = new dojo.html.set(dojo.byId("resultTime_id"),phenomText(coObs.phenomenonTime)); 396 397 398 // map 399 // following line is used to do the call to map object in cedaol JS file: 400 // uncomment to implement - removed at present due to issue with openlayers. 401 402 try { 403 cedaol.drawMap(coObs.geographicExtent,'map',ids); 404 } 405 catch(err){ 406 console.log('map plotting issue') 407 } 408 409 // lower tab area content 410 411 // lineage 412 var dataLineage_id = new dojo.html.set(dojo.byId("dataLineage_id"),'<p>' + coObs.dataLineage + '</p>'); 413 96 414 } 97 415 } 98 return ret99 416 } 100 101 function resultTime(timeDetails){102 timeArray = {};103 if (timeDetails){104 if (timeDetails.hasOwnProperty('position')){105 idate = timeDetails.position.date8601106 timeArray['startDate'] = buildTimeString(idate.year, idate.month, idate.day,107 idate.hour, idate.minute, idate.second)108 timeArray['endDate'] = null109 }110 111 if (timeDetails.hasOwnProperty('begin')){112 idate = timeDetails.begin.position.date8601113 timeArray['startDate'] = buildTimeString(idate.year, idate.month, idate.day,114 idate.hour, idate.minute, idate.second)115 }116 if (timeDetails.hasOwnProperty('end')){117 idate = timeDetails.begin.position.date8601118 timeArray['endDate'] = buildTimeString(idate.year, idate.month, idate.day,119 isdate.hour, idate.minute, idate.second)120 }121 } else {122 timeArray['startDate'] = 'not defined'123 timeArray['endDate'] = 'not defined'124 }125 timeArray['timeString'] = '<p>Data Start Date: <b>'+ timeArray['startDate']126 if (!timeArray['timeString']){127 timeArray['timeString'] = timeArray['timeString'] + '</b></p><p>Data End Date: <b>' + timeArray['endDate']128 }129 return timeArray130 }131 132 function getRelatedParties(coObs){133 var relatedPartyDict = {};134 for (loopVal=0; loopVal<coObs.relatedParty.length; loopVal++){135 //var names=[];136 137 var details = {} ;138 if (typeof coObs.relatedParty[loopVal].role !='undefined'){139 140 if (typeof coObs.relatedParty[loopVal].role !='undefined' && coObs.relatedParty[loopVal].role !=null && coObs.relatedParty[loopVal].party.length > 0){141 for (loopInner=0; loopInner<coObs.relatedParty[loopVal].party.length; loopInner++){142 var innerDetails = {};143 innerDetails['type'] = coObs.relatedParty[loopVal].party[loopInner].__class__144 145 if (coObs.relatedParty[loopVal].role == 'pointofcontact'){146 try{147 innerDetails['helpEmail'] = coObs.relatedParty[loopVal].party[loopInner].contactInfo[0].address.electronicMailAddress[0];148 innerDetails['helpString'] = '<p>For assistance please contact <a href="mailto:' + innerDetails['helpEmail'] + '">'+ coObs.relatedParty[loopVal].party[loopInner].name +'</a>.</p>'149 }150 catch(err){151 innerDetails['helpString'] = '<p>For assistance email <a href="mailto:support@ceda.ac.uk"> CEDA Support</a>.</p>'152 }153 }154 details[coObs.relatedParty[loopVal].party[loopInner].name] = innerDetails155 156 relatedPartyDict[coObs.relatedParty[loopVal].role] = details;//names;157 158 }159 }160 }161 }162 //innerDetails['helpString'] = '<p>For assistance email <a href="mailto:support@ceda.ac.uk"> CEDA Support</a>.</p>'163 164 return relatedPartyDict165 }166 167 168 function citeNameArrange(nameIn,type){169 // function to strip off additional info from the name and then to prepare the name if individual for citation, e.g.170 // G Vaughan (University of Manchester), PI should be just "Vaughan, G" in citation.171 172 if (type == 'CI_Organisation'){173 return nameIn.split(' (')[0]174 }175 else {176 if (nameIn != 'unknonwn'){177 var nameInPartsClean = nameIn.split(',')178 var nameInParts = nameInPartsClean[0].split(' (')[0].split(' ')179 leadname = nameInParts[0]180 return nameInPartsClean[0].split(' (')[0].split(leadname + ' ')[1] + ', ' + leadname181 }182 else {return nameIn}183 }184 }185 186 function getObjectByIndex(obj) {187 foo = dojo.map(obj, function(item){ return item });188 }189 190 191 192 function createCitation(coObs,ids,rps,pubDetails,guid){193 var citationString ='';194 authName = functional.keys(rps['author'])[0]195 citationString += '<p>' + citeNameArrange(authName,rps['author'][authName].type);196 if (rps.hasOwnProperty('coinvestigator')){197 var orgCoauth = '';198 var indCoauth = '';199 200 for (loopVal=0; loopVal<functional.keys(rps['coinvestigator']).length; loopVal++){201 202 var coInvName = functional.keys(rps['coinvestigator'])[loopVal];203 if (rps['coinvestigator'][coInvName].type == 'CI_Organisation'){204 orgCoauth += '; ' + citeNameArrange(coInvName,rps['coinvestigator'][coInvName].type);205 }206 else {207 208 indCoauth +='; ' + citeNameArrange(coInvName,rps['coinvestigator'][coInvName].type);209 }210 }211 citationString += orgCoauth;212 citationString += indCoauth;213 214 }215 var dataYear=(ids.hasOwnProperty("DOI") && ids["DOI"].doiDate != pubDetails['pubYear'])?ids['DOI'].doiDate:pubDetails['pubYear'];216 var titleString = ids['ceda_title'].code;217 citationString += ', (' + dataYear + '): ' + titleString218 219 if (titleString.substring(titleString.length -1, length) != '.'){220 citationString += '.';221 }222 citationString += '[Internet]'223 224 if (rps.hasOwnProperty('publisher')){225 citationString += ' ' + functional.keys(rps['publisher'])[0] +'.';226 }227 else {228 citationString += ' Centre for Environmental Data Archival.';229 }230 if (ids.hasOwnProperty('DOI')){231 var doi = ids['DOI'].code;232 var doiHttp = (doi.substring(0,18) != 'http://dx.doi.org/')?doiHttp = 'http://dx.doi.org/' + doi : doi;233 citationString += ' doi:' + '<a href="' + doiHttp + '">' + doiHttp.substring(18,doiHttp.length) + '</a>';234 }235 else {236 var citeURL = 'http://www.ceda.ac.uk/datacat/'237 citationString += ' Available from: ' + '<a href="' + citeURL + guid + '">' + citeURL + guid + '</a>';238 }239 citationString += '</p>'240 return citationString241 }242 243 244 function accessLink(permission){245 var accessString = '';246 247 if (permission != null ){248 var split = permission.useLimitation[0].split(' http://')249 split[1] = split[1].trim()250 if (split[1][split[1].length] == '.'){split[1] = split[1].substring[0,split[1].length - 1]}251 accessString = '<p>' + split[0] + ' <a href="http://' + split[1] + '">' + 'http://' +split[1] + '</a></p>'252 253 }254 if (accessString == '' ){255 accessString = '<p>These data may be open access. Please contact the data centre to enquire about access to these data.</p>'256 }257 258 return accessString259 }260 261 function geogExtent(extents) {262 try {263 var box_extents = [extents[0].westBoundLongitude,extents[0].southBoundLatitude,extents[0].eastBoundLongitude,extents[0].northBoundLatitude]264 }265 266 catch(err){267 var box_extents = [-180,-90,180,90]268 }269 270 return box_extents271 }272 273 function bboxText(box_extents){274 275 return '<p><b>Bounding Box:</b>:</p><p>N: ' + box_extents[3] + '<br />W: ' + box_extents[0] + ' E: ' + box_extents[2] + '<br />S: '+ box_extents[1] + '</p>'276 }277 278 279 function phenomText(timeBounds){280 281 return '<p><b>Start time:</b>:' + timeBounds.startDate + '</p>' + '<p><b>End time:</b>:' + timeBounds.endDate + '</p>'282 }283 284 285 286 function keywordsText(keywords){287 var keytext = '';288 for (var i = 0; i < keywords.length; i++) {289 keytext = keywords[i].keyword[0]290 }291 return keytext292 }293 294 require(['dojo/ready', 'dojo/parser', 'dojo/_base/json',295 'dijit/TitlePane','dojo/html'], function(ready, parser){296 ready(function(){297 //----------------------------------------------298 //----- Initializes the necessary widgets ------299 //----------------------------------------------300 // var button = new dijit.form.Button({301 // type: "submit",302 // label: "Search",303 //onClick: function(){ console.log("First button was clicked!"); }304 // }, "search_obs");305 // button.startup();306 307 //----------------------------------------------308 //---------- Loads the widgets values ----------309 //----------------------------------------------310 311 var old_json = dojo.byId('old_coObs_id').value;312 var json = dojo.byId('coObs_id').value;313 var isChrome = /(chrome)[ \/]([\w.]+)/i.test(navigator.userAgent);314 315 if (json == ''){316 var title_id = new dojo.html.set(dojo.byId("title_id"),'<h3>The required item does not exist.</h3>');317 common.fadeOutNode("lower_section")318 common.fadeOutNode("upper_section")319 return320 }321 322 var guid = dojo.byId('guid_id').value;323 coObs = dojo.fromJson(json);324 old_coObs = dojo.fromJson(old_json);325 var coOobs = ' ';326 327 if (coObs != '' && old_coObs != ''){328 329 if (isChrome){330 console.log(coObs)331 console.log(old_coObs)332 }333 334 var ids = getIDs(coObs.identifier);335 var pubDetails_old = publicationDetails(old_coObs,ids);336 var old_rps = getRelatedParties(old_coObs);337 338 // top left content339 340 var pubString = '<p> Record Status: <b>'+ pubDetails_old['pubType'] +'</b><br /> Available: <b>' + coObs.resultTime.year +'-'+ timeLead(coObs.resultTime.month) + '-' + timeLead(coObs.resultTime.day) +'</b></p>';341 var pubDetails_id = new dojo.html.set(dojo.byId("pubDetails_id"),pubString);342 343 // main tabbed area344 345 // title346 try {347 var title_id = new dojo.html.set(dojo.byId("title_id"),'<h3>'+ ids['ceda_title'].code+'</h3>');348 }349 catch(err){350 console.log('no title')351 }352 353 // citation354 var citation_id = new dijit.TitlePane(355 {356 title: 'Citation', content: createCitation(old_coObs,ids,old_rps,pubDetails_old,guid)357 },"citation_id");358 citation_id.startup();359 360 // previous citations361 if (ids.hasOwnProperty("moles2url")){362 var pastCitation_id = new dijit.TitlePane(363 {364 title: "Previous Identifiers Used:", content: '<a href="'+ids['moles2url'].code+'">'+ids['moles2url'].code+'</a>', open: 0365 },"pastCitation_id");366 pastCitation_id.startup();367 }368 369 // description370 var description_id = new dijit.TitlePane(371 {372 title: 'Description', content: coObs.description, open:1373 },"description_id");374 description_id.startup();375 376 // accordion content377 378 // download379 var dataLink_id = new dojo.html.set(dojo.byId("datalink_id"),downloadLink(old_coObs.result));380 // access381 var access_id = new dojo.html.set(dojo.byId("access_id"),accessLink(old_coObs.permission));382 383 try {384 var help_id = new dojo.html.set(dojo.byId("help_id"),old_rps['pointofcontact'][functional.keys(old_rps['pointofcontact'])[0]].helpString);385 }386 catch(err){387 console.log('no point of contact given')388 }389 390 // bbox391 var bbox_id = new dijit.TitlePane(392 {393 title: 'Geographical Extent', content: bboxText(geogExtent(coObs.geographicExtent)), open:1394 },"bbox_id");395 bbox_id.startup();396 397 // phenom time (users see this is the result time!)398 var resultTime_id = new dijit.TitlePane(399 {400 title: 'Data Temporal Range', content: phenomText(coObs.phenomenonTime), open:1401 402 }, "resultTime_id");403 resultTime_id.startup();404 405 // var resultTime_id = new dojo.html.set(dojo.byId("resultTime_id"),phenomText(coObs.phenomenonTime));406 407 408 // map409 // following line is used to do the call to map object in cedaol JS file:410 // uncomment to implement - removed at present due to issue with openlayers.411 412 try {413 cedaol.drawMap(coObs.geographicExtent,'map',ids);414 }415 catch(err){416 console.log('map plotting issue')417 }418 419 // lower tab area content420 421 // lineage422 var dataLineage_id = new dojo.html.set(dojo.byId("dataLineage_id"),'<p>' + coObs.dataLineage + '</p>');423 424 }425 // below is old stuff that is being re-worked to seciton above.426 427 if (coOobs != ''){428 var ids = getIDs(coObs);429 if (isChrome){430 console.log(coObs)431 console.log(coObs.identifier.length)432 }433 434 // var rps = getRelatedParties(coObs);435 436 // var pubDetails_id = new dojo.html.set(dojo.byId("pubDetails_id"),pubDetails['pubString']);437 438 // if (coObs.resultAccumulation != null) {439 // var freqText = (ids.hasOwnProperty('DOI'))?'notPlanned':coObs.resultAccumulation.value;440 // var updateFreq_id = new dojo.html.set(dojo.byId("updateFreq_id"),'<p>Date Update Frequency: <b>'+freqText+'</b></p>');441 // }442 443 // var citation_id = new dijit.TitlePane(444 // {445 // // title: 'Citation', content: createCitation(coObs_old,ids,rps,pubDetails,guid)446 // },"citation_id");447 // citation_id.startup();448 449 450 451 // cedaol.drawMap(coObs.geographicExtent,'map',ids);452 453 // var resultTime_id = new dojo.html.set(dojo.byId("resultTime_id"),resultTime(coObs.phenomenonTime)['timeString']);454 455 456 // dojo.attr("help_id",'value','');457 458 // var docLink_id = new dojo.html.set(dojo.byId("docLink_id"),docLinkObj(ids['moles2url'].code));459 460 // var bbox_id = new dijit.TitlePane(461 // {462 // title: 'Geographical Extent', content: bboxText(coObs.geographicExtent), open:0463 // },"bbox_id");464 // bbox_id.startup();465 //var dublinCoreHolder_id = new dojo.html.set(dojo.byId("dublinCoreHolder_id"),dubCoreContent(coObs,rps));466 467 // var keywords_id = new dijit.TitlePane(468 // {469 // title: 'Keywords', content: keywordsText(coObs.keywords), open:1470 // },"keywords_id");471 //keywords_id.startup();472 473 // var description_id = new dijit.TitlePane(474 // {475 // title: 'Description', content: coObs.description, open:1476 // },"description_id");477 //description_id.startup();478 479 // var dataLineage_id = new dojo.html.set(dojo.byId("dataLineage_id"),'<p>' + coObs.dataLineage + '</p>');480 // if (coObs.inSupportOf.hasOwnProperty('abstract')){481 // if (coObs.inSupportOf.abstract != null){482 // var project_id = new dijit.TitlePane(483 // {484 // title: 'Project Abstract', content: '<p>'+coObs.inSupportOf.abstract+'</p>', open:0485 // },"project_id");486 // project_id.startup();487 // }488 489 // }490 //dataLineage.startup();491 //dojo.attr("records_dataLineage", 'value', coObs.dataLineage);492 493 }494 });495 });496 417 });
Note: See TracChangeset
for help on using the changeset viewer.