Changeset 27257 for main


Ignore:
Timestamp:
2013-04-24T21:20:27+12:00 (11 years ago)
Author:
ak19
Message:

Add User Comment form. Allows adding username, timestamp and comment to a document. Need to still display the just-added comment when the ajax reloads the page. Also should not display the form on a non-doc page, like when browsing a classifier.

Location:
main/trunk/greenstone2
Files:
3 edited

Legend:

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

    r25396 r27257  
    105105<table width=_pagewidth_ cellpadding=0 cellspacing=0 border=0>
    106106<tr><td align=left valign=top>
     107_usercomment_
    107108_prevarrow_
    108109</td><td align=right valign=top>
     
    118119_prevarrow_<br>
    119120_nextarrow_
     121}
     122
     123#######################################################################
     124# section for adding user comments: consists of form and its javascript
     125#######################################################################
     126
     127# For
     128# http://stackoverflow.com/questions/4264091/input-type-submit-instead-of-input-type-button-with-ajax
     129# http://stackoverflow.com/questions/8869341/ajax-form-submit-with-submit-button
     130
     131_usercomment_ {
     132
     133<form name="AddUserCommentForm">
     134<p>_textcommentusername_ <input type="text" name="username"></p>
     135<p>
     136_textaddusercomment_
     137<textarea name="comment" rows="10" cols="70"></textarea>
     138<input type=hidden name="d" value="_cgiargd_">
     139</p>
     140
     141<input type="submit" value="_textaddcomment_" onclick="addUserComment(document.AddUserCommentForm.username.value, document.AddUserCommentForm.comment.value, document.AddUserCommentForm.d.value); return false;">
     142</form>
     143
     144<script type="text/javascript"> 
     145    function addUserComment(_username, _comment, _docid) \{
     146
     147        // Want to store username, timestamp and comment in import/metadata.xml, archives/doc.xml
     148        // and index/col.gdb.
     149
     150        // For getting the current time, see
     151        // http://stackoverflow.com/questions/3830244/get-current-date-time-in-seconds
     152        var _timestamp = new Date().getTime(); // div by 1000 to get seconds. valueOf() may return string
     153
     154        //alert("username:" + _username
     155        //+ "\\ncomment: " + _comment
     156        //+ "\\ncollection: " + collection
     157        //+ "\\ndocid: " + _docid
     158        //+ "\\ntimestamp: " + _timestamp);
     159
     160
     161        // To make individual api calls to set username meta, then timestamp then comment meta:
     162        // GSAPI already knows the collection
     163        //gsapi.setMetadata(_docid, "username", null, _username, "accumulate", "import|archives|index");
     164        //gsapi.setMetadata(_docid, "usertimestamp", null, _timestamp, "accumulate", "import|archives|index");
     165        //gsapi.setMetadata(_docid, "usercomment", null, _comment, "accumulate", "import|archives|index");
     166
     167
     168        // Use the new JSON metatable format to set username, timestamp and comment meta for docid in one go
     169
     170        // For creating the JSON object that gets turned into a string, see
     171        // http://msdn.microsoft.com/en-us/library/ie/cc836459%28v=vs.94%29.aspx
     172        // http://jsfiddle.net/qmacro/W54hy/
     173       
     174        var username_rec = \{
     175            metaname: "username",
     176            metavals: [_username]
     177        \};
     178
     179        var timestamp_rec = \{
     180            metaname: "timestamp",
     181            metavals: [_timestamp]
     182        \};
     183
     184        var comment_rec = \{
     185            metaname: "comment",
     186            metavals: [_comment]
     187        \};
     188
     189        var doc_rec = \{
     190            docid: _docid,
     191            metatable: [username_rec, timestamp_rec, comment_rec],
     192            metamode: "accumulate"
     193        \};
     194
     195        var docArray = [doc_rec];
     196
     197        //alert(JSON.stringify(docArray));
     198
     199        // GSAPI already knows the collection
     200        gsapi.setMetadataArray(docArray, "accumulate","import|archives|index");
     201
     202    \}
     203</script>
    120204}
    121205
  • main/trunk/greenstone2/macros/english.dm

    r27060 r27257  
    336336}
    337337
     338_textcommentusername_ {User name:}
     339_textaddusercomment_ {Add user comment:}
     340_textaddcomment_ {add comment}
     341
    338342_textgoto_ {go to page}
    339343_textintro_ { <i>(introductory text)</i>}
  • main/trunk/greenstone2/web/script/gsajaxapi.js

    r24072 r27257  
    139139    }
    140140   
    141 
    142    
    143    
    144    
    145141    this.setLiveMetadata = function(id,metaname,metavalue)
    146142    {
     
    155151        this.urlGetSync(url);
    156152    }
    157    
     153
     154    // New
     155    // The where parameter can be specified as one or more of: import, archives, index, live
     156    // 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
     158    this.setMetadata = function(docid,metaname,metapos,metavalue,metamode,where)
     159    {
     160        var mdserver = this.metadataserverURL();
     161   
     162        var params = "a=set-metadata";
     163    if(where != null) {
     164        params += "&where=" + where; // if where not specified, meta-server will default to setting index meta
     165        //} else {
     166        //    params += "&where=import|archives|index";
     167    }
     168        params += "&c="+collect_;
     169        params += "&d="+docid;
     170        params += "&metaname=" + metaname;
     171        if (metapos!=null) {
     172            params += "&metapos=" + metapos;
     173        }
     174        params += "&metavalue=" + metavalue;
     175    if (metamode!=null) {
     176            params += "&metamode=" + metamode;
     177    }
     178   
     179        this.urlGetSync(mdserver + "?" + params);
     180        //this.urlPostSync(mdserver,params);
     181    }
     182
     183    // New
     184    // The where parameter can be specified as one or more of: import, archives, index, live
     185    // separated by |. If null, it is assumed to be index which is the original default
     186    // behaviour of calling set-metadata-array). E.g. where=import|archives|index
     187    this.setMetadataArray = function(docArray,metamode,where)
     188    {
     189    docArrayJSON = JSON.stringify(docArray);
     190   
     191    var mdserver = this.metadataserverURL();
     192   
     193    var params = "a=set-metadata-array";
     194    if(where != null) {
     195        params += "&where=" + where; // if where not specified, meta-server will default to setting index meta
     196        //} else {
     197        //    params += "&where=import|archives|index";
     198    }
     199    params += "&c="+collect_;
     200    params += "&json="+docArrayJSON;
     201   
     202    if (metamode!=null) {
     203        params += "&metamode=" + metamode;
     204    }
     205   
     206    this.urlGetSync(mdserver + "?" + params);
     207   
     208    }
     209
    158210    this._setMetadata = function(mode,docid,metaname,metapos,metavalue,metamode)
    159211    {
     
    168220        }
    169221        params += "&metavalue=" + metavalue;
    170         if (metamode!=null) {
     222    if (metamode!=null) {
    171223            params += "&metamode=" + metamode;
    172         }
     224    }
    173225   
    174226        this.urlGetSync(mdserver + "?" + params);
     
    177229   
    178230   
    179     this._setDocumentArrayMetadata = function(mode,docArray,metamode)
    180     {
    181         docArrayJSON = JSON.stringify(docArray);
    182  
    183         var mdserver = this.metadataserverURL();
    184    
    185         var params = "a=set" + mode + "-metadata-array";
    186         params += "&c="+collect_;
    187         params += "&json="+docArrayJSON;
    188    
    189         if (metamode!=null) {
    190             params += "&metamode=" + metamode;
    191         }
    192        
    193         this.urlGetSync(mdserver + "?" + params);
    194    
    195     }
     231    this._setDocumentArrayMetadata = function(mode,docArray,metamode)
     232    {
     233    docArrayJSON = JSON.stringify(docArray);
     234   
     235    var mdserver = this.metadataserverURL();
     236   
     237    var params = "a=set" + mode + "-metadata-array";
     238    params += "&c="+collect_;
     239    params += "&json="+docArrayJSON;
     240   
     241    if (metamode!=null) {
     242        params += "&metamode=" + metamode;
     243    }
     244   
     245    this.urlGetSync(mdserver + "?" + params);
     246   
     247    }
    196248   
    197249   
Note: See TracChangeset for help on using the changeset viewer.