var app = window.app || {}; app.event = app.event || {}; app.event.attendee = app.event.attendee || {}; app.event.attendee.admin = app.event.attendee.admin || {}; app.event.attendee.admin.List = qs.createObject(); app.event.attendee.admin.List.prototype = { initialize: function (options) { this.options = $.extend({ listId: undefined, requestUrl: undefined, switchDialog: undefined }, options); this.listNode = $('#' + this.options.listId); this.initEvents(); return this; }, initEvents: function () { this.listNode.find('[data-role="paid-switch"]').on('click', _.bind(this.onPaidSwitchClick, this)); return this; }, onPaidSwitchClick: function (e) { e.preventDefault(); var target = $(e.target), attendeeId = target.data('attendeeId'), paid = target.data('paid'); if ('n' === paid) { this.showPaidSwitchDialog(_.bind(this.onDialogSave, this, attendeeId, true)); } else { this.sendSwitchRequest(attendeeId, false); } return null; }, showPaidSwitchDialog: function (completeCallback) { $.fancybox(this.options.switchDialog, { autoDimensions: false, 'width': 'auto', 'height': 100, showCloseButton: false, onComplete: function () { var dialog = $('[data-role="paid-switch-dialog"]'); dialog.find('[data-role="btn-save"]').on('click', completeCallback); dialog.find('[data-role="btn-cancel"]').on('click', function (e) { e.preventDefault(); $.fancybox.close(); }); } }); return this; }, onDialogSave: function (attendeeId, paid, e) { e.preventDefault(); var dialog = $('[data-role="paid-switch-dialog"]'), paymentMethod = dialog.find('[name="paymentMethod"]').val(); this.sendSwitchRequest(attendeeId, paid, paymentMethod); return this; }, sendSwitchRequest: function (attendeeId, paid, paymentMethod) { qs.ajax(this.options.requestUrl, { action: 'paidSwitch', id: +attendeeId, paid: paid ? 1 : 0, paymentMethod: paymentMethod }).done(_.bind(this.onSwitchComplete, this)); return this; }, /** * @param {Object} response * @param {Boolean} [response.isError] * @returns {*} */ onSwitchComplete: function (response) { if (!response.isError) { window.location.reload(); } return this; } };