One Hat Cyber Team
  • Dir : ~/usr/local/psa/admin/cp/public/javascript/app/
  • View File Name : rating.js.map
    ' +\n '
    ' +\n '
    ' +\n `
    ${this.lmsg('voteDislikeHint')}
    ` +\n '
    ' +\n '
    ' +\n '' +\n '' +\n '' +\n ''\n ),\n buttons: [{\n title: this.lmsg('voteButtonOk'),\n id: 'rating-vote-button-ok',\n class: 'action',\n handler: this.handleVoteButton.bind(this),\n }, {\n title: Locale.getSection('components.buttons').lmsg('cancel'),\n id: 'rating-vote-button-cancel',\n handler(event, popup) {\n popup.hide();\n },\n }],\n ...config,\n });\n\n this.dialogCause = this._getConfigParam('dialogCause', 'manual');\n this.supportUrl = this._getConfigParam('supportUrl');\n }\n\n _initComponentElement() {\n super._initComponentElement();\n\n render(this._componentElement.querySelector('#nps-rating'), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(i => (\n createElement('label', {\n class: `nps-survey__score nps-survey__score--${i}`,\n onclick: this.checkPossibleSendVote.bind(this),\n }, [\n createElement('input', { type: 'radio', name: 'nps-survey-option', value: i }),\n createElement('span', { class: 'nps-survey__score-label' }),\n ])\n )));\n }\n\n show() {\n super.show();\n this.showTime = Date.now();\n }\n\n hide() {\n super.hide();\n\n if (this.voted) {\n return;\n }\n\n if (this.checkPossibleSendVote() || this.getFeedbackLike() || this.getFeedbackDislike()) {\n this.sendVote();\n }\n\n if (this.dialogCause === 'timeout') {\n this.sendPostpone();\n }\n }\n\n handleVoteButton() {\n if (!this.checkPossibleSendVote()) {\n return;\n }\n\n this.voted = true;\n this.sendVote();\n this.hide();\n\n new ThankDialog({\n supportUrl: this.supportUrl,\n feedbackLike: this.getFeedbackLike(),\n feedbackDislike: this.getFeedbackDislike(),\n });\n }\n\n checkPossibleSendVote() {\n const survey = this._componentElement.querySelector('.nps-survey');\n const rate = this.getRate();\n\n if (rate) {\n survey.classList.remove('error');\n const errorField = survey.querySelector('.field-errors');\n if (errorField) {\n errorField.parentNode.removeChild(errorField);\n }\n } else {\n survey.classList.add('error');\n const errorField = survey.querySelector('.field-errors');\n if (!errorField) {\n render(survey, (\n '' +\n `${this.lmsg('voteRequire')}` +\n ''\n ));\n }\n }\n\n return rate;\n }\n\n getRate() {\n const checked = this._componentElement.querySelector(`#${this.getId()}-form input[name=nps-survey-option]:checked`);\n return checked ? checked.value : '';\n }\n\n getFeedbackLike() {\n return this._componentElement.querySelector('#rating-like').value.trim();\n }\n\n getFeedbackDislike() {\n return this._componentElement.querySelector('#rating-dislike').value.trim();\n }\n\n sendVote() {\n api.post(prepareUrl('/admin/rating/vote'), {\n voted: this.voted,\n dialogCause: this.dialogCause,\n rate: this.getRate(),\n feedbackLike: this.getFeedbackLike(),\n feedbackDislike: this.getFeedbackDislike(),\n dialogDuration: Math.round((Date.now() - this.showTime) / 1000),\n dialogAtPage: window.location.pathname,\n });\n }\n\n sendPostpone() {\n api.post(prepareUrl('/admin/rating/postpone'));\n }\n}\n\nclass ThankDialog extends Popup {\n _initConfiguration(config) {\n this.setLocale(Locale.getSection('components.rating'));\n\n let buttons = [{\n title: this.lmsg('thankButtonClose'),\n class: 'action',\n handler(event, popup) {\n popup.hide();\n },\n }];\n\n let content = `

    ${this.lmsg('thankHint')}

    `;\n if (config.feedbackDislike) {\n const message = this.lmsg('thankSupportCenter', {\n link: `${this.lmsg('supportCenter')}`,\n });\n content += `

    ${message}

    `;\n } else if (config.feedbackLike) {\n const introduction = this.lmsg('introductionText', { message: config.feedbackLike });\n content += '
    ' +\n `

    ${this.lmsg('thankSocialChoose')}

    ` +\n `` +\n '
    ' +\n 'Tweet' +\n `${this.lmsg('inviteButtonClose')}` +\n '
    ';\n buttons = [];\n }\n\n super._initConfiguration({\n id: 'thank-dialog',\n title: this.lmsg('thankTitle'),\n closeButtonEnabled: true,\n hideOnEscape: true,\n content,\n buttons,\n ...config,\n });\n }\n\n _addEvents() {\n super._addEvents();\n\n if (document.getElementById('rating-dialog-support-link')) {\n document.getElementById('rating-dialog-support-link').addEventListener('click', () => {\n api.post(prepareUrl('/admin/rating/support-center'));\n });\n }\n if (document.getElementById('rating-dialog-tweet-button')) {\n document.getElementById('rating-dialog-tweet-button').addEventListener('click', () => {\n window.open(\n `${prepareUrl('/admin/rating/social')}?button=twitter&text=${encodeURIComponent(document.getElementById('rating-dialog-share-text').value)}`,\n 'social-share',\n 'width=600,height=460',\n );\n this.hide();\n });\n }\n if (document.getElementById('rating-dialog-close-button')) {\n document.getElementById('rating-dialog-close-button').addEventListener('click', () => {\n this.hide();\n });\n }\n }\n}\n\nexport default props => new VoteDialog(props);\n"],"names":["VoteDialog","Popup","_initConfiguration","config","this","setLocale","Locale","getSection","super","id","title","lmsg","closeButtonEnabled","hideOnEscape","content","buttons","class","handler","handleVoteButton","bind","event","popup","hide","dialogCause","_getConfigParam","supportUrl","_initComponentElement","render","_componentElement","querySelector","map","i","createElement","onclick","checkPossibleSendVote","type","name","value","show","showTime","Date","now","voted","getFeedbackLike","getFeedbackDislike","sendVote","sendPostpone","ThankDialog","feedbackLike","feedbackDislike","survey","rate","getRate","classList","remove","errorField","parentNode","removeChild","add","checked","getId","trim","api","post","prepareUrl","dialogDuration","Math","round","dialogAtPage","window","location","pathname","link","introduction","message","_addEvents","document","getElementById","addEventListener","open","encodeURIComponent","props"],"sourceRoot":""}