Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Feedback.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /* global $, APP, config, interfaceConfig, JitsiMeetJS */
  2. import UIEvents from "../../service/UI/UIEvents";
  3. import UIUtil from "./util/UIUtil";
  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="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. '<a><i class="icon-star icon-star-full"></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. var createRateFeedbackHTML = function () {
  48. var rate = APP.translation.translateString('dialog.rateExperience'),
  49. help = APP.translation.translateString('dialog.feedbackHelp');
  50. return `
  51. <div class="feedback-rating text-center">
  52. <h2>${ rate }</h2>
  53. <p class="star-label">&nbsp;</p>
  54. <div id="stars" class="feedback-stars">
  55. <a class="star-btn">
  56. <i class="fa fa-star shake-rotate"></i>
  57. </a>
  58. <a class="star-btn">
  59. <i class="fa fa-star shake-rotate"></i>
  60. </a>
  61. <a class="star-btn">
  62. <i class="fa fa-star shake-rotate"></i>
  63. </a>
  64. <a class="star-btn">
  65. <i class="fa fa-star shake-rotate"></i>
  66. </a>
  67. <a class="star-btn">
  68. <i class="fa fa-star shake-rotate"></i>
  69. </a>
  70. </div>
  71. <p>&nbsp;</p>
  72. <p>${ help }</p>
  73. </div>
  74. `;
  75. };
  76. /**
  77. * The callback function corresponding to the openFeedbackWindow parameter.
  78. *
  79. * @type {function}
  80. */
  81. var feedbackWindowCallback = null;
  82. /**
  83. * Shows / hides the feedback button.
  84. * @private
  85. */
  86. function _toggleFeedbackIcon() {
  87. $('#feedbackButtonDiv').toggleClass("hidden");
  88. }
  89. /**
  90. * Shows / hides the feedback button.
  91. * @param {show} set to {true} to show the feedback button or to {false}
  92. * to hide it
  93. * @private
  94. */
  95. function _showFeedbackButton (show) {
  96. var feedbackButton = $("#feedbackButtonDiv");
  97. if (show)
  98. feedbackButton.css("display", "block");
  99. else
  100. feedbackButton.css("display", "none");
  101. }
  102. /**
  103. * Defines all methods in connection to the Feedback window.
  104. *
  105. * @type {{feedbackScore: number, openFeedbackWindow: Function,
  106. * toggleStars: Function, hoverStars: Function, unhoverStars: Function}}
  107. */
  108. var Feedback = {
  109. /**
  110. * The feedback score. -1 indicates no score has been given for now.
  111. */
  112. feedbackScore: -1,
  113. /**
  114. * Initialise the Feedback functionality.
  115. * @param emitter the EventEmitter to associate with the Feedback.
  116. */
  117. init: function (emitter) {
  118. // CallStats is the way we send feedback, so we don't have to initialise
  119. // if callstats isn't enabled.
  120. if (!APP.conference.isCallstatsEnabled())
  121. return;
  122. // If enabled property is still undefined, i.e. it hasn't been set from
  123. // some other module already, we set it to true by default.
  124. if (typeof this.enabled == "undefined")
  125. this.enabled = true;
  126. _showFeedbackButton(this.enabled);
  127. $("#feedbackButton").click(function (event) {
  128. Feedback.openFeedbackWindow();
  129. });
  130. // Show / hide the feedback button whenever the film strip is
  131. // shown / hidden.
  132. emitter.addListener(UIEvents.TOGGLE_FILM_STRIP, function () {
  133. _toggleFeedbackIcon();
  134. });
  135. },
  136. /**
  137. * Enables/ disabled the feedback feature.
  138. */
  139. enableFeedback: function (enable) {
  140. if (this.enabled !== enable)
  141. _showFeedbackButton(enable);
  142. this.enabled = enable;
  143. },
  144. /**
  145. * Indicates if the feedback functionality is enabled.
  146. *
  147. * @return true if the feedback functionality is enabled, false otherwise.
  148. */
  149. isEnabled: function() {
  150. return this.enabled && APP.conference.isCallstatsEnabled();
  151. },
  152. /**
  153. * Returns true if the feedback window is currently visible and false
  154. * otherwise.
  155. * @return {boolean} true if the feedback window is visible, false
  156. * otherwise
  157. */
  158. isVisible: function() {
  159. return $(".feedback").is(":visible");
  160. },
  161. /**
  162. * Opens the feedback window.
  163. */
  164. openFeedbackWindow: function (callback) {
  165. feedbackWindowCallback = callback;
  166. // Add all mouse and click listeners.
  167. var onLoadFunction = function (event) {
  168. $('#stars >a').each(function(index) {
  169. // On star mouse over.
  170. $(this).get(0).onmouseover = function(){
  171. Feedback.hoverStars(index);
  172. };
  173. // On star mouse leave.
  174. $(this).get(0).onmouseleave = function(){
  175. Feedback.unhoverStars(index);
  176. };
  177. // On star click.
  178. $(this).get(0).onclick = function(){
  179. Feedback.toggleStars(index);
  180. Feedback.feedbackScore = index+1;
  181. // If the feedback is less than 3 stars we're going to
  182. // ask the user for more information.
  183. if (Feedback.feedbackScore > 3) {
  184. APP.conference.sendFeedback(Feedback.feedbackScore, "");
  185. if (feedbackWindowCallback)
  186. feedbackWindowCallback();
  187. else
  188. APP.UI.messageHandler.closeDialog();
  189. }
  190. else {
  191. feedbackDialog.goToState('detailed_feedback');
  192. }
  193. };
  194. // Init stars to correspond to previously entered feedback.
  195. if (Feedback.feedbackScore > 0
  196. && index < Feedback.feedbackScore) {
  197. Feedback.hoverStars(index);
  198. Feedback.toggleStars(index);
  199. }
  200. });
  201. };
  202. // Defines the different states of the feedback window.
  203. var states = {
  204. overall_feedback: {
  205. html: createRateFeedbackHTML(),
  206. persistent: false,
  207. buttons: {},
  208. closeText: '',
  209. focus: "div[id='stars']",
  210. position: {width: 500}
  211. },
  212. detailed_feedback: {
  213. html: constructDetailedFeedbackHtml(),
  214. buttons: {"Submit": true, "Cancel": false},
  215. closeText: '',
  216. focus: "textarea[id='feedbackTextArea']",
  217. position: {width: 500},
  218. submit: function(e,v,m,f) {
  219. e.preventDefault();
  220. if (v) {
  221. var feedbackDetails
  222. = document.getElementById("feedbackTextArea").value;
  223. if (feedbackDetails && feedbackDetails.length > 0) {
  224. APP.conference.sendFeedback( Feedback.feedbackScore,
  225. feedbackDetails);
  226. }
  227. if (feedbackWindowCallback)
  228. feedbackWindowCallback();
  229. else
  230. APP.UI.messageHandler.closeDialog();
  231. } else {
  232. // User cancelled
  233. if (feedbackWindowCallback)
  234. feedbackWindowCallback();
  235. else
  236. APP.UI.messageHandler.closeDialog();
  237. }
  238. }
  239. }
  240. };
  241. // Create the feedback dialog.
  242. var feedbackDialog
  243. = APP.UI.messageHandler.openDialogWithStates(
  244. states,
  245. { persistent: false,
  246. buttons: {},
  247. closeText: '',
  248. loaded: onLoadFunction,
  249. position: {width: 500}}, null);
  250. JitsiMeetJS.analytics.sendEvent('feedback.open');
  251. },
  252. /**
  253. * Toggles the appropriate css class for the given number of stars, to
  254. * indicate that those stars have been clicked/selected.
  255. *
  256. * @param starCount the number of stars, for which to toggle the css class
  257. */
  258. toggleStars: function (starCount)
  259. {
  260. $('#stars >a >i').each(function(index) {
  261. if (index <= starCount) {
  262. $(this).removeClass("icon-star");
  263. }
  264. else
  265. $(this).addClass("icon-star");
  266. });
  267. },
  268. /**
  269. * Toggles the appropriate css class for the given number of stars, to
  270. * indicate that those stars have been hovered.
  271. *
  272. * @param starCount the number of stars, for which to toggle the css class
  273. */
  274. hoverStars: function (starCount)
  275. {
  276. $('#stars >a >i').each(function(index) {
  277. if (index <= starCount)
  278. $(this).addClass("starHover");
  279. });
  280. },
  281. /**
  282. * Toggles the appropriate css class for the given number of stars, to
  283. * indicate that those stars have been un-hovered.
  284. *
  285. * @param starCount the number of stars, for which to toggle the css class
  286. */
  287. unhoverStars: function (starCount)
  288. {
  289. $('#stars >a >i').each(function(index) {
  290. if (index <= starCount && $(this).hasClass("icon-star"))
  291. $(this).removeClass("starHover");
  292. });
  293. }
  294. };
  295. // Exports the Feedback class.
  296. module.exports = Feedback;