From c1f7e0676fd934e7aeff0795d9d38fa0da359a83 Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Fri, 12 Aug 2016 17:11:15 -0300 Subject: [PATCH] Add botoes de insercao de Disp no padr do bootstrap --- sapl/compilacao/views.py | 30 ++++++++++++++----- sapl/static/js/compilacao_edit.js | 16 +++++----- sapl/static/styles/compilacao.scss | 17 +++++++++++ .../compilacao/ajax_actions_dinamic_edit.html | 23 ++++++++++++++ 4 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 sapl/templates/compilacao/ajax_actions_dinamic_edit.html diff --git a/sapl/compilacao/views.py b/sapl/compilacao/views.py index baa47a0fa..c08d36ea7 100644 --- a/sapl/compilacao/views.py +++ b/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 (%s)' % ( 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 (%s)' % ( 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 (%s)' % ( 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) diff --git a/sapl/static/js/compilacao_edit.js b/sapl/static/js/compilacao_edit.js index 3d1302f8d..b95a7f08a 100644 --- a/sapl/static/js/compilacao_edit.js +++ b/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); diff --git a/sapl/static/styles/compilacao.scss b/sapl/static/styles/compilacao.scss index 3c58ddb8b..564da9554 100644 --- a/sapl/static/styles/compilacao.scss +++ b/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; + + } + } + } } } diff --git a/sapl/templates/compilacao/ajax_actions_dinamic_edit.html b/sapl/templates/compilacao/ajax_actions_dinamic_edit.html new file mode 100644 index 000000000..efab7f4ee --- /dev/null +++ b/sapl/templates/compilacao/ajax_actions_dinamic_edit.html @@ -0,0 +1,23 @@ +{% load i18n %} + +
+ {% if object.dispositivo_subsequente == None %} + {% for inserts in allowed_inserts %} + {% if inserts.itens %} + +
+ + + +
+ {% endif %} + {% endfor %} + {%endif%} +