-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #374 from marmelab/multi_select_list
[RFR] Add optional selection column to list
- Loading branch information
Showing
27 changed files
with
661 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/javascripts/ng-admin/Crud/button/maBatchDeleteButton.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/*global define*/ | ||
|
||
define(function () { | ||
'use strict'; | ||
|
||
function maBatchDeleteButtonDirective($state) { | ||
return { | ||
restrict: 'E', | ||
scope: { | ||
'entity': '&', | ||
'selection': '&', | ||
}, | ||
link: function ($scope) { | ||
$scope.gotoBatchDelete = function () { | ||
var entity = $scope.entity(); | ||
var ids = $scope.selection().map(function(entry) { | ||
return entry.identifierValue | ||
}); | ||
$state.go('batchDelete', { ids: ids, entity: entity.name() }); | ||
}; | ||
}, | ||
template: | ||
'<span ng-click="gotoBatchDelete()">' + | ||
'<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete' + | ||
'</span>' | ||
|
||
}; | ||
} | ||
|
||
maBatchDeleteButtonDirective.$inject = ['$state']; | ||
|
||
return maBatchDeleteButtonDirective; | ||
}); |
63 changes: 63 additions & 0 deletions
63
src/javascripts/ng-admin/Crud/delete/BatchDeleteController.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/*global define*/ | ||
|
||
define(function () { | ||
'use strict'; | ||
|
||
var BatchDeleteController = function ($scope, $state, $stateParams, $filter, $location, $window, DeleteQueries, notification, view) { | ||
this.$scope = $scope; | ||
this.$state = $state; | ||
this.$stateParams = $stateParams; | ||
this.$filter = $filter; | ||
this.$location = $location; | ||
this.$window = $window; | ||
this.DeleteQueries = DeleteQueries; | ||
this.notification = notification; | ||
this.view = view; | ||
this.entity = view.getEntity(); | ||
this.entityIds = $stateParams.ids; | ||
this.selection = []; // fixme: query db to get selection | ||
this.title = view.title(); | ||
this.description = view.description(); | ||
this.actions = view.actions(); | ||
this.loadingPage = false; | ||
this.fields = this.$filter('orderElement')(view.fields()); | ||
|
||
$scope.$on('$destroy', this.destroy.bind(this)); | ||
}; | ||
|
||
BatchDeleteController.prototype.batchDelete = function () { | ||
var notification = this.notification, | ||
$state = this.$state, | ||
entityName = this.entity.name(); | ||
|
||
this.DeleteQueries.batchDelete(this.view, this.entityIds).then(function () { | ||
$state.go($state.get('list'), { 'entity': entityName }); | ||
}, function (response) { | ||
// @TODO: share this method when splitting controllers | ||
var body = response.data; | ||
if (typeof body === 'object') { | ||
body = JSON.stringify(body); | ||
} | ||
|
||
notification.log('Oops, an error occured : (code: ' + response.status + ') ' + body, {addnCls: 'humane-flatty-error'}); | ||
}); | ||
}; | ||
|
||
BatchDeleteController.prototype.back = function () { | ||
this.$window.history.back(); | ||
}; | ||
|
||
BatchDeleteController.prototype.destroy = function () { | ||
this.$scope = undefined; | ||
this.$state = undefined; | ||
this.$stateParams = undefined; | ||
this.$filter = undefined; | ||
this.$location = undefined; | ||
this.$window = undefined; | ||
this.DeleteQueries = undefined; | ||
}; | ||
|
||
BatchDeleteController.$inject = ['$scope', '$state', '$stateParams', '$filter', '$location', '$window', 'DeleteQueries', 'notification', 'view']; | ||
|
||
return BatchDeleteController; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<div class="row list-header"> | ||
<div class="col-lg-12"> | ||
<ma-view-actions override="batchDeleteController.actions" selection="batchDeleteController.selection" entity="batchDeleteController.entity"> | ||
<ma-list-button entity="entity"></ma-list-button> | ||
</ma-view-actions> | ||
|
||
<div class="page-header"> | ||
<h1 compile="batchDeleteController.title"> | ||
Delete {{ batchDeleteController.entityIds.length }} {{ batchDeleteController.view.entity.name() | humanize | pluralize }} | ||
</h1> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col-lg-12"> | ||
<p>Are you sure ?</p> | ||
<button class="btn btn-danger" ng-click="batchDeleteController.batchDelete()">Yes</button> | ||
<button class="btn btn-default" ng-click="batchDeleteController.back()">No</button> | ||
</div> | ||
</div> | ||
|
||
<div ng-if="selection" class="row list-view" ng-class="'ng-admin-entity-' + batchDeleteController.entity.name()"> | ||
<div class="col-lg-12"> | ||
<ma-datagrid name="{{ batchDeleteController.view.name() }}" | ||
entries="batchDeleteController.selection" | ||
fields="::batchDeleteController.fields" | ||
entity="::batchDeleteController.entity"> | ||
</ma-datagrid> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/javascripts/ng-admin/Crud/list/maDatagridItemSelector.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/*global define*/ | ||
|
||
define(function () { | ||
'use strict'; | ||
|
||
function DatagridItemSelectorDirective() { | ||
return { | ||
restrict: 'E', | ||
scope: { | ||
entry: '=', | ||
selection: '=', | ||
toggleSelect: '&' | ||
}, | ||
template: '<input type="checkbox" ng-click="toggle(entry)" ng-checked="selection.indexOf(entry) !== -1"/>', | ||
link: function (scope) { | ||
scope.toggle = function (entry) { | ||
scope.toggleSelect({entry: entry}); | ||
}; | ||
} | ||
}; | ||
} | ||
|
||
DatagridItemSelectorDirective.$inject = []; | ||
|
||
return DatagridItemSelectorDirective; | ||
}); |
29 changes: 29 additions & 0 deletions
29
src/javascripts/ng-admin/Crud/list/maDatagridMultiSelector.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/*global define*/ | ||
|
||
define(function () { | ||
'use strict'; | ||
|
||
function DatagridMultiSelectorDirective() { | ||
return { | ||
restrict: 'E', | ||
scope: { | ||
entries: '=', | ||
selection: '=', | ||
toggleSelectAll: '&' | ||
}, | ||
template: '<input type="checkbox" ng-click="toggleSelectAll()" ng-checked="selection.length == entries.length" />', | ||
link: function (scope, element) { | ||
scope.$watch('selection', function (selection) { | ||
element.children()[0].indeterminate = selection.length > 0 && selection.length != scope.entries.length; | ||
}); | ||
scope.$watch('entries', function (entries) { | ||
element.children()[0].indeterminate = scope.selection.length > 0 && scope.selection.length != entries.length; | ||
}); | ||
} | ||
}; | ||
} | ||
|
||
DatagridMultiSelectorDirective.$inject = []; | ||
|
||
return DatagridMultiSelectorDirective; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/*global define*/ | ||
|
||
define(function (require) { | ||
'use strict'; | ||
|
||
var viewActionsTemplate = require('text!./view-batch-actions.html'); | ||
|
||
function ViewBatchActionsDirective($injector) { | ||
var $compile = $injector.get('$compile'); | ||
|
||
return { | ||
restrict: 'E', | ||
transclude: true, | ||
scope: { | ||
'entity': '=', | ||
'selection': '=', | ||
'buttons': '&' | ||
}, | ||
template: viewActionsTemplate, | ||
link: function(scope) { | ||
|
||
scope.isopen = false; | ||
|
||
scope.toggleDropdown = function($event) { | ||
$event.preventDefault(); | ||
$event.stopPropagation(); | ||
scope.isopen = !scope.isopen; | ||
}; | ||
|
||
scope.buttons = scope.buttons(); | ||
if (typeof scope.buttons === 'string') { | ||
scope.customTemplate = scope.buttons; | ||
scope.buttons = null; | ||
} | ||
|
||
} | ||
}; | ||
} | ||
|
||
ViewBatchActionsDirective.$inject = ['$injector']; | ||
|
||
return ViewBatchActionsDirective; | ||
}); |
Oops, something went wrong.