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

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