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

Feedback.js 9.2KB

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