Changeset 31342

Show
Ignore:
Timestamp:
24.01.2017 00:11:15 (3 years ago)
Author:
davidb
Message:

Some initial progress on collection to workset conversion

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • other-projects/hathitrust/wcsa/vol-checker/WebContent/HT-HTRC_Mashup.user.js

    r31331 r31342  
    1212// ==/UserScript== 
    1313 
    14 // grant GM_xmlhttpRequest 
    15 // grant GM_getValue 
    16 // grant GM_setValue 
    17 // grant GM_addStyle 
    18  
    19 var http_servlet_url="http://bedrock.resnet.cms.waikato.ac.nz:8686/vol-checker/"; 
    20 var https_servlet_url="https://bedrock.resnet.cms.waikato.ac.nz:8643/vol-checker/"; 
     14 
     15var https_servlet_url="https://bedrock.resnet.cms.waikato.ac.nz/vol-checker/"; 
    2116 
    2217function mashupInit() { 
     
    172167 
    173168            if (ids_exist[k]) { 
    174             $id_div.find("ul").append("<li title=\""+k+"\" style=\"color: #924a0b;\"><a>Download Extracted Features</a></li>"); // ✓ 
     169            var encoded_id=encodeURIComponent(k); 
     170            var ef_url = https_servlet_url + "VolumeCheck?download-id=" + encoded_id; 
     171            var atag = "<a href=\""+ ef_url +"\"><span class=\"icomoon icomoon-download\"></span>Download Extracted Features</a>"; 
     172 
     173            $id_div.find("ul").append("<li title=\""+k+"\" style=\"color: #924a0b;\">"+atag+"</li>"); // ✓ 
    175174            } 
    176175            else { 
     
    191190    //console.log("*** GM httpRequest made "); 
    192191    } 
     192 
     193    // Look for collection set download button 
     194 
     195 
     196    var $col_download_button = $('form button[data-tracking-action="MB Download Metadata'); 
     197    if ($col_download_button.length >0) { 
     198        var $download_form=$col_download_button.parent(); 
     199        $download_form.append("<button id=\"col-to-workset-download\" class=\"btn btn-mini\" style=\"margin-top: 12px;\"><i class=\"icomoon icomoon-download\"></i> Convert to HTRC Workset</button>"); 
     200    var $workset_download_button = $('#col-to-workset-download'); 
     201    $workset_download_button.click(function(event) { 
     202            event.preventDefault(); 
     203 
     204        var action = $download_form.attr("action"); 
     205        var action_url = action; 
     206        // Extract hidden elems from, e.g. <input type="hidden" name="c" value="464226859" /><input type="hidden" name="a" value="download" /><input type="hidden" name="format" value="text" /> 
     207        var $hidden_inputs = $download_form.find("input[type=\"hidden\"]"); 
     208        for (var i=0; i<$hidden_inputs.length; i++) { 
     209            var hidden_input = $hidden_inputs[i]; 
     210            //console.log("**** i: " + i + " val = " + $hidden_inputs[i]); 
     211 
     212            if (i===0) { 
     213                action_url += "?"; 
     214            } 
     215            else { 
     216                action_url += "&"; 
     217            } 
     218            var $hidden_input = $(hidden_input); 
     219            action_url += $hidden_input.attr("name") + "=" + $hidden_input.attr("value"); 
     220 
     221            //console.log("download form: " + $hidden_input.attr("name") + "=" + $hidden_input.attr("value")); 
     222        } 
     223 
     224 
     225        console.log("workset download url: " + action_url); 
     226        //window.location.href = action_url; 
     227        }); 
     228 
     229    } 
     230 
     231 
    193232} 
    194233