Commit dee54f993fd636e4ac1f21463620b758e97a3f94

Authored by Felipe Henrique de Almeida Bormann
2 parents 81b068e1 235d498a

Merge branch 'refactoring' of https://github.com/amadeusproject/amadeuslms into refactoring

amadeus/static/css/base/amadeus.css
... ... @@ -126,6 +126,19 @@
126 126 margin-bottom: 15px;
127 127 }
128 128  
  129 +.ms-container {
  130 + width: 100% !important;
  131 +}
  132 +
  133 +#coordinators_accordion .panel-heading {
  134 + background: #FFFFFF;
  135 + border: none;
  136 +}
  137 +
  138 +#coordinators_accordion .panel-collapse {
  139 + padding: 10px;
  140 +}
  141 +
129 142 /* category app ends */
130 143  
131 144 .clearfix{
... ...
amadeus/static/img/switch.png 0 → 100644

540 Bytes

categories/templates/categories/_form.html 0 → 100644
... ... @@ -0,0 +1,118 @@
  1 +{% load widget_tweaks static i18n switchevenodd %}
  2 +
  3 +<form method="post" action="" enctype="multipart/form-data">
  4 + {% csrf_token %}
  5 + {% for field in form %}
  6 + {% if field.auto_id == 'id_coordinators' %}
  7 + <div class="panel-group" id="coordinators_accordion" role="tablist" aria-multiselectable="true">
  8 + <div class="panel panel-info">
  9 + <div class="panel-heading">
  10 + <div class="row">
  11 + <div class="col-md-12">
  12 + <a data-parent="#coordinators_accordion" data-toggle="collapse" href="#coords">
  13 + <h4 class="panel-title">
  14 + <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button><label for="{{ field.auto_id }}">{{ field.label }}</label>
  15 + </h4>
  16 + </a>
  17 + </div>
  18 + </div>
  19 + </div>
  20 + <div id="coords" class="panel-collapse collapse">
  21 + <p><em>{% trans 'Atribute coordinators role to users' %}:</em></p>
  22 + {% render_field field class='form-control' %}
  23 + </div>
  24 + </div>
  25 + </div>
  26 + {% else %}
  27 + <div class="form-group {% if form.has_error %} has-error {% endif %} is-fileinput">
  28 + {% if field.auto_id != 'id_visible' %}
  29 + <label for="{{ field.auto_id }}">{{ field.label }}</label>
  30 + {% endif %}
  31 + {% if field.auto_id == 'id_visible' %}
  32 + <div class="checkbox">
  33 + <label for="{{ field.auto_id }}">
  34 + {% render_field field %} {{field.label}}
  35 + </label>
  36 + </div>
  37 + {% elif field.auto_id == 'id_description' %}
  38 + {% render_field field class='form-control text_wysiwyg' %}
  39 + {% else %}
  40 + {% render_field field class='form-control' %}
  41 + {% endif %}
  42 + <span class="help-block">{{ field.help_text }}</span>
  43 + {% if field.errors %}
  44 + <div class="row">
  45 + </br>
  46 + <div class="alert alert-danger alert-dismissible" role="alert">
  47 + <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  48 + <span aria-hidden="true">&times;</span>
  49 + </button>
  50 + <ul>
  51 + {% for error in field.errors %}
  52 + <li>{{ error }}</li>
  53 + {% endfor %}
  54 + </ul>
  55 + </div>
  56 + </div>
  57 + {% endif %}
  58 + </div>
  59 + {% endif %}
  60 + {% endfor %}
  61 + <div class="row text-center">
  62 + <input type="submit" value="{% trans 'Register' %}" class="btn btn-primary btn-raised" />
  63 + </div>
  64 +</form>
  65 +
  66 +<script type="text/javascript">
  67 + $('#id_coordinators').multiSelect({
  68 + selectableHeader: "<input type='text' class='form-control search-input category-search-users' autocomplete='off' placeholder='{% trans "try an username" %} '>",
  69 + selectionHeader: "<input type='text' class='form-control search-input category-search-users' autocomplete='off' placeholder='{% trans "try an username" %} '>",
  70 + afterInit: function(ms){
  71 + var that = this,
  72 + $selectableSearch = that.$selectableUl.prev(),
  73 + $selectionSearch = that.$selectionUl.prev(),
  74 + selectableSearchString = '#'+that.$container.attr('id')+' .ms-elem-selectable:not(.ms-selected)',
  75 + selectionSearchString = '#'+that.$container.attr('id')+' .ms-elem-selection.ms-selected';
  76 +
  77 + that.qs1 = $selectableSearch.quicksearch(selectableSearchString)
  78 + .on('keydown', function(e){
  79 + if (e.which === 40){
  80 + that.$selectableUl.focus();
  81 + return false;
  82 + }
  83 + });
  84 +
  85 + that.qs2 = $selectionSearch.quicksearch(selectionSearchString)
  86 + .on('keydown', function(e){
  87 + if (e.which == 40){
  88 + that.$selectionUl.focus();
  89 + return false;
  90 + }
  91 + });
  92 + },
  93 + afterSelect: function(){
  94 + this.qs1.cache();
  95 + this.qs2.cache();
  96 + },
  97 + afterDeselect: function(){
  98 + this.qs1.cache();
  99 + this.qs2.cache();
  100 + }
  101 + });// Used to create multi-select css style
  102 +
  103 + $('.collapse').on('show.bs.collapse', function (e) {
  104 + if($(this).is(e.target)){
  105 + var btn = $(this).parent().find('.fa-angle-right');
  106 +
  107 + btn.switchClass("fa-angle-right", "fa-angle-down", 250, "easeInOutQuad");
  108 + }
  109 + });
  110 +
  111 + $('.collapse').on('hide.bs.collapse', function (e) {
  112 + if($(this).is(e.target)){
  113 + var btn = $(this).parent().find('.fa-angle-down');
  114 +
  115 + btn.switchClass("fa-angle-down", "fa-angle-right", 250, "easeInOutQuad");
  116 + }
  117 + });
  118 +</script>
0 119 \ No newline at end of file
... ...
categories/templates/categories/create.html
1   -{% extends 'categories/home.html' %}
  1 +{% extends 'categories/list.html' %}
2 2  
3 3 {% load widget_tweaks static i18n permission_tags django_bootstrap_breadcrumbs switchevenodd %}
4 4  
5 5 {% block breadcrumbs %}
6   - {{ block.super }}
7   - {% breadcrumb 'Create Category' 'categories:create' %}
  6 + {{ block.super }}
  7 + {% breadcrumb 'Create Category' 'categories:create' %}
8 8 {% endblock %}
9 9  
10 10 {% block content %}
11   -<div class="card card-content">
12   - <div class="card-body">
13   - <form method="post" action="" enctype="multipart/form-data">
14   - {% csrf_token %}
15   - {% for field in form %}
16   - <div class="form-group {% if form.has_error %} has-error {% endif %} is-fileinput">
17   - {% if field.auto_id != 'id_visible' %}
18   - <label for="{{ field.auto_id }}">{{ field.label }}</label>
19   - {% endif %}
20   - {% if field.auto_id == 'id_init_register_date' or field.auto_id == 'id_end_register_date' or field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date'%}
21   - <input type="text" class="form-control date-picker" name="{{field.name}}" value="{{field.value|date}}" min="{{now|date:'SHORT_DATE_FORMAT'}}">
22   - {% elif field.auto_id == 'id_visible' %}
23   - <div class="checkbox">
24   - <label for="{{ field.auto_id }}">
25   - {% render_field field %} {{field.label}}
26   - </label>
27   - </div>
28   - {% elif field.auto_id == 'id_description' %}
29   - {% render_field field class='form-control text_wysiwyg' %}
30   -
31   -
32   - {% comment %}
33   -
34   - {% endcomment %}
35   - {% elif field.auto_id == 'id_coordinators' %}
36   - <select id="{{field.auto_id}}" multiple="multiple" class="form-control"
37   - style="position: absolute; left: -9999px;" name="coordinators">
38   -
39   - {% for value, name in form.fields.coordinators.choices %}
40   - <option value="{{value}}">{{name}}</option>
41   - {% endfor %}
42   - </select>
43   -
44   - {% else %}
45   - {% render_field field class='form-control' %}
46   - {% endif %}
47   - <span class="help-block">{{ field.help_text }}</span>
48   - {% if field.errors %}
49   - <div class="row">
50   - </br>
51   - <div class="alert alert-danger alert-dismissible" role="alert">
52   - <button type="button" class="close" data-dismiss="alert" aria-label="Close">
53   - <span aria-hidden="true">&times;</span>
54   - </button>
55   - <ul>
56   - {% for error in field.errors %}
57   - <li>{{ error }}</li>
58   - {% endfor %}
59   - </ul>
60   - </div>
61   - </div>
62   - {% endif %}
63   - </div>
64   - {% endfor %}
65   - <div class="row text-center">
66   - <input type="submit" value="{% trans 'Register' %}" class="btn btn-primary btn-raised" />
67   - </div>
68   - </form>
  11 + <div class="card card-content">
  12 + <div class="card-body">
  13 + {% include 'categories/_form.html' %}
  14 + </div>
69 15 </div>
70   -</div>
71   -</br>
72   -</br>
73   -</br>
74   -<script type="text/javascript">
75   - var locale = navigator.language || navigator.userLanguage;
76   - $('.date-picker').datepicker({
77   - language: locale,
78   - });
79   -
80   - $('#id_coordinators').multiSelect({
81   - selectableHeader: "<input type='text' class='search-input category-search-users' autocomplete='off' placeholder='{% trans "try an username" %} '>",
82   - selectionHeader: "<input type='text' class='search-input category-search-users' autocomplete='off' placeholder='{% trans "try an username" %} '>",
83   - afterInit: function(ms){
84   - var that = this,
85   - $selectableSearch = that.$selectableUl.prev(),
86   - $selectionSearch = that.$selectionUl.prev(),
87   - selectableSearchString = '#'+that.$container.attr('id')+' .ms-elem-selectable:not(.ms-selected)',
88   - selectionSearchString = '#'+that.$container.attr('id')+' .ms-elem-selection.ms-selected';
89   -
90   - that.qs1 = $selectableSearch.quicksearch(selectableSearchString)
91   - .on('keydown', function(e){
92   - if (e.which === 40){
93   - that.$selectableUl.focus();
94   - return false;
95   - }
96   - });
97   -
98   - that.qs2 = $selectionSearch.quicksearch(selectionSearchString)
99   - .on('keydown', function(e){
100   - if (e.which == 40){
101   - that.$selectionUl.focus();
102   - return false;
103   - }
104   - });
105   - },
106   - afterSelect: function(){
107   - this.qs1.cache();
108   - this.qs2.cache();
109   - },
110   - afterDeselect: function(){
111   - this.qs1.cache();
112   - this.qs2.cache();
113   - }
114   - });// Used to create multi-select css style
115   -</script>
  16 + <br clear="all">
  17 + <br clear="all">
116 18 {% endblock %}
117 19 \ No newline at end of file
... ...
categories/views.py
... ... @@ -32,7 +32,6 @@ class IndexView(views.SuperuserRequiredMixin, LoginRequiredMixin, ListView):
32 32 template_name = 'categories/list.html'
33 33 context_object_name = 'categories'
34 34  
35   -
36 35 def get_queryset(self):
37 36 result = super(IndexView, self).get_queryset()
38 37  
... ... @@ -77,8 +76,6 @@ class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, LogMixin, Creat
77 76 template_name = 'categories/create.html'
78 77 success_url = reverse_lazy('categories:index')
79 78  
80   -
81   -
82 79 def get_initial(self):
83 80 initial = super(CreateCategory, self).get_initial()
84 81  
... ... @@ -89,19 +86,25 @@ class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, LogMixin, Creat
89 86 initial['description'] = category.description
90 87 initial['name'] = category.name
91 88 initial['visible'] = category.visible
92   -
93 89  
94 90 self.log_action = 'replicate'
95 91  
96 92 self.log_context['replicated_category_id'] = category.id
97 93 self.log_context['replicated_category_name'] = category.name
98 94 self.log_context['replicated_category_slug'] = category.slug
  95 +
99 96 return initial
100 97  
101 98 def get_context_data(self, **kwargs):
102 99 context = super(CreateCategory, self).get_context_data(**kwargs)
103 100 context['users_count'] = User.objects.all().count()
104 101 context['switch'] = True
  102 +
  103 + if self.kwargs.get('slug'):
  104 + context['title'] = _('Replicate Category')
  105 + else:
  106 + context['title'] = _('Create Category')
  107 +
105 108 return context
106 109  
107 110  
... ... @@ -145,7 +148,6 @@ class DeleteCategory(LogMixin, DeleteView):
145 148 model = Category
146 149 template_name = 'categories/delete.html'
147 150  
148   -
149 151 def delete(self, request, *args, **kwargs):
150 152 category = get_object_or_404(Category, slug = self.kwargs.get('slug'))
151 153 subjects = Subject.objects.filter(category = category)
... ... @@ -181,7 +183,6 @@ class UpdateCategory(LogMixin, UpdateView):
181 183 login_url = reverse_lazy("users:login")
182 184 redirect_field_name = 'next'
183 185  
184   -
185 186 def get_success_url(self):
186 187 self.log_context['category_id'] = self.object.id
187 188 self.log_context['category_name'] = self.object.name
... ... @@ -191,8 +192,15 @@ class UpdateCategory(LogMixin, UpdateView):
191 192  
192 193 objeto = self.object.name
193 194 messages.success(self.request, _('Category "%s" updated successfully!')%(objeto))
  195 +
194 196 return reverse_lazy('categories:index')
195 197  
  198 + def get_context_data(self, **kwargs):
  199 + context = super(UpdateCategory, self).get_context_data(**kwargs)
  200 + context['title'] = _('Update Category')
  201 +
  202 + return context
  203 +
196 204 @log_decorator_ajax('category', 'view', 'category')
197 205 def category_view_log(request, category):
198 206 action = request.GET.get('action')
... ...