mirror of
				https://github.com/ae-utbm/sith.git
				synced 2025-11-04 11:03:04 +00:00 
			
		
		
		
	Election list deletion and ux improvements
This commit is contained in:
		
							
								
								
									
										22
									
								
								core/static/core/js/shorten.min.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								core/static/core/js/shorten.min.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
				
			|||||||
 | 
					// Copyright 2013 Viral Patel and other contributors
 | 
				
			||||||
 | 
					// http://viralpatel.net
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Permission is hereby granted, free of charge, to any person obtaining
 | 
				
			||||||
 | 
					// a copy of this software and associated documentation files (the
 | 
				
			||||||
 | 
					// "Software"), to deal in the Software without restriction, including
 | 
				
			||||||
 | 
					// without limitation the rights to use, copy, modify, merge, publish,
 | 
				
			||||||
 | 
					// distribute, sublicense, and/or sell copies of the Software, and to
 | 
				
			||||||
 | 
					// permit persons to whom the Software is furnished to do so, subject to
 | 
				
			||||||
 | 
					// the following conditions:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// The above copyright notice and this permission notice shall be
 | 
				
			||||||
 | 
					// included in all copies or substantial portions of the Software.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 | 
				
			||||||
 | 
					// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 | 
				
			||||||
 | 
					// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 | 
				
			||||||
 | 
					// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 | 
				
			||||||
 | 
					// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 | 
				
			||||||
 | 
					// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 | 
				
			||||||
 | 
					// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 | 
				
			||||||
 | 
					!function(e){e.fn.shorten=function(s){"use strict";var t={showChars:100,minHideChars:10,ellipsesText:"...",moreText:"more",lessText:"less",onLess:function(){},onMore:function(){},errMsg:null,force:!1};return s&&e.extend(t,s),e(this).data("jquery.shorten")&&!t.force?!1:(e(this).data("jquery.shorten",!0),e(document).off("click",".morelink"),e(document).on({click:function(){var s=e(this);return s.hasClass("less")?(s.removeClass("less"),s.html(t.moreText),s.parent().prev().animate({height:"0%"},function(){s.parent().prev().prev().show()}).hide("fast",function(){t.onLess()})):(s.addClass("less"),s.html(t.lessText),s.parent().prev().animate({height:"100%"},function(){s.parent().prev().prev().hide()}).show("fast",function(){t.onMore()})),!1}},".morelink"),this.each(function(){var s=e(this),n=s.html(),r=s.text().length;if(r>t.showChars+t.minHideChars){var o=n.substr(0,t.showChars);if(o.indexOf("<")>=0){for(var a=!1,i="",h=0,l=[],c=null,f=0,u=0;u<=t.showChars;f++)if("<"!=n[f]||a||(a=!0,c=n.substring(f+1,n.indexOf(">",f)),"/"==c[0]?c!="/"+l[0]?t.errMsg="ERROR en HTML: the top of the stack should be the tag that closes":l.shift():"br"!=c.toLowerCase()&&l.unshift(c)),a&&">"==n[f]&&(a=!1),a)i+=n.charAt(f);else if(u++,h<=t.showChars)i+=n.charAt(f),h++;else if(l.length>0){for(j=0;j<l.length;j++)i+="</"+l[j]+">";break}o=e("<div/>").html(i+'<span class="ellip">'+t.ellipsesText+"</span>").html()}else o+=t.ellipsesText;var m='<div class="shortcontent">'+o+'</div><div class="allcontent">'+n+'</div><span><a href="javascript://nop/" class="morelink">'+t.moreText+"</a></span>";s.html(m),s.find(".allcontent").hide(),e(".shortcontent p:last",s).css("margin-bottom",0)}}))}}(jQuery);
 | 
				
			||||||
@@ -128,6 +128,14 @@ class ElectionList(models.Model):
 | 
				
			|||||||
    title = models.CharField(_('title'), max_length=255)
 | 
					    title = models.CharField(_('title'), max_length=255)
 | 
				
			||||||
    election = models.ForeignKey(Election, related_name='election_lists', verbose_name=_("election"))
 | 
					    election = models.ForeignKey(Election, related_name='election_lists', verbose_name=_("election"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def can_be_edited_by(self, user):
 | 
				
			||||||
 | 
					        return user.can_edit(self.election)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def delete(self):
 | 
				
			||||||
 | 
					        for candidature in self.candidatures.all():
 | 
				
			||||||
 | 
					            candidature.delete()
 | 
				
			||||||
 | 
					        super(ElectionList, self).delete()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __str__(self):
 | 
					    def __str__(self):
 | 
				
			||||||
        return self.title
 | 
					        return self.title
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -265,7 +265,12 @@ th {
 | 
				
			|||||||
                <thead>
 | 
					                <thead>
 | 
				
			||||||
                    <th>{% trans %}Blank vote{% endtrans %}</th>
 | 
					                    <th>{% trans %}Blank vote{% endtrans %}</th>
 | 
				
			||||||
                    {%- for election_list in election_lists %}
 | 
					                    {%- for election_list in election_lists %}
 | 
				
			||||||
                    <th>{{ election_list.title }}</th>
 | 
					                    <th>
 | 
				
			||||||
 | 
					                        {{ election_list.title }}
 | 
				
			||||||
 | 
					                        {% if user.can_edit(election_list) and election.is_vote_editable -%}
 | 
				
			||||||
 | 
					                            - <a href="{{ url('election:delete_list', list_id=election_list.id) }}">{% trans %}Delete{% endtrans %}</a>
 | 
				
			||||||
 | 
					                        {% endif %}
 | 
				
			||||||
 | 
					                    </th>
 | 
				
			||||||
                    {%- endfor %}
 | 
					                    {%- endfor %}
 | 
				
			||||||
                </thead>
 | 
					                </thead>
 | 
				
			||||||
                {%- for role in election.roles.all() %}
 | 
					                {%- for role in election.roles.all() %}
 | 
				
			||||||
@@ -279,8 +284,9 @@ th {
 | 
				
			|||||||
                                <a href="{{url('election:update_role', role_id=role.id)}}">{% trans %}Edit{% endtrans %}</a>
 | 
					                                <a href="{{url('election:update_role', role_id=role.id)}}">{% trans %}Edit{% endtrans %}</a>
 | 
				
			||||||
                                <a href="{{url('election:delete_role', role_id=role.id)}}">{% trans %}Delete{% endtrans %}</a>
 | 
					                                <a href="{{url('election:delete_role', role_id=role.id)}}">{% trans %}Delete{% endtrans %}</a>
 | 
				
			||||||
                            {%- endif -%}
 | 
					                            {%- endif -%}
 | 
				
			||||||
                            <br><span>{{ role.description }}</span>
 | 
					                            <br><span class='role__description'><p>{{ role.description }}</p></span>
 | 
				
			||||||
                            {%- if role.max_choice > 1 and not election.has_voted(user) and election.can_vote(user) %}
 | 
					                            {%- if role.max_choice > 1 and not election.has_voted(user) and election.can_vote(user) %}
 | 
				
			||||||
 | 
					                            <br>
 | 
				
			||||||
                            <strong class="role__multiple-choices-label">{% trans %}You may choose up to{% endtrans %} {{ role.max_choice }} {% trans %}people.{% endtrans %}</strong>
 | 
					                            <strong class="role__multiple-choices-label">{% trans %}You may choose up to{% endtrans %} {{ role.max_choice }} {% trans %}people.{% endtrans %}</strong>
 | 
				
			||||||
                            {%- endif %}
 | 
					                            {%- endif %}
 | 
				
			||||||
                            {%- if election_form.errors[role.title] is defined %}
 | 
					                            {%- if election_form.errors[role.title] is defined %}
 | 
				
			||||||
@@ -319,9 +325,6 @@ th {
 | 
				
			|||||||
                                        </div>
 | 
					                                        </div>
 | 
				
			||||||
                                        <figcaption class="candidate__details">
 | 
					                                        <figcaption class="candidate__details">
 | 
				
			||||||
                                            <cite class="candidate__full-name">{{ candidature.user.first_name }} <em class="candidate__nick-name">{{candidature.user.nick_name or ''}} </em>{{ candidature.user.last_name }}</cite>
 | 
					                                            <cite class="candidate__full-name">{{ candidature.user.first_name }} <em class="candidate__nick-name">{{candidature.user.nick_name or ''}} </em>{{ candidature.user.last_name }}</cite>
 | 
				
			||||||
                                            {%- if not election.is_vote_finished %}
 | 
					 | 
				
			||||||
                                            <q class="candidate__program">{{ candidature.program or '' }}</q>
 | 
					 | 
				
			||||||
                                            {%- endif %}
 | 
					 | 
				
			||||||
                                            {%- if user.can_edit(candidature) -%}
 | 
					                                            {%- if user.can_edit(candidature) -%}
 | 
				
			||||||
                                            {% if election.is_vote_editable %}
 | 
					                                            {% if election.is_vote_editable %}
 | 
				
			||||||
                                            <a href="{{url('election:update_candidate', candidature_id=candidature.id)}}">{% trans %}Edit{% endtrans %}</a>
 | 
					                                            <a href="{{url('election:update_candidate', candidature_id=candidature.id)}}">{% trans %}Edit{% endtrans %}</a>
 | 
				
			||||||
@@ -330,6 +333,9 @@ th {
 | 
				
			|||||||
                                            <a href="{{url('election:delete_candidate', candidature_id=candidature.id)}}">{% trans %}Delete{% endtrans %}</a>
 | 
					                                            <a href="{{url('election:delete_candidate', candidature_id=candidature.id)}}">{% trans %}Delete{% endtrans %}</a>
 | 
				
			||||||
                                            {%- endif -%}
 | 
					                                            {%- endif -%}
 | 
				
			||||||
                                            {%- endif -%}
 | 
					                                            {%- endif -%}
 | 
				
			||||||
 | 
					                                            {%- if not election.is_vote_finished %}
 | 
				
			||||||
 | 
					                                            <q class="candidate__program">{{ candidature.program | markdown or '' }}</q>
 | 
				
			||||||
 | 
					                                            {%- endif %}
 | 
				
			||||||
                                        </figcaption>
 | 
					                                        </figcaption>
 | 
				
			||||||
                                    </figure>
 | 
					                                    </figure>
 | 
				
			||||||
                                    {%- if election.can_vote(user) %}
 | 
					                                    {%- if election.can_vote(user) %}
 | 
				
			||||||
@@ -382,6 +388,18 @@ th {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
{% block script %}
 | 
					{% block script %}
 | 
				
			||||||
{{ super() }}
 | 
					{{ super() }}
 | 
				
			||||||
 | 
					<script src="{{ static('core/js/shorten.min.js') }}"></script>
 | 
				
			||||||
 | 
					<script type="text/javascript">
 | 
				
			||||||
 | 
					$('.role__description').shorten({
 | 
				
			||||||
 | 
					    moreText: "{% trans %}Show more{% endtrans %}",
 | 
				
			||||||
 | 
					    lessText: "{% trans %}Show less{% endtrans %}"
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					$('.candidate__program').shorten({
 | 
				
			||||||
 | 
					    moreText: "{% trans %}Show more{% endtrans %}",
 | 
				
			||||||
 | 
					    lessText: "{% trans %}Show less{% endtrans %}",
 | 
				
			||||||
 | 
					    showChars: 200
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
<script type="text/javascript">
 | 
					<script type="text/javascript">
 | 
				
			||||||
document.querySelectorAll('.role__multiple-choices').forEach(setupRestrictions);
 | 
					document.querySelectorAll('.role__multiple-choices').forEach(setupRestrictions);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,6 +9,7 @@ urlpatterns = [
 | 
				
			|||||||
    url(r'^(?P<election_id>[0-9]+)/edit$', ElectionUpdateView.as_view(), name='update'),
 | 
					    url(r'^(?P<election_id>[0-9]+)/edit$', ElectionUpdateView.as_view(), name='update'),
 | 
				
			||||||
    url(r'^(?P<election_id>[0-9]+)/delete$', ElectionDeleteView.as_view(), name='delete'),
 | 
					    url(r'^(?P<election_id>[0-9]+)/delete$', ElectionDeleteView.as_view(), name='delete'),
 | 
				
			||||||
    url(r'^(?P<election_id>[0-9]+)/list/add$', ElectionListCreateView.as_view(), name='create_list'),
 | 
					    url(r'^(?P<election_id>[0-9]+)/list/add$', ElectionListCreateView.as_view(), name='create_list'),
 | 
				
			||||||
 | 
					    url(r'^(?P<list_id>[0-9]+)/list/delete$', ElectionListDeleteView.as_view(), name='delete_list'),
 | 
				
			||||||
    url(r'^(?P<election_id>[0-9]+)/role/create$', RoleCreateView.as_view(), name='create_role'),
 | 
					    url(r'^(?P<election_id>[0-9]+)/role/create$', RoleCreateView.as_view(), name='create_role'),
 | 
				
			||||||
    url(r'^(?P<role_id>[0-9]+)/role/edit$', RoleUpdateView.as_view(), name='update_role'),
 | 
					    url(r'^(?P<role_id>[0-9]+)/role/edit$', RoleUpdateView.as_view(), name='update_role'),
 | 
				
			||||||
    url(r'^(?P<role_id>[0-9]+)/role/delete$', RoleDeleteView.as_view(), name='delete_role'),
 | 
					    url(r'^(?P<role_id>[0-9]+)/role/delete$', RoleDeleteView.as_view(), name='delete_role'),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -538,3 +538,19 @@ class RoleDeleteView(CanEditMixin, DeleteView):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def get_success_url(self, **kwargs):
 | 
					    def get_success_url(self, **kwargs):
 | 
				
			||||||
        return reverse_lazy('election:detail', kwargs={'election_id': self.election.id})
 | 
					        return reverse_lazy('election:detail', kwargs={'election_id': self.election.id})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class ElectionListDeleteView(CanEditMixin, DeleteView):
 | 
				
			||||||
 | 
					    model = ElectionList
 | 
				
			||||||
 | 
					    template_name = 'core/delete_confirm.jinja'
 | 
				
			||||||
 | 
					    pk_url_kwarg = 'list_id'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def dispatch(self, request, *args, **kwargs):
 | 
				
			||||||
 | 
					        self.object = self.get_object()
 | 
				
			||||||
 | 
					        self.election = self.object.election
 | 
				
			||||||
 | 
					        if not self.election.is_vote_editable:
 | 
				
			||||||
 | 
					            raise PermissionDenied
 | 
				
			||||||
 | 
					        return super(ElectionListDeleteView, self).dispatch(request, *args, **kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get_success_url(self, **kwargs):
 | 
				
			||||||
 | 
					        return reverse_lazy('election:detail', kwargs={'election_id': self.election.id})
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user