Ignore:
Timestamp:
2011-12-16T13:42:28+13:00 (12 years ago)
Author:
sjb48
Message:

Tidied up format functionality.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/oran/js/format_util.js

    r24900 r24907  
    22console.log("Loading format_util.js\n");
    33
    4 // Ensures that a change to a text field is remembered
     4/* Ensures that a change to a text field is remembered */
    55function onTextChange(item, text)
    66{
     
    99}
    1010
    11 // Ensures that a change to a select field is remembered
     11/* Ensures that a change to a select field is remembered */
    1212function onSelectChange(item)
    1313{
     
    2424}
    2525
     26
     27/* Get substring */
    2628function getSubstring(str, first, last)
    2729{
     
    3436    var substring = str.substring(first_index, last_index);
    3537
    36     console.log(substring);
    37 
    3838    return substring;
    3939}
     
    4141function getXSLT(classname)
    4242{
     43    console.log("*** Function getXSLT ***");
    4344    var myurl = document.URL;
    4445
    45     //var collection_name = getSubstring(myurl, "&c", "&");
    4646    var document_id = getSubstring(myurl, "&d", "&");
    4747    var document_type = getSubstring(myurl, "&dt", "&");
    48     var prev_action = getSubstring(myurl, "&p.a", "&");
    49     console.log("Prev action: "+ prev_action);
    50     var prev_service = getSubstring(myurl, "&p.s", "&");
    51     console.log("Prev service: "+ prev_service);
    52 
    53     //var post_url = "http://localhost:8383/greenstone3/dev?a=d&c=" + collection_name + "&d=" + document_id + "&dt=" + document_type + "&p.a=" + prev_action + "&p.s=" + prev_service + "&o=skinandlib";
     48
    5449    var post_url = host_info.pre_URL +"?a=d&c=" + host_info.collection_name + "&d=" + document_id + "&dt=" + document_type + "&o=skinandlib";
    5550
    56     $.post(post_url, {data: classname}, function(data) {
    57             console.log("Success, we have received data");
    58             console.log(data);
     51    $.post(post_url, function(data) {
     52            console.log("Success, we have received the XSLT for the relevant page part");
    5953            classname = "." + classname;
    60             console.log(classname);
    61             var content = $(data).find(classname);
    62             console.log(content.innerXHTML());
    63             console.log(content.xml());
    64             console.log(content);
     54            /* There seemed to be a problem with MIME types for the data received from the post. */
     55            /* The best fix for now is to set the data type to text and then reparse as xml */
     56            xml = $.parseXML(data);
     57            var content = $( xml ).find(classname);
     58            /* The xml() function is provided by jquery.xml.js (included by formatmanager.xsl) */
    6559            $("#XSLTcode").val(content.xml());
    66             }, 'xml');
     60            }, 'text');
    6761}
    6862
     
    162156    CURRENT_SELECT_VALUE = ""; //global - gets set by ui.draggable
    163157
    164     console.log(gs.xsltParams.interface_name);
    165     console.log(gs.collectionMetadata.httpPath);
    166     console.log(document.URL);
    167158    var r = /(https?:\/\/)?([\da-z\.-]+):(\d+)\/([\da-z]+)\/([\da-z]+)\?.*&c=([\da-z\.-]+).*/;
    168159    var s = document.URL;
     
    184175    host_info.pre_URL = "http://" + host_info.host_name + ":" + host_info.port + "/" + host_info.library + "/" + host_info.servlet;
    185176    console.log("Pre URL: " + host_info.pre_URL);
    186 
    187     /*
    188     var collection = "";
    189    
    190     var regex = new RegExp("[?&]c=");
    191     var matches = regex.exec(document.URL);
    192     if(matches != null)
    193     {
    194         var startIndex = matches.index;
    195         var endIndex = document.URL.indexOf("&", startIndex + 1);
    196        
    197         if(endIndex == -1)
    198         {
    199             endIndex = document.URL.length;
    200         }
    201        
    202         collection = document.URL.substring(startIndex, endIndex);
    203     }
    204     */
    205177
    206178    /*
Note: See TracChangeset for help on using the changeset viewer.