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

Feedback.js 8.4KB

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