X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/514e98aeae05045d0086aae39960124a572e646f..0fd55a38c4873d5916a3553d7510b9308f4eee6d:/platforma/static/js/main.js diff --git a/platforma/static/js/main.js b/platforma/static/js/main.js index 3c1a3c00..f94e04ee 100644 --- a/platforma/static/js/main.js +++ b/platforma/static/js/main.js @@ -328,8 +328,8 @@ function reverseTransform(editor, cont, errorCont, dontBlock) { $.blockUI({message: 'Ładowanie...'}); } setTimeout(function() { - html2xml({ - xml: serializer.serializeToString($('#html-view div').get(0)), + html2text({ + element: $('#html-view div').get(0), success: function(text) { editor.setCode(text); if (!dontBlock) { @@ -398,7 +398,7 @@ function html(element) { return true; } - var ANNOT_ALLOWED = ['wyroznienie']; + var ANNOT_ALLOWED = ['wyroznienie', 'slowo_obce', 'osoba']; function html2plainText(fragment) { var text = ""; @@ -595,9 +595,9 @@ function html(element) { var serializer = new XMLSerializer(); - html2xml({ - xml: serializer.serializeToString($box[0]), - inner: true, + html2text({ + element: $box[0], + stripOuter: true, success: function(text) { $('textarea', $overlay).val($.trim(text)); @@ -616,7 +616,7 @@ function html(element) { xml2html({ xml: '<' + nodeName + '>' + insertedText + '', success: function(element) { - $box.html($(element).html()); + $origin.html($(element).html()); $overlay.remove(); }, error: function(text) { @@ -659,6 +659,13 @@ function html(element) { if (!editable.hasClass('active')) { editable.addClass('active').append(button); } + if (editable.is('.annotation-inline-box')) { + $('*[x-annotation-box]', editable) + .css({position: 'absolute', left: event.clientX - editable.offset().left + 5, top: event.clientY - editable.offset().top + 5}) + .show(); + } else { + $('*[x-annotation-box]').hide(); + } }); $('.motyw').live('click', function() { @@ -676,6 +683,78 @@ function html(element) { }); } +/* + * History + */ + +function refreshHistory(callback){ + $.blockUI({ + message: 'Odświeżanie historii...' + }); + + $.ajax({ + url: document.location.href + '/history', + dataType: 'json', + error: function() { + $('#history-view .message-box').html('Nie udało się odświeżyć historii').show(); + $.unblockUI(); + }, + success: function(data) { + $('#history-view .message-box').hide(); + var changes_list = $('#changes-list'); + changes_list.html(''); + + $.each(data, function() { + var val = this[0]; + changes_list.append('' + +'' + + '' + +''+ this[0]+'' + +''+ this[3]+'' + +''+ this[2]+'' + +''+ this[1]+'') + }); + $.unblockUI(); + if(callback) callback(); + } + }); +}; + +function historyDiff(callback) { + var changelist = $('#changes-list'); + var rev_a = $("input[name='rev_from']:checked", changelist); + var rev_b = $("input[name='rev_to']:checked", changelist); + + if (rev_a.length != 1 || rev_b.length != 1) { + window.alert("Musisz zaznaczyć dwie wersje do porównania."); + return false; + } + + if (rev_a.val() == rev_b.val()) { + window.alert("Musisz zaznaczyć dwie różne wersje do porównania."); + return false; + } + + $.blockUI({ + message: 'Wczytywanie porównania...' + }); + + $.ajax({ + url: document.location.href + '/diff/'+rev_a.val() + '/'+ rev_b.val(), + dataType: 'html', + error: function() { + $.unblockUI(); + window.alert('Nie udało się wykonać porównania :(.') + }, + success: function(data) { + $.unblockUI(); + var diffview = $('#diff-view'); + diffview.html(data); + diffview.show(); + } + }); +} + $(function() { gallery('#sidebar', $('#document-meta .gallery').html()); @@ -684,13 +763,14 @@ $(function() { CodeMirror.fromTextArea('id_text', { parserfile: 'parsexml.js', path: STATIC_URL + "js/lib/codemirror/", - stylesheet: STATIC_URL + "css/xmlcolors.css", + stylesheet: STATIC_URL + "css/xmlcolors_15032010.css", parserConfig: { useHTMLKludges: false }, - iframeClass: 'xml-iframe', + iframeClass: 'xml-iframe', textWrapping: true, - lineNumbers: true, + lineNumbers: true, + width: "100%", tabMode: 'spaces', indentUnit: 0, initCallback: function(editor) { @@ -747,29 +827,31 @@ $(function() { $('#save-cancel').click(function() { $.unblockUI(); }); - - function changeTab(callback) { - if ($('#simple-view-tab').hasClass('active')) { - return; - } - $('#simple-view-tab').addClass('active'); - $('#source-view-tab').removeClass('active'); - $('#source-editor').hide(); - $('#simple-editor').show(); + + var tabs = $('ol#tabs li'); + + tabs.click(function(event, callback) { + tabs.removeClass('active'); + $('.editor').hide(); + $(this).addClass('active'); + $('#' + $(this).attr('ui:related')).show(); + $(this).trigger('wl:tabload', callback); + }); + + + $('#simple-view-tab').bind('wl:tabload', function(event, callback) { transform(editor, callback); - } - $('#simple-view-tab').click(function() { changeTab(); }); - - $('#source-view-tab').click(function() { - if ($(this).hasClass('active')) { - return; - } - $(this).addClass('active'); - $('#simple-view-tab').removeClass('active'); - $('#simple-editor').hide(); - $('#source-editor').show(); - reverseTransform(editor); }); + + $('#source-view-tab').bind('wl:tabload', function(event, callback) { + reverseTransform(editor, callback); + }); + + $('#history-view-tab').bind('wl:tabload', function(event, callback) { + refreshHistory(callback); + }); + + $('#make-diff-button').click(historyDiff); $('#source-editor .toolbar button').click(function(event) { event.preventDefault(); @@ -777,7 +859,7 @@ $(function() { scriptletCenter.scriptlets[$(this).attr('ui:action')](editor, params); }); - $('.toolbar select').change(function() { + $('.toolbar select').change(function(event) { var slug = $(this).val(); $('.toolbar-buttons-container').hide().filter('[data-group=' + slug + ']').show(); @@ -787,7 +869,12 @@ $(function() { $('.toolbar-buttons-container').hide(); $('.toolbar select').change(); - changeTab(function() { $('#loading-overlay').fadeOut() }, function() { $('#loading-overlay').fadeOut() }, true) + + $('#simple-view-tab').trigger('click', + function() { + $('#loading-overlay').fadeOut(); + return false; + }); } }); @@ -800,15 +887,18 @@ $(function() { $('.vsplitbar').click(function() { if ($('#sidebar').width() == 0) { $('#sidebar').width(480).css({right: 0}).show(); - $('#source-editor, #simple-editor').css({right: 495}); + $('#editor .editor').css({right: 495}); $('.vsplitbar').css({right: 480}).addClass('active'); } else { $('#sidebar').width(0).hide(); - $('#source-editor, #simple-editor').css({right: 15}); + $('#editor .editor').css({right: 15}); $('.vsplitbar').css({right: 0}).removeClass('active'); } $(window).resize(); }); - + + $(window).bind('beforeunload', function(event) { + return "Na stronie mogą być niezapisane zmiany."; + }); });