/** * @requires $ jQuery * @requires _ UnderscoreJS * @requires qs */ (function (/* Object */ ns) { 'use strict'; /** * @alias app.event.attendee.admin.Form * @param {Object} options * @constructor */ var Form = function (options) { this.construct.apply(this, arguments); }; Form.prototype.construct = function (options) { this.options = $.extend({ nodeIds: { paymentEnabled: undefined, paymentType: undefined, amount: undefined } }, options); this.node = {}; if (this.options.nodeIds.paymentEnabled && this.options.nodeIds.paymentType) { this.initPaymentType(); } }; Form.prototype.initPaymentType = function () { this.node.$paymentEnabled = $('#' + this.options.nodeIds.paymentEnabled); this.node.$paymentType = $('#' + this.options.nodeIds.paymentType); this.node.$amount = $('#' + this.options.nodeIds.amount); this.node.$paymentEnabled.on('change', _.bind(this.onPaymentEnabledChange, this)); this.node.$paymentType.on('change', _.bind(this.onPaymentTypeChange, this)); this.onPaymentEnabledChange(); this.onPaymentTypeChange(); }; Form.prototype.onPaymentEnabledChange = function () { var fieldset = this.node.$paymentEnabled.closest('fieldset').find('dl:first'); if (this.node.$paymentEnabled.is(':checked')) { fieldset.show(); } else { fieldset.hide(); } return this; }; Form.prototype.onPaymentTypeChange = function () { if ('comp' === this.node.$paymentType.val()) { this.node.$amount.val('0'); this.node.$amount.prop('readOnly', true); } else { if (this.node.$amount.prop('readOnly')) { this.node.$amount.prop('readOnly', false); this.node.$amount.val(''); } } }; ns.Form = Form; })(qs.defineNS('app.event.attendee.admin'));