/** * @required $ jQuery */ (function (ns) { /** * @alias app.application.document.List * @param {Object} options * @constructor */ ns.List = function (options) { this.construct.apply(this, arguments); }; var fn = ns.List.prototype; fn.construct = function (options) { this.options = $.extend({ ajaxUrl: undefined, }, options); if (!this.options.ajaxUrl) { alert('AJAX URL is empty'); return; } this.$checkboxes = $('.review-checkbox'); if (!this.$checkboxes.length) { return; } this.initActions(); }; fn.initActions = function () { var that = this; this.$checkboxes.bind('click', function (ev) { var $el = $(ev.target); var data = { id: $el.attr('data-id'), reviewed: $el.attr('checked') ? 1 : 0, action: 'changeReviewed' }; that.$checkboxes.not('.disabled').attr('disabled', 'disabled'); $.ajax({ url: that.options.ajaxUrl, data: data, dataType: 'json', type: 'POST', success: function (data) { $el.attr('checked', data.documentReviewed); var $tr = $el.closest('tr'); $tr.removeClass(); $tr.addClass(data.documentStatus); that.$checkboxes.not('.disabled').removeAttr('disabled'); }, error: function (jqXHR, textStatus) { alert(textStatus); that.$checkboxes.not('.disabled').removeAttr('disabled'); }, }); }); }; })(qs.defineNS('app.application.document'));