您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Feedback.js 11KB

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