Browse Source

migra js das notas

pull/2485/head
Leandro Roberto 7 years ago
parent
commit
823e91ac11
  1. 2
      sapl-frontend/src/apps/compilacao/js/compilacao.js
  2. 14
      sapl-frontend/src/apps/compilacao/js/compilacao_notas.js
  3. 124
      sapl-frontend/src/apps/compilacao/js/compilacao_view.js
  4. 44
      sapl-frontend/src/apps/compilacao/main.js
  5. 4
      sapl/templates/base.html

2
sapl-frontend/src/apps/compilacao/js/compilacao.js

@ -168,7 +168,7 @@
$.get(opts['url_form'], function(data) { $.get(opts['url_form'], function(data) {
container_ds.html(data); container_ds.html(data);
var modal_ds = $('#modal-ds'); var modal_ds = $('#modal-ds');
OptionalCustomFrontEnd().init(); //OptionalCustomFrontEnd().init();
modal_ds.find("select[name='tipo_ta']").change(function(event) { modal_ds.find("select[name='tipo_ta']").change(function(event) {
var url = ''; var url = '';

14
sapl-frontend/src/apps/compilacao/js/compilacao_notas.js

@ -31,8 +31,7 @@ function onEventsDneExec(pk, model) {
} }
} }
function onSubmitEditNVForm(event) {
var onSubmitEditNVForm = function(event) {
var url = ''; var url = '';
var model = 'nota'; var model = 'nota';
@ -76,7 +75,7 @@ var onSubmitEditNVForm = function(event) {
} }
); );
} }
var onDelete = function(event) { function onDelete(event) {
var model = $(event).attr('model'); var model = $(event).attr('model');
@ -138,6 +137,9 @@ function onReadyNotasVides() {
}); });
} }
$(document).ready(function() { export default {
onReadyNotasVides() onEventsDneExec,
}); onSubmitEditNVForm,
onDelete,
onReadyNotasVides
}

124
sapl-frontend/src/apps/compilacao/js/compilacao_view.js

@ -1,8 +1,6 @@
let JsDiff = require('diff'); let JsDiff = require("diff");
function isElementInViewport(el) { function isElementInViewport(el) {
//special bonus for those using jQuery
if (typeof jQuery === "function" && el instanceof jQuery) { if (typeof jQuery === "function" && el instanceof jQuery) {
el = el[0]; el = el[0];
} }
@ -12,20 +10,19 @@ function isElementInViewport (el) {
return ( return (
rect.top >= 0 && rect.top >= 0 &&
rect.left >= 0 && rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */ rect.bottom <=
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */ (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
); );
} }
function textoMultiVigente(item, diff) { function textoMultiVigente(item, diff) {
var elv = null; var elv = null;
var ldpts = $(".dptt") var ldpts = $(".dptt");
for (var i = 0; i < ldpts.length; i++) { for (var i = 0; i < ldpts.length; i++) {
if ($(ldpts[i]).hasClass('displaynone')) if ($(ldpts[i]).hasClass("displaynone")) continue;
continue;
if (isElementInViewport(ldpts[i])) { if (isElementInViewport(ldpts[i])) {
if (i+1 < ldpts.length) if (i + 1 < ldpts.length) elv = ldpts[i + 1];
elv = ldpts[i+1];
else { else {
elv = ldpts[i]; elv = ldpts[i];
} }
@ -33,8 +30,8 @@ function textoMultiVigente(item, diff) {
} }
} }
$(".cp .tipo-vigencias a").removeClass("selected") $(".cp .tipo-vigencias a").removeClass("selected");
$(item).addClass("selected") $(item).addClass("selected");
$(".dptt.desativado").removeClass("displaynone"); $(".dptt.desativado").removeClass("displaynone");
$(".dtxt").removeClass("displaynone"); $(".dtxt").removeClass("displaynone");
$(".dtxt.diff").remove(); $(".dtxt.diff").remove();
@ -42,50 +39,53 @@ function textoMultiVigente(item, diff) {
if (diff) { if (diff) {
$(".dtxt[id^='da'").each(function() { $(".dtxt[id^='da'").each(function() {
if (
if ( $(this).html().search( /<\/\w+>/g ) > 0) $(this)
.html()
.search(/<\/\w+>/g) > 0
)
return; return;
var pk = $(this).attr('pk') var pk = $(this).attr("pk");
var pks = $(this).attr('pks') var pks = $(this).attr("pks");
var a = $('#d'+pks).contents().filter(function () { var a = $("#d" + pks)
.contents()
.filter(function() {
return this.nodeType === Node.TEXT_NODE; return this.nodeType === Node.TEXT_NODE;
}); });
var b = $('#da'+pk).contents().filter(function () { var b = $("#da" + pk)
.contents()
.filter(function() {
return this.nodeType === Node.TEXT_NODE; return this.nodeType === Node.TEXT_NODE;
}); });
var diff = JsDiff.diffWordsWithSpace($(a).text(), $(b).text()); var diff = JsDiff.diffWordsWithSpace($(a).text(), $(b).text());
if (diff.length > 0) { if (diff.length > 0) {
$('#d'+pks).closest('.desativado').addClass("displaynone"); $("#d" + pks)
.closest(".desativado")
.addClass("displaynone");
var clone = $('#da'+pk).clone();
$('#da'+pk).after( clone );
$('#da'+pk).addClass('displaynone');
$(clone).addClass('diff').html('');
var clone = $("#da" + pk).clone();
$("#da" + pk).after(clone);
$("#da" + pk).addClass("displaynone");
$(clone)
.addClass("diff")
.html("");
diff.forEach(function(part) { diff.forEach(function(part) {
var color = part.added ? '#018' : //var color = part.added ? "#018" : part.removed ? "#faa" : "";
part.removed ? '#faa' : '';
var span = document.createElement('span'); var span = document.createElement("span");
var value = part.value; var value = part.value;
if (part.removed) { if (part.removed) {
$(span).addClass('desativado') $(span).addClass("desativado");
value += ' '; value += " ";
} } else if (part.added) {
else if (part.added) { $(span).addClass("added");
$(span).addClass('added')
} }
span.appendChild(document.createTextNode(value)); span.appendChild(document.createTextNode(value));
@ -98,25 +98,28 @@ function textoMultiVigente(item, diff) {
if (elv) { if (elv) {
try { try {
$('html, body').animate({ $("html, body").animate(
scrollTop: $(elv).parent().offset().top - 60 {
}, 0); scrollTop:
} $(elv)
catch(err) { .parent()
.offset().top - 60
},
0
);
} catch (err) {
console.log(err);
} }
} }
} }
function textoVigente(item, link) { function textoVigente(item, link) {
var elv = null; var elv = null;
var ldpts = $(".dptt") var ldpts = $(".dptt");
for (var i = 0; i < ldpts.length; i++) { for (var i = 0; i < ldpts.length; i++) {
if ($(ldpts[i]).hasClass('displaynone')) if ($(ldpts[i]).hasClass("displaynone")) continue;
continue;
if (isElementInViewport(ldpts[i])) { if (isElementInViewport(ldpts[i])) {
if (i+1 < ldpts.length) if (i + 1 < ldpts.length) elv = ldpts[i + 1];
elv = ldpts[i+1];
else { else {
elv = ldpts[i]; elv = ldpts[i];
} }
@ -124,21 +127,26 @@ function textoVigente(item, link) {
} }
} }
$(".cp .tipo-vigencias a").removeClass("selected") $(".cp .tipo-vigencias a").removeClass("selected");
$(item).addClass("selected") $(item).addClass("selected");
$(".dptt.desativado").addClass("displaynone"); $(".dptt.desativado").addClass("displaynone");
$(".nota-alteracao").removeClass("displaynone"); $(".nota-alteracao").removeClass("displaynone");
if (!link) if (!link) $(".nota-alteracao").addClass("displaynone");
$(".nota-alteracao").addClass("displaynone");
if (elv) { if (elv) {
try { try {
$('html, body').animate({ $("html, body").animate(
scrollTop: $(elv).parent().offset().top - 60 {
}, 0); scrollTop:
} $(elv)
catch(err) { .parent()
.offset().top - 60
},
0
);
} catch (err) {
console.log(err);
} }
} }
} }
@ -147,4 +155,4 @@ export default {
isElementInViewport, isElementInViewport,
textoMultiVigente, textoMultiVigente,
textoVigente textoVigente
} };

44
sapl-frontend/src/apps/compilacao/main.js

@ -1,40 +1,30 @@
//import JsDiff from "diff/dist/diff"; // TODO: migrar compilacao para VueJs
import compilacao from "./js/compilacao"; import compilacao from "./js/compilacao";
import compilacao_view from "./js/compilacao_view"; import compilacao_view from "./js/compilacao_view";
import compilacao_notas from "./js/compilacao_notas";
import _ from "lodash"; import _ from "lodash";
//import "./js/compilacao_notas";
//import "./js/compilacao_edit"; //import "./js/compilacao_edit";
//require("imports-loader?this=>window!./js/compilacao.js"); _.forEach(_.merge(_.merge(compilacao, compilacao_notas),compilacao_view), function(func, key) {
//require("imports-loader?this=>window!./js/compilacao_edit.js");
//require("imports-loader?this=>window!./js/compilacao_notas.js");
//require("imports-loader?this=>window!./js/compilacao_view.js");
_.forEach(compilacao, function (func, key) {
window[key] = func; window[key] = func;
});
_.forEach(compilacao_view, function (func, key) {
window[key] = func;
}); });
$(document).ready(function() { $(document).ready(function() {
setTimeout(function() { setTimeout(function() {
var href = location.href.split('#') var href = location.href.split("#");
if (href.length == 2) { if (href.length == 2) {
try { try {
$('html, body').animate({ $("html, body").animate(
scrollTop: $('#dptt' + href[1] ).offset().top - window.innerHeight / 9 {
}, 0); scrollTop:
} $("#dptt" + href[1]).offset().top - window.innerHeight / 9
catch(err) { },
0
);
} catch (err) {
console.log(err);
} }
} }
}, 100); }, 100);
@ -47,10 +37,10 @@ $(document).ready(function() {
}); });
$(".dpt.bloco_alteracao .dpt").each(function() { $(".dpt.bloco_alteracao .dpt").each(function() {
var nivel = parseInt($(this).attr('nivel')); var nivel = parseInt($(this).attr("nivel"));
$(this).css("z-index", 15 - nivel);
$(this).css('z-index', 15-nivel)
}); });
onReadyNotasVides();
}); });

4
sapl/templates/base.html

@ -252,9 +252,7 @@
<!-- Placed at the end of the document so the pages load faster --> <!-- Placed at the end of the document so the pages load faster -->
<script type="text/javascript" src="{% static 'js/jquery.runner.js' %}"></script>
<script type="text/javascript" src="{% static 'jsdiff/diff.min.js' %}"></script>
@ -262,6 +260,8 @@
{# Incorporado em sapl-frontend#} {# Incorporado em sapl-frontend#}
<script type="text/javascript" src="{% static 'js/jquery.runner.js' %}"></script>
<script type="text/javascript" src="{% static 'jsdiff/diff.min.js' %}"></script>
<script type="text/javascript" src="{% static 'js/app.js' %}"></script> <script type="text/javascript" src="{% static 'js/app.js' %}"></script>
<script src="{% static 'tinymce/tinymce.min.js' %}"></script> <script src="{% static 'tinymce/tinymce.min.js' %}"></script>
<script type="text/javascript" src="{% static 'jquery-ui/jquery-ui.min.js' %}"></script> <script type="text/javascript" src="{% static 'jquery-ui/jquery-ui.min.js' %}"></script>

Loading…
Cancel
Save