From bd46c83fb692a4d3225c36df1d79609cffbf1e58 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 21 Aug 2017 11:55:01 +0200 Subject: [PATCH] BrowseImportantPaste: Fixed a bug where onClickListener was not set when the table was only 1 page long --- .../templates/important_paste_by_module.html | 89 ++++++++++--------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/var/www/modules/browsepastes/templates/important_paste_by_module.html b/var/www/modules/browsepastes/templates/important_paste_by_module.html index 14048bbb..15fec49a 100644 --- a/var/www/modules/browsepastes/templates/important_paste_by_module.html +++ b/var/www/modules/browsepastes/templates/important_paste_by_module.html @@ -120,6 +120,10 @@ $("#myTable_"+moduleName).attr('data-numElem', "{{ all_path|length }}"); $(document).ready(function(){ $('[data-toggle="tooltip"]').tooltip(); + $("[data-toggle='modal']").off('click.openmodal').on("click.openmodal", function (event) { + //get_html_and_update_modal(event); + get_html_and_update_modal(event, $(this)); + }); search_table = $('#myTable_'+moduleName).DataTable({ "order": [[ 2, "desc" ]] }); @@ -182,6 +186,50 @@ $(document).ready(function(){ $("#load-more-button").hide(); } + function get_html_and_update_modal(event, truemodal) { + event.preventDefault(); + + var modal=truemodal; + var url = " {{ url_for('showsavedpastes.showpreviewpaste') }}?paste=" + modal.attr('data-path') + "&num=" + modal.attr('data-num'); + last_clicked_paste = modal.attr('data-num'); + $.get(url, function (data) { + + // verify that the reveived data is really the current clicked paste. Otherwise, ignore it. + var received_num = parseInt(data.split("|num|")[1]); + if (received_num == last_clicked_paste && can_change_modal_content) { + can_change_modal_content = false; + + // clear data by removing html, body, head tags. prevent dark modal background stack bug. + var cleared_data = data.split("")[1].split("")[0]; + $("#mymodalbody").html(cleared_data); + + var button = $(''); + button.tooltip(); + $("#mymodalbody").children(".panel-default").append(button); + + $("#button_show_path").attr('href', $(modal).attr('data-url')); + $("#button_show_path").show('fast'); + $("#loading-gif-modal").css("visibility", "hidden"); // Hide the loading GIF + if ($("[data-initsize]").attr('data-initsize') < char_to_display) { // All the content is displayed + nothing_to_display(); + } + // On click, donwload all paste's content + $("#load-more-button").on("click", function (event) { + if (complete_paste == null) { //Donwload only once + $.get("{{ url_for('showsavedpastes.getmoredata') }}"+"?paste="+$(modal).attr('data-path'), function(data, status){ + complete_paste = data; + update_preview(); + }); + } else { + update_preview(); + } + }); + } else if (can_change_modal_content) { + $("#mymodalbody").html("Ignoring previous not finished query of paste #" + received_num); + } + }); + } + // Use to bind the button with the new displayed data // (The bind do not happens if the dataTable is in tabs and the clicked data is in another page) @@ -191,46 +239,7 @@ $(document).ready(function(){ $('[data-toggle="tooltip"]').tooltip(); // On click, get html content from url and update the corresponding modal $("[data-toggle='modal']").off('click.openmodal').on("click.openmodal", function (event) { - event.preventDefault(); - var modal=$(this); - var url = " {{ url_for('showsavedpastes.showpreviewpaste') }}?paste=" + $(this).attr('data-path') + "&num=" + $(this).attr('data-num'); - last_clicked_paste = $(this).attr('data-num'); - $.get(url, function (data) { - - // verify that the reveived data is really the current clicked paste. Otherwise, ignore it. - var received_num = parseInt(data.split("|num|")[1]); - if (received_num == last_clicked_paste && can_change_modal_content) { - can_change_modal_content = false; - - // clear data by removing html, body, head tags. prevent dark modal background stack bug. - var cleared_data = data.split("")[1].split("")[0]; - $("#mymodalbody").html(cleared_data); - - var button = $(''); - button.tooltip(); - $("#mymodalbody").children(".panel-default").append(button); - - $("#button_show_path").attr('href', $(modal).attr('data-url')); - $("#button_show_path").show('fast'); - $("#loading-gif-modal").css("visibility", "hidden"); // Hide the loading GIF - if ($("[data-initsize]").attr('data-initsize') < char_to_display) { // All the content is displayed - nothing_to_display(); - } - // On click, donwload all paste's content - $("#load-more-button").on("click", function (event) { - if (complete_paste == null) { //Donwload only once - $.get("{{ url_for('showsavedpastes.getmoredata') }}"+"?paste="+$(modal).attr('data-path'), function(data, status){ - complete_paste = data; - update_preview(); - }); - } else { - update_preview(); - } - }); - } else if (can_change_modal_content) { - $("#mymodalbody").html("Ignoring previous not finished query of paste #" + received_num); - } - }); + get_html_and_update_modal(event, $(this)); }); } );