--- /dev/null
+<i ng-if=":: $ctrl.settings.draggable" class="crm-i fa-sort-amount-asc" title="{{:: ts('Drag columns to reposition') }}"></i>
+<div class="btn-group" ng-if=":: $ctrl.settings.actions">
+ <button type="button" class="btn btn-secondary-outline" ng-click="$ctrl.toggleAllRows()" ng-disabled="$ctrl.loading || !$ctrl.results.length" title="{{ $ctrl.selectedRows.length ? ts('Select none') : ts('Select all') }}">
+ <i class="crm-i" ng-class="{'fa-square-o': !$ctrl.selectedRows.length, 'fa-minus-square-o': !$ctrl.allRowsSelected && $ctrl.selectedRows.length, 'fa-check-square-o': $ctrl.allRowsSelected}"></i>
+ </button>
+ <button type="button" class="btn btn-secondary-outline dropdown-toggle" ng-click="$ctrl.selectAllMenuOpen = true;" ng-disabled="$ctrl.loading || !$ctrl.results.length" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+ <span class="caret"></span>
+ </button>
+ <ul class="dropdown-menu" ng-if="$ctrl.selectAllMenuOpen">
+ <li>
+ <a href ng-click="$ctrl.selectNone()">
+ {{:: ts('None') }}
+ </a>
+ </li>
+ <li>
+ <a href ng-click="$ctrl.selectPage()">
+ {{ $ctrl.rowCount > $ctrl.results.length ? ts('This Page') : ts('All') }}
+ </a>
+ </li>
+ <li ng-if="$ctrl.rowCount > $ctrl.results.length">
+ <a href ng-click="$ctrl.selectAllPages()">
+ {{:: ts('All Pages') }}
+ </a>
+ </li>
+ </ul>
+</div>
// Trait properties get mixed into display controller using angular.extend()
return {
- selectedRows: [],
- allRowsSelected: false,
+ // Use ajax to select all rows on every page
+ selectAllPages: function() {
+ var ctrl = this;
+ ctrl.loadingAllRows = ctrl.allRowsSelected = true;
+ var params = ctrl.getApiParams('id');
+ crmApi4('SearchDisplay', 'run', params).then(function(ids) {
+ ctrl.loadingAllRows = false;
+ ctrl.selectedRows = _.uniq(_.toArray(ids));
+ });
+ },
+
+ // Select all rows on the current page
+ selectPage: function() {
+ this.allRowsSelected = true;
+ this.selectedRows = _.uniq(_.pluck(this.results, 'key'));
+ },
+
+ // Clear selection
+ selectNone: function() {
+ this.allRowsSelected = false;
+ this.selectedRows = [];
+ },
// Toggle the "select all" checkbox
- selectAllRows: function() {
- var ctrl = this;
+ toggleAllRows: function() {
// Deselect all
- if (ctrl.allRowsSelected) {
- ctrl.allRowsSelected = false;
- ctrl.selectedRows.length = 0;
- return;
+ if (this.selectedRows && this.selectedRows.length) {
+ this.selectNone();
}
// Select all
- ctrl.allRowsSelected = true;
- if (ctrl.page === 1 && ctrl.results.length < ctrl.limit) {
- ctrl.selectedRows = _.pluck(ctrl.results, 'key');
- return;
+ else if (this.page === 1 && this.rowCount === this.results.length) {
+ this.selectPage();
}
// If more than one page of results, use ajax to fetch all ids
- ctrl.loadingAllRows = true;
- var params = ctrl.getApiParams('id');
- crmApi4('SearchDisplay', 'run', params).then(function(ids) {
- ctrl.loadingAllRows = false;
- ctrl.selectedRows = _.toArray(ids);
- });
+ else {
+ this.selectAllPages();
+ }
},
// Toggle row selection
- selectRow: function(row, event) {
+ toggleRow: function(row, event) {
+ this.selectedRows = this.selectedRows || [];
var ctrl = this,
index = ctrl.selectedRows.indexOf(row.key);
selectRange(allRows, nearestBefore + 1, checkboxPosition -1);
}
}
- ctrl.selectedRows.push(row.key);
+ ctrl.selectedRows = _.uniq(ctrl.selectedRows.concat([row.key]));
ctrl.allRowsSelected = (ctrl.rowCount === ctrl.selectedRows.length);
} else {
ctrl.allRowsSelected = false;
return this.allRowsSelected || _.includes(this.selectedRows, row.key);
},
+ isPageSelected: function() {
+ return (this.allRowsSelected && this.rowCount === this.results.length) ||
+ (!this.allRowsSelected && this.selectedRows && this.selectedRows.length === this.results.length);
+ },
+
refreshAfterTask: function() {
- this.selectedRows.length = 0;
+ this.selectedRows = [];
this.allRowsSelected = false;
this.rowCount = undefined;
this.runSearch();
// Add onChangeFilters callback (gets merged with others via angular.extend)
onChangeFilters: [function() {
// Reset selection when filters are changed
- this.selectedRows.length = 0;
+ this.selectedRows = [];
this.allRowsSelected = false;
}],
// Add onPostRun callback (gets merged with others via angular.extend)
onPostRun: [function(results, status, editedRow) {
- if (editedRow && status === 'success') {
+ if (editedRow && status === 'success' && this.selectedRows) {
// If edited row disappears (because edits cause it to not meet search criteria), deselect it
var index = this.selectedRows.indexOf(editedRow.key);
if (index > -1 && !_.findWhere(results, {key: editedRow.key})) {