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.4KB

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