diff --git a/src/ggrc_reporting_dashboard/assets/javascripts/apps/requests_dashboard.js b/src/ggrc_reporting_dashboard/assets/javascripts/apps/requests_dashboard.js index c55664a..6da913c 100644 --- a/src/ggrc_reporting_dashboard/assets/javascripts/apps/requests_dashboard.js +++ b/src/ggrc_reporting_dashboard/assets/javascripts/apps/requests_dashboard.js @@ -38,51 +38,57 @@ // table data for program stats requests_data: {}, requests_loaded: false, - filters: {} - }, - init: function () { - var filter = ReportingDashboardExtension.utils.getFiltersFromUrl(window.location.href); - CMS.Models.ReportingAuditRequests.findAll(filter).then(function (data) { - this.scope.attr('requests_data', data[0]); - this.scope.attr('requests_loaded', true); - this.scope.attr('filters.refresh', function() { - var filter = { - audits_selected_id: this.scope.filters.audits_selected_id, - owners_selected_id: this.scope.filters.owners_selected_id, - verifiers_selected_id: this.scope.filters.verifiers_selected_id, - selected_status: this.scope.filters.selected_status, - due_on: this.scope.filters.due_on - }; - CMS.Models.ReportingAuditRequests.findAll(filter).then(function (data) { + filters: { + request_status: ["Open", "In Progress", + "Finished", "Verified", "Overdue"], + selected_status: '' + }, + required_filters: ['audits_selected_id', 'owners_selected_id', + 'verifiers_selected_id', 'selected_status', 'due_on'] + getRequests: function (filter) { + this.scope.attr('requests_loaded', false); + return CMS.Models.ReportingAuditRequests + .findAll(filter) + .then(function (data) { this.scope.attr('requests_data', data[0]); this.scope.attr('requests_loaded', true); }.bind(this)); - }.bind(this)); - var status_option_list = [{title: "(All)", value: ''}].concat( - ["Open", "In Progress", "Finished", "Verified", "Overdue"].map( - function (e) { return {title: e, value: e} })); - this.scope.attr('filters.statuses', status_option_list); - this.scope.attr('filters.selected_status', '') - }.bind(this)); + } + }, + init: function () { + var filter = ReportingDashboardExtension.utils.getFiltersFromUrl(window.location.href); + this.scope.getRequests(filter); // Bind Audits filter dropdown CMS.Models.Audit.findAll().then(function(data) { - var options_list = [{title: "(All)", value: ''}].concat( - can.map(data, function (e) {return {title: e.title, value: e.id}})); - this.scope.attr('filters.audits', options_list); + this.scope.attr('filters.audits', data); this.scope.attr('filters.audits_selected_id', ''); }.bind(this)); // Bind Assignees filter dropdown CMS.Models.Person.findAll().then(function(data) { - var options_list = [{title: "(All)", value: ''}].concat( - can.map(data, function (e) {return {title: e.name, value: e.id}})); - this.scope.attr('filters.owners', options_list); - this.scope.attr('filters.verifiers', options_list); + this.scope.attr('filters.owners', data); + this.scope.attr('filters.verifiers', data); this.scope.attr('filters.owners_selected_id', ''); this.scope.attr('filters.verifiers_selected_id', ''); this.scope.attr('filters.due_on', ''); }.bind(this)); + }, + events: { + '{scope} filters': function (scope) { + var filter; + if (_.every(filters, _.negate(_.isNull))) { + return; + } + filter = { + audits_selected_id: this.scope.filters.audits_selected_id, + owners_selected_id: this.scope.filters.owners_selected_id, + verifiers_selected_id: this.scope.filters.verifiers_selected_id, + selected_status: this.scope.filters.selected_status, + due_on: this.scope.filters.due_on + }; + this.scope.getRequests(filter); + } } }); @@ -91,17 +97,20 @@ template: can.view(GGRC.mustache_path + '/reporting_dashboard/requests_filter.mustache'), scope: { - filters: null, + filters: null }, events: { - '{scope.filters} change': function () { - if ((this.scope.filters.audits_selected_id != null) - && (this.scope.filters.owners_selected_id != null) - && (this.scope.filters.verifiers_selected_id != null) - && (this.scope.filters.selected_status != null) - && (this.scope.filters.due_on != null)) { - this.scope.filters.refresh(); - } + bla: function () { + }, + '{scope.filters} audits_selected_id': 'bla', + '{scope.filters} audits_selected_id': function () { + // if ((this.scope.filters.audits_selected_id != null) + // && (this.scope.filters.owners_selected_id != null) + // && (this.scope.filters.verifiers_selected_id != null) + // && (this.scope.filters.selected_status != null) + // && (this.scope.filters.due_on != null)) { + // this.scope.filters.refresh(); + // } } } })