Skip to content

Commit

Permalink
add batchDelete view
Browse files Browse the repository at this point in the history
  • Loading branch information
ThieryMichel committed Mar 30, 2015
1 parent 59714bc commit deb8f57
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/javascripts/ng-admin/Crud/CrudModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ define(function (require) {
CrudModule.controller('ShowController', require('ng-admin/Crud/show/ShowController'));
CrudModule.controller('FormController', require('ng-admin/Crud/form/FormController'));
CrudModule.controller('DeleteController', require('ng-admin/Crud/delete/DeleteController'));
CrudModule.controller('BatchDeleteController', require('ng-admin/Crud/batchDelete/BatchDeleteController'));

CrudModule.service('RetrieveQueries', require('ng-admin/Crud/repository/RetrieveQueries'));
CrudModule.service('CreateQueries', require('ng-admin/Crud/repository/CreateQueries'));
Expand Down Expand Up @@ -74,6 +75,7 @@ define(function (require) {
CrudModule.directive('maShowButton', require('ng-admin/Crud/button/maShowButton'));
CrudModule.directive('maListButton', require('ng-admin/Crud/button/maListButton'));
CrudModule.directive('maDeleteButton', require('ng-admin/Crud/button/maDeleteButton'));
CrudModule.directive('maBatchDeleteButton', require('ng-admin/Crud/button/maBatchDeleteButton'));

CrudModule.directive('maViewActions', require('ng-admin/Crud/misc/ViewActions'));
CrudModule.directive('maViewBatchActions', require('ng-admin/Crud/misc/ViewBatchActions'));
Expand Down
33 changes: 33 additions & 0 deletions src/javascripts/ng-admin/Crud/batchDelete/BatchDeleteController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*global define*/

define(function () {
'use strict';

var BatchDeleteController = function ($scope, $stateParams, $filter, $anchorScroll, progression, view) {
this.$scope = $scope;
this.$stateParams = $stateParams;
this.$filter = $filter;
this.progression = progression;
this.view = view;
this.entity = view.getEntity();
this.selection = $stateParams.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.destroy = function () {
this.$scope = undefined;
this.$stateParams = undefined;
this.$filter = undefined;
this.$anchorScroll = undefined;
};

BatchDeleteController.$inject = ['$scope', '$stateParams', '$filter', '$anchorScroll', 'progression', 'view'];

return BatchDeleteController;
});
32 changes: 32 additions & 0 deletions src/javascripts/ng-admin/Crud/batchDelete/batchDelete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<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>

<ma-view-batch-actions ng-if="batchDeleteController.selection" buttons="batchDeleteController.batchActions" selection="batchDeleteController.selection"></ma-view-batch-actions>
<div class="page-header">
<h1 compile="batchDeleteController.title">
Delete {{ 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.delete()">Yes</button>
<button class="btn btn-default" ng-click="batchDeleteController.back()">No</button>
</div>
</div>

<div 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>
30 changes: 30 additions & 0 deletions src/javascripts/ng-admin/Crud/button/maBatchDeleteButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*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();
$state.go('batchDelete', {selection: $scope.selection(), entity: entity.name()});
};
},
template:
'<a ng-click="gotoBatchDelete()">' +
'<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>&nbsp;Delete' +
'</a>'

};
}

maBatchDeleteButtonDirective.$inject = ['$state'];

return maBatchDeleteButtonDirective;
});
2 changes: 1 addition & 1 deletion src/javascripts/ng-admin/Crud/list/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ma-create-button ng-if="!entity.isReadOnly" entity="entity"></ma-create-button>
</ma-view-actions>

<ma-view-batch-actions ng-if="listController.selection" buttons="listController.batchActions" selection="listController.selection"></ma-view-batch-actions>
<ma-view-batch-actions ng-if="listController.selection" buttons="listController.batchActions" selection="listController.selection" entity="listController.entity"></ma-view-batch-actions>
<div class="page-header">
<h1 compile="listController.title">
{{ listController.view.entity.name() | humanize | pluralize }} list
Expand Down
2 changes: 1 addition & 1 deletion src/javascripts/ng-admin/Crud/misc/view-batch-actions.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ul class="dropdown-menu" role="menu">
<li ng-repeat="button in buttons" ng-switch="button">
<span ng-switch-when="delete">
<a>Delete<a/>
<ma-batch-delete-button selection="selection" entity="entity"/>
</span>
<span ng-switch-default>
<span compile="button"></span>
Expand Down
22 changes: 21 additions & 1 deletion src/javascripts/ng-admin/Crud/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ define(function (require) {
showTemplate = require('text!./show/show.html'),
createTemplate = require('text!./form/create.html'),
editTemplate = require('text!./form/edit.html'),
deleteTemplate = require('text!./delete/delete.html');
deleteTemplate = require('text!./delete/delete.html'),
batchDeleteTemplate = require('text!./batchDelete/batchDelete.html');

function templateProvider(viewName, defaultView) {
return ['$stateParams', 'NgAdminConfiguration', function ($stateParams, Configuration) {
Expand Down Expand Up @@ -169,6 +170,25 @@ define(function (require) {
}]
}
});

$stateProvider
.state('batchDelete', {
parent: 'main',
url: '/batch-delete/:entity/:ids',
controller: 'BatchDeleteController',
controllerAs: 'batchDeleteController',
templateProvider: templateProvider('BatchDeleteView', batchDeleteTemplate),
params: {
entity: {},
selection: [],
},
resolve: {
view: viewProvider('BatchDeleteView'),
params: ['$stateParams', function ($stateParams) {
return $stateParams;
}]
}
});
}

routing.$inject = ['$stateProvider'];
Expand Down
10 changes: 10 additions & 0 deletions src/javascripts/ng-admin/es6/lib/Entity/Entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import CreateView from '../View/CreateView';
import EditView from '../View/EditView';
import DeleteView from '../View/DeleteView';
import ShowView from '../View/ShowView';
import BatchDeleteView from '../View/BatchDeleteView';

class Entity {
constructor(name) {
Expand Down Expand Up @@ -90,6 +91,13 @@ class Entity {
return this._views["DeleteView"];
}

/**
* @deprecated Use .views["BatchDeleteView"] instead
*/
batchDeleteView() {
return this._views["BatchDeleteView"];
}

/**
* @deprecated Use .views["ShowView"] instead
*/
Expand All @@ -111,6 +119,7 @@ class Entity {
"CreateView": new CreateView().setEntity(this),
"EditView": new EditView().setEntity(this),
"DeleteView": new DeleteView().setEntity(this),
"BatchDeleteView": new BatchDeleteView().setEntity(this),
"ShowView": new ShowView().setEntity(this)
};
}
Expand All @@ -127,6 +136,7 @@ class Entity {
this._views["CreateView"].disable();
this._views["EditView"].disable();
this._views["DeleteView"].disable();
this._views["BatchDeleteView"].disable();

return this;
}
Expand Down
11 changes: 11 additions & 0 deletions src/javascripts/ng-admin/es6/lib/View/BatchDeleteView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import View from './View';

class BatchDeleteView extends View {
constructor(name) {
super(name);

this._type = 'BatchDeleteView';
}
}

export default BatchDeleteView;

0 comments on commit deb8f57

Please sign in to comment.