[chronojump-server] Added creating player functionality
- From: Max Ros i Morejon <maxros src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump-server] Added creating player functionality
- Date: Fri, 22 Feb 2019 10:45:52 +0000 (UTC)
commit 02ffb21a5d73ee828950edce9f29e37add6b9833
Author: Max Ros i Morejon <mros33 gmail com>
Date: Fri Feb 22 11:44:40 2019 +0100
Added creating player functionality
.../chronojump_networks/organizations/api/views.py | 15 +++++++
.../players/add_edit_player_form.html | 6 ++-
.../organizations/players/players_list.html | 47 ++++++++++++++++++++++
3 files changed, 67 insertions(+), 1 deletion(-)
---
diff --git a/chronojumpserver-django/chronojump_networks/organizations/api/views.py
b/chronojumpserver-django/chronojump_networks/organizations/api/views.py
index 3847018..586be7d 100644
--- a/chronojumpserver-django/chronojump_networks/organizations/api/views.py
+++ b/chronojumpserver-django/chronojump_networks/organizations/api/views.py
@@ -114,6 +114,21 @@ class PlayerListView(ListCreateAPIView):
organization_id = int(self.kwargs['organization_id'])
return Player.objects.filter(organization_id=organization_id)
+ def create(self, request, *args, **kwargs):
+ print("crea player")
+ data = dict(request.data)
+ # TODO: Sure there is a better way to do this
+ o = Player.objects.create(
+ name = str(data['name'][0]),
+ #image = str(data['image'][0]),
+ number = int(data['number'][0]),
+ height = float(data['height'][0]),
+ weight = float(data['weight'][0]),
+ rfid = str(data['rfid'][0]),
+ organization_id = int(self.kwargs['organization_id'])
+ )
+ s = PlayerSerializer(o)
+ return Response(s.data)
def register_rfid(request):
"""Call an external program to read rfid and return the value read."""
diff --git
a/chronojumpserver-django/chronojump_networks/templates/organizations/players/add_edit_player_form.html
b/chronojumpserver-django/chronojump_networks/templates/organizations/players/add_edit_player_form.html
index 34cf671..58acc20 100644
--- a/chronojumpserver-django/chronojump_networks/templates/organizations/players/add_edit_player_form.html
+++ b/chronojumpserver-django/chronojump_networks/templates/organizations/players/add_edit_player_form.html
@@ -12,7 +12,7 @@
</div>
<div class="modal-body">
- <!--input type="hidden" id="personId" />-->
+ <input type="hidden" id="personId" />
<form>
<div class="row">
@@ -21,6 +21,10 @@
<label for="photo">{% trans 'Photography' %}</label>
<img src="..." alt="..." class="img-thumbnail">
</div>
+ <div class="form-group">
+ <label for="number">{% trans 'Number' %}</label>
+ <input name="number" class="form-control" id="number"
type="number">
+ </div>
</div>
<div class="col-sm-8">
<div class="form-group">
diff --git a/chronojumpserver-django/chronojump_networks/templates/organizations/players/players_list.html
b/chronojumpserver-django/chronojump_networks/templates/organizations/players/players_list.html
index 7ac1a40..a042040 100644
--- a/chronojumpserver-django/chronojump_networks/templates/organizations/players/players_list.html
+++ b/chronojumpserver-django/chronojump_networks/templates/organizations/players/players_list.html
@@ -158,6 +158,53 @@
})
})
+
+ $('#btnAddModifyPlayer').on('click', function(e) {
+ console.log("botó addmodifyplayer 0");
+ e.preventDefault();
+ $('#personId').val('');
+ var player = serializePlayer();
+ console.log(player.id);
+ putPlayer(player);
+ })
+
+ // Get all the values in the form into json object
+ function serializePlayer() {
+ let player_id = $('#personId').val();
+ let player_name = $('#fullname').val();
+ let player_height = $('#height').val();
+ let player_weight = $('#weight').val();
+// let player_image = $('#photo').val();
+ let player_number = $('#number').val();
+ let player_rfid = $('#input_rfid').val();
+ var player = {
+ 'id': player_id,
+ 'name': player_name,
+ 'height': player_height,
+ 'weight': player_weight,
+// 'image': player_image,
+ 'number': player_number,
+ 'rfid': player_rfid
+ }
+ console.log(player);
+ return player;
+ }
+
+ function putPlayer(player) {
+ // TODO: Add validation
+ console.log("botó addmodifyplayer 1");
+ $.ajax({
+ 'url': "{% url 'api_organizations:players_list' organization_id=user.organization.id %}",
+ 'method': 'POST',
+ 'data': player,
+ success: function(data) {
+ alert("The player has been added");
+ table_players.ajax.reload();
+ $('#addPlayerModalForm').modal('hide');
+ }
+
+ })
+ }
});
</script>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]