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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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";
Note: See TracChangeset for help on using the changeset viewer.