Changeset 31559
- Timestamp:
- 2017-03-31T20:51:11+13:00 (7 years ago)
- Location:
- main/trunk/greenstone3/web/interfaces/default
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/interfaces/default/js/javascript-global-functions.js
r31558 r31559 467 467 // check for any caller overrides 468 468 if(opts != null) { 469 //if(opts["use_payload_in_data_not_url_form"] != null) {470 // _use_payload_in_data_not_url_form = opts["use_payload_in_data_not_url_form"];471 //}472 469 if(opts["requestMethod"] != null) { 473 470 method = opts["requestMethod"]; … … 502 499 if(_use_payload_in_data_not_url_form) { // using data payload to do AJAX (regardless of request method) 503 500 504 //method = "POST";505 506 501 // for get-meta operations, go directly through metadata-server.pl 507 502 // for set-meta ops, should go via GS3 authentication, which is off the GS3 library servlet … … 519 514 // finally, can do the AJAX call 520 515 521 console.log("*** Away to call: " + url);516 //console.log("*** Away to call: " + url); 522 517 var ajaxResponse = async_setting ? "*** No response received yet, async ajax request" : null; 523 518 … … 529 524 .success(function(response) { 530 525 ajaxResponse = response; 531 console.log("** (" + callingFunction + ") Response received from server: " + ajaxResponse);526 // console.log("** (" + callingFunction + ") Response received from server: " + ajaxResponse); 532 527 533 528 //var xml = $.parseXML(response); … … 564 559 } 565 560 566 console.log("*** (" + callingFunction + ") Response from server: " + ajaxResponse);567 568 } 569 570 console.log("*** Finished ajax call to: " + url);571 console.log("*** Got response: " + ajaxResponse);561 // console.log("*** (" + callingFunction + ") Response from server: " + ajaxResponse); 562 563 } 564 565 // console.log("*** Finished ajax call to: " + url); 566 // console.log("*** Got response: " + ajaxResponse); 572 567 573 568 return ajaxResponse; -
main/trunk/greenstone3/web/interfaces/default/js/user_comments.js
r31558 r31559 10 10 // http://stackoverflow.com/questions/33514915/what-s-the-difference-between-and-while-declaring-a-javascript-array 11 11 // http://www.nfriedly.com/techblog/2009/06/advanced-javascript-objects-arrays-and-array-like-objects/ 12 // stackoverflow.com/questions/36661748/what-is-the-exact-negation-of-ifvariable-in-javascript 13 // http://stackoverflow.com/questions/784929/what-is-the-not-not-operator-in-javascript 12 14 13 15 /*************** … … 15 17 ****************/ 16 18 19 // avoid making usercomments js functions global (which attaches them as properties to the window object) 17 20 gs.usercomments = {}; 18 21 … … 28 31 29 32 // don't bother loading comments if we're not on a document page (in which case there's no docid) 30 var doc_id = gs.variables["d"]; ///"_cgiargdJssafe_"; //escape("cgiargd"); 31 32 // stackoverflow.com/questions/36661748/what-is-the-exact-negation-of-ifvariable-in-javascript 33 if(!doc_id) { // vs http://stackoverflow.com/questions/784929/what-is-the-not-not-operator-in-javascript 34 33 var doc_id = gs.variables["d"]; ///"_cgiargdJssafe_" in GS2 34 35 if(!doc_id) { 35 36 return; 36 37 } … … 40 41 // asynchronously, this is to help prevent any overlap in these functions' access of meta files in 41 42 // index|archives|import. 43 // Prevent users from adding comments by disabling the submit button 44 // until existing comments have been retrieved and displayed 42 45 var submitButton = document.getElementById("usercommentSubmitButton"); 43 46 if(submitButton) { // there'll be no submitButton if the comment form is not displayed (user not logged in) … … 45 48 } 46 49 47 48 // don't allow users to add comments (disable the submit button)49 // until existing comments have been retrieved and displayed50 //document.getElementById("usercommentSubmitButton").disabled = true;51 52 50 // Since we have a docid, get toplevel section of the docid 53 51 … … 78 76 79 77 var docArray = [doc_rec]; 80 //alert(JSON.stringify(docArray));81 78 82 79 //var json_result_str = gs.functions.getMetadataArray(gs.variables["c"], gs.variables["site"], docArray, "index"); … … 100 97 // Using JavaScript's feature sensing to detect which of the two we're dealing with: 101 98 var json_result_str = (data.responseText) ? data.responseText : data; 102 // http://stackoverflow.com/questions/6286542/how-can-i-check-if-a-var-is-a-string-in-javascript 103 //var json_result_str = (typeof data !== 'string') ? data.responseText : data; 104 //alert("Type of ajax get result: " + typeof (data)); 105 106 // alert(json_result_str); 107 console.log("Got to display: " + json_result_str); 99 100 //console.log("Got user comments to display: " + json_result_str); 101 108 102 var result = JSON.parse(json_result_str); 109 103 // result contains only one docrec (result[0]), since we asked for the usercomments of one docid 110 104 var metatable = result[0].metatable; 111 // alert(JSON.stringify(metatable));112 105 113 106 var i = 0; … … 122 115 attr.nodeValue="usercommentheading"; 123 116 heading.setAttributeNode(attr); 124 var txt=document.createTextNode(gs.variables["textusercommentssection"]); ///"_textusercommentssection_" );117 var txt=document.createTextNode(gs.variables["textusercommentssection"]); ///"_textusercommentssection_" in GS2 125 118 heading.appendChild(txt); 126 119 usercommentdiv.appendChild(heading); … … 141 134 var comment = metatable[2].metavals[i].metavalue; 142 135 143 //alert("Comment: " + username + " " + timestamp + " " + comment);144 145 136 // No need to sort by time, as the meta are already stored sorted 146 137 // and hence retrieved in the right order by using the i (metapos) counter … … 156 147 157 148 var submitButton = document.getElementById("usercommentSubmitButton"); 158 // Now we've finished loading all user comments, allow the user to add a comment 149 // Now we've finished loading all user comments, 150 // allow the user to add a comment by enabling the submit button again 159 151 if(submitButton) { 160 152 submitButton.disabled = false; … … 165 157 gs.usercomments.displayInUserCommentList = function(usercommentdiv, username, timestamp, comment) { 166 158 167 //alert("Comment: " + username + " " + timestamp + " " + comment);168 169 159 var divgroup=document.createElement("div"); 170 160 var attr=document.createAttribute("class"); … … 198 188 } 199 189 200 201 // Unused. Replaced in favour of call to escape() in setMetaArray function that calls urlPostSync202 // http://stackoverflow.com/questions/6020714/escape-html-using-jquery203 gs.usercomments.safeHTML = function(str) {204 return str.replace("&", "&").replace("<", "<").replace(">", ">").replace('"',""").replace("'","'").replace("/", "/"); //"\\""205 }206 207 208 190 gs.usercomments.addUserComment = function(_username, _comment, _docid, doc) { 209 191 … … 214 196 var trimmed_comment = _comment.replace(/^\s+|\s+$/g, ''); 215 197 216 if(!trimmed_comment) { // || !trimmed_username198 if(!trimmed_comment) { 217 199 doc.AddUserCommentForm.comment.value = ""; 218 200 //document.AddUserCommentForm.username.value = ""; 219 document.getElementById("usercommentfeedback").innerHTML = gs.variables["textisempty"]; ///"_textisempty_" ;201 document.getElementById("usercommentfeedback").innerHTML = gs.variables["textisempty"]; ///"_textisempty_" in GS2 220 202 return; 221 203 } … … 236 218 var _timestamp = new Date().getTime(); // div by 1000 to get seconds. valueOf() may return string 237 219 238 //alert("username:" + _username 239 //+ "\\ncomment: " + _comment 240 //+ "\\ncollection: " + collection 241 //+ "\\ndocid: " + _docid 242 //+ "\\ntimestamp: " + _timestamp); 243 244 245 // Entity encode the values before storing (at least <, >, forward slash. 246 // And single and double quote, ampersand) 247 // http://stackoverflow.com/questions/6020714/escape-html-using-jquery 248 // setMetadataArray escapes the entire JSON, is that better than escaping individually here? 249 //_docid = escape(_docid); 250 //_timestamp = escape(_timestamp); 251 //_username = escape(_username); //safeHTML(_username); 252 //_comment = escape(_comment); //safeHTML(_comment); 253 254 // Use this if making individual api calls to set username meta, then timestamp then comment meta 255 // GSAPI already knows the collection 256 //gsapi.setMetadata(_docid, "username", null, _username, "accumulate", "import|archives|index"); 257 //gsapi.setMetadata(_docid, "usertimestamp", null, _timestamp, "accumulate", "import|archives|index"); 258 //gsapi.setMetadata(_docid, "usercomment", null, _comment, "accumulate", "import|archives|index"); 220 // setMetadataArray escapes the entire JSON, so we don't individually escape the fields here 221 // If we did, and called gsapi.setMetadata or gs.functions (in javascript-global-functions.js) instead, 222 // then resort to escaping first, e.g. 223 // _comment = escape(_comment); 224 // gsapi.setMetadata(_docid, "usercomment", null, _comment, "accumulate", "import|archives|index"); 259 225 260 226 … … 287 253 288 254 var docArray = [doc_rec]; 289 290 //alert(JSON.stringify(docArray));291 255 292 256 // Don't allow the user to submit further comments until the metadata has been updated … … 301 265 function(ajaxResult) { return gs.usercomments.doneUpdatingMetatada(ajaxResult, _username, _timestamp, _comment); }, 302 266 false); // false for asynchronous, 303 // this is ok since we're disabling the comment submit button, so no further set-meta-array calls can be304 // made until the ajax call returns and the callback is called which re-enables the submit button267 // async here is ok since we're disabling the comment submit button, so no further set-meta-array calls 268 // can be made until the ajax call returns and the callback is called which re-enables the submit button 305 269 // But disabling submit does not protect against concurrent access such as someone else editing the 306 270 // document (doing set-meta operations, updating archives/index/import) at the same time as someone else … … 311 275 gs.usercomments.doneUpdatingMetatada = function(data, _username, _timestamp, _comment) 312 276 { 313 314 277 // data is xmlHttpRequest Object if gsajaxapi is used for the ajax call. 315 278 // And data is a string if jQuery AJAX was used. 316 279 // Using JavaScript's feature sensing to detect which of the two we're dealing with: 317 280 var result = (data.responseText) ? data.responseText : data; 318 // http://stackoverflow.com/questions/6286542/how-can-i-check-if-a-var-is-a-string-in-javascript319 //var result = (typeof data !== 'string') ? data.responseText : data;320 // alert("Type of ajax set result: " + typeof(data));321 322 //alert("Received post response to setMeta: " + result); // just the HTML page323 281 324 282 // clear the comment field as it has now been submitted, but not the username field … … 336 294 errormessage="ERROR: Unable to add comment. " + error; 337 295 document.getElementById("usercommentfeedback").innerHTML = errormessage; 338 //alert("Result: " + result);339 296 } 340 297 else if (responseErrorIndex != -1) { … … 344 301 errormessage="ERROR: Unable to add comment. " + error; 345 302 document.getElementById("usercommentfeedback").innerHTML = errormessage; 346 //alert("Result: " + result);347 303 } 348 304 else { // success! 349 document.getElementById("usercommentfeedback").innerHTML = gs.variables["textcommentsubmitted"]; ///"_textcommentsubmitted_" ;305 document.getElementById("usercommentfeedback").innerHTML = gs.variables["textcommentsubmitted"]; ///"_textcommentsubmitted_" in GS2 350 306 351 307 // update display of existing user comments to show the newly added comment … … 364 320 gs.usercomments.loadUserComments(); 365 321 366 //$("div#commentarea").html("<textarea required=\"required\" name=\"comment\" rows=\"10\" cols=\"64\" placeholder=\"Add your comment here...\"></textarea>");367 322 $("div#commentarea").html('<textarea required="required" name="comment" rows="10" cols="64" placeholder="Add your comment here..."></textarea>'); 368 323 -
main/trunk/greenstone3/web/interfaces/default/transform/layouts/usercomments.xsl
r31558 r31559 42 42 <div> 43 43 <p><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'usercomments.add')"/></p> 44 <!-- The textarea will be added in by javascript into div#commentarea to avoid the problem of XML turning empty tags into self-closing ones and a self-closing text-area becomes invalid HTML -->44 <!-- The textarea will be added in by javascript into div#commentarea to avoid the problem of XML turning empty tags into self-closing ones and a self-closing text-area becomes invalid HTML. It will look like: --> 45 45 <!--<textarea required="required" name="comment" rows="10" cols="64" placeholder="Add your comment here..."></textarea>--> 46 46 <div id="commentarea">Comment area to appear here</div>
Note:
See TracChangeset
for help on using the changeset viewer.