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 9.1KB

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