collaboration.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*******************************************************************************
  2. AToMPM - A Tool for Multi-Paradigm Modelling
  3. Copyright (c) 2011 Raphael Mannadiar (raphael.mannadiar@mail.mcgill.ca)
  4. Modified by Conner Hansen (chansen@crimson.ua.edu)
  5. This file is part of AToMPM.
  6. AToMPM is free software: you can redistribute it and/or modify it under the
  7. terms of the GNU Lesser General Public License as published by the Free Software
  8. Foundation, either version 3 of the License, or (at your option) any later
  9. version.
  10. AToMPM is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  12. PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License along
  14. with AToMPM. If not, see <http://www.gnu.org/licenses/>.
  15. *******************************************************************************/
  16. Collaboration = function(){
  17. //css/html based on http://net.tutsplus.com/tutorials/javascript-ajax/how-to-create-a-simple-web-based-chat-application/
  18. /**
  19. * This enables the collaboration links so that they can be selected
  20. */
  21. this.enableCollaborationLinks = function()
  22. {
  23. $('#a_screenshare').attr('href', 'mailto:?'+
  24. 'subject='+encodeURIComponent('atompm screenshare invitation')+
  25. '&body='+encodeURIComponent('follow this link \n\t'+
  26. window.location.href+'?cswid='+__wid+'&host='+__user+
  27. '\nto join '+__user+' in an atompm shared-screen session'));
  28. $('#a_screenshare').attr('class', 'enabled_link unselectable');
  29. $('#a_modelshare').attr('href', 'mailto:?'+
  30. 'subject='+encodeURIComponent('atompm modelshare invitation')+
  31. '&body='+encodeURIComponent('follow this link \n\t'+
  32. window.location.href+'?cswid='+__wid+'&aswid='+__aswid+'&host='+__user+
  33. '\nto join '+__user+' in an atompm shared-model session'));
  34. $('#a_modelshare').attr('class', 'enabled_link unselectable');
  35. };
  36. /**
  37. * Toggles the chat window between the opened and closed states
  38. *
  39. * Credits to Maris Jukss
  40. */
  41. this.toggleChat = function() {
  42. var name = $("#chatName");
  43. var chat = $("#chat");
  44. var text = $("#showChat");
  45. if(chat.css("display") == "block") {
  46. chat.css("display", "none");
  47. text.html("Open Chat");
  48. }
  49. else {
  50. chat.css("display", "block");
  51. text.html("");
  52. name.html(window.localStorage.getItem('user'));
  53. }
  54. };
  55. /**
  56. * Sends the entered text to the other user and then
  57. * clears the chat window
  58. */
  59. this.sendText = function(){
  60. // var text = document.getElementById("usermsg").value;
  61. var userMsg = $("#usermsg");
  62. var text = userMsg.val();
  63. if (text) {
  64. HttpUtils.httpReq(
  65. 'POST',
  66. 'plugins/chat/chat?wid='+__wid,
  67. '<b>'+window.localStorage.getItem('user')+'</b>: '+text,
  68. function(statusCode,resp)
  69. {
  70. //call back here
  71. });
  72. userMsg.val("");
  73. }
  74. };
  75. /**
  76. * Updates the chat window
  77. */
  78. this.updateChat = function( text, name ){
  79. var chatbox = $("#chatbox");
  80. var currentTime = new Date();
  81. var hours = currentTime.getHours();
  82. var minutes = currentTime.getMinutes();
  83. var oldH = chatbox.scrollHeight-20;
  84. if (minutes < 10)
  85. minutes = "0" + minutes;
  86. // Include the text in the chatbox
  87. chatbox.html( chatbox.html() + "<div class='msgln'>("+hours+":"+minutes+") "+text+"<br></div>" );
  88. // Get the new height
  89. var newH = chatbox.prop("scrollHeight") - 20;
  90. if (newH > oldH) {
  91. chatbox.attr("scrollTop", 100000 + "px");
  92. }
  93. };
  94. return this;
  95. }();