You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Feedback.js 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /* global $, APP, config, interfaceConfig */
  2. /*
  3. * Created by Yana Stamcheva on 2/10/15.
  4. */
  5. var messageHandler = require("./util/MessageHandler");
  6. /**
  7. * Constructs the html for the overall feedback window.
  8. *
  9. * @returns {string} the constructed html string
  10. */
  11. var constructOverallFeedbackHtml = function() {
  12. var feedbackQuestion = (Feedback.feedbackScore < 0)
  13. ? '<br/><br/>' + APP.translation
  14. .translateString("dialog.feedbackQuestion")
  15. : '';
  16. var message = '<div class="feedback"><div>' +
  17. '<div class="feedbackTitle">' +
  18. APP.translation.translateString("dialog.thankYou",
  19. {appName:interfaceConfig.APP_NAME}) +
  20. '</div>' +
  21. feedbackQuestion +
  22. '</div><br/><br/>' +
  23. '<div id="stars">' +
  24. '<a><i class="fa fa-star-o fa fa-star"></i></a>' +
  25. '<a><i class="fa fa-star-o fa fa-star"></i></a>' +
  26. '<a><i class="fa fa-star-o fa fa-star"></i></a>' +
  27. '<a><i class="fa fa-star-o fa fa-star"></i></a>' +
  28. '<a><i class="fa fa-star-o fa fa-star"></i></a>' +
  29. '</div></div>';
  30. return message;
  31. };
  32. /**
  33. * Constructs the html for the detailed feedback window.
  34. *
  35. * @returns {string} the contructed html string
  36. */
  37. var constructDetailedFeedbackHtml = function() {
  38. // Construct the html, which will be served as a dialog message.
  39. var message = '<div class="feedback">' +
  40. '<div class="feedbackTitle">' +
  41. APP.translation.translateString("dialog.sorryFeedback") +
  42. '</div><br/><br/>' +
  43. '<div class="feedbackDetails">' +
  44. '<textarea id="feedbackTextArea" rows="10" cols="50" autofocus>' +
  45. '</textarea>' +
  46. '</div></div>';
  47. return message;
  48. };
  49. /**
  50. * The callback function corresponding to the openFeedbackWindow parameter.
  51. *
  52. * @type {function}
  53. */
  54. var feedbackWindowCallback = null;
  55. /**
  56. * Defines all methods in connection to the Feedback window.
  57. *
  58. * @type {{feedbackScore: number, openFeedbackWindow: Function,
  59. * toggleStars: Function, hoverStars: Function, unhoverStars: Function}}
  60. */
  61. var Feedback = {
  62. /**
  63. * The feedback score. -1 indicates no score has been given for now.
  64. */
  65. feedbackScore: -1,
  66. /**
  67. * Initialise the Feedback functionality.
  68. */
  69. init: function () {
  70. // CallStats is the way we send feedback, so we don't have to initialise
  71. // if callstats isn't enabled.
  72. if (!APP.conference.isCallstatsEnabled())
  73. return;
  74. $("div.feedbackButton").css("display", "block");
  75. $("#feedbackButton").click(function (event) {
  76. Feedback.openFeedbackWindow();
  77. });
  78. },
  79. /**
  80. * Indicates if the feedback functionality is enabled.
  81. *
  82. * @return true if the feedback functionality is enabled, false otherwise.
  83. */
  84. isEnabled: function() {
  85. return APP.conference.isCallstatsEnabled();
  86. },
  87. /**
  88. * Opens the feedback window.
  89. */
  90. openFeedbackWindow: function (callback) {
  91. feedbackWindowCallback = callback;
  92. // Add all mouse and click listeners.
  93. var onLoadFunction = function (event) {
  94. $('#stars >a').each(function(index) {
  95. // On star mouse over.
  96. $(this).get(0).onmouseover = function(){
  97. Feedback.hoverStars(index);
  98. };
  99. // On star mouse leave.
  100. $(this).get(0).onmouseleave = function(){
  101. Feedback.unhoverStars(index);
  102. };
  103. // On star click.
  104. $(this).get(0).onclick = function(){
  105. Feedback.toggleStars(index);
  106. Feedback.feedbackScore = index+1;
  107. // If the feedback is less than 3 stars we're going to
  108. // ask the user for more information.
  109. if (Feedback.feedbackScore > 3) {
  110. APP.conference.sendFeedback(Feedback.feedbackScore, "");
  111. if (feedbackWindowCallback)
  112. feedbackWindowCallback();
  113. else
  114. APP.UI.messageHandler.closeDialog();
  115. }
  116. else {
  117. feedbackDialog.goToState('detailed_feedback');
  118. }
  119. };
  120. // Init stars to correspond to previously entered feedback.
  121. if (Feedback.feedbackScore > 0
  122. && index < Feedback.feedbackScore) {
  123. Feedback.hoverStars(index);
  124. Feedback.toggleStars(index);
  125. }
  126. });
  127. };
  128. // Defines the different states of the feedback window.
  129. var states = {
  130. overall_feedback: {
  131. html: constructOverallFeedbackHtml(),
  132. persistent: false,
  133. buttons: {},
  134. closeText: '',
  135. focus: "div[id='stars']",
  136. position: {width: 500}
  137. },
  138. detailed_feedback: {
  139. html: constructDetailedFeedbackHtml(),
  140. buttons: {"Submit": true, "Cancel": false},
  141. closeText: '',
  142. focus: "textarea[id='feedbackTextArea']",
  143. position: {width: 500},
  144. submit: function(e,v,m,f) {
  145. e.preventDefault();
  146. if (v) {
  147. var feedbackDetails
  148. = document.getElementById("feedbackTextArea").value;
  149. if (feedbackDetails && feedbackDetails.length > 0)
  150. APP.conference.sendFeedback( Feedback.feedbackScore,
  151. feedbackDetails);
  152. if (feedbackWindowCallback)
  153. feedbackWindowCallback();
  154. else
  155. APP.UI.messageHandler.closeDialog();
  156. } else {
  157. // User cancelled
  158. if (feedbackWindowCallback)
  159. feedbackWindowCallback();
  160. else
  161. APP.UI.messageHandler.closeDialog();
  162. }
  163. }
  164. }
  165. };
  166. // Create the feedback dialog.
  167. var feedbackDialog
  168. = APP.UI.messageHandler.openDialogWithStates(
  169. states,
  170. { persistent: false,
  171. buttons: {},
  172. closeText: '',
  173. loaded: onLoadFunction,
  174. position: {width: 500}}, null);
  175. },
  176. /**
  177. * Toggles the appropriate css class for the given number of stars, to
  178. * indicate that those stars have been clicked/selected.
  179. *
  180. * @param starCount the number of stars, for which to toggle the css class
  181. */
  182. toggleStars: function (starCount)
  183. {
  184. $('#stars >a >i').each(function(index) {
  185. if (index <= starCount) {
  186. $(this).removeClass("fa-star-o");
  187. }
  188. else
  189. $(this).addClass("fa-star-o");
  190. });
  191. },
  192. /**
  193. * Toggles the appropriate css class for the given number of stars, to
  194. * indicate that those stars have been hovered.
  195. *
  196. * @param starCount the number of stars, for which to toggle the css class
  197. */
  198. hoverStars: function (starCount)
  199. {
  200. $('#stars >a >i').each(function(index) {
  201. if (index <= starCount)
  202. $(this).addClass("starHover");
  203. });
  204. },
  205. /**
  206. * Toggles the appropriate css class for the given number of stars, to
  207. * indicate that those stars have been un-hovered.
  208. *
  209. * @param starCount the number of stars, for which to toggle the css class
  210. */
  211. unhoverStars: function (starCount)
  212. {
  213. $('#stars >a >i').each(function(index) {
  214. if (index <= starCount && $(this).hasClass("fa-star-o"))
  215. $(this).removeClass("starHover");
  216. });
  217. }
  218. };
  219. // Exports the Feedback class.
  220. module.exports = Feedback;