Changeset 23312 for main/trunk


Ignore:
Timestamp:
2010-11-10T16:01:41+13:00 (13 years ago)
Author:
sjb48
Message:

Working on saving a modified format statement. Traversing the DOM using JS was unsuccessful so need to figure out how to get the HTML describing the format statement back to the server so it can be processed by Java or XSLT.

Location:
main/trunk/greenstone3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java

    r23298 r23312  
    263263            logger.error("BEFORE Modify node attribute = "+result.getAttributes().getNamedItem("href").getNodeValue());
    264264            String url = result.getAttributes().getNamedItem("href").getNodeValue();
    265             url = url + "&excerptid=gs_content";
     265            url = url + "&excerptid=results";
    266266            result.getAttributes().getNamedItem("href").setNodeValue(url);
    267267            logger.error("AFTER Modify node attribute = "+result.getAttributes().getNamedItem("href").getNodeValue());
  • main/trunk/greenstone3/web/interfaces/oran/js/gui_div.js

    r23298 r23312  
    33
    44var initialised_iframe = "false";
     5
     6function createFormatStatement()
     7{
     8
     9    var formatStatement = document.getElementById('formatStatement');
     10    console.log(formatStatement);
     11    if(formatStatement.hasChildNodes())
     12    {
     13        var formatstring = traverse(formatStatement, "");
     14        console.log(formatstring);
     15
     16        // var children = $(formatStatement).children('div');
     17        // for(var i=0; i < children.length; i++)
     18        //    traverse(children[i], formatstring)
     19     
     20        /*
     21        var children = formatStatement.childNodes; //[]getChildNodes();
     22        var current;
     23        for(var i = 0; i < formatStatement.childNodes.length; i++)
     24        {
     25            current = formatStatement.childNodes[i];
     26            //console.log(current.nodeName);
     27            //console.log(current.nodeType);
     28            if(current.nodeName=='DIV')
     29            {
     30                //console.log(current);
     31                //console.log(current.className);
     32                var gsf = find_class(current);
     33                console.log(gsf);
     34            }
     35        }
     36        */
     37    }
     38}
     39
     40function traverse(node, formatstring)
     41  {
     42    //console.log("node=("+node.nodeName+","+node.nodeType+")");
     43
     44    if(node.nodeName=='DIV')
     45    {
     46        console.log("Found a div" +node.nodeName+","+node.nodeType);
     47        formatstring = formatstring + find_class(node);
     48        console.log(formatstring);
     49    }
     50
     51    var children = $(node).children();
     52    for(var i=0; i < children.length; i++)
     53        formatstring = formatstring + traverse(children[i], formatstring);
     54
     55    return formatstring;
     56  }
     57       
     58
     59/*
     60    console.log("node=("+node.nodeName+","+node.nodeType+")");
     61
     62    if(node.children.length == 0) //hasChildNodes())
     63    {
     64        console.log("No children so return");
     65        return "";
     66    }
     67
     68    if(node.nodeName=='DIV')
     69    {
     70        console.log("Found a div");
     71        formatstring = formatstring + find_class(node);
     72    }       
     73   
     74    for(var i = 0; i < node.children.length; i++)
     75        return recursiveTraverse(node.children[i], formatstring);
     76   
     77
     78    return formatstring;
     79  }
     80*/
     81
     82function find_class(current)
     83{
     84    var classes = current.className.split(' ');
     85    var none = "";
     86    for(var i = 0; i < classes.length; i++)
     87    {
     88        switch(classes[i])
     89        {
     90            case 'gsf_template':
     91              return create_gsf_template(current);
     92            default:
     93            {
     94              console.log("Class not found");
     95              return none;
     96            }
     97        }
     98    }
     99}
     100
     101function create_gsf_template(current)
     102{
     103    // find match text which is an input with class match
     104    var match = $(current).find('.match')[0].value;
     105    console.log(match);
     106   
     107    // find mode text which is an input with class mode
     108    var mode = $(current).find('.mode')[0].value;
     109    console.log(mode);
     110
     111    // "<gsf:template match=\"classifierNode\" mode=\"horizontal\">"
     112    var gsf = "<gsf:template match=\"" + match + "\"";
     113    if(mode != "vertical")
     114        gsf = gsf + " mode=\"" + mode + "\"";
     115    gsf = gsf + ">";
     116   
     117    return gsf;
     118
     119}
     120
    5121/*
    6122$("#iframe").ready(function(){
     
    107223            a = preview_html.substring(0,end_index);
    108224            b = preview_html.substring(end_index);
    109             preview_html = a.concat("&excerptid=gs_content", b);
     225            preview_html = a.concat("&excerptid=results", b);
    110226            console.log(preview_html);
    111             start_index = end_index + "&excerptid=gs_content\">".length;
     227            start_index = end_index + "&excerptid=results\">".length;
    112228        }
    113229    }
     230
     231    // Split the html code in to three parts
     232    var first_index = preview_html.indexOf("<ul id=\"results\"");
     233    console.log("First index is "+first_index);
     234    var second_index = preview_html.indexOf("</ul>", first_index) + "</ul>".length;
     235    console.log("Second index is "+second_index);
     236
     237    var first_half = preview_html.substring(0, first_index);
     238    var iframe_code = preview_html.substring(first_index, second_index);
     239    var second_half = preview_html.substring(second_index);
     240
     241    //$('#my_categories').innerHTML = first_half.concat(second_half);
     242    document.getElementById("my_categories").innerHTML = first_half.concat(second_half);
    114243
    115244    // Put the content in the iframe
     
    119248        console.log(preview_html);
    120249        iframe_document.open();
    121         iframe_document.writeln(preview_html); //.concat("&excerptid=gs_content"));
     250        iframe_document.writeln(iframe_code); //.concat("&excerptid=gs_content"));
    122251        iframe_document.close();
    123252        initialised_iframe = "true";
  • main/trunk/greenstone3/web/interfaces/oran/transform/layouts/main.xsl

    r23298 r23312  
    173173
    174174    <td width="75%">
     175
     176    <button id="updateFormatStatement" type="button" onclick="createFormatStatement()">Update Format Statement</button>
    175177
    176178    <div id="formatStatement">
     
    239241<!-- *************************************************************************************** -->
    240242<H2>Preview</H2>
     243
     244                    <div id="my_categories"><xsl:text> </xsl:text></div>
     245
    241246                    <iframe name="preview" id="iframe" width="98%" height="300">Your browser does not support iframes</iframe>
    242247
  • main/trunk/greenstone3/web/interfaces/oran/transform/layouts/xml-to-gui.xsl

    r23255 r23312  
    236236            <xsl:variable name="mode">
    237237                <xsl:choose>
    238                     <xsl:when test="not(@mode)"> <!-- parameter has not been supplied -->
    239                     </xsl:when>
    240                     <xsl:otherwise>MODE=<input type="text" name="rawtextinput" size="10" value="{@mode}"/></xsl:otherwise>
     238                    <xsl:when test="not(@mode)">MODE=<input class="mode" type="text" name="rawtextinput" size="10" value="vertical"/></xsl:when>
     239                    <xsl:otherwise>MODE=<input class="mode" type="text" name="rawtextinput" size="10" value="{@mode}"/></xsl:otherwise>
    241240                </xsl:choose>
    242241            </xsl:variable>
    243242   
    244             <table class="header"><tbody><tr><td class="header">MATCH=<input type="text" name="rawtextinput" size="10" value="{@match}"/></td><td class="header"><xsl:copy-of select="$mode"/></td><td class="header"><a href="#" class="minmax ui-icon ui-icon-plusthick" title="Click me to expand">[+]</a></td><td class="header"><a href="#" class="remove ui-icon ui-icon-closethick" title="Click me to remove"/></td></tr></tbody></table>
     243            <table class="header"><tbody><tr><td class="header">MATCH=<input class="match" type="text" name="rawtextinput" size="10" value="{@match}"/></td><td class="header"><xsl:copy-of select="$mode"/></td><td class="header"><a href="#" class="minmax ui-icon ui-icon-plusthick" title="Click me to expand">[+]</a></td><td class="header"><a href="#" class="remove ui-icon ui-icon-closethick" title="Click me to remove"/></td></tr></tbody></table>
    245244
    246245                <table class="table" border="1">
Note: See TracChangeset for help on using the changeset viewer.