Merge "fix table delete bug & collect table events"
This commit is contained in:
commit
92d4713e10
@ -23,13 +23,22 @@
|
||||
controller.$inject = [
|
||||
'$q',
|
||||
'$scope',
|
||||
'horizon.framework.widgets.table.events',
|
||||
'horizon.framework.widgets.magic-search.events',
|
||||
'horizon.framework.widgets.magic-search.service',
|
||||
'horizon.framework.util.actions.action-result.service',
|
||||
'horizon.framework.conf.resource-type-registry.service'
|
||||
];
|
||||
|
||||
function controller($q, $scope, events, searchService, actionResultService, registry) {
|
||||
function controller(
|
||||
$q,
|
||||
$scope,
|
||||
hzTableEvents,
|
||||
magicSearchEvents,
|
||||
searchService,
|
||||
actionResultService,
|
||||
registry
|
||||
) {
|
||||
var ctrl = this;
|
||||
var lastSearchQuery = {};
|
||||
|
||||
@ -43,7 +52,7 @@
|
||||
ctrl.itemInTransitionFunction = itemInTransitionFunction;
|
||||
|
||||
// Watch for changes to search bar
|
||||
$scope.$on(events.SERVER_SEARCH_UPDATED, handleServerSearch);
|
||||
$scope.$on(magicSearchEvents.SERVER_SEARCH_UPDATED, handleServerSearch);
|
||||
|
||||
// Watch for changes to resourceTypeName
|
||||
$scope.$watch(
|
||||
@ -155,7 +164,8 @@
|
||||
|
||||
// Handle deleted items
|
||||
if (deletedIds.length) {
|
||||
ctrl.itemsSrc = difference(ctrl.itemsSrc, deletedIds,'id');
|
||||
ctrl.itemsSrc = difference(ctrl.itemsSrc, deletedIds, 'id');
|
||||
$scope.$broadcast(hzTableEvents.CLEAR_SELECTIONS);
|
||||
}
|
||||
|
||||
// Handle updated and created items
|
||||
|
@ -19,6 +19,10 @@
|
||||
.module('horizon.framework.widgets.table')
|
||||
.directive('hzSelectAll', hzSelectAll);
|
||||
|
||||
hzSelectAll.$inject = [
|
||||
'horizon.framework.widgets.table.events'
|
||||
];
|
||||
|
||||
/**
|
||||
* @ngdoc directive
|
||||
* @name horizon.framework.widgets.table.directive:hzSelectAll
|
||||
@ -62,7 +66,7 @@
|
||||
* controller.
|
||||
*
|
||||
*/
|
||||
function hzSelectAll() {
|
||||
function hzSelectAll(events) {
|
||||
var directive = {
|
||||
restrict: 'A',
|
||||
require: [ '^hzTable', '^stTable' ],
|
||||
@ -96,7 +100,7 @@
|
||||
var unWatchRowsLength = scope.$watch('rows.length', updateSelectAll);
|
||||
|
||||
// watch for row selection
|
||||
var unWatchRowSelected = scope.$on('hzTable:rowSelected', updateSelectAll);
|
||||
var unWatchRowSelected = scope.$on(events.ROW_SELECTED, updateSelectAll);
|
||||
|
||||
// deregister $watch, $on on destroy
|
||||
scope.$on('$destroy', function () {
|
||||
|
@ -19,7 +19,10 @@
|
||||
.module('horizon.framework.widgets.table')
|
||||
.controller('TableController', TableController);
|
||||
|
||||
TableController.$inject = ['$scope'];
|
||||
TableController.$inject = [
|
||||
'$scope',
|
||||
'horizon.framework.widgets.table.events'
|
||||
];
|
||||
|
||||
/**
|
||||
* @ngdoc controller
|
||||
@ -32,10 +35,10 @@
|
||||
*
|
||||
* Note that clearSelected is private and event driven.
|
||||
* To clear all of the selected checkboxes after an action, such as
|
||||
* delete, emit the event `hzTable:clearSelected` from your table
|
||||
* delete, broadcast the event `hzTable:clearSelected` from your table
|
||||
* controller.
|
||||
*/
|
||||
function TableController($scope) {
|
||||
function TableController($scope, events) {
|
||||
|
||||
var ctrl = this;
|
||||
ctrl.trackId = 'id';
|
||||
@ -47,7 +50,7 @@
|
||||
|
||||
////////////////////
|
||||
|
||||
var clearWatcher = $scope.$on('hzTable:clearSelected', clearSelected);
|
||||
var clearWatcher = $scope.$on(events.CLEAR_SELECTIONS, clearSelected);
|
||||
$scope.$on('$destroy', function() {
|
||||
clearWatcher();
|
||||
});
|
||||
@ -86,7 +89,7 @@
|
||||
* matching event bindings
|
||||
*/
|
||||
var rowObj = { row: row, checkedState: checkedState };
|
||||
$scope.$broadcast('hzTable:rowSelected', rowObj);
|
||||
$scope.$broadcast(events.ROW_SELECTED, rowObj);
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,7 +97,7 @@
|
||||
* Broadcast row expansion
|
||||
*/
|
||||
function broadcastExpansion(item) {
|
||||
$scope.$broadcast('hzTable:rowExpanded', item);
|
||||
$scope.$broadcast(events.ROW_EXPANDED, item);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
@ -48,5 +48,10 @@
|
||||
*/
|
||||
.constant('horizon.framework.widgets.table.filterPlaceholderText',
|
||||
gettext('Filter')
|
||||
);
|
||||
)
|
||||
.constant('horizon.framework.widgets.table.events', {
|
||||
CLEAR_SELECTIONS: 'hzTable:clearSelections',
|
||||
ROW_SELECTED: 'hzTable:rowSelected',
|
||||
ROW_EXPANDED: 'hzTable:rowExpanded'
|
||||
});
|
||||
})();
|
||||
|
Loading…
x
Reference in New Issue
Block a user