Skip to content

Commit

Permalink
Team Creator v0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
alumarcu committed Apr 4, 2016
1 parent b84bec5 commit 6c3fd48
Show file tree
Hide file tree
Showing 7 changed files with 381 additions and 17 deletions.
35 changes: 28 additions & 7 deletions dream/engine/soccer/static/js/team_creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ dream.TeamCreator = function() {
$(document).ready(function() {
$(document).foundation(); // Initializes foundation

// Balance equalizer inside reveal
$(document).on('opened.fndtn.reveal', '[data-reveal]', function () {
$(document).foundation('equalizer');
});
// Balance equalizer inside reveal (columns should have equal height)
$(document).on('opened.fndtn.reveal', '[data-reveal]', function () {
$(document).foundation('equalizer');
});

// TODO: Move this into its own namespace
// TODO: Nu se tine cont de paginare la grilaj
var clubs_table = $('#tbl-clubs').DataTable({
serverSide: true, // Tell it I want to call the server
processing: true, // Loading screen enable
Expand Down Expand Up @@ -45,9 +46,29 @@ $(document).on('opened.fndtn.reveal', '[data-reveal]', function () {
}
});

//$('#btn-new-club').click(function() {
// $('#modal-new-club').foundation('reveal', 'open');
//});
$('#btn-new-club').click(function(e) {
e.preventDefault();

var formContent = $('#new-club').serializeJSON();
var params = {'new-club': JSON.stringify(formContent)};

$.ajax({
url: dream.Context['team-creator-api'],
type: 'POST',
data: params,
dataType: 'json',
success: function(data) {
$('#modal-new-club').foundation('reveal', 'close');
// TODO:Clear the form

// TODO: Move clubs_table in a property
clubs_table.ajax.reload();

// TODO: Should display notification message here
},
beforeSend: dream.utils.setCsrfToken()
})
});


});
Expand Down
13 changes: 7 additions & 6 deletions dream/engine/soccer/templates/dev/team_creator.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h3>{% trans 'Team Creator' %}</h3>
<div class="row fluid">
<div class="small-12 columns">
<ul class="button-group">
<li><a id="btn-new-club" data-reveal-id="modal-new-club" class="button">{% trans 'New Club' %}</a></li>
<li><a id="btn-modal-new-club" data-reveal-id="modal-new-club" class="button">{% trans 'New Club' %}</a></li>
<li><a id="btn-sel-duplicate" class="button">{% trans 'Duplicate' %}</a></li>
<li><a id="btn-sel-delete" class="button">{% trans 'Delete' %}</a></li>
</ul>
Expand Down Expand Up @@ -53,16 +53,16 @@ <h2 id="heading-new-club">{% trans 'Define new club' %}</h2>
<div class="small-8 medium-8 columns" data-equalizer-watch>
<form id="new-club">
<label for="club-name">{% trans 'Club Name' %}
<input type="text" name="new-club[club-name]" id="club-name" value=""/>
<input type="text" name="club-name" id="club-name" value=""/>
</label>
<label for="manager-name">{% trans 'Club Name' %}
<input type="text" name="new-club[manager-name]" id="manager-name" value=""/>
<label for="manager-name">{% trans 'Manager Name' %}
<input type="text" name="manager-name" id="manager-name" value=""/>
</label>
<button class="button success right">{% trans 'Create Club' %}</button>
<button id="btn-new-club" class="button success right">{% trans 'Create Club' %}</button>
</form>
</div>
<div class="small-4 medium-4 columns panel" data-equalizer-watch>
<a class="button right" id="btn-auto-create">{% trans 'Auto create' %}</a>
<a href="#" class="button right" id="btn-auto-create">{% trans 'Auto Create' %}</a>
</div>
</div>

Expand All @@ -73,6 +73,7 @@ <h2 id="heading-new-club">{% trans 'Define new club' %}</h2>

{% block javascripts %}
{{ block.super }}
<script type="text/javascript" src="{% static 'jquery/plugins/jquery.serializejson.min.js' %}"></script>
<script type="text/javascript" src="{% static 'foundation/5.5.1/js/foundation/foundation.equalizer.js' %}"></script>
<script type="text/javascript" src="{% static 'datatables/1.10.11/js/jquery.dataTables.min.js' %}"></script>
<script type="text/javascript" src="{% static 'datatables/1.10.11/js/dataTables.foundation.min.js' %}"></script>
Expand Down
35 changes: 32 additions & 3 deletions dream/engine/soccer/views/dev/team_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.shortcuts import render
from django.http import JsonResponse
from django.db.models import Count
from json import loads as json_decode


class TeamCreatorView(View):
Expand All @@ -20,9 +21,10 @@ def post(self, request):
query = request.POST
response = {}

if request.is_ajax:
if 'clubs-table' in query:
response.update(self.get_clubs_table(query))
if 'clubs-table' in query:
response.update(self.get_clubs_table(query))
if 'new-club' in query:
response.update(self.create_new_club(query))

return JsonResponse(response)

Expand Down Expand Up @@ -62,3 +64,30 @@ def get_clubs_table(self, query):
'recordsTotal': len(clubs),
'recordsFiltered': len(clubs)
}

def create_new_club(self, query):
from django.utils.html import escape
from django.utils.text import slugify
from dream.site.services import SignupService

form_data = json_decode(query['new-club'])

data = {}
data['manager_name'] = escape(form_data['manager-name'])
data['username'] = slugify(data['manager_name']).replace('-', '_')
data['email'] = data['username'].replace('-', '') + '@dream11.io'
data['club_name'] = escape(form_data['club-name'])

data['country'] = 1 # Assumed to be "intl"
data['password'] = 'dev'

response = {'is_error': False}

try:
service = SignupService()
service.create_account(data)
except Exception as e:
response['is_error'] = True
response['message'] = str(e)

return response
1 change: 1 addition & 0 deletions dream/site/services/signup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def create_account(self, data):
manager = builder.build_manager(user, data)
manager.save()

# [TODO] Country should not be passed by id but by country code instead
country = Country.objects.get(pk=data['country'])
club = builder.build_club(manager, country, data)
club.save()
Expand Down
1 change: 0 additions & 1 deletion dream/static/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Global helper styles
/*
DataTables integration fixes
*/

.paginate_button.current, .paginate_button.current:hover {
color: transparent !important;
border: none !important;
Expand Down
Loading

0 comments on commit 6c3fd48

Please sign in to comment.