Changeset 27293 for main/trunk/greenstone2/macros
- Timestamp:
- 2013-05-02T17:43:31+12:00 (11 years ago)
- Location:
- main/trunk/greenstone2/macros
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/macros/document.dm
r27281 r27293 166 166 167 167 function addUserComment(_username, _comment, _docid, doc) \{ 168 169 // don't add empty strings for name/comment 170 171 // http://stackoverflow.com/questions/498970/how-do-i-trim-a-string-in-javascript 172 var trimmed_username=_username.replace(/^\s+|\s+$/g, ''); 173 var trimmed_comment = _comment.replace(/^\s+|\s+$/g, ''); 174 175 if(!trimmed_username || !trimmed_comment) \{ 176 doc.AddUserCommentForm.comment.value = ""; 177 doc.AddUserCommentForm.username.value = ""; 178 doc.getElementById("usercommentfeedback").innerHTML = "_text-is-empty_"; 179 return; 180 \} 181 168 182 // Need to the add user comment meta of username, timestamp and comment to the 169 183 // topmost section of the document. So only get the docId up to any period mark: … … 241 255 242 256 // update display of existing user comments to show the newly added comment 243 loadUserComments(); 257 var usercommentdiv = document.getElementById("usercomments"); 258 if(usercommentdiv != undefined) \{ 259 displayInUserCommentList(usercommentdiv, _username, _timestamp, _comment); 260 \} 244 261 \} 245 262 </script> -
main/trunk/greenstone2/macros/english.dm
r27259 r27293 340 340 _textaddcomment_ {add comment} 341 341 _textcommentsubmitted_ {Comment Submitted} 342 _text-is-empty_ {Can't add empty values} 342 343 343 344 _textgoto_ {go to page} -
main/trunk/greenstone2/macros/style.dm
r27282 r27293 244 244 // http://stackoverflow.com/questions/6312993/javascript-seconds-to-time-with-format-hhmmss 245 245 // Call as: alert(timestamp.printTime()); 246 String.prototype.printTime = function () \{247 var timestamp = parseInt(this, 10); // don't forget the second param248 var date = new Date( timestamp);246 function formatTime(timestamp) \{ 247 var int_timestamp = parseInt(timestamp, 10); // don't forget the second param 248 var date = new Date(int_timestamp); 249 249 return date.toLocaleDateString() + " " + date.toLocaleTimeString(); 250 250 \} … … 313 313 314 314 metapos++; 315 username = gsapi.getArchivesMetadata(doc_id, "username", metapos); 315 username = gsapi.getArchivesMetadata(doc_id, "username", metapos);//, "_cgiargun_", "_cgiargpw_"); 316 316 \} 317 317 318 318 // No need to sort by time, 319 // as the array is already stored sorted and hence retrieved in the right order by using metapos tcounter319 // as the array is already stored sorted and hence retrieved in the right order by using metapos counter 320 320 // If sorting the array of comment records, which would be by timestamp, see 321 321 // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/sort … … 328 328 329 329 // create the output HTML for all comments in one go now 330 // (we do this here altogether to hopefully avoid reloading the page for each comment)330 // (we do this here for all values together to hopefully avoid reloading the page for each comment) 331 331 332 332 for(var i = 0; i < metapos; i++) \{ … … 339 339 340 340 // for each usercomment, create a child div with the username, timestamp and comment 341 342 var divgroup=document.createElement("div"); 343 var attr=document.createAttribute("class"); 344 attr.nodeValue="usercomment"; 345 divgroup.setAttributeNode(attr); 346 347 var divuser=document.createElement("div"); 348 var divtime=document.createElement("div"); 349 var divcomment=document.createElement("div"); 350 351 352 divgroup.appendChild(divuser); 353 var txt=document.createTextNode(username); 354 divuser.appendChild(txt); 355 356 divgroup.appendChild(divtime); 357 txt=document.createTextNode(timestamp.printTime()); // formate timestamp for date/time display 358 divtime.appendChild(txt); 359 360 divgroup.appendChild(divcomment); 361 txt=document.createTextNode(comment); 362 divcomment.appendChild(txt); 363 364 usercommentdiv.appendChild(divgroup); 341 displayInUserCommentList(usercommentdiv, username, timestamp, comment); 365 342 \} 366 343 … … 368 345 \} 369 346 347 function displayInUserCommentList(usercommentdiv, username, timestamp, comment) \{ 348 349 var divgroup=document.createElement("div"); 350 var attr=document.createAttribute("class"); 351 attr.nodeValue="usercomment"; 352 divgroup.setAttributeNode(attr); 353 354 var divuser=document.createElement("div"); 355 var divtime=document.createElement("div"); 356 var divcomment=document.createElement("div"); 357 358 359 divgroup.appendChild(divuser); 360 var txt=document.createTextNode(username); 361 divuser.appendChild(txt); 362 363 divgroup.appendChild(divtime); 364 txt=document.createTextNode(formatTime(timestamp)); // format timestamp for date/time display 365 divtime.appendChild(txt); 366 367 divgroup.appendChild(divcomment); 368 txt=document.createTextNode(comment); 369 divcomment.appendChild(txt); 370 371 usercommentdiv.appendChild(divgroup); 372 373 \} 370 374 371 375 // http://stackoverflow.com/questions/807878/javascript-that-executes-after-page-load
Note:
See TracChangeset
for help on using the changeset viewer.