/** * @requires $ jQuery * @requires _ UnderscoreJS */ (function (/* Object */ ns) { 'use strict'; /** * @alias app.event.attendee.admin.List * @param {Object} options * @constructor */ ns.List = function (options) { this.construct.apply(this, arguments); }; ns.List.prototype.construct = function (options) { this.eventId = options.eventId; this.statusElements = $(options.statusElementsSelector); this.statusElements.change(_.bind(this.statusOnChange, this)); }; ns.List.prototype.statusOnChange = function (e) { var request = { id: $(e.target).data('id'), action: 'setStatus', status: e.target.value }; qs.ajax(qs.constant('BASE_URL') + '/' + qs.constant('CURRENT_PAGE'), request) .done(_.bind(this.statusOnChangeDone, this, e.target)); }; ns.List.prototype.statusOnChangeDone = function (element, response) { if (response.isError) { element.value = response.status; } var tr = qs.dom.getParentTag(element, 'TR'); this.renderLinksItem(response.linksItem); this.renderColumns(tr, response.columns || {}); }; ns.List.prototype.renderColumns = function (tr, columns) { for (var name in columns) { if (!columns.hasOwnProperty(name)) { continue; } var column = columns[name]; $('.' + column.tdCls, tr).replaceWith(column.html); } }; ns.List.prototype.renderLinksItem = function (item) { $('#' + item.id).replaceWith(item.html); }; })(qs.defineNS('app.event.attendee.admin'));