Changeset 32298 for main

Show
Ignore:
Timestamp:
23.07.2018 13:59:46 (13 months ago)
Author:
kjdon
Message:

modified code to provide berry basket links as greenstone doc links, or source doc links, as specified by options at top of file

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/default/js/berrybasket/berrycheckout.js

    r30822 r32298  
     1// The default link type in the basket - "document" = greenstone version of the document, "source" = link to source file eg pdf. 
     2var default_link_type = "document"; // "source" or "document" 
     3// use the appropriate one of these to override the default for particular collections. 
     4var source_link_collections = new Array(); // or add list of collections like ["pdfberry", "mgppdemo"]; 
     5var document_link_collections = new Array(); // or add list of collections as above. 
     6 
    17var docList = new Array(); 
    28var urlonly = false; 
     
    915var mailwin; 
    1016 
    11 var options = new Array(3); 
    12 options[0] = 'fullview'; 
    13 options[1] = 'textview'; 
    14 options[2] = 'email'; 
     17var options = ['fullview', 'textview', 'email']; 
    1518 
    1619function navigate(e){ 
     
    148151        img.setAttribute("width", "15px"); 
    149152        li.appendChild(img); 
    150          
    151         a.href =gs.xsltParams.library_name + "?a=d&c="+doc['collection']+"&d="+doc['name']; 
    152                  
     153 
     154            a.href=generateURL(doc); 
    153155        a.appendChild(document.createTextNode(doc['title']));  
    154156        if (doc['root_title'] != ""){ 
     
    357359} 
    358360 
     361function getDefaultLinkType(collection) { 
     362    var link_type;  
     363    if (document_link_collections.includes(collection)) { 
     364    link_type = "document"; 
     365    } else if (source_link_collections.includes(collection)) { 
     366    link_type = "source"; 
     367    } 
     368    else { 
     369    link_type = default_link_type; 
     370    if (link_type != "source" && link_type != "document") { 
     371        link_type = "document"; //the default default 
     372    } 
     373    } 
     374    return link_type; 
     375} 
     376    
     377function generateURL(doc) { 
     378 
     379    var url; 
     380    var doc_url = document.URL; 
     381    var root_url = doc_url.substring(0,doc_url.indexOf('?')); 
     382 
     383    var link_type = getDefaultLinkType(doc["collection"]); 
     384    if (link_type == "document") { 
     385    url = root_url+"?a=d&c="+doc["collection"]+"&d="+doc["name"]; 
     386    } else if (link_type == "source") {  
     387    // remove library 
     388    root_url = root_url.substring(0, root_url.lastIndexOf('/')); 
     389    url = root_url+"/sites/"+gs.xsltParams.site_name+"/collect/"+doc['collection']+"/index/assoc/"+doc["assocfilepath"]+"/"+doc["srclinkFile"]; 
     390    } 
     391    return url; 
     392} 
     393 
     394 
    359395function populateUrls(parea){ 
    360396 
    361397    var urls=""; 
    362     var doc_url = document.URL; 
    363     var root_url = doc_url.substring(0,doc_url.indexOf('?')); 
    364  
    365398    for (var i in docList){ 
    366         var doc = docList[i]; 
    367         urls +=root_url+"?a=d&c="+doc["collection"]+"&d="+doc["name"]+"\n\n"; 
     399        var doc = docList[i]; 
     400        urls += generateURL(doc)+"\n\n"; 
    368401    } 
    369402 
     
    374407function populateUrlsAndMetadata(parea){ 
    375408 
    376     var doc_url = document.URL; 
    377     var root_url = doc_url.substring(0,doc_url.indexOf('?')); 
    378409    var fulltext=""; 
    379410 
    380411    for (var i in docList){ 
    381         var doc = docList[i]; 
    382         var url =root_url+"?a=d&c="+doc['collection']+"&d="+doc['name']+"\n"; 
    383         var metadata = ""; 
     412        var doc = docList[i]; 
     413        var url = generateURL(doc)+"\n"; 
     414 
     415        var metadata = ""; 
    384416        if (doc['title']) { 
    385417        metadata += gs.text.berry.doc_title+": "+doc['title']+"\n";