src/main/webapp/admin_components/admin-eventlist/admin-eventlist.html
<!--
SportChef – Sports Competition Management Software
Copyright (C) 2015 Marcus Fihlon
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/ <http://www.gnu.org/licenses/>>.
-->
<link rel="import" href="../../bower_components/polymer/polymer.html" />
<link rel="import" href="../../bower_components/iron-ajax/iron-ajax.html" />
<link rel="import" href="../../bower_components/paper-listbox/paper-listbox.html" />
<link rel="import" href="../../bower_components/paper-item/paper-item.html" />
<link rel="import" href="../../bower_components/iron-icon/iron-icon.html" />
<link rel="import" href="../../bower_components/iron-icons/iron-icons.html" />
<link rel="import" href="../../sportchef_components/sportchef-jquery/sportchef-jquery.html" />
<dom-module id="admin-eventlist">
<template>
<paper-card heading="Delete Events" data-i18n="admin-eventlist.heading" data-i18n-attribute="heading">
<div class="card-content">
<paper-listbox>
<iron-ajax auto url="/api/events" handle-as="json" last-response="{{ajaxResponse}}"></iron-ajax>
<template is="dom-repeat" items="[[ajaxResponse]]">
<paper-item id="paper-item-{{item.eventId}}">
{{item.title}}
<paper-button data-event-id$="{{item.eventId}}" data-event-title$="{{item.title}}" onclick="deleteEvent(this);" title="Delete" data-i18n="admin-eventlist.delete" data-i18n-attribute="title">
<iron-icon icon="icons:delete"></iron-icon>
</paper-button>
</paper-item>
</template>
</paper-listbox>
</div>
</paper-card>
</template>
<script>
function deleteEvent(button) {
var eventId = $(button).attr('data-event-id');
var eventTitle = $(button).attr('data-event-title');
if (confirm('Are you sure you want delete event #' + eventId + ' "' + eventTitle + '"?')) {
$.ajax({
method: 'DELETE',
url: '/api/events/' + eventId
})
.error(function(jqXHR, textStatus, errorThrown){
alert(textStatus);
})
.success(function(data, textStatus, jqXHR) {
$('#paper-item-' + eventId).hide();
});
}
}
// register a new element called sportchef-events
Polymer({
is: "admin-eventlist"
});
</script>
</dom-module>