/** * @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.$checkboxes.bind('click', $.proxy(this.onCheckboxClick, this)); }; fn.onCheckboxClick = function (ev) { var $el = $(ev.target); var data = { id: $el.data('id'), reviewed: $el.prop('checked') ? 1 : 0, }; this.$checkboxes.not('.disabled').prop('disabled', true); $.ajax(this.options.ajaxUrl, { data: data, dataType: 'json', success: function (data) { $el.prop('checked', data.documentReviewed); var $tr = $el.closest('tr'); $tr.removeClass(); $tr.addClass(data.documentStatus); }, error: function (jqXHR, textStatus) { alert(textStatus); }, complete: $.proxy(function () { this.$checkboxes.not('.disabled').prop('disabled', false); }, this), }); }; })(qs.defineNS('app.application.document'));