admin.js
2 months ago
admin.min.js
2 months ago
chart.js
2 years ago
chart.min.js
1 year ago
customize-controls.js
1 year ago
customize-controls.min.js
1 year ago
customize-preview.js
1 year ago
customize-preview.min.js
1 year ago
deactivation-feedback.js
2 years ago
deactivation-feedback.min.js
2 years ago
editor.js
8 years ago
editor.min.js
5 years ago
everest-forms-survey-polls-quiz-builder.js
2 years ago
everest-forms-survey-polls-quiz-builder.min.js
2 years ago
evf-admin-email.js
2 years ago
evf-admin-email.min.js
1 year ago
evf-clipboard.js
8 years ago
evf-clipboard.min.js
8 years ago
evf-enhanced-select.js
3 years ago
evf-enhanced-select.min.js
2 years ago
evf-file-uploader.js
2 years ago
evf-file-uploader.min.js
2 years ago
evf-setup.js
2 years ago
evf-setup.min.js
2 years ago
extensions.js
3 years ago
extensions.min.js
2 years ago
form-builder.js
2 weeks ago
form-builder.min.js
2 weeks ago
form-template-controller.js
3 years ago
form-template-controller.min.js
3 years ago
printThis.min.js
2 years ago
progressbar.js
2 years ago
progressbar.min.js
1 year ago
randomColor.js
2 years ago
randomColor.min.js
2 years ago
settings.js
3 weeks ago
settings.min.js
3 weeks ago
shortcode-form-embed.js
2 years ago
shortcode-form-embed.min.js
2 years ago
tool-import-entries.js
2 years ago
tool-import-entries.min.js
2 years ago
tools.js
2 months ago
tools.min.js
2 months ago
upgrade.js
2 months ago
upgrade.min.js
2 months ago
everest-forms-survey-polls-quiz-builder.js
1230 lines
| 1 | /** |
| 2 | * EverestFormsSurvey JS |
| 3 | */ |
| 4 | ( function ( $, params ) { |
| 5 | var everest; |
| 6 | var field_ids; |
| 7 | var EverestFormsSurvey = { |
| 8 | settings: { |
| 9 | fieldReportData : {}, |
| 10 | charts: {}, |
| 11 | spinner: '<div class="evf-survey-loader"><i class="evf-loading evf-loading-active" /></div>' |
| 12 | }, |
| 13 | |
| 14 | init: function() { |
| 15 | everest = this.settings; |
| 16 | EverestFormsSurvey.bindUIActions(); |
| 17 | }, |
| 18 | |
| 19 | /** |
| 20 | * Element bindings |
| 21 | */ |
| 22 | bindUIActions: function() { |
| 23 | |
| 24 | var $single_page_container = $( document ).find('.everest-forms-survey-block-container[data-page-type="single-page"]' ); |
| 25 | var form_id = $( $single_page_container ).attr('data-form-id'); |
| 26 | if( $single_page_container.length > 0 ) { |
| 27 | field_ids = JSON.parse( $( $single_page_container ).attr('data-field-ids') ); |
| 28 | EverestFormsSurvey.showSurveyQuestionReport( $single_page_container, field_ids[0], false, form_id, 0 ); |
| 29 | } |
| 30 | |
| 31 | $('.everest-forms-field-option-row-input_type select').trigger('change'); |
| 32 | |
| 33 | $( document ).on( 'ready', function(e) { |
| 34 | $('.everest-forms-survey-selection select#everest-forms-survey-question-list').trigger('change'); |
| 35 | }); |
| 36 | |
| 37 | $( document.body ).on( 'init_field_options_toggle', function(e) { |
| 38 | EverestFormsSurvey.choicesInit(); |
| 39 | }); |
| 40 | |
| 41 | $( document ).on( 'click', '.evf-survey-choices a.add', function(e) { |
| 42 | EverestFormsSurvey.fieldChoiceAdd(e, this); |
| 43 | }); |
| 44 | |
| 45 | $( document ).on( 'click', '.evf-survey-choices a.remove', function(e) { |
| 46 | EverestFormsSurvey.fieldChoiceDelete(e, this); |
| 47 | }); |
| 48 | $( document ).on( 'click', '.add_feedback', function(e) { |
| 49 | EverestFormsSurvey.feedbackAdd(e, this); |
| 50 | }); |
| 51 | $( document ).on( 'click', '.remove_feedback', function(e) { |
| 52 | EverestFormsSurvey.feedbackRemove(e, this); |
| 53 | }); |
| 54 | |
| 55 | // Print all entried summary |
| 56 | $( document ).on( 'click', '#everest-forms-print-entried-summary', function() { |
| 57 | var entriedSummary = $( this ).closest('.everest-forms-survey-block-container'); |
| 58 | $( entriedSummary ).printThis ({ |
| 59 | debug: false, |
| 60 | importCSS: true, |
| 61 | importStyle: false, |
| 62 | printContainer: true, |
| 63 | pageTitle: "", |
| 64 | removeInline: false, |
| 65 | printDelay: 333, |
| 66 | header: null, |
| 67 | footer: null, |
| 68 | base: false , |
| 69 | formValues: true, |
| 70 | canvas: true, |
| 71 | doctypeString: "...", |
| 72 | removeScripts: false, |
| 73 | copyTagClasses: false |
| 74 | }); |
| 75 | }); |
| 76 | |
| 77 | // Print the selected summary only |
| 78 | $( document ).on( 'click', '#everest-forms-entried-summary-specific-field', function() { |
| 79 | var entriedSummary = $( this ).closest('.everest-forms-survey-block'); |
| 80 | $( entriedSummary ).printThis ({ |
| 81 | debug: false, |
| 82 | importCSS: true, |
| 83 | importStyle: false, |
| 84 | printContainer: true, |
| 85 | pageTitle: "", |
| 86 | removeInline: false, |
| 87 | printDelay: 333, |
| 88 | header: null, |
| 89 | footer: null, |
| 90 | base: false , |
| 91 | formValues: true, |
| 92 | canvas: true, |
| 93 | removeScripts: false, |
| 94 | copyTagClasses: false |
| 95 | }); |
| 96 | }); |
| 97 | |
| 98 | $( document ).on( 'input', '.everest-forms-field-option-likert .evf-survey-choices input', function() { |
| 99 | var $list = $( this ).closest( '.evf-survey-choices' ), |
| 100 | fieldID = $list.data( 'field-id' ), |
| 101 | ul = $( this ).closest( 'ul' ); |
| 102 | |
| 103 | EverestFormsSurvey.fieldChoiceUpdate( fieldID ); |
| 104 | |
| 105 | /** |
| 106 | * Update the error-message input field's label |
| 107 | */ |
| 108 | if ( 'likert_rows' === ul.data('choice-type') ) { |
| 109 | EverestFormsSurvey.requiredFieldMessageInputFieldUpdate( ul, $( this ).closest( 'li' ), this ); |
| 110 | } |
| 111 | }); |
| 112 | |
| 113 | $( document ).on( 'change', '.everest-forms-field-option-row-input_type select', function() { |
| 114 | var fieldID = $( this ).parent().data('field-id'); |
| 115 | EverestFormsSurvey.fieldChoiceUpdate( fieldID ); |
| 116 | }); |
| 117 | |
| 118 | $( document ).on('change', '.evf-survey-choices input.default', function (e) { |
| 119 | var fieldID = $( this ).closest('.evf-survey-choices').data('field-id'); |
| 120 | $(this).parent('li').siblings().children('.default').prop('checked',false); |
| 121 | EverestFormsSurvey.fieldChoiceUpdate( fieldID ); |
| 122 | }); |
| 123 | |
| 124 | $( document ).on('keyup', '.everest-forms-field-option-row-highest_rating_text input', function (e) { |
| 125 | EverestFormsSurvey.scaleRatingText( e, this, 'highest' ); |
| 126 | }); |
| 127 | |
| 128 | $( document ).on('keyup', '.everest-forms-field-option-row-lowest_rating_text input', function (e) { |
| 129 | EverestFormsSurvey.scaleRatingText( e, this, 'lowest' ); |
| 130 | }); |
| 131 | |
| 132 | // Rating point validation error tips. |
| 133 | $( document.body ) |
| 134 | |
| 135 | .on( 'blur', '.evf-input-highest-rating-point[type=number], .evf-input-lowest-rating-point[type=number], .score_to[type=number]', function() { |
| 136 | $( '.evf_error_tip' ).fadeOut( '100', function() { $( this ).remove(); } ); |
| 137 | }) |
| 138 | |
| 139 | .on( 'change click', '.evf-input-highest-rating-point[type=number]', function(e) { |
| 140 | var highest_rating_point = parseInt( $( this ).val(), 10 ), |
| 141 | lowest_rating_point = parseInt( $( this ).parent().next().find( '.evf-input-lowest-rating-point[name*=lowest_rating_point]' ).val(), 10 ); |
| 142 | |
| 143 | if ( highest_rating_point > 100 ) { |
| 144 | $( this ).val('100'); |
| 145 | EverestFormsSurvey.scaleRatingPoint( e, $(this), 'highest'); |
| 146 | } else if ( highest_rating_point <= lowest_rating_point ) { |
| 147 | $( this ).val( lowest_rating_point + 1 ); |
| 148 | EverestFormsSurvey.scaleRatingPoint( e, $(this), 'highest'); |
| 149 | } |
| 150 | }) |
| 151 | |
| 152 | .on( 'keyup click', '.evf-input-highest-rating-point[type=number]', function() { |
| 153 | var highest_rating_point = parseInt( $( this ).val(), 10 ), |
| 154 | lowest_rating_point = parseInt( $( this ).parent().next().find( '.evf-input-lowest-rating-point[name*=lowest_rating_point]' ).val(), 10 ); |
| 155 | |
| 156 | if ( highest_rating_point > 100 ) { |
| 157 | $( document.body ).triggerHandler( 'evf_add_error_tip', [ $(this), 'i18n_field_highest_rating_greater_than_max_value_error', params ] ); |
| 158 | } else if ( highest_rating_point <= lowest_rating_point ) { |
| 159 | $( document.body ).triggerHandler( 'evf_add_error_tip', [ $(this), 'i18n_field_greater_than_lowest_point_error', params ] ); |
| 160 | } else { |
| 161 | if ( highest_rating_point <= lowest_rating_point ) { |
| 162 | $( document.body ).triggerHandler( 'evf_remove_error_tip', [ $(this), 'i18n_field_greater_than_lowest_point_error' ] ); |
| 163 | } else { |
| 164 | $( document.body ).triggerHandler( 'evf_remove_error_tip', [ $(this), 'i18n_field_highest_rating_greater_than_max_value_error' ] ); |
| 165 | } |
| 166 | } |
| 167 | }) |
| 168 | |
| 169 | .on( 'change click', '.evf-input-lowest-rating-point[type=number]', function(e) { |
| 170 | var lowest_rating_point = parseInt( $( this ).val(), 10 ), |
| 171 | highest_rating_point = parseInt( $( this ).parent().prev().find( '.evf-input-highest-rating-point[name*=highest_rating_point]' ).val(), 10 ); |
| 172 | |
| 173 | if ( lowest_rating_point < 0 ) { |
| 174 | $( this ).val('0'); |
| 175 | EverestFormsSurvey.scaleRatingPoint( e, $(this), 'lowest'); |
| 176 | } |
| 177 | if ( lowest_rating_point >= highest_rating_point ) { |
| 178 | $( this ).val( highest_rating_point - 1 ); |
| 179 | EverestFormsSurvey.scaleRatingPoint( e, $(this), 'lowest'); |
| 180 | } |
| 181 | }) |
| 182 | |
| 183 | .on( 'keyup click', '.evf-input-lowest-rating-point[type=number]', function() { |
| 184 | var lowest_rating_point = parseInt( $( this ).val(), 10 ), |
| 185 | highest_rating_point = parseInt( $( this ).parent().prev().find( '.evf-input-highest-rating-point[name*=highest_rating_point]' ).val(), 10 ); |
| 186 | |
| 187 | if ( lowest_rating_point < 0 ) { |
| 188 | $( document.body ).triggerHandler( 'evf_add_error_tip', [ $(this), 'i18n_field_lowest_rating_lower_than_min_value_error', params ] ); |
| 189 | } |
| 190 | if ( lowest_rating_point >= highest_rating_point ) { |
| 191 | $( document.body ).triggerHandler( 'evf_add_error_tip', [ $(this), 'i18n_field_less_than_highest_point_error', params ] ); |
| 192 | } else { |
| 193 | $( document.body ).triggerHandler( 'evf_remove_error_tip', [ $(this), 'i18n_field_less_than_highest_point_error' ] ); |
| 194 | } |
| 195 | }); |
| 196 | |
| 197 | $( document ).on('keyup input', '.everest-forms-field-option-row-highest_rating_point input', function (e) { |
| 198 | EverestFormsSurvey.scaleRatingPoint( e, this, 'highest'); |
| 199 | }); |
| 200 | |
| 201 | $( document ).on('keyup input', '.everest-forms-field-option-row-lowest_rating_point input', function (e) { |
| 202 | EverestFormsSurvey.scaleRatingPoint( e, this, 'lowest' ); |
| 203 | }); |
| 204 | |
| 205 | $( document ).on('change', '#everest-forms-panel-field-settings-enable_quiz', function (e) { |
| 206 | EverestFormsSurvey.showQuizFieldOption( e, this ); |
| 207 | }); |
| 208 | |
| 209 | $( document ).on('change', '#everest-forms-panel-field-settings-enable_survey', function (e) { |
| 210 | EverestFormsSurvey.showSurveyFieldOption( e, this ); |
| 211 | }); |
| 212 | $( document ).on('change', '.evf_quiz_enable_container input', function (e) { |
| 213 | EverestFormsSurvey.showQuizOptionField( e, this ); |
| 214 | }); |
| 215 | $( document ).on('change', '.evf_survey_enable_container input', function (e) { |
| 216 | EverestFormsSurvey.EnableSurveyOptionField( e, this ); |
| 217 | }); |
| 218 | $( document ).on( 'change', '#everest-forms-survey-question-list', function(e) { |
| 219 | var field_id = $(this).val(); |
| 220 | EverestFormsSurvey.showSurveyQuestionReport( $(this).closest('.everest-forms-survey-header'), field_id ); |
| 221 | }); |
| 222 | |
| 223 | $( document ).on( 'change', '#survey-filter-by-form', function(e) { |
| 224 | EverestFormsSurvey.showSurveyQuestionReportByForm( e, this ); |
| 225 | }); |
| 226 | |
| 227 | $( document ).on( 'change', '.evf-correct-answers input[type=radio]', function(e) { |
| 228 | EverestFormsSurvey.clickOneRadio( e, this ); |
| 229 | }); |
| 230 | |
| 231 | $( document ).on( 'input', '.evf-choices-list input[type="text"]', function(e) { |
| 232 | EverestFormsSurvey.livePreviewOnCorrectAnswer(e, this); |
| 233 | }); |
| 234 | |
| 235 | $( document ).on( 'click', '.evf-choices-list .remove', function(e) { |
| 236 | EverestFormsSurvey.removeRowCorrectAnswer(e, this); |
| 237 | }); |
| 238 | |
| 239 | $( document ).on( 'click', '.evf-choices-list .add', function(e) { |
| 240 | EverestFormsSurvey.addNewRowCorrectAnswer(e, this); |
| 241 | }); |
| 242 | |
| 243 | $( document ).on('change', '#everest-forms-panel-field-settings-over_all_feedback', function (e) { |
| 244 | EverestFormsSurvey.showQuizOverAllOption( e, this ); |
| 245 | }); |
| 246 | $( document ).on('change', '#everest-forms-panel-field-settings-quiz_reporting', function (e) { |
| 247 | EverestFormsSurvey.showQuizReportingOption( e, this ); |
| 248 | }); |
| 249 | |
| 250 | $( document ).on( 'click', '.survey-block-statistic-overview button', function(e) { |
| 251 | var field_id = $(this).data('field-id'), |
| 252 | type = $( this ).data('type'); |
| 253 | $( this ).siblings().removeClass('current-tab-active'); |
| 254 | $( this ).addClass('current-tab-active'); |
| 255 | everest.charts[field_id].destroy(); |
| 256 | var everestFormsSurveyCanvas = $( this ).parent().siblings('.survey-block-chart-overview').find('.everest-forms-chart-canvas'); |
| 257 | var canvas = everestFormsSurveyCanvas.get(0).getContext('2d'); |
| 258 | EverestFormsSurvey.generateChart( field_id, type, canvas ); |
| 259 | }); |
| 260 | |
| 261 | $( document ).on( 'keyup input', '.score_to', function(e) { |
| 262 | EverestFormsSurvey.changeScoreFrom( e, this ); |
| 263 | }); |
| 264 | |
| 265 | $( document ).on( 'change click', '.score_to', function(e) { |
| 266 | var $this = $( this ), |
| 267 | to_score = parseInt( $this.val() ), |
| 268 | from_score = parseInt( $this.closest('.evf-form-group').find('.score_from').val() ); |
| 269 | if( from_score >= to_score && to_score != '' ){ |
| 270 | $this.val( from_score + 1 ); |
| 271 | } |
| 272 | if( to_score > 100 ){ |
| 273 | $this.val(100); |
| 274 | } |
| 275 | $( document.body ).triggerHandler( 'evf_remove_error_tip', [ $this, 'i18n_field_to_score_is_empty_error' ] ); |
| 276 | }); |
| 277 | |
| 278 | // Live effect for Yes No field style option. |
| 279 | $( document ).on( 'change', '.everest-forms-field-option-row-style select', function() { |
| 280 | var $this = $( this ), |
| 281 | value = $this.val(), |
| 282 | id = $this.parent().data( 'field-id' ), |
| 283 | yes_color = $( '#everest-forms-field-option-row-'+ id +'-yes_icon_color button[class="button wp-color-result"]' ).css( 'backgroundColor' ), |
| 284 | no_color = $( '#everest-forms-field-option-row-'+ id +'-no_icon_color button[class="button wp-color-result"]' ).css( 'backgroundColor' ), |
| 285 | yes_label = $( '#everest-forms-field-option-row-'+ id +'-yes_label input[type="text"]' ).val(), |
| 286 | no_label = $( '#everest-forms-field-option-row-'+ id +'-no_label input[type="text"]' ).val(), |
| 287 | html_div = $( '#everest-forms-field-' + id ).find( '.yes-no-preview' ), |
| 288 | html = ''; |
| 289 | |
| 290 | EverestFormsSurvey.checkSelectedYesNoVariation( value ); |
| 291 | |
| 292 | if ( 'with_icon' === value ) { |
| 293 | html_div.removeClass( 'icon-text' ).removeClass( 'text-only' ); |
| 294 | |
| 295 | html = '<span class="yes yes-no-icon"><svg width="32" height="32" viewBox="0 0 24 24" style="fill:' + yes_color + '"><path d="M1 21h4V9H1v12zm22-11c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-1.91l-.01-.01L23 10z"></path></svg></span>'; |
| 296 | html += '<span class="no yes-no-icon"><svg width="32" height="32" viewBox="0 0 24 24" style="fill:' + no_color + '"><path d="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v1.91l.01.01L1 14c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L9.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm4 0v12h4V3h-4z"></path></svg></span>'; |
| 297 | } else if ( 'with_text' === value ) { |
| 298 | html_div.addClass( ' text-only' ).removeClass( 'icon-text' ); |
| 299 | |
| 300 | html = '<input type="text" value="'+ yes_label +'" disabled /><input type="text" value="'+ no_label +'" disabled />'; |
| 301 | } else if ( 'with_icon_text' === value ) { |
| 302 | html_div.addClass( ' icon-text' ).removeClass( 'text-only' ); |
| 303 | |
| 304 | html = '<span class="yes yes-no-icon"><svg width="32" height="32" viewBox="0 0 24 24" style="fill:' + yes_color + '"><path d="M1 21h4V9H1v12zm22-11c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-1.91l-.01-.01L23 10z"></path></svg><label>'+ yes_label +'</label></span>'; |
| 305 | html += '<span class="no yes-no-icon"><svg width="32" height="32" viewBox="0 0 24 24" style="fill:' + no_color + '"><path d="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v1.91l.01.01L1 14c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L9.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm4 0v12h4V3h-4z"></path></svg><label>'+ no_label +'</label></span>'; |
| 306 | } |
| 307 | |
| 308 | html_div.html( html ); |
| 309 | }); |
| 310 | |
| 311 | $( document ).on( 'click', '.everest-forms-field.everest-forms-field-yes-no', function() { |
| 312 | var fieldId = $( this ).data( 'field-id' ), |
| 313 | value = $('#everest-forms-field-option-'+ fieldId +' option:selected').val(); |
| 314 | |
| 315 | EverestFormsSurvey.checkSelectedYesNoVariation( value ); |
| 316 | } ); |
| 317 | |
| 318 | $( document ).on( 'input', '.everest-forms-field-option-row-yes_label input[type="text"]', function() { |
| 319 | var fieldId = $( this ).parent().data( 'field-id' ), |
| 320 | value = $( this ).val(); |
| 321 | $('#everest-forms-field-'+ fieldId +' .yes-no-preview :input:first' ).val( value ); |
| 322 | $('#everest-forms-field-'+ fieldId +' .yes-no-preview .yes.yes-no-icon label' ).text( value ); |
| 323 | } ); |
| 324 | |
| 325 | $( document ).on( 'input', '.everest-forms-field-option-row-no_label input[type="text"]', function() { |
| 326 | var fieldId = $( this ).parent().data( 'field-id' ), |
| 327 | value = $( this ).val(); |
| 328 | $('#everest-forms-field-'+ fieldId +' .yes-no-preview :input:last' ).val( value ); |
| 329 | $('#everest-forms-field-'+ fieldId +' .yes-no-preview .no.yes-no-icon label' ).text( value ); |
| 330 | } ); |
| 331 | |
| 332 | // Yes No Colorpicker. |
| 333 | $( document ).on( 'click', '.everest-forms-field-yes-no', function() { |
| 334 | $( '.everest-forms-field-option-row-yes_icon_color input.evf-colorpicker' ).wpColorPicker({ |
| 335 | change: function( event ) { |
| 336 | var $this = $( this ), |
| 337 | value = $this.val(), |
| 338 | id = $this.closest( '.everest-forms-field-option-row' ).data( 'field-id' ), |
| 339 | $icons = $( '#everest-forms-field-'+id +' .yes svg' ); |
| 340 | $icons.css( 'fill', value ); |
| 341 | } |
| 342 | }); |
| 343 | }); |
| 344 | |
| 345 | $( document ).on( 'click', '.everest-forms-field-yes-no', function() { |
| 346 | $( '.everest-forms-field-option-row-no_icon_color input.evf-colorpicker' ).wpColorPicker({ |
| 347 | change: function( event ) { |
| 348 | var $this = $( this ), |
| 349 | value = $this.val(), |
| 350 | id = $this.closest( '.everest-forms-field-option-row' ).data( 'field-id' ), |
| 351 | $icons = $( '#everest-forms-field-'+id +' .no svg' ); |
| 352 | $icons.css( 'fill', value ); |
| 353 | } |
| 354 | }); |
| 355 | }); |
| 356 | |
| 357 | }, |
| 358 | |
| 359 | changeScoreFrom: function( e, el ){ |
| 360 | var $this = $( el ); |
| 361 | to_score = parseInt( $this.val() ), |
| 362 | value = ''; |
| 363 | if ( to_score < 100 ){ |
| 364 | value = to_score + 1; |
| 365 | $this.closest('.evf-form-group').next().find('.score_from').val( value ); |
| 366 | } |
| 367 | from_score = parseInt( $this.closest('.evf-form-group').find('.score_from').val() ); |
| 368 | if( from_score >= to_score ){ |
| 369 | $( document.body ).triggerHandler( 'evf_add_error_tip', [ $this, 'i18n_field_from_score_greater_than_to_score', params ] ); |
| 370 | } else { |
| 371 | $( document.body ).triggerHandler( 'evf_remove_error_tip', [ $this, 'i18n_field_from_score_greater_than_to_score' ] ); |
| 372 | } |
| 373 | }, |
| 374 | |
| 375 | clickOneRadio: function( e, el ){ |
| 376 | var $this = $( el ); |
| 377 | $this.closest('.evf-correct-answers').find('input[type="radio"]').prop('checked', false); |
| 378 | $this.prop('checked', true ); |
| 379 | }, |
| 380 | |
| 381 | addNewRowCorrectAnswer: function( e, el ){ |
| 382 | var $this = $( el ), |
| 383 | dataKey = $this.closest('li').attr('data-key'), |
| 384 | nextDataKey = $this.closest('li').next('li').attr('data-key'), |
| 385 | label = $this.closest('li').next('li').children('.label').val(), |
| 386 | field_id = $this.closest('.evf-choices-list').attr('data-field-id'); |
| 387 | current = $this.closest('.everest-forms-field-option-group-basic').siblings('.everest-forms-field-option-group-quiz').find('.everest-forms-field-option-row-correct_answer .evf-correct-answers').find("li[data-key='" + dataKey + "']").clone(); |
| 388 | current.attr('data-key',nextDataKey); |
| 389 | current.find('input').attr('name','form_fields['+field_id+'][correct_answer]['+nextDataKey+']'); |
| 390 | current.find('span').text(label); |
| 391 | $( current ).insertAfter( $('.everest-forms-field-option-row-correct_answer .evf-correct-answers').find("li[data-key='" + dataKey + "']") ); |
| 392 | }, |
| 393 | |
| 394 | removeRowCorrectAnswer: function( e, el ){ |
| 395 | var $this = $( el ), |
| 396 | dataKey = $this.closest('li').attr('data-key'); |
| 397 | if( $this.closest( '.evf-choices-list' ).find( 'li' ).length > 1 ){ |
| 398 | $this.closest('.everest-forms-field-option-group-basic').siblings('.everest-forms-field-option-group-quiz').find('.everest-forms-field-option-row-correct_answer .evf-correct-answers').find("li[data-key='" + dataKey + "']").remove(); |
| 399 | } |
| 400 | }, |
| 401 | |
| 402 | livePreviewOnCorrectAnswer: function( e, el ){ |
| 403 | var $this = $( el ), |
| 404 | dataKey = $this.closest('li').attr('data-key'); |
| 405 | if ( $('.everest-forms-field-option-row-correct_answer .evf-correct-answers').length > 0 ) { |
| 406 | $this.closest('.everest-forms-field-option-group-basic').siblings('.everest-forms-field-option-group-quiz').find('.everest-forms-field-option-row-correct_answer .evf-correct-answers').find("li[data-key='" + dataKey + "']").find('span').text($this.val()); |
| 407 | } |
| 408 | }, |
| 409 | |
| 410 | showSurveyQuestionReportByForm: function ( e, el ){ |
| 411 | var $this = $( el ), |
| 412 | form_id = $this.val(); |
| 413 | $this.siblings('i').remove(); |
| 414 | $this.siblings( '.everest-forms-survey-block').remove(); |
| 415 | $( everest.spinner ).insertAfter( $this ); |
| 416 | if( form_id ){ |
| 417 | var $url = params.admin_url+'admin.php?page=evf-entries&view=all-report&form-id='+form_id; |
| 418 | window.location.href = $url; |
| 419 | $this.siblings('.evf-survey-loader').remove(); |
| 420 | } |
| 421 | }, |
| 422 | |
| 423 | showSurveyQuestionReport: function ( container, field_id, single, form_id, currentIndex ){ |
| 424 | var $this = $( container ); |
| 425 | single = typeof single !== 'undefined' ? single : true; |
| 426 | form_id = typeof form_id !== 'undefined' ? form_id : false; |
| 427 | if ( ! form_id ) { |
| 428 | var form_id = $('#filter-by-form').val(); |
| 429 | } |
| 430 | if( single ) { |
| 431 | $this.siblings('.everest-forms-survey-block').remove(); |
| 432 | } |
| 433 | // Fire AJAX |
| 434 | var data = { |
| 435 | action : 'everest_forms_survey_generate_report', |
| 436 | field_id : field_id, |
| 437 | form_id : form_id, |
| 438 | security: params.ajax_nonce |
| 439 | } |
| 440 | if( single ) { |
| 441 | $this.siblings('.evf-survey-loader').remove(); |
| 442 | $( everest.spinner ).insertAfter( $this ); |
| 443 | }else{ |
| 444 | $this.append( everest.spinner ); |
| 445 | } |
| 446 | $.ajax({ |
| 447 | url: params.ajax_url, |
| 448 | data: data, |
| 449 | type: 'POST', |
| 450 | |
| 451 | success: function( response ) { |
| 452 | if( single ) { |
| 453 | $this.siblings('.evf-survey-loader').remove(); |
| 454 | var newAppendedElements = $( response.data.html ).insertAfter( $this ); |
| 455 | }else{ |
| 456 | $this.find('.evf-survey-loader').remove(); |
| 457 | var newAppendedElements = $( response.data.html ).appendTo( $this ); |
| 458 | } |
| 459 | |
| 460 | if( $(newAppendedElements).find( '#survery-circle-'+field_id ).length ) { |
| 461 | var progressData = $( '#survery-circle-'+field_id ).data('value'); |
| 462 | var bar = new ProgressBar.Circle( '#survery-circle-'+field_id, { |
| 463 | color: '#333840', |
| 464 | // This has to be the same size as the maximum width to |
| 465 | // prevent clipping |
| 466 | strokeWidth: 4, |
| 467 | trailWidth: 4, |
| 468 | easing: 'easeInOut', |
| 469 | duration: 1400, |
| 470 | text: { |
| 471 | autoStyleContainer: false |
| 472 | }, |
| 473 | from: { color: '#8e42eb', width: 4 }, |
| 474 | to: { color: '#8e42eb', width: 4 }, |
| 475 | // Set default step function for all animate calls |
| 476 | step: function(state, circle) { |
| 477 | circle.path.setAttribute('stroke', state.color); |
| 478 | circle.path.setAttribute('stroke-width', state.width); |
| 479 | |
| 480 | var value = Math.round(circle.value() * 100); |
| 481 | if (value === 0) { |
| 482 | circle.setText(''); |
| 483 | } else { |
| 484 | circle.setText(value); |
| 485 | } |
| 486 | |
| 487 | } |
| 488 | }); |
| 489 | bar.text.style.fontFamily = '"Raleway", Helvetica, sans-serif'; |
| 490 | bar.text.style.fontSize = '2rem'; |
| 491 | |
| 492 | bar.animate(progressData/100); // Number from 0.0 to 1.0 |
| 493 | } |
| 494 | everest.fieldReportData[field_id] = response.data.report; |
| 495 | var everestFormsSurveyCanvas = $( newAppendedElements ).find('.survey-block-chart-overview .everest-forms-chart-canvas'); |
| 496 | if( everestFormsSurveyCanvas.length !== 0 ){ |
| 497 | var canvas = everestFormsSurveyCanvas.get(0).getContext('2d'); |
| 498 | EverestFormsSurvey.generateChart( field_id, 'bar', canvas ); |
| 499 | } |
| 500 | if( field_ids && field_ids.length > currentIndex + 1 ) { |
| 501 | currentIndex++; |
| 502 | EverestFormsSurvey.showSurveyQuestionReport( container, field_ids[currentIndex], single, form_id, currentIndex ); |
| 503 | } |
| 504 | } |
| 505 | }); |
| 506 | }, |
| 507 | |
| 508 | generateChart: function ( fieldID, chartType, canvas ){ |
| 509 | var config = false; |
| 510 | reportData = everest.fieldReportData[fieldID]; |
| 511 | if( null != reportData || undefined != typeof reportData ) { |
| 512 | // For Bar |
| 513 | if ( 'bar' === chartType ) { |
| 514 | config = { |
| 515 | type: 'bar', |
| 516 | data: { |
| 517 | labels: Object.keys( reportData ), |
| 518 | datasets: [{ |
| 519 | label: 'Data', |
| 520 | hoverBackgroundColor: randomColor({ luminosity: 'light', count: Object.values( reportData ).length}), |
| 521 | backgroundColor: randomColor({ luminosity: 'light', count: Object.values( reportData ).length}), |
| 522 | data: Object.values( reportData ) |
| 523 | }] |
| 524 | }, |
| 525 | options: { |
| 526 | responsive: true, |
| 527 | maintainAspectRatio: false, |
| 528 | legend: { |
| 529 | display: false |
| 530 | }, |
| 531 | tooltips: { |
| 532 | callbacks: { |
| 533 | label: function( item ) { |
| 534 | return item.yLabel + '%'; |
| 535 | } |
| 536 | } |
| 537 | }, |
| 538 | scales: { |
| 539 | xAxes: [{ |
| 540 | gridLines: { |
| 541 | display: false |
| 542 | }, |
| 543 | ticks: { |
| 544 | fontSize: 14, |
| 545 | callback: function( value ) { |
| 546 | if ( typeof value === 'string' && value.length > 20 ) { |
| 547 | return value.substring( 0,20 ) + '...'; |
| 548 | } |
| 549 | return value; |
| 550 | } |
| 551 | } |
| 552 | }], |
| 553 | yAxes: [{ |
| 554 | ticks: { |
| 555 | min: 0, |
| 556 | max: 100, |
| 557 | stepSize: 20, |
| 558 | fontColor: '#999999', |
| 559 | fontSize: 11, |
| 560 | callback: function( value ) { |
| 561 | return value + '%'; |
| 562 | } |
| 563 | } |
| 564 | }] |
| 565 | } |
| 566 | } |
| 567 | }; |
| 568 | } else if ( 'pie' === chartType ) { |
| 569 | config = { |
| 570 | type: 'pie', |
| 571 | data: { |
| 572 | labels: Object.keys( reportData ), |
| 573 | datasets: [{ |
| 574 | hoverBackgroundColor: '#2b8fd2', |
| 575 | data: Object.values( reportData ), |
| 576 | backgroundColor: randomColor({ luminosity: 'light', count: Object.values( reportData ).length}) |
| 577 | }] |
| 578 | }, |
| 579 | options: { |
| 580 | responsive: true, |
| 581 | maintainAspectRatio: false, |
| 582 | legend: { |
| 583 | position: 'right', |
| 584 | labels : { |
| 585 | fontSize: 14, |
| 586 | padding: 15, |
| 587 | generateLabels: function(chart) { |
| 588 | var data = chart.data; |
| 589 | if (data.labels.length && data.datasets.length) { |
| 590 | return data.labels.map(function(label, i) { |
| 591 | var meta = chart.getDatasetMeta(0); |
| 592 | var ds = data.datasets[0]; |
| 593 | var arc = meta.data[i]; |
| 594 | var custom = arc && arc.custom || {}; |
| 595 | var valueAtIndexOrDefault = Chart.helpers.valueAtIndexOrDefault; |
| 596 | var arcOpts = chart.options.elements.arc; |
| 597 | var fill = custom.backgroundColor ? custom.backgroundColor : valueAtIndexOrDefault(ds.backgroundColor, i, arcOpts.backgroundColor); |
| 598 | var stroke = custom.borderColor ? custom.borderColor : valueAtIndexOrDefault(ds.borderColor, i, arcOpts.borderColor); |
| 599 | var bw = custom.borderWidth ? custom.borderWidth : valueAtIndexOrDefault(ds.borderWidth, i, arcOpts.borderWidth); |
| 600 | if ( label.length > 20 ) { |
| 601 | label = label.substring( 0,20 ) + '...'; |
| 602 | } |
| 603 | return { |
| 604 | text: label, |
| 605 | fillStyle: fill, |
| 606 | strokeStyle: stroke, |
| 607 | lineWidth: bw, |
| 608 | hidden: isNaN(ds.data[i]) || meta.data[i].hidden, |
| 609 | index: i |
| 610 | }; |
| 611 | }); |
| 612 | } |
| 613 | return []; |
| 614 | } |
| 615 | } |
| 616 | }, |
| 617 | tooltips: { |
| 618 | callbacks: { |
| 619 | label: function( item, data ) { |
| 620 | return data['labels'][item['index']] + ' - ' + data['datasets'][0]['data'][item['index']] + '%'; |
| 621 | } |
| 622 | } |
| 623 | } |
| 624 | } |
| 625 | }; |
| 626 | } else if ( 'line' === chartType ) { |
| 627 | config = { |
| 628 | type: 'line', |
| 629 | data: { |
| 630 | labels: Object.keys( reportData ), |
| 631 | datasets: [{ |
| 632 | fill: false, |
| 633 | data: Object.values( reportData ) |
| 634 | }] |
| 635 | }, |
| 636 | options: { |
| 637 | responsive: true, |
| 638 | maintainAspectRatio: false, |
| 639 | legend: { |
| 640 | display: false |
| 641 | }, |
| 642 | tooltips: { |
| 643 | callbacks: { |
| 644 | label: function( item, data ) { |
| 645 | return data['datasets'][0]['data'][item['index']] + '%'; |
| 646 | } |
| 647 | } |
| 648 | }, |
| 649 | scales: { |
| 650 | xAxes: [{ |
| 651 | gridLines: { |
| 652 | display: false |
| 653 | }, |
| 654 | ticks: { |
| 655 | fontSize: 14, |
| 656 | callback: function( value ) { |
| 657 | if ( typeof value === 'string' && value.length > 20 ) { |
| 658 | return value.substring( 0,20 ) + '...'; |
| 659 | } |
| 660 | return value; |
| 661 | } |
| 662 | } |
| 663 | }], |
| 664 | yAxes: [{ |
| 665 | ticks: { |
| 666 | min: 0, |
| 667 | max: 100, |
| 668 | stepSize: 20, |
| 669 | fontColor: '#999999', |
| 670 | fontSize: 11, |
| 671 | callback: function( value ) { |
| 672 | return value + '%'; |
| 673 | } |
| 674 | } |
| 675 | }] |
| 676 | } |
| 677 | } |
| 678 | } |
| 679 | } |
| 680 | } |
| 681 | if ( config ) { |
| 682 | everest.charts[fieldID] = new Chart(canvas, config ); |
| 683 | } |
| 684 | |
| 685 | }, |
| 686 | |
| 687 | /** |
| 688 | * Show the Quiz Field option if quiz is enabled inside the field. |
| 689 | */ |
| 690 | showQuizOptionField: function ( e, el){ |
| 691 | e.preventDefault(); |
| 692 | var $this = $( el ); |
| 693 | |
| 694 | if( $this.closest('.quiz-option').siblings('.survey-option').children('.evf_survey_enable_container' ).children('input').prop('checked') === true && $this.prop('checked') === true ){ |
| 695 | $this.closest('.quiz-option').children('.everst-forms-field-quiz-settings').removeClass('everest-forms-hidden'); |
| 696 | $this.closest('.quiz-option').children('.everst-forms-field-quiz-settings').addClass('everest-forms-show'); |
| 697 | $.alert({ |
| 698 | title: false, |
| 699 | content: "You do have survey enabled for this field. Do you want to change it on Quiz?", |
| 700 | icon: 'dashicons dashicons-info', |
| 701 | type: 'blue', |
| 702 | closeIcon: false, |
| 703 | backgroundDismiss: false, |
| 704 | buttons: { |
| 705 | "Yes": function() { |
| 706 | $this.closest('.quiz-option').siblings('.survey-option').children('.evf_survey_enable_container' ).children('input').prop('checked', false); |
| 707 | $this.prop('checked',true); |
| 708 | }, |
| 709 | "No": function() { |
| 710 | $this.prop('checked', false); |
| 711 | if( $this.closest('.quiz-option').children('.everst-forms-field-quiz-settings').hasClass('everest-forms-show') ) { |
| 712 | $this.closest('.quiz-option').children('.everst-forms-field-quiz-settings').removeClass('everest-forms-show').addClass('everest-forms-hidden'); |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | } |
| 717 | }); |
| 718 | }else if( $this.prop('checked') === true ) { |
| 719 | $this.closest('.quiz-option').children('.everst-forms-field-quiz-settings').removeClass('everest-forms-hidden'); |
| 720 | $this.closest('.quiz-option').children('.everst-forms-field-quiz-settings').addClass('everest-forms-show'); |
| 721 | }else{ |
| 722 | $this.closest('.quiz-option').children('.everst-forms-field-quiz-settings').removeClass('everest-forms-show'); |
| 723 | $this.closest('.quiz-option').children('.everst-forms-field-quiz-settings').addClass('everest-forms-hidden'); |
| 724 | } |
| 725 | |
| 726 | // $this.closest('.quiz-option').children('.everst-forms-field-quiz-settings').toggleClass('everest-forms-hidden everest-forms-show'); |
| 727 | |
| 728 | }, |
| 729 | |
| 730 | /** |
| 731 | * Show the Survey Field option if survey is enabled inside the field. |
| 732 | */ |
| 733 | EnableSurveyOptionField: function ( e, el){ |
| 734 | e.preventDefault(); |
| 735 | var $this = $( el ); |
| 736 | |
| 737 | if( $this.closest('.survey-option').siblings('.quiz-option').children('.evf_quiz_enable_container' ).children('input').prop('checked') === true ){ |
| 738 | $.alert({ |
| 739 | title: false, |
| 740 | content: "You do have Quiz enabled for this field. Do you want to change it on Survey?", |
| 741 | icon: 'dashicons dashicons-info', |
| 742 | type: 'blue', |
| 743 | closeIcon: false, |
| 744 | backgroundDismiss: false, |
| 745 | buttons: { |
| 746 | "Yes": function() { |
| 747 | $this.closest('.survey-option').siblings('.quiz-option').children('.evf_quiz_enable_container' ).children('input').prop('checked', false); |
| 748 | if ( $this.closest('.survey-option').siblings('.quiz-option').children('.everst-forms-field-quiz-settings').hasClass('everest-forms-show') ) { |
| 749 | $this.closest('.survey-option').siblings('.quiz-option').children('.everst-forms-field-quiz-settings').removeClass('everest-forms-show').addClass('everest-forms-hidden'); |
| 750 | } |
| 751 | $this.prop('checked',true); |
| 752 | }, |
| 753 | "No": function() { |
| 754 | $this.prop('checked', false); |
| 755 | } |
| 756 | } |
| 757 | }); |
| 758 | } |
| 759 | |
| 760 | }, |
| 761 | |
| 762 | /** |
| 763 | * Show the Quiz Field option if quiz is enabled |
| 764 | */ |
| 765 | showQuizFieldOption: function ( e, el){ |
| 766 | e.preventDefault(); |
| 767 | var $this = $( el ); |
| 768 | |
| 769 | if( $this.prop('checked') === true ) { |
| 770 | $('.quiz-option .evf_quiz_enable_container input').prop( 'checked', true ); |
| 771 | if ( $('#everest-forms-panel-field-settings-enable_survey').prop('checked') === true ) { |
| 772 | $.alert({ |
| 773 | title: false, |
| 774 | content: "You do have survey forms. Do you want to change it on Quiz Form?", |
| 775 | icon: 'dashicons dashicons-info', |
| 776 | closeIcon: false, |
| 777 | backgroundDismiss: false, |
| 778 | type: 'blue', |
| 779 | buttons: { |
| 780 | "Yes": function() { |
| 781 | $('.quiz-option').children('.everst-forms-field-quiz-settings').removeClass('everest-forms-hidden').addClass('everest-forms-show'); |
| 782 | $('#everest-forms-panel-field-settings-enable_survey').prop('checked', false); |
| 783 | $('.survey-option .evf_survey_enable_container input').prop('checked', false); |
| 784 | $this.prop('checked',true); |
| 785 | if( $this.closest('.evf-quiz-section').children('.evf-quiz-settings').hasClass('everest-forms-hidden') ) { |
| 786 | $this.closest('.evf-quiz-section').children('.evf-quiz-settings').removeClass('everest-forms-hidden').addClass('everest-forms-show'); |
| 787 | } |
| 788 | }, |
| 789 | "No": function() { |
| 790 | $this.prop('checked', false); |
| 791 | $('.quiz-option .evf_quiz_enable_container input').prop( 'checked', false ); |
| 792 | if( $this.closest('.evf-quiz-section').children('.evf-quiz-settings').hasClass('everest-forms-show') ) { |
| 793 | $this.closest('.evf-quiz-section').children('.evf-quiz-settings').removeClass('everest-forms-show').addClass('everest-forms-hidden'); |
| 794 | } |
| 795 | } |
| 796 | } |
| 797 | }); |
| 798 | } else { |
| 799 | $this.closest('.evf-quiz-section').children('.evf-quiz-settings').toggleClass('everest-forms-hidden everest-forms-show'); |
| 800 | } |
| 801 | } else { |
| 802 | $('.quiz-option .evf_quiz_enable_container input').prop( 'checked', false ); |
| 803 | if( $this.closest('.evf-quiz-section').children('.evf-quiz-settings').hasClass('everest-forms-show') ) { |
| 804 | $this.closest('.evf-quiz-section').children('.evf-quiz-settings').removeClass('everest-forms-show').addClass('everest-forms-hidden'); |
| 805 | } |
| 806 | } |
| 807 | }, |
| 808 | |
| 809 | /** |
| 810 | * Show the overall feedback option if overall feedback is enabled. |
| 811 | */ |
| 812 | showQuizOverAllOption: function ( e, el){ |
| 813 | var $this = $( el ); |
| 814 | if( true == $this.prop('checked') ) { |
| 815 | $this.closest('.everest-forms-overall-feedback').addClass('feedback-enabled'); |
| 816 | $this.closest('.everest-forms-overall-feedback').children('.overall-feedback-options-list').removeClass('everest-forms-hidden').addClass('everest-forms-show'); |
| 817 | } else { |
| 818 | $this.closest('.everest-forms-overall-feedback').removeClass('feedback-enabled'); |
| 819 | // $this.closest('.everest-forms-overall-feedback').children('.overall-feedback-options-list').find('input, textarea').val(''); |
| 820 | $this.closest('.everest-forms-overall-feedback').children('.overall-feedback-options-list').removeClass('everest-forms-show').addClass('everest-forms-hidden'); |
| 821 | } |
| 822 | }, |
| 823 | /** |
| 824 | * Show the quiz reporting options. |
| 825 | */ |
| 826 | showQuizReportingOption: function ( e, el){ |
| 827 | var $this = $( el ); |
| 828 | if( true == $this.prop('checked') ) { |
| 829 | $this.closest('.evf-quiz-reporting').children('.evf-quiz-reporting-options').removeClass('everest-forms-hidden').addClass('everest-forms-show'); |
| 830 | } else { |
| 831 | // $this.closest('.everest-forms-overall-feedback').children('.overall-feedback-options-list').find('input, textarea').val(''); |
| 832 | $this.closest('.evf-quiz-reporting').children('.evf-quiz-reporting-options').removeClass('everest-forms-show').addClass('everest-forms-hidden'); |
| 833 | } |
| 834 | }, |
| 835 | |
| 836 | /** |
| 837 | * Show the Quiz Field option if survey is enabled |
| 838 | */ |
| 839 | showSurveyFieldOption: function ( e, el){ |
| 840 | e.preventDefault(); |
| 841 | var $this = $( el ); |
| 842 | if ( $this.prop('checked') === true ) { |
| 843 | $('.survey-option .evf_survey_enable_container input').prop( 'checked', true ); |
| 844 | if( $('#everest-forms-panel-field-settings-enable_quiz:checked').prop('checked') === true ) { |
| 845 | $.alert({ |
| 846 | title: false, |
| 847 | content: "You do have Quiz form. Do you want to change it on Survey Form?", |
| 848 | icon: 'dashicons dashicons-info', |
| 849 | type: 'blue', |
| 850 | closeIcon: false, |
| 851 | backgroundDismiss: false, |
| 852 | buttons: { |
| 853 | "Yes": function() { |
| 854 | $('#everest-forms-panel-field-settings-enable_quiz').prop('checked', false); |
| 855 | $('.quiz-option .evf_quiz_enable_container input').prop('checked', false); |
| 856 | $this.prop('checked',true); |
| 857 | if ( $('.evf-quiz-settings').hasClass('everest-forms-show') ) { |
| 858 | $('.evf-quiz-settings input[type="checkbox"]').prop('checked', false); |
| 859 | $('.evf-quiz-settings').removeClass('everest-forms-show').addClass('everest-forms-hidden'); |
| 860 | } |
| 861 | if ( $('.everst-forms-field-quiz-settings').hasClass('everest-forms-show') ) { |
| 862 | $('.evf-quiz-settings input[type="text"]').val(''); |
| 863 | $('.evf-quiz-settings input[type="number"]').val(''); |
| 864 | $('.evf-quiz-settings input[type="radio"]').prop('checked', false); |
| 865 | $('.evf-quiz-settings input[type="checkbox"]').prop('checked', false); |
| 866 | $('.everst-forms-field-quiz-settings').removeClass('everest-forms-show').addClass('everest-forms-hidden'); |
| 867 | } |
| 868 | }, |
| 869 | "No": function() { |
| 870 | $this.prop('checked', false); |
| 871 | $('.survey-option .evf_survey_enable_container input').prop( 'checked', false ); |
| 872 | } |
| 873 | |
| 874 | } |
| 875 | }); |
| 876 | } |
| 877 | } else { |
| 878 | $('.survey-option .evf_survey_enable_container input').prop( 'checked', false ); |
| 879 | } |
| 880 | |
| 881 | }, |
| 882 | |
| 883 | /** |
| 884 | * Live Preview of Scale Rating Rating Text |
| 885 | */ |
| 886 | scaleRatingText: function ( e, el, level){ |
| 887 | e.preventDefault(); |
| 888 | var $this = $( el ), |
| 889 | container = ''; |
| 890 | previewVal = $this.val(); |
| 891 | |
| 892 | if ( 'lowest' === level ) { |
| 893 | var field_id = $this.closest('.everest-forms-field-option-row-lowest_rating_text').attr('data-field-id'); |
| 894 | container = $('#everest-forms-field-' + field_id +'').find('.lowest-rating'); |
| 895 | } else { |
| 896 | var field_id = $this.closest('.everest-forms-field-option-row-highest_rating_text').attr('data-field-id'); |
| 897 | container = $('#everest-forms-field-' + field_id +'').find('.highest-rating'); |
| 898 | } |
| 899 | |
| 900 | container.text(previewVal); |
| 901 | |
| 902 | }, |
| 903 | |
| 904 | /** |
| 905 | * Live Preview of Scale Rating Rating Point |
| 906 | */ |
| 907 | scaleRatingPoint: function ( e, el, level ){ |
| 908 | e.preventDefault(); |
| 909 | var $this = $( el ), |
| 910 | field_id = $this.closest('.everest-forms-field-option-row-' + level + '_rating_point').data('field-id'), |
| 911 | container = $('#everest-forms-field-' + field_id +''); |
| 912 | lowest_point = parseInt( $('#everest-forms-field-option-' + field_id + '-lowest_rating_point').val() ), |
| 913 | hightest_point = parseInt( $('#everest-forms-field-option-' + field_id + '-highest_rating_point').val() ), |
| 914 | ratingDiff = hightest_point - lowest_point; |
| 915 | previewVal = $this.val(); |
| 916 | |
| 917 | if( hightest_point > lowest_point ) { |
| 918 | $('#everest-forms-field-'+field_id+'').find('.everest-forms-scale-rating-table').find('.highest-rating').parent('th').attr( 'colspan', ratingDiff+1 ); |
| 919 | container.find('.everest-forms-scale-rating-table tbody tr').empty(); |
| 920 | for ( var $i = lowest_point; $i <= hightest_point; $i++ ) { |
| 921 | container.find('.everest-forms-scale-rating-table tbody tr').append('<td><input type="radio" disabled><label>' + $i + '</label></td>'); |
| 922 | } |
| 923 | } |
| 924 | }, |
| 925 | |
| 926 | /** |
| 927 | * Sortable Handler. |
| 928 | */ |
| 929 | choicesInit: function () { |
| 930 | $( 'ul.evf-survey-choices' ).sortable({ |
| 931 | items: 'li', |
| 932 | axis: 'y', |
| 933 | helper: '.sort', |
| 934 | scrollSensitivity: 40, |
| 935 | }); |
| 936 | }, |
| 937 | |
| 938 | /** |
| 939 | * Add field choice |
| 940 | * |
| 941 | */ |
| 942 | fieldChoiceAdd: function( e, el ) { |
| 943 | e.preventDefault(); |
| 944 | var $this = $( el ), |
| 945 | clone = $this.closest('li').clone(); |
| 946 | clone.find('input').val(''); |
| 947 | var ul = $this.closest('.evf-survey-choices'); |
| 948 | var field_id = ul.data('field-id'); |
| 949 | var next_id = ul.attr('data-next-id'); |
| 950 | var choice_type = ul.attr('data-choice-type'); |
| 951 | |
| 952 | clone.attr('data-key', next_id); |
| 953 | clone.find('.default').attr('name', 'form_fields[' + field_id + '][' + choice_type + '][' + next_id + '][default]'); |
| 954 | clone.find('.label').attr('name', 'form_fields[' + field_id + '][' + choice_type + '][' + next_id + ']'); |
| 955 | $this.closest('li').after(clone); |
| 956 | next_id++; |
| 957 | $this.closest('.evf-survey-choices').attr('data-next-id',next_id); |
| 958 | EverestFormsSurvey.fieldChoiceUpdate( field_id ); |
| 959 | |
| 960 | /** |
| 961 | * Add new required-field-message field if a new likert row was added |
| 962 | */ |
| 963 | if ( 'likert_rows' === ul.data( 'choice-type' ) ) { |
| 964 | var next_to_li = $this.closest( 'li' ); |
| 965 | EverestFormsSurvey.requiredFieldMessageInputFieldAdd( ul, next_to_li, clone ); |
| 966 | } |
| 967 | }, |
| 968 | |
| 969 | /** |
| 970 | * Delete field choice. |
| 971 | */ |
| 972 | fieldChoiceDelete: function(e, el) { |
| 973 | |
| 974 | e.preventDefault(); |
| 975 | |
| 976 | var $this = $(el), |
| 977 | ul = $this.closest('.evf-survey-choices'), |
| 978 | field_id = ul.data('field-id'), |
| 979 | $list = $this.parent().parent(), |
| 980 | total = $list.find('li').length; |
| 981 | |
| 982 | if (total == '1') { |
| 983 | $.alert({ |
| 984 | title: false, |
| 985 | content: evf_data.i18n_row_locked_msg, |
| 986 | icon: 'dashicons dashicons-info', |
| 987 | type: 'blue', |
| 988 | buttons: { |
| 989 | ok: { |
| 990 | text: evf_data.i18n_ok, |
| 991 | btnClass: 'btn-confirm', |
| 992 | keys: [ 'enter' ] |
| 993 | } |
| 994 | } |
| 995 | }); |
| 996 | } else { |
| 997 | /** |
| 998 | * Remove the corresponding required-field-message field if a likert row is to be removed |
| 999 | */ |
| 1000 | if ( 'likert_rows' === ul.data( 'choice-type' ) ) { |
| 1001 | var key = $this.parent().data( 'key' ); |
| 1002 | EverestFormsSurvey.requiredFieldMessageInputFieldDelete( field_id, key ); |
| 1003 | } |
| 1004 | |
| 1005 | $this.parent().remove(); |
| 1006 | EverestFormsSurvey.fieldChoiceUpdate( field_id ); |
| 1007 | } |
| 1008 | }, |
| 1009 | |
| 1010 | /** |
| 1011 | * Update required-field-message field's label |
| 1012 | * |
| 1013 | */ |
| 1014 | requiredFieldMessageInputFieldUpdate: function(ul, li, target) { |
| 1015 | var key = li.data( 'key' ), |
| 1016 | field_id = ul.data( 'field-id' ), |
| 1017 | id = '#everest-forms-field-option-row-' + field_id + '-required-field-message-' + key; |
| 1018 | |
| 1019 | $( id ).find( 'label' )[0].firstChild.nodeValue = $( target ).val(); |
| 1020 | }, |
| 1021 | |
| 1022 | /** |
| 1023 | * Add new required-field-message field |
| 1024 | * |
| 1025 | */ |
| 1026 | requiredFieldMessageInputFieldAdd: function( ul, next_to_li, new_li ) { |
| 1027 | var field_id = ul.data('field-id'); |
| 1028 | var next_to_key = next_to_li.data('key'); |
| 1029 | var new_key = new_li.data('key'); |
| 1030 | var $next_to = $( '#everest-forms-field-option-row-' + field_id + '-required-field-message-' + next_to_key ); |
| 1031 | var $new_field = $next_to.clone(); |
| 1032 | |
| 1033 | // Update container. |
| 1034 | var cloned_container_class = 'everest-forms-field-option-row-required-field-message-' + next_to_key; |
| 1035 | var new_container_class = 'everest-forms-field-option-row-required-field-message-' + new_key; |
| 1036 | var new_container_id = 'everest-forms-field-option-row-' + field_id + '-required-field-message-' + new_key; |
| 1037 | |
| 1038 | $new_field.attr( 'id', new_container_id ).removeClass( cloned_container_class ).addClass( new_container_class ); |
| 1039 | |
| 1040 | // Update label. |
| 1041 | var new_for = 'everest-forms-field-option-' + field_id + '-required-field-message-' + new_key; |
| 1042 | var new_label = new_li.find('input').val(); |
| 1043 | |
| 1044 | $new_field.find( 'label' ).attr( 'for', new_for ); |
| 1045 | $new_field.find( 'label' )[0].firstChild.nodeValue = new_label; |
| 1046 | |
| 1047 | // Update tooltip. |
| 1048 | var tooltip_text = 'Enter a message to show for this row if it\'s required.'; |
| 1049 | |
| 1050 | $new_field.find('label').find('i').tooltipster({ |
| 1051 | onlyOne : false, |
| 1052 | position : 'bottom', |
| 1053 | content : tooltip_text |
| 1054 | }); |
| 1055 | |
| 1056 | // Update input field. |
| 1057 | var new_input_id = 'everest-forms-field-option-' + field_id + '-required-field-message-' + new_key; |
| 1058 | var new_input_name = 'form_fields[' + field_id + '][required-field-message-' + new_key + ']'; |
| 1059 | var new_input_value = 'This field is required.'; |
| 1060 | |
| 1061 | $new_field.find('input').attr( 'id', new_input_id ).attr( 'name', new_input_name ).val( new_input_value ); |
| 1062 | |
| 1063 | // Insert the edited field. |
| 1064 | $next_to.after( $new_field ); |
| 1065 | }, |
| 1066 | |
| 1067 | /** |
| 1068 | * Delete required-field-message field. |
| 1069 | */ |
| 1070 | requiredFieldMessageInputFieldDelete: function( field_id, key ) { |
| 1071 | var container_id = '#everest-forms-field-option-row-' + field_id + '-required-field-message-' + key; |
| 1072 | |
| 1073 | $( container_id ).remove(); |
| 1074 | }, |
| 1075 | |
| 1076 | /** |
| 1077 | * Add feedback. |
| 1078 | */ |
| 1079 | feedbackAdd: function( e, el ) { |
| 1080 | e.preventDefault(); |
| 1081 | var $this = $( el ); |
| 1082 | if ( $this.siblings('.evf-form-group').find('.score_to').last().val() >= 100 ){ |
| 1083 | $.alert({ |
| 1084 | title: false, |
| 1085 | content: "You can only add feedback for the score 100% or below.", |
| 1086 | icon: 'dashicons dashicons-info', |
| 1087 | type: 'blue', |
| 1088 | buttons: { |
| 1089 | ok: { |
| 1090 | text: evf_data.i18n_ok, |
| 1091 | btnClass: 'btn-confirm', |
| 1092 | keys: [ 'enter' ] |
| 1093 | } |
| 1094 | } |
| 1095 | }); |
| 1096 | } else if( $this.siblings('.evf-form-group').find('.score_to').last().val() === '') { |
| 1097 | $( document.body ).triggerHandler( 'evf_add_error_tip', [ $this.siblings('.evf-form-group').find('.score_to').last(), 'i18n_field_to_score_is_empty_error', params ] ); |
| 1098 | } else { |
| 1099 | var clone = $this.siblings('.evf-form-group').last().clone(); |
| 1100 | clone.find('input').val(''); |
| 1101 | clone.find('textarea').val(''); |
| 1102 | var container = $this.closest('.overall-feedback-option'); |
| 1103 | var next_id = container.attr('data-next-id'); |
| 1104 | clone.attr('data-key', next_id); |
| 1105 | clone.find('.score_from').attr('name', 'settings[score_feedback][' + next_id + '][from]'); |
| 1106 | clone.find('.score_from').attr('value', parseInt( $this.siblings('.evf-form-group').find('.score_to').last().val() ) + 1 ); |
| 1107 | clone.find('.score_to').attr('name', 'settings[score_feedback][' + next_id + '][to]'); |
| 1108 | clone.find('.feedback-options-message').attr('name', 'settings[score_feedback][' + next_id + '][feedback]'); |
| 1109 | $this.siblings('.evf-form-group').last().after(clone); |
| 1110 | next_id++; |
| 1111 | $this.closest('.overall-feedback-option').attr('data-next-id',next_id); |
| 1112 | } |
| 1113 | }, |
| 1114 | |
| 1115 | /** |
| 1116 | * Delete feedback. |
| 1117 | */ |
| 1118 | feedbackRemove: function(e, el) { |
| 1119 | e.preventDefault(); |
| 1120 | var $this = $(el), |
| 1121 | container = $this.closest('.overall-feedback-option'), |
| 1122 | total = container.find('.evf-form-group').length; |
| 1123 | |
| 1124 | if (total == '1') { |
| 1125 | $.alert({ |
| 1126 | title: false, |
| 1127 | content: evf_data.i18n_row_locked_msg, |
| 1128 | icon: 'dashicons dashicons-info', |
| 1129 | type: 'blue', |
| 1130 | buttons: { |
| 1131 | ok: { |
| 1132 | text: evf_data.i18n_ok, |
| 1133 | btnClass: 'btn-confirm', |
| 1134 | keys: [ 'enter' ] |
| 1135 | } |
| 1136 | } |
| 1137 | }); |
| 1138 | } else { |
| 1139 | if( $this.closest('.evf-form-group').next('.evf-form-group').length != 0 ) { |
| 1140 | $this.closest('.evf-form-group').next('.evf-form-group').find('.score_from').val($this.closest('.evf-form-group').find('.score_from').val()); |
| 1141 | } |
| 1142 | $this.closest('.evf-form-group').remove(); |
| 1143 | } |
| 1144 | }, |
| 1145 | |
| 1146 | /** |
| 1147 | * Update Field choice. |
| 1148 | * |
| 1149 | */ |
| 1150 | fieldChoiceUpdate: function( fieldID ) { |
| 1151 | $('.everest-forms-likert-dd-options').removeClass('everest-forms-show'); |
| 1152 | $('.everest-forms-likert-dd-options').addClass('everest-forms-hidden'); |
| 1153 | var selected_choice = $( '#everest-forms-field-option-row-' + fieldID + '-drop_down_choices' ).find('.evf-survey-choices .default:checked').next('.label').val(); |
| 1154 | var first_choice = $( '#everest-forms-field-option-row-' + fieldID + '-drop_down_choices' ).find('.evf-survey-choices').find('.label').first().val(); |
| 1155 | var data = { |
| 1156 | rows: {}, |
| 1157 | columns: {}, |
| 1158 | colCount: 0, |
| 1159 | inputType: $( '#everest-forms-field-option-' + fieldID + '-input_type' ).val(), |
| 1160 | selected_choice: 'undefined' != typeof selected_choice ? selected_choice : first_choice, |
| 1161 | }; |
| 1162 | |
| 1163 | if ( data.inputType === 'select') { |
| 1164 | $('.everest-forms-likert-dd-options').removeClass('everest-forms-hidden'); |
| 1165 | $('.everest-forms-likert-dd-options').addClass('everest-forms-show'); |
| 1166 | } |
| 1167 | |
| 1168 | // Get columns. |
| 1169 | $( '#everest-forms-field-option-row-'+fieldID + '-columns .evf-survey-choices li').each( function() { |
| 1170 | var $this = $( this ), |
| 1171 | key = $this.data( 'key' ), |
| 1172 | value = $this.find( 'input' ).val(); |
| 1173 | |
| 1174 | data.columns['c'+key] = { |
| 1175 | key: key, |
| 1176 | value: value |
| 1177 | }; |
| 1178 | |
| 1179 | data.colCount++; |
| 1180 | }); |
| 1181 | |
| 1182 | // Get rows. |
| 1183 | $( '#everest-forms-field-option-row-'+fieldID + '-rows .evf-survey-choices li').each( function() { |
| 1184 | var $this = $( this ), |
| 1185 | key = $this.data( 'key' ), |
| 1186 | value = $this.find( 'input' ).val(); |
| 1187 | |
| 1188 | data.rows['r'+key] = { |
| 1189 | key: key, |
| 1190 | value: value |
| 1191 | }; |
| 1192 | }); |
| 1193 | |
| 1194 | data.width = 80 / data.colCount; |
| 1195 | |
| 1196 | var likertPreview = wp.template( 'everest-forms-likert-field-preview' ); |
| 1197 | $( '#everest-forms-field-' + fieldID ).find( 'table' ).replaceWith( likertPreview( data ) ); |
| 1198 | }, |
| 1199 | |
| 1200 | /** |
| 1201 | * Check for Yes/No field variations |
| 1202 | * |
| 1203 | */ |
| 1204 | checkSelectedYesNoVariation: function( value ) { |
| 1205 | $( '.everest-forms-field-option-row-yes_icon_color' ).hide(); |
| 1206 | $( '.everest-forms-field-option-row-no_icon_color' ).hide(); |
| 1207 | $( '.everest-forms-field-option-row-yes_label' ).hide(); |
| 1208 | $( '.everest-forms-field-option-row-no_label' ).hide(); |
| 1209 | |
| 1210 | if ( 'with_icon_text' === value ) { |
| 1211 | $( '.everest-forms-field-option-row-yes_icon_color' ).show(); |
| 1212 | $( '.everest-forms-field-option-row-no_icon_color' ).show(); |
| 1213 | $( '.everest-forms-field-option-row-yes_label' ).show(); |
| 1214 | $( '.everest-forms-field-option-row-no_label' ).show(); |
| 1215 | } |
| 1216 | |
| 1217 | if ( 'with_icon' === value ) { |
| 1218 | $( '.everest-forms-field-option-row-yes_icon_color' ).show(); |
| 1219 | $( '.everest-forms-field-option-row-no_icon_color' ).show(); |
| 1220 | } |
| 1221 | |
| 1222 | if ( 'with_text' === value ) { |
| 1223 | $( '.everest-forms-field-option-row-yes_label' ).show(); |
| 1224 | $( '.everest-forms-field-option-row-no_label' ).show(); |
| 1225 | } |
| 1226 | } |
| 1227 | } |
| 1228 | EverestFormsSurvey.init(jQuery); |
| 1229 | })( jQuery, everest_forms_survey_polls_quiz_builder ); |
| 1230 |