Skip to content

Commit 684f95e

Browse files
authored
✨ Delete Multiple Elections (#440)
Parent issue: sequentech/meta#229
1 parent 8556fdd commit 684f95e

File tree

7 files changed

+145
-20
lines changed

7 files changed

+145
-20
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<div class="modal-header dialog-header-warning">
2+
<h4 class="modal-title">
3+
<span class="glyphicon glyphicon-info-sign">
4+
</span>
5+
<span class="title" ng-i18next>avAdmin.elections.deleteElections.title</span>
6+
<button type="button" class="close pull-right" ng-click="cancel()">×</button>
7+
</h4>
8+
</div>
9+
10+
<div class="modal-body">
11+
<p>
12+
<span ng-i18next>
13+
[i18next]({electionids: electionIds})avAdmin.elections.deleteElections.body
14+
</span>
15+
</p>
16+
</div>
17+
18+
<div class="modal-footer">
19+
<button class="btn btn-success" ng-click="ok()">
20+
<span ng-i18next>ok </span>
21+
</button>
22+
<button class="btn btn-cancel" ng-click="cancel()">
23+
<span ng-i18next> avCommon.cancel </span>
24+
</button>
25+
</div>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
angular.module('avAdmin')
2+
.controller('DeleteElectionsModal',
3+
function($scope, $modalInstance, electionIds)
4+
{
5+
$scope.electionIds = electionIds;
6+
7+
$scope.ok = function () {
8+
$modalInstance.close('ok');
9+
};
10+
11+
$scope.cancel = function () {
12+
$modalInstance.dismiss('cancel');
13+
};
14+
});

avAdmin/admin-directives/elections/elections.html

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ <h2 ng-i18next>
4444
ui-sref="admin.new()">
4545
<i class="fa fa-plus"></i>
4646
</button>
47+
48+
<button
49+
class="btn btn-default delete-elections"
50+
ng-if="hasPerms(['create'])"
51+
ng-click="deleteSelected()">
52+
<i class="fa fa-trash"></i>
53+
</button>
4754

4855
<ul class="nav nav-pills">
4956
<li
@@ -101,23 +108,26 @@ <h2 ng-i18next>
101108

102109
<tr ng-repeat="election in elections | filter:q | orderBy:'-id'">
103110
<td class="td-1">
104-
<a
105-
ng-if="!election.children_election_info"
106-
ui-sref="admin.dashboard({id: election.id})"
107-
class="padded">
108-
{{ election.id }}
109-
</a>
110-
<a
111-
ng-if="!!election.children_election_info"
112-
ng-click="toggleShowChildren(election)"
113-
class="padded child-dropdown">
114-
<span
115-
ng-class="{'glyphicon-menu-right': !election.showingChildren, 'glyphicon-menu-down': !!election.showingChildren}"
116-
class="glyphicon"
117-
aria-hidden="true">
118-
</span>
119-
{{ election.id }}
120-
</a>
111+
<div class="election-td-init">
112+
<input type="checkbox" ng-click="toggleSelectedElection(election.id)">
113+
<a
114+
ng-if="!election.children_election_info"
115+
ui-sref="admin.dashboard({id: election.id})"
116+
class="padded">
117+
{{ election.id }}
118+
</a>
119+
<a
120+
ng-if="!!election.children_election_info"
121+
ng-click="toggleShowChildren(election)"
122+
class="padded child-dropdown">
123+
<span
124+
ng-class="{'glyphicon-menu-right': !election.showingChildren, 'glyphicon-menu-down': !!election.showingChildren}"
125+
class="glyphicon"
126+
aria-hidden="true">
127+
</span>
128+
{{ election.id }}
129+
</a>
130+
</div>
121131
</td>
122132
<td class="main td-7">
123133
<a ui-sref="admin.dashboard({id: election.id})">

avAdmin/admin-directives/elections/elections.js

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ angular.module('avAdmin')
2727
scope.nomore = false;
2828
scope.list = {type: 'all'};
2929
scope.elections = [];
30+
scope.selectedElections = {};
3031

3132
/**
3233
* Downloads elections from Elections api, initialize them and
@@ -182,6 +183,61 @@ angular.module('avAdmin')
182183
scope.loadMoreElections(true);
183184
}
184185

186+
function getElectionIds() {
187+
return Object.entries(scope.selectedElections)
188+
.filter(function (input) {
189+
// input = [k, v]
190+
return input[1];
191+
})
192+
.map(function (input) {
193+
// input = [k, v]
194+
return input[0];
195+
});
196+
}
197+
198+
function doDeleteElections(electionIds) {
199+
// download children and add them after the index in the list
200+
Authmethod
201+
.deleteElections(electionIds)
202+
.then(
203+
function(response)
204+
{
205+
reloadList();
206+
},
207+
function onError(response)
208+
{
209+
scope.loading = false;
210+
scope.error = response.data;
211+
}
212+
);
213+
}
214+
215+
function deleteSelected() {
216+
// show the initial edit dialog
217+
$modal.open({
218+
templateUrl: "avAdmin/admin-directives/elections/delete-elections-modal.html",
219+
controller: "DeleteElectionsModal",
220+
size: 'lg',
221+
resolve: {
222+
electionIds: function () {
223+
return getElectionIds()
224+
.join(", ");
225+
}
226+
}
227+
228+
// when the edit dialog has been shown, then we default to not showing it
229+
// again unless necessary (setting the skip edit dialog to true) and
230+
// continue to the confirmation dialog
231+
}).result.then(function () {
232+
var electionIds = getElectionIds();
233+
doDeleteElections(electionIds);
234+
});
235+
}
236+
237+
function toggleSelectedElection(electionId) {
238+
scope.selectedElections[electionId] = !scope.selectedElections[electionId];
239+
}
240+
185241
scope.exhtml = [];
186242
Plugins.hook(
187243
'admin-elections-list-extra-html',
@@ -194,7 +250,9 @@ angular.module('avAdmin')
194250
loadMoreElections: loadMoreElections,
195251
setListType: setListType,
196252
toggleShowChildren: toggleShowChildren,
197-
reloadList: reloadList
253+
reloadList: reloadList,
254+
deleteSelected: deleteSelected,
255+
toggleSelectedElection: toggleSelectedElection,
198256
});
199257
}
200258

avAdmin/admin-directives/elections/elections.less

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@
1818
[av-admin-elections] {
1919

2020
.td-1 {
21-
width: 8.33%;
21+
width: 12%;
22+
.election-td-init {
23+
display: flex;
24+
padding-left: 8px;
25+
input {
26+
min-width: 14px;
27+
margin-left: 14px;
28+
}
29+
}
2230
}
2331

2432
.td-2 {
@@ -42,7 +50,7 @@
4250
}
4351

4452
.td-7 {
45-
width: 58.33%;
53+
width: 54%;
4654
}
4755

4856
.td-8 {
@@ -118,6 +126,11 @@
118126
}
119127

120128
.new-election {
129+
margin-right: 5px;
130+
float: left;
131+
}
132+
133+
.delete-elections {
121134
margin-right: 20px;
122135
float: left;
123136
}

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
<script src="avAdmin/admin-directives/success-action/success-action.js" class="app"></script>
8383
<script src="avAdmin/admin-directives/census-field/census-field.js" class="app"></script>
8484
<script src="avAdmin/admin-directives/elections/erase-draft-modal.js" class="app"></script>
85+
<script src="avAdmin/admin-directives/elections/delete-elections-modal.js" class="app"></script>
8586
<script src="avAdmin/admin-directives/elections/use-draft-modal.js" class="app"></script>
8687
<script src="avAdmin/admin-directives/elections/elections.js" class="app"></script>
8788
<script src="avAdmin/admin-directives/elcensus/elcensus.js" class="app"></script>

locales/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@
335335
"eraseDraftModal": {
336336
"title": "Do you want to erase the election draft?",
337337
"body": "This action will erase the election draft with title '__title__'. This action cannot be reverted. Do you wish to proceed?"
338+
},
339+
"deleteElections": {
340+
"title": "Do you want to delete the following elections?",
341+
"body": "This action will delete the elections with ids: __electionids__. This action cannot be reverted. Do you wish to proceed?"
338342
}
339343
},
340344
"action": {

0 commit comments

Comments
 (0)