Changeset 27277

Show
Ignore:
Timestamp:
29.04.2013 20:25:28 (6 years ago)
Author:
ak19
Message:

Adding an Ajax Synchronous Post method to gsajaxapi.js which is then used by the setMetadataArray() that is called from document.dm. Also corrected a variable misspelling in baseaction (authenication changed to authentication) so that locating perl code that deals with authentication may become easier.

Location:
main/trunk/greenstone2
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/macros/document.dm

    r27260 r27277  
    151151<script type="text/javascript">   
    152152 
    153     // http://stackoverflow.com/questions/3830244/get-current-date-time-in-seconds 
     153    // Unused. Replaced in favour of call to escape() in setMetaArray function that calls urlPostSync 
     154    // http://stackoverflow.com/questions/6020714/escape-html-using-jquery 
    154155    function safeHTML(str) \{ 
    155156         return str.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace('"',"&quot;").replace("'","&#x27;").replace("/", "&#x2F;"); //"\\"" 
    156157    \}  
     158 
    157159 
    158160    function addUserComment(_username, _comment, _docid, doc) \{ 
     
    163165            _docid = _docid.substring(0, period); 
    164166        \} 
    165          
    166         // Entity encode the values before storing (at least <, >, /. And single and double quote, ampersand) 
    167         // http://stackoverflow.com/questions/6020714/escape-html-using-jquery 
    168         _username = safeHTML(_username); 
    169         _comment = safeHTML(_comment);       
     167 
    170168 
    171169        // Want to store username, timestamp and comment in import/metadata.xml, archives/doc.xml 
     
    183181 
    184182 
    185         // To make individual api calls to set username meta, then timestamp then comment meta: 
     183        // Entity encode the values before storing (at least <, >, /. And single and double quote, ampersand) 
     184        // http://stackoverflow.com/questions/6020714/escape-html-using-jquery 
     185        // setMetadataArray escapes the entire JSON, is that better than escaping individually here? 
     186        //_docid = escape(_docid); 
     187        //_timestamp = escape(_timestamp); 
     188        //_username = escape(_username); //safeHTML(_username); 
     189        //_comment = escape(_comment); //safeHTML(_comment); 
     190 
     191        // Use this if making individual api calls to set username meta, then timestamp then comment meta 
    186192        // GSAPI already knows the collection 
    187193        //gsapi.setMetadata(_docid, "username", null, _username, "accumulate", "import|archives|index"); 
     
    222228 
    223229        // GSAPI already knows the collection 
    224         gsapi.setMetadataArray(docArray, "accumulate","import|archives|index"); 
    225         //doc.AddUserCommentForm.comment.value = "submitted"; 
    226         doc.getElementById("usercommentfeedback").innerHTML = "_textcommentsubmitted_"; //"submitted"; // <p id="feedback"></p> 
     230        gsapi.setMetadataArray(docArray, "accumulate", "import|archives|index");         
     231        doc.AddUserCommentForm.comment.value = ""; 
     232        doc.AddUserCommentForm.username.value = ""; 
     233        doc.getElementById("usercommentfeedback").innerHTML = "_textcommentsubmitted_"; 
    227234    \} 
    228235</script> 
  • main/trunk/greenstone2/perllib/cgiactions/baseaction.pm

    r27261 r27277  
    3131use inexport; 
    3232 
    33 our $authenication_enabled = 0; 
     33our $authentication_enabled = 0; 
    3434our $mail_enabled = 0; 
    3535 
     
    7171        $err_mess .= "    Compulsory args: "; 
    7272        my @comp_args = ("c"); 
    73         push(@comp_args,"un") if ($authenication_enabled); 
     73        push(@comp_args,"un") if ($authentication_enabled); 
    7474        push(@comp_args,@{$action_table->{$a}->{'compulsory-args'}}); 
    7575        $err_mess .= join(", ", @comp_args); 
     
    7878 
    7979        my @opt_args = (); 
    80         push(@opt_args,"un") if (!$authenication_enabled); 
     80        push(@opt_args,"un") if (!$authentication_enabled); 
    8181        push(@opt_args,@{$action_table->{$a}->{'optional-args'}}); 
    8282 
  • main/trunk/greenstone2/web/script/gsajaxapi.js

    r27257 r27277  
    138138       return xmlHttp.responseText; 
    139139    } 
    140      
     140 
     141    // New, an Ajax Synchronous Post method. 
     142// http://www.degraeve.com/reference/simple-ajax-example.php 
     143// Async vs Sync: http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp  
     144// Also: 
     145// http://stackoverflow.com/questions/6312447/in-an-ajax-post-do-i-need-to-urlencode-parameters-before-sending 
     146// http://api.jquery.com/jQuery.post/ 
     147// http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp 
     148    this.urlPostSync = function(scriptURL, params) { 
     149    var xmlHttp=false; 
     150       try { 
     151         // Firefox, Opera 8.0+, Safari 
     152         xmlHttp=new XMLHttpRequest(); 
     153       } 
     154       catch (e) { 
     155         // Internet Explorer 
     156         try { 
     157           xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
     158         } 
     159         catch (e) { 
     160           try { 
     161             xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 
     162           } 
     163           catch (e) { 
     164             alert("Your browser does not support AJAX!"); 
     165             return false; 
     166           } 
     167         } 
     168       } 
     169 
     170    // e.g. scriptURL: /greenstone/cgi-bin/metadata-server.pl 
     171    xmlHttp.open('POST', scriptURL, false); // false means synchronous 
     172    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
     173     
     174    // If asynchronous: 
     175//    xmlHttp.onreadystatechange = function() { 
     176//        if (xmlHttp.readyState == 4) { 
     177//            updatepage(xmlHttp.responseText); 
     178//        } 
     179//    } 
     180 
     181    xmlHttp.send(params); // needs to be escaped/encoded 
     182 
     183    //alert(xmlHttp.responseText); // if synchronous, process xmlHttp.responseText AFTER send() call 
     184    return xmlHttp.responseText; 
     185} 
     186 
    141187    this.setLiveMetadata = function(id,metaname,metavalue) 
    142188    { 
     
    155201    // The where parameter can be specified as one or more of: import, archives, index, live  
    156202    // separated by |. If null, it is assumed to be index which is the original default  
    157     // behaviour of calling set-metadata). E.g. where=import|archives|index 
     203    // behaviour of calling set-metadata. E.g. where=import|archives|index 
    158204    this.setMetadata = function(docid,metaname,metapos,metavalue,metamode,where) 
    159205    { 
     
    177223    } 
    178224     
    179         this.urlGetSync(mdserver + "?" + params); 
    180         //this.urlPostSync(mdserver,params); 
     225        //this.urlGetSync(mdserver + "?" + params); 
     226        this.urlPostSync(mdserver,params); 
    181227    } 
    182228 
     
    191237    var mdserver = this.metadataserverURL(); 
    192238     
    193     var params = "a=set-metadata-array"; 
     239    var params = "a=" + escape("set-metadata-array"); //"a=set-metadata-array"; 
    194240    if(where != null) { 
    195         params += "&where=" + where; // if where not specified, meta-server will default to setting index meta 
     241        params += "&where=" + escape(where); // if where not specified, meta-server will default to setting index meta 
    196242        //} else { 
    197243        //    params += "&where=import|archives|index"; 
    198244    } 
    199     params += "&c="+collect_; 
    200     params += "&json="+docArrayJSON; 
     245    params += "&c="+escape(collect_); 
     246    params += "&json="+escape(docArrayJSON); 
    201247     
    202248    if (metamode!=null) { 
    203         params += "&metamode=" + metamode; 
    204     } 
    205      
    206     this.urlGetSync(mdserver + "?" + params); 
    207      
     249        params += "&metamode=" + escape(metamode); 
     250    } 
     251     
     252    //this.urlGetSync(mdserver + "?" + params); 
     253    this.urlPostSync(mdserver,params);   
    208254    } 
    209255