collaboration.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* This file is part of AToMPM - A Tool for Multi-Paradigm Modelling
  2. * Copyright 2011 by the AToMPM team and licensed under the LGPL
  3. * See COPYING.lesser and README.md in the root of this project for full details
  4. */
  5. Collaboration = function(){
  6. //css/html based on http://net.tutsplus.com/tutorials/javascript-ajax/how-to-create-a-simple-web-based-chat-application/
  7. /**
  8. * This enables the collaboration links so that they can be selected
  9. */
  10. this.enableCollaborationLinks = function()
  11. {
  12. $('#a_screenshare').attr('href', 'mailto:?'+
  13. 'subject='+encodeURIComponent('atompm screenshare invitation')+
  14. '&body='+encodeURIComponent('follow this link \n\t'+
  15. window.location.href+'?cswid='+__wid+'&host='+__user+
  16. '\nto join '+__user+' in an atompm shared-screen session'));
  17. $('#a_screenshare').attr('class', 'enabled_link unselectable');
  18. $('#a_modelshare').attr('href', 'mailto:?'+
  19. 'subject='+encodeURIComponent('atompm modelshare invitation')+
  20. '&body='+encodeURIComponent('follow this link \n\t'+
  21. window.location.href+'?cswid='+__wid+'&aswid='+__aswid+'&host='+__user+
  22. '\nto join '+__user+' in an atompm shared-model session'));
  23. $('#a_modelshare').attr('class', 'enabled_link unselectable');
  24. };
  25. /**
  26. * Toggles the chat window between the opened and closed states
  27. *
  28. * Credits to Maris Jukss
  29. */
  30. this.toggleChat = function() {
  31. var name = $("#chatName");
  32. var chat = $("#chat");
  33. var text = $("#showChat");
  34. if(chat.css("display") == "block") {
  35. chat.css("display", "none");
  36. text.html("Open Chat");
  37. }
  38. else {
  39. chat.css("display", "block");
  40. text.html("");
  41. name.html(window.localStorage.getItem('user'));
  42. }
  43. };
  44. /**
  45. * Sends the entered text to the other user and then
  46. * clears the chat window
  47. */
  48. this.sendText = function(){
  49. // var text = document.getElementById("usermsg").value;
  50. var userMsg = $("#usermsg");
  51. var text = userMsg.val();
  52. if (text) {
  53. HttpUtils.httpReq(
  54. 'POST',
  55. 'plugins/chat/chat?wid='+__wid,
  56. '<b>'+window.localStorage.getItem('user')+'</b>: '+text,
  57. function(statusCode,resp)
  58. {
  59. //call back here
  60. });
  61. userMsg.val("");
  62. }
  63. };
  64. /**
  65. * Updates the chat window
  66. */
  67. this.updateChat = function( text, name ){
  68. var chatbox = $("#chatbox");
  69. var currentTime = new Date();
  70. var hours = currentTime.getHours();
  71. var minutes = currentTime.getMinutes();
  72. var oldH = chatbox.scrollHeight-20;
  73. if (minutes < 10)
  74. minutes = "0" + minutes;
  75. // Include the text in the chatbox
  76. chatbox.html( chatbox.html() + "<div class='msgln'>("+hours+":"+minutes+") "+text+"<br></div>" );
  77. // Get the new height
  78. var newH = chatbox.prop("scrollHeight") - 20;
  79. if (newH > oldH) {
  80. chatbox.attr("scrollTop", 100000 + "px");
  81. }
  82. };
  83. return this;
  84. }();