| 1 |
(function($) { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
function AysSurveyMakerCondTerms(element, options){ |
| 5 |
this.el = element; |
| 6 |
this.$el = $(element); |
| 7 |
this.htmlClassPrefix = 'ays_survey_'; |
| 8 |
this.dbOptions = undefined; |
| 9 |
this.htmlPrefix = 'ays_'; |
| 10 |
this.addSection = this.htmlPrefix+'terms_and_condition_add'; |
| 11 |
this.init(); |
| 12 |
|
| 13 |
return this; |
| 14 |
} |
| 15 |
|
| 16 |
AysSurveyMakerCondTerms.prototype.init = function() { |
| 17 |
var _this = this; |
| 18 |
_this.setEvents(); |
| 19 |
}; |
| 20 |
|
| 21 |
AysSurveyMakerCondTerms.prototype.setEvents = function(e){ |
| 22 |
var _this = this; |
| 23 |
|
| 24 |
_this.$el.on("click" , "."+_this.htmlClassPrefix+"add_new_textarea", function(){ |
| 25 |
_this.addTermsConds(); |
| 26 |
}); |
| 27 |
|
| 28 |
_this.$el.on("click" , "."+_this.htmlClassPrefix+"remove_textarea", function(){ |
| 29 |
_this.deleteTermsConds($(this)); |
| 30 |
}); |
| 31 |
} |
| 32 |
|
| 33 |
AysSurveyMakerCondTerms.prototype.addTermsConds = function (element){ |
| 34 |
var deleteImageUrl = SurveyMakerAdmin.icons.deleteTermsAndConds; |
| 35 |
var content = ''; |
| 36 |
|
| 37 |
var addedTermsandConds = this.$el.find("."+this.htmlClassPrefix+"terms_conditions_edit_block"); |
| 38 |
var addedTermsandCondsId = this.$el.find("."+this.htmlClassPrefix+"terms_conditions_edit_block:last-child"); |
| 39 |
var dataId = addedTermsandConds.length >= 1 ? addedTermsandCondsId.data("conditionId") + 1 : 1; |
| 40 |
|
| 41 |
var termsCondsMessageAttrName = this.newTermsCondsMessageAttrName( this.addSection , dataId , "messages" ); |
| 42 |
|
| 43 |
content += '<div class = "ays_survey_terms_conditions_edit_block" data-condition-id="' + dataId + '">'; |
| 44 |
content += '<div class="ays_survey_terms_and_conditions_checkbox">'; |
| 45 |
content += '<div class="ays-survey-icons">' |
| 46 |
content += '<img src="'+SurveyMakerAdmin.icons.checkboxUnchecked+'">' |
| 47 |
content += '</div>' |
| 48 |
content += '</div>'; |
| 49 |
content += '<div class="ays_survey_terms_and_conditions_textarea_div">'; |
| 50 |
content += '<textarea name="' + termsCondsMessageAttrName + '"></textarea>'; |
| 51 |
content += '</div>'; |
| 52 |
content += '<div class="ays_survey_icons appsMaterialWizButtonPapericonbuttonEl">'; |
| 53 |
content += '<img class="ays_survey_remove_textarea" src="' + deleteImageUrl + '">'; |
| 54 |
content += '</div>'; |
| 55 |
content += '</div>'; |
| 56 |
|
| 57 |
$(document).find('.ays_survey_terms_and_conditions_content').append(content); |
| 58 |
} |
| 59 |
|
| 60 |
AysSurveyMakerCondTerms.prototype.deleteTermsConds = function (element){ |
| 61 |
var $this = element; |
| 62 |
var $thisMainParent = $this.parent().parent(); |
| 63 |
$thisMainParent.remove(); |
| 64 |
} |
| 65 |
|
| 66 |
AysSurveyMakerCondTerms.prototype.newTermsCondsMessageAttrName = function (termCondName, termCondId, messageText){ |
| 67 |
var _this = this; |
| 68 |
return termCondName + '['+ termCondId +']['+ messageText +']'; |
| 69 |
|
| 70 |
} |
| 71 |
|
| 72 |
$.fn.AysSurveyTermsAndConditions = function(options) { |
| 73 |
return this.each(function() { |
| 74 |
if (!$.data(this, 'AysSurveyTermsAndConditions')) { |
| 75 |
$.data(this, 'AysSurveyTermsAndConditions', new AysSurveyMakerCondTerms(this, options)); |
| 76 |
} else { |
| 77 |
try { |
| 78 |
$(this).data('AysSurveyTermsAndConditions').init(); |
| 79 |
} catch (err) { |
| 80 |
console.error('AysSurveyTermsAndConditions has not initiated properly'); |
| 81 |
} |
| 82 |
} |
| 83 |
}); |
| 84 |
}; |
| 85 |
|
| 86 |
$(document).find('.ays_survey_terms_and_conditions_all_inputs_block').AysSurveyTermsAndConditions(); |
| 87 |
})(jQuery); |
| 88 |
|