Browse Source

Add botoes de insercao de Disp no padr do bootstrap

pull/590/head
LeandroRoberto 9 years ago
parent
commit
c1f7e0676f
  1. 30
      sapl/compilacao/views.py
  2. 16
      sapl/static/js/compilacao_edit.js
  3. 17
      sapl/static/styles/compilacao.scss
  4. 23
      sapl/templates/compilacao/ajax_actions_dinamic_edit.html

30
sapl/compilacao/views.py

@ -15,6 +15,7 @@ from django.http.response import (HttpResponse, HttpResponseRedirect,
from django.shortcuts import get_object_or_404, redirect
from django.utils.dateparse import parse_date
from django.utils.decorators import method_decorator
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _
from django.views.generic.base import TemplateView
from django.views.generic.detail import DetailView
@ -1464,7 +1465,7 @@ class ActionDeleteDispositivoMixin(ActionsCommonsMixin):
class ActionDispositivoCreateMixin(ActionsCommonsMixin):
def json_provaveis_inserts(self, context=None):
def allowed_inserts(self):
request = self.request
try:
if request and 'perfil_estrutural' not in request.session:
@ -1484,15 +1485,15 @@ class ActionDispositivoCreateMixin(ActionsCommonsMixin):
else:
prox_possivel = None
result = [{'tipo_insert': _('Inserir Depois'),
result = [{'tipo_insert': force_text(_('Inserir Depois')),
'icone': '↷ ',
'action': 'add_next',
'itens': []},
{'tipo_insert': _('Inserir Dentro'),
{'tipo_insert': force_text(_('Inserir Dentro')),
'icone': '⇲ ',
'action': 'add_in',
'itens': []},
{'tipo_insert': _('Inserir Antes'),
{'tipo_insert': force_text(_('Inserir Antes')),
'icone': '↶ ',
'action': 'add_prior',
'itens': []}
@ -1528,7 +1529,7 @@ class ActionDispositivoCreateMixin(ActionsCommonsMixin):
'class_css': dp.tipo_dispositivo.class_css,
'tipo_pk': dp.tipo_dispositivo.pk,
'variacao': 0,
'provavel': '%s (%s)' % (
'provavel': '%s <small>(%s)</small>' % (
dp.rotulo_padrao(local_insert=1),
dp.tipo_dispositivo.nome,),
'dispositivo_base': base.pk})
@ -1556,7 +1557,7 @@ class ActionDispositivoCreateMixin(ActionsCommonsMixin):
r.append({'class_css': dp.tipo_dispositivo.class_css,
'tipo_pk': dp.tipo_dispositivo.pk,
'variacao': flag_variacao,
'provavel': '%s (%s)' % (
'provavel': '%s <small>(%s)</small>' % (
dp.rotulo_padrao(local_insert),
dp.tipo_dispositivo.nome,),
'dispositivo_base': base.pk})
@ -1655,7 +1656,7 @@ class ActionDispositivoCreateMixin(ActionsCommonsMixin):
r = [{'class_css': td.class_css,
'tipo_pk': td.pk,
'variacao': 0,
'provavel': '%s (%s)' % (
'provavel': '%s <small>(%s)</small>' % (
base.rotulo_padrao(1, paradentro),
td.nome,),
'dispositivo_base': base.pk}]
@ -1684,10 +1685,12 @@ class ActionDispositivoCreateMixin(ActionsCommonsMixin):
# tipb.dispositivo_de_alteracao:
# result.pop()
return result
except Exception as e:
print(e)
return result
return {}
def set_dvt(self, context):
# Dispositivo de Vigência do Texto Original e de Dpts Alterados
@ -2075,6 +2078,17 @@ class DispositivoDinamicEditView(
self.form_class = DispositivoEdicaoBasicaForm
context = self.get_context_data()
return self.render_to_response(context)
elif action.startswith('get_actions'):
self.form_class = None
self.template_name = 'compilacao/ajax_actions_dinamic_edit.html'
self.object = Dispositivo.objects.get(
pk=self.kwargs['dispositivo_id'])
context = {}
context['object'] = self.object
context['allowed_inserts'] = self.allowed_inserts()
return self.render_to_response(context)
elif action.startswith('json_'):
context = self.get_context_data()
return self.render_to_json_response(context)

16
sapl/static/js/compilacao_edit.js

@ -38,6 +38,8 @@ function DispositivoEdit() {
return;
}
instance.clearEditSelected();
instance.loadActionsEdit(dpt);
dpt.on('get_form_base', function () {
var _this = $(this);
@ -72,26 +74,26 @@ function DispositivoEdit() {
});
}
});
instance.loadActionsProvaveisInserts(pk)
});
instance.loadForm(dpt, 'get_form_base');
}
instance.loadActionsProvaveisInserts = function(pk) {
var url = pk+'/refresh?action=json_provaveis_inserts';
instance.waitShow();
instance.loadActionsEdit = function(dpt) {
var pk = dpt.attr('pk');
var url = pk+'/refresh?action=get_actions';
$.get(url).done(function(data) {
console.log(data);
dpt.find('.dpt-actions').first().html(data);
});
}
instance.loadForm = function(dpt, trigger) {
var pk = dpt.attr('pk');
if (editortype == "construct")
return;
var dpt_form = dpt.children().filter('.dpt-form');
if (dpt_form.length == 1) {
var pk = dpt.attr('pk');
var url = pk+'/refresh?action='+trigger;
$.get(url).done(function(data) {
dpt_form.html(data);

17
sapl/static/styles/compilacao.scss

@ -702,6 +702,23 @@ a:link:after, a:visited:after {
& > .dpt-actions-fixed {
display: none;
}
.dropdown-menu {
right: auto !important;
left: 0;
padding: 2px 0;
& > .top.arrow {
right: 88%;
left: auto;
}
li {
a {
padding-top: 2px;
padding-bottom: 2px;
}
}
}
}
}

23
sapl/templates/compilacao/ajax_actions_dinamic_edit.html

@ -0,0 +1,23 @@
{% load i18n %}
<div class="btn-group" role="group">
{% if object.dispositivo_subsequente == None %}
{% for inserts in allowed_inserts %}
{% if inserts.itens %}
<div class="btn-group" role="group">
<button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
{{inserts.icone|safe}}<span>{{inserts.tipo_insert}}</span>
</button>
<ul class="dropdown-menu">
<div class="arrow top"></div>
{% for item in inserts.itens %}
<li><a class="btn-inserts btn-action" action="{{inserts.action}}" pk="{{item.dispositivo_base}}" variacao="{{item.variacao}}" tipo_pk="{{item.tipo_pk}}">{{item.provavel|safe}}</a></li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endfor %}
{%endif%}
</div>
Loading…
Cancel
Save