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

FeedbackWindow.js 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /* global $, APP, interfaceConfig, AJS */
  2. const selector = '#aui-feedback-dialog';
  3. /**
  4. * Toggles the appropriate css class for the given number of stars, to
  5. * indicate that those stars have been clicked/selected.
  6. *
  7. * @param starCount the number of stars, for which to toggle the css class
  8. */
  9. function toggleStars(starCount) {
  10. $('#stars > a').each(function(index, el) {
  11. if (index <= starCount) {
  12. el.classList.add("starHover");
  13. } else
  14. el.classList.remove("starHover");
  15. });
  16. }
  17. /**
  18. * Constructs the html for the rated feedback window.
  19. *
  20. * @returns {string} the contructed html string
  21. */
  22. function createRateFeedbackHTML() {
  23. let rateExperience
  24. = APP.translation.translateString('dialog.rateExperience'),
  25. feedbackHelp = APP.translation.translateString('dialog.feedbackHelp');
  26. let starClassName = (interfaceConfig.ENABLE_FEEDBACK_ANIMATION)
  27. ? "icon-star shake-rotate"
  28. : "icon-star";
  29. return `
  30. <div class="aui-dialog2-content feedback__content">
  31. <form action="javascript:false;" onsubmit="return false;">
  32. <div class="feedback__rating">
  33. <h2>${ rateExperience }</h2>
  34. <p class="star-label">&nbsp;</p>
  35. <div id="stars" class="feedback-stars">
  36. <a class="star-btn">
  37. <i class=${ starClassName }></i>
  38. </a>
  39. <a class="star-btn">
  40. <i class=${ starClassName }></i>
  41. </a>
  42. <a class="star-btn">
  43. <i class=${ starClassName }></i>
  44. </a>
  45. <a class="star-btn">
  46. <i class=${ starClassName }></i>
  47. </a>
  48. <a class="star-btn">
  49. <i class=${ starClassName }></i>
  50. </a>
  51. </div>
  52. <p>&nbsp;</p>
  53. <p>${ feedbackHelp }</p>
  54. </div>
  55. <textarea id="feedbackTextArea" rows="10" cols="40" autofocus>
  56. </textarea>
  57. </form>
  58. <footer class="aui-dialog2-footer feedback__footer">
  59. <div class="aui-dialog2-footer-actions">
  60. <button
  61. id="dialog-close-button"
  62. class="aui-button aui-button_close">Close</button>
  63. <button
  64. id="dialog-submit-button"
  65. class="aui-button aui-button_submit">Submit</button>
  66. </div>
  67. </footer>
  68. </div>
  69. `;
  70. }
  71. /**
  72. * Callback for Rate Feedback
  73. *
  74. * @param Feedback
  75. */
  76. let onLoadRateFunction = function (Feedback) {
  77. $('#stars > a').each((index, el) => {
  78. el.onmouseover = function(){
  79. toggleStars(index);
  80. };
  81. el.onmouseleave = function(){
  82. toggleStars(Feedback.feedbackScore - 1);
  83. };
  84. el.onclick = function(){
  85. Feedback.feedbackScore = index + 1;
  86. };
  87. });
  88. // Init stars to correspond to previously entered feedback.
  89. if (Feedback.feedbackScore > 0) {
  90. toggleStars(Feedback.feedbackScore - 1);
  91. }
  92. if (Feedback.feedbackText && Feedback.feedbackText.length > 0)
  93. $('#feedbackTextArea').text(Feedback.feedbackText);
  94. let submitBtn = Feedback.$el.find('#dialog-submit-button');
  95. let closeBtn = Feedback.$el.find('#dialog-close-button');
  96. if (submitBtn && submitBtn.length) {
  97. submitBtn.on('click', (e) => {
  98. e.preventDefault();
  99. Feedback.onFeedbackSubmitted();
  100. });
  101. }
  102. if (closeBtn && closeBtn.length) {
  103. closeBtn.on('click', (e) => {
  104. e.preventDefault();
  105. Feedback.hide();
  106. });
  107. }
  108. $('#feedbackTextArea').focus();
  109. };
  110. /**
  111. * @class Dialog
  112. *
  113. */
  114. export default class Dialog {
  115. constructor(options) {
  116. this.feedbackScore = -1;
  117. this.feedbackText = null;
  118. this.submitted = false;
  119. this.onCloseCallback = null;
  120. this.states = {
  121. rate_feedback: {
  122. getHtml: createRateFeedbackHTML,
  123. onLoad: onLoadRateFunction
  124. }
  125. };
  126. this.state = options.state || 'rate_feedback';
  127. this.window = AJS.dialog2(selector, {
  128. closeOnOutsideClick: true
  129. });
  130. this.$el = this.window.$el;
  131. AJS.dialog2(selector).on("hide", function() {
  132. if (this.onCloseCallback) {
  133. this.onCloseCallback();
  134. this.onCloseCallback = null;
  135. }
  136. }.bind(this));
  137. this.setState();
  138. }
  139. setState(state) {
  140. let newState = state || this.state;
  141. let htmlStr = this.states[newState].getHtml(this);
  142. this.$el.html(htmlStr);
  143. this.states[newState].onLoad(this);
  144. }
  145. show(cb) {
  146. this.setState('rate_feedback');
  147. if (typeof cb == 'function') {
  148. this.onCloseCallback = cb;
  149. }
  150. this.window.show();
  151. }
  152. hide() {
  153. this.window.hide();
  154. }
  155. onFeedbackSubmitted() {
  156. let message = this.$el.find('textarea').val();
  157. let self = this;
  158. if (message && message.length > 0) {
  159. self.feedbackText = message;
  160. }
  161. APP.conference.sendFeedback(self.feedbackScore,
  162. self.feedbackText);
  163. // TO DO: make sendFeedback return true or false.
  164. self.submitted = true;
  165. this.hide();
  166. }
  167. }