@@ -12,6 +12,7 @@ <h1>User Rankings</h1>
1212 < th > Rank</ th >
1313 < th > Username</ th >
1414 < th > Rating</ th >
15+ < th > Action</ th >
1516 </ tr >
1617 </ thead >
1718 < tbody >
@@ -20,6 +21,7 @@ <h1>User Rankings</h1>
2021 < td > {{ page_obj.start_index|add:forloop.counter|add:-1 }}</ td >
2122 < td > < a href ="{% url 'auth:profile' user.username %} "> {{ user.username }}</ a > </ td >
2223 < td > {{ user.rating }}</ td >
24+ < td > {% if user.username in users_with_submissions %}< button type ="button " class ="btn btn-primary btn-sm " data-toggle ="modal " data-target ="#requestMatchModal " data-username ="{{ user.username }} "> Request Match</ button > {% endif %}</ td >
2325 </ tr >
2426 {% endfor %}
2527 </ tbody >
@@ -41,4 +43,60 @@ <h1>User Rankings</h1>
4143 </ ul >
4244 </ nav >
4345</ div >
46+
47+ < div class ="modal fade " id ="requestMatchModal " tabindex ="-1 " role ="dialog " aria-labelledby ="requestMatchModalLabel " aria-hidden ="true ">
48+ < div class ="modal-dialog " role ="document ">
49+ < div class ="modal-content ">
50+ < div class ="modal-header ">
51+ < h5 class ="modal-title " id ="requestMatchModalLabel "> Request a Match</ h5 >
52+ < button type ="button " class ="close " data-dismiss ="modal " aria-label ="Close ">
53+ < span aria-hidden ="true "> ×</ span >
54+ </ button >
55+ </ div >
56+ < form id ="requestMatchForm " method ="post " action ="{% url 'games:request_match' %} ">
57+ {% csrf_token %}
58+ < div class ="modal-body ">
59+ {{ form.as_p }}
60+ </ div >
61+ < div class ="modal-footer ">
62+ < button type ="button " class ="btn btn-secondary " data-dismiss ="modal "> Cancel</ button >
63+ < button type ="submit " class ="btn btn-primary "> Request Match</ button >
64+ </ div >
65+ </ form >
66+ </ div >
67+ </ div >
68+ </ div >
69+
70+ < script >
71+ $ ( '#requestMatchModal' ) . on ( 'show.bs.modal' , function ( event ) {
72+ var button = $ ( event . relatedTarget ) ;
73+ var username = button . data ( 'username' ) ;
74+ var form = $ ( '#requestMatchForm' ) ;
75+ var action = form . attr ( 'action' ) ;
76+ if ( action . indexOf ( '?' ) > - 1 ) {
77+ action = action . split ( '?' ) [ 0 ] ;
78+ }
79+ form . attr ( 'action' , action + '?opponent=' + encodeURIComponent ( username ) ) ;
80+
81+ var select = form . find ( 'select[name="opponent"]' ) ;
82+ select . find ( 'option' ) . each ( function ( ) {
83+ if ( $ ( this ) . text ( ) . indexOf ( '(' + username + ')' ) !== - 1 ) {
84+ select . val ( $ ( this ) . val ( ) ) ;
85+ return false ;
86+ }
87+ } ) ;
88+
89+ select . prop ( 'disabled' , true ) ;
90+ } ) ;
91+
92+ $ ( '#requestMatchModal' ) . on ( 'hidden.bs.modal' , function ( ) {
93+ var form = $ ( '#requestMatchForm' ) ;
94+ var select = form . find ( 'select[name="opponent"]' ) ;
95+ select . prop ( 'disabled' , false ) ;
96+ } ) ;
97+
98+ $ ( '#requestMatchForm' ) . on ( 'submit' , function ( ) {
99+ $ ( this ) . find ( 'select[name="opponent"]' ) . prop ( 'disabled' , false ) ;
100+ } ) ;
101+ </ script >
44102{% endblock %}
0 commit comments