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.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.