Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Feedback.js 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /* global $, APP, config, interfaceConfig, JitsiMeetJS */
  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="icon-star icon-star-full"></i></a>' +
  22. '<a><i class="icon-star icon-star-full"></i></a>' +
  23. '<a><i class="icon-star icon-star-full"></i></a>' +
  24. '<a><i class="icon-star icon-star-full"></i></a>' +
  25. '<a><i class="icon-star icon-star-full"></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. * Returns true if the feedback window is currently visible and false
  124. * otherwise.
  125. * @return {boolean} true if the feedback window is visible, false
  126. * otherwise
  127. */
  128. isVisible: function() {
  129. return $(".feedback").is(":visible");
  130. },
  131. /**
  132. * Opens the feedback window.
  133. */
  134. openFeedbackWindow: function (callback) {
  135. feedbackWindowCallback = callback;
  136. // Add all mouse and click listeners.
  137. var onLoadFunction = function (event) {
  138. $('#stars >a').each(function(index) {
  139. // On star mouse over.
  140. $(this).get(0).onmouseover = function(){
  141. Feedback.hoverStars(index);
  142. };
  143. // On star mouse leave.
  144. $(this).get(0).onmouseleave = function(){
  145. Feedback.unhoverStars(index);
  146. };
  147. // On star click.
  148. $(this).get(0).onclick = function(){
  149. Feedback.toggleStars(index);
  150. Feedback.feedbackScore = index+1;
  151. // If the feedback is less than 3 stars we're going to
  152. // ask the user for more information.
  153. if (Feedback.feedbackScore > 3) {
  154. APP.conference.sendFeedback(Feedback.feedbackScore, "");
  155. if (feedbackWindowCallback)
  156. feedbackWindowCallback();
  157. else
  158. APP.UI.messageHandler.closeDialog();
  159. }
  160. else {
  161. feedbackDialog.goToState('detailed_feedback');
  162. }
  163. };
  164. // Init stars to correspond to previously entered feedback.
  165. if (Feedback.feedbackScore > 0
  166. && index < Feedback.feedbackScore) {
  167. Feedback.hoverStars(index);
  168. Feedback.toggleStars(index);
  169. }
  170. });
  171. };
  172. // Defines the different states of the feedback window.
  173. var states = {
  174. overall_feedback: {
  175. html: constructOverallFeedbackHtml(),
  176. persistent: false,
  177. buttons: {},
  178. closeText: '',
  179. focus: "div[id='stars']",
  180. position: {width: 500}
  181. },
  182. detailed_feedback: {
  183. html: constructDetailedFeedbackHtml(),
  184. buttons: {"Submit": true, "Cancel": false},
  185. closeText: '',
  186. focus: "textarea[id='feedbackTextArea']",
  187. position: {width: 500},
  188. submit: function(e,v,m,f) {
  189. e.preventDefault();
  190. if (v) {
  191. var feedbackDetails
  192. = document.getElementById("feedbackTextArea").value;
  193. if (feedbackDetails && feedbackDetails.length > 0) {
  194. APP.conference.sendFeedback( Feedback.feedbackScore,
  195. feedbackDetails);
  196. }
  197. if (feedbackWindowCallback)
  198. feedbackWindowCallback();
  199. else
  200. APP.UI.messageHandler.closeDialog();
  201. } else {
  202. // User cancelled
  203. if (feedbackWindowCallback)
  204. feedbackWindowCallback();
  205. else
  206. APP.UI.messageHandler.closeDialog();
  207. }
  208. }
  209. }
  210. };
  211. // Create the feedback dialog.
  212. var feedbackDialog
  213. = APP.UI.messageHandler.openDialogWithStates(
  214. states,
  215. { persistent: false,
  216. buttons: {},
  217. closeText: '',
  218. loaded: onLoadFunction,
  219. position: {width: 500}}, null);
  220. JitsiMeetJS.analytics.sendEvent('feedback.open');
  221. },
  222. /**
  223. * Toggles the appropriate css class for the given number of stars, to
  224. * indicate that those stars have been clicked/selected.
  225. *
  226. * @param starCount the number of stars, for which to toggle the css class
  227. */
  228. toggleStars: function (starCount)
  229. {
  230. $('#stars >a >i').each(function(index) {
  231. if (index <= starCount) {
  232. $(this).removeClass("icon-star");
  233. }
  234. else
  235. $(this).addClass("icon-star");
  236. });
  237. },
  238. /**
  239. * Toggles the appropriate css class for the given number of stars, to
  240. * indicate that those stars have been hovered.
  241. *
  242. * @param starCount the number of stars, for which to toggle the css class
  243. */
  244. hoverStars: function (starCount)
  245. {
  246. $('#stars >a >i').each(function(index) {
  247. if (index <= starCount)
  248. $(this).addClass("starHover");
  249. });
  250. },
  251. /**
  252. * Toggles the appropriate css class for the given number of stars, to
  253. * indicate that those stars have been un-hovered.
  254. *
  255. * @param starCount the number of stars, for which to toggle the css class
  256. */
  257. unhoverStars: function (starCount)
  258. {
  259. $('#stars >a >i').each(function(index) {
  260. if (index <= starCount && $(this).hasClass("icon-star"))
  261. $(this).removeClass("starHover");
  262. });
  263. }
  264. };
  265. // Exports the Feedback class.
  266. module.exports = Feedback;