| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 | 
							- /* global $, APP, interfaceConfig, AJS */
 - /* jshint -W101 */
 - 
 - const selector = '#aui-feedback-dialog';
 - 
 - /**
 -  * Toggles the appropriate css class for the given number of stars, to
 -  * indicate that those stars have been clicked/selected.
 -  *
 -  * @param starCount the number of stars, for which to toggle the css class
 -  */
 - let toggleStars = function(starCount) {
 -     $('#stars > a').each(function(index, el) {
 -         if (index <= starCount) {
 -             el.classList.add("starHover");
 -         } else
 -             el.classList.remove("starHover");
 -     });
 - };
 - 
 - /**
 -  * Constructs the html for the detailed feedback window.
 -  *
 -  * @returns {string} the contructed html string
 -  */
 - let constructDetailedFeedbackHtml = function() {
 - 
 -     return `
 -         <div class="aui-dialog2-content feedback__content">
 -             <div class="feedback__details">
 -                 <p>${APP.translation.translateString("dialog.sorryFeedback")}</p>
 -                 <br/><br/>
 -                 <textarea id="feedbackTextArea" rows="10" cols="50" autofocus></textarea>
 -             </div>
 -         </div>
 -         <footer class="aui-dialog2-footer feedback__footer">
 -             <div class="aui-dialog2-footer-actions">
 -                 <button id="dialog-close-button" class="aui-button aui-button_close">Close</button>
 -                 <button id="dialog-submit-button" class="aui-button aui-button_submit">Submit</button>
 -             </div>
 -         </footer>
 -         `;
 - };
 - 
 - /**
 -  * Constructs the html for the rated feedback window.
 -  *
 -  * @returns {string} the contructed html string
 -  */
 - let createRateFeedbackHTML = function (Feedback) {
 -     let rateExperience
 -             = APP.translation.translateString('dialog.rateExperience'),
 -         feedbackHelp = APP.translation.translateString('dialog.feedbackHelp'),
 -         feedbackQuestion = (Feedback.feedbackScore < 0)
 -         ? `<p><br/>${APP.translation.translateString('dialog.feedbackQuestion')}</p>`
 -         : '';
 - 
 -     let starClassName = (interfaceConfig.ENABLE_FEEDBACK_ANIMATION)
 -                             ? "icon-star shake-rotate"
 -                             : "icon-star";
 - 
 -     return `
 -         <div class="aui-dialog2-content feedback__content">
 -             ${feedbackQuestion}
 -             <form action="javascript:false;" onsubmit="return false;">
 -                 <div class="feedback__rating">
 -                     <h2>${ rateExperience }</h2>
 -                     <p class="star-label"> </p>
 -                     <div id="stars" class="feedback-stars">
 -                         <a class="star-btn">
 -                             <i class=${ starClassName }></i>
 -                         </a>
 -                         <a class="star-btn">
 -                             <i class=${ starClassName }></i>
 -                         </a>
 -                         <a class="star-btn">
 -                             <i class=${ starClassName }></i>
 -                         </a>
 -                         <a class="star-btn">
 -                             <i class=${ starClassName }></i>
 -                         </a>
 -                         <a class="star-btn">
 -                             <i class=${ starClassName }></i>
 -                         </a>
 -                     </div>
 -                     <p> </p>
 -                     <p>${ feedbackHelp }</p>
 -                 </div>
 -             </form>
 -         </div>
 - `;
 - };
 - 
 - /**
 -  * Callback for Rate Feedback
 -  *
 -  * @param Feedback
 -  */
 - let onLoadRateFunction = function (Feedback) {
 -     $('#stars > a').each((index, el) => {
 -         el.onmouseover = function(){
 -             toggleStars(index);
 -         };
 -         el.onmouseleave = function(){
 -             toggleStars(Feedback.feedbackScore - 1);
 -         };
 -         el.onclick = function(){
 -             Feedback.feedbackScore = index + 1;
 - 
 -             // If the feedback is less than 3 stars we're going to
 -             // ask the user for more information.
 -             if (Feedback.feedbackScore > 3) {
 -                 APP.conference.sendFeedback(Feedback.feedbackScore, "");
 -                 Feedback.hide();
 -             } else {
 -                 Feedback.setState('detailed_feedback');
 -             }
 -         };
 -     });
 - 
 -     // Init stars to correspond to previously entered feedback.
 -     if (Feedback.feedbackScore > 0) {
 -         toggleStars(Feedback.feedbackScore - 1);
 -     }
 - };
 - 
 - /**
 -  * Callback for Detailed Feedback
 -  *
 -  * @param Feedback
 -  */
 - let onLoadDetailedFunction = function(Feedback) {
 -     let submitBtn = Feedback.$el.find('#dialog-submit-button');
 -     let closeBtn = Feedback.$el.find('#dialog-close-button');
 - 
 -     if (submitBtn && submitBtn.length) {
 -         submitBtn.on('click', (e) => {
 -             e.preventDefault();
 -             Feedback.onFeedbackSubmitted();
 -         });
 -     }
 -     if (closeBtn && closeBtn.length) {
 -         closeBtn.on('click', (e) => {
 -             e.preventDefault();
 -             Feedback.hide();
 -         });
 -     }
 - 
 -     $('#feedbackTextArea').focus();
 - };
 - 
 - /**
 -  * @class Dialog
 -  *
 -  */
 - export default class Dialog {
 - 
 -     constructor(options) {
 -         this.feedbackScore = -1;
 -         this.onCloseCallback = null;
 - 
 -         this.states = {
 -             rate_feedback: {
 -                 getHtml: createRateFeedbackHTML,
 -                 onLoad: onLoadRateFunction
 -             },
 -             detailed_feedback: {
 -                 getHtml: constructDetailedFeedbackHtml,
 -                 onLoad: onLoadDetailedFunction
 -             }
 -         };
 -         this.state = options.state || 'rate_feedback';
 - 
 -         this.window = AJS.dialog2(selector, {
 -             closeOnOutsideClick: true
 -         });
 -         this.$el = this.window.$el;
 - 
 -         this.setState();
 -     }
 - 
 -     setState(state) {
 -         let newState = state || this.state;
 - 
 -         let htmlStr = this.states[newState].getHtml(this);
 - 
 -         this.$el.html(htmlStr);
 - 
 -         this.states[newState].onLoad(this);
 -     }
 - 
 -     show(cb) {
 -         this.setState('rate_feedback');
 -         if (typeof cb == 'function') {
 -             this.onCloseCallback = cb;
 -         }
 - 
 -         this.window.show();
 - 
 -     }
 - 
 -     hide() {
 -         this.window.hide();
 - 
 -         if (this.onCloseCallback) {
 -             this.onCloseCallback();
 -             this.onCloseCallback = null;
 -         }
 -     }
 - 
 -     onFeedbackSubmitted() {
 -         let message = this.$el.find('textarea').val();
 -         let self = this;
 - 
 -         if (message && message.length > 0) {
 -             APP.conference.sendFeedback(
 -                 self.feedbackScore,
 -                 message);
 -         }
 -         this.hide();
 -     }
 - 
 - }
 
 
  |