var App_SchoolFile = qs.create(); App_SchoolFile.prototype = { idForm: null, form: null, type: 'school', init: function (options) { new App_SchoolFile(options); }, initialize: function (options) { this.setOptions(options); if (this.form) { this.initFrom(); } this.hideElementsByType(); return true; }, initFrom: function () { this.initOtherSchool(); this.initSummativeAssessmentNumber(); return true; }, setOptions: function (options) { if (typeof options == 'object') { for (var field in options) { var value = options[field]; if (typeof value == 'string' && !value.length) { continue; } switch (field) { case 'idForm': this.setIdForm(value); break; default: this[field] = value; } } } return true; }, setIdForm: function (id) { this.form = $('#' + id); if ($(this.form).size()) { this.idForm = id; return true } this.form = null; alert('App_SchoolFile: Can not find form element'); return false; }, initOtherSchool: function () { var checkbox = $('#otherSchool'); if ($(checkbox).size()) { var obj = this; $(checkbox).click(function () { obj.processOtherSchool(this); }); this.processOtherSchool(checkbox); } return true; }, processOtherSchool: function (checkbox) { var element = $('#otherSchoolName-element'); var label = $('#otherSchoolName-label'); if ($(element).size() && $(label).size()) { if ($(checkbox).prop('checked')) { $(label).show(); $(element).show(); $('#idSchool').prop('disabled', true); } else { $(label).hide(); $(element).hide(); $('#idSchool').prop('disabled', false); } } return true; }, initSummativeAssessmentNumber: function () { var select = $('#idLessonType'); if ($(select).size()) { var obj = this; $(select).change(function () { obj.processSummativeAssessmentNumber(this); }).keyup(function () { obj.processSummativeAssessmentNumber(this); }); this.processSummativeAssessmentNumber(select); } return true; }, processSummativeAssessmentNumber: function (select) { var element = $('#summativeAssessmentNumber-element'); var label = $('#summativeAssessmentNumber-label'); if ($(element).size() && $(label).size()) { if ($(select).val() == 2) { $(label).show(); $(element).show(); } else { $(label).hide(); $(element).hide(); } } return true; }, doHideElementsByType: function () { var $radios = $('input[name=type]:checked'); var ddStrand= 'dd:has(.strand)'; var ddSchool= 'dd:has(.school)'; var trStrand= 'tr:has(.strand)'; var trSchool= 'tr:has(.school)'; var hideClass = 'hideStrand'; var textId = 'p span strong'; if($radios.val() == this.type) { $(ddStrand).prev().addClass(hideClass); $(ddStrand + ', ' + trStrand).addClass(hideClass); $(ddSchool).prev().removeClass(hideClass); $(ddSchool + ', ' + trSchool).removeClass(hideClass); $(textId).html(this.scoolMessage); } else { $(ddStrand).prev().removeClass(hideClass); $(ddStrand + ', ' + trStrand).removeClass(hideClass); $(ddSchool).prev().addClass(hideClass); $(ddSchool + ', ' + trSchool).addClass(hideClass); $(textId).html(this.strandMessage); } return true; }, hideElementsByType: function () { var that = this; $('input[name=type]').change(function(){ that.doHideElementsByType(); }); this.doHideElementsByType(); return true; } }; $(function () { App_SchoolFile.prototype.hideElementsByType(); });