From eb06224fc3a8b348abc593515b627a3f9e81acd4 Mon Sep 17 00:00:00 2001 From: rarog Date: Mon, 6 Nov 2017 00:49:18 +0100 Subject: [PATCH] Issue #15 - more work on tables - Ensure that after suggestion deletion the entry is redrawn in the main table. (Possible Details button colour change) - Don't jump to page 1 when an item is redrawn in the main table. - Don't jump to page 1 of suggestions, when a vote is cast, a suggestion is added, edited or deleted. --- public/js/translations.js | 9 +++++---- public/js/translations.min.js | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/public/js/translations.js b/public/js/translations.js index c669eef..42cd8a1 100644 --- a/public/js/translations.js +++ b/public/js/translations.js @@ -121,7 +121,7 @@ function refreshTranslationEntry(app, resource, entry) { table.row("#translation-" + entry) .data(data[0]) - .draw(); + .draw(false); hideModalSpinner(true); enableBootstrapTooltips(); @@ -261,7 +261,7 @@ $("#modalContainer").on("click", ".suggestionVote", function(event) { $("#modalContainer #suggestions").DataTable() .row("#suggestion-" + suggestion) .data(data["suggestion"]) - .draw(); + .draw(false); enableBootstrapTooltips(); } else { addModalAlertMessage(); @@ -336,7 +336,7 @@ $("#modalContainer").on("click", ".suggestionAddEditSubmit", function(event) { table.row("#suggestion-" + suggestion) .data(data["suggestion"]); } - table.draw(); + table.draw(false); $("#modalContainer #suggestionAddEdit").collapse("hide"); enableBootstrapTooltips(); @@ -381,10 +381,11 @@ $("#modalContainer").on("click", ".suggestionDelete", function(event) { var table = $("#modalContainer #suggestions").DataTable(); table.row("#suggestion-" + suggestion) .remove(); - table.draw(); + table.draw(false); } $("#modalContainer #suggestionAddEdit").collapse("hide"); + refreshTranslation = true; } else { addModalAlertMessage(); } diff --git a/public/js/translations.min.js b/public/js/translations.min.js index 02cd77f..bf19640 100644 --- a/public/js/translations.min.js +++ b/public/js/translations.min.js @@ -3,4 +3,4 @@ * @copyright Copyright (c) 2017 Andrej Sinicyn * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License version 3 or later */ -var curResources=resources;var refreshTranslation=false;function enableBootstrapTooltips(){$(function(){$('[data-toggle="tooltip"]').tooltip({container:"body"})})}function hideSelectionHint(a){var b=$("#selectionHint");if(a){b.addClass("hidden")}else{b.removeClass("hidden")}}function hideSpinner(a){var b=$("#spinner");if(a){b.addClass("hidden")}else{b.removeClass("hidden")}}function hideTranslationRow(a){var c=$("#translationRow");if(a){c.addClass("hidden");$("translationTableBody").empty()}else{c.removeClass("hidden");var b=$("#translations").DataTable()}}function setSelectionNeededState(){hideSelectionHint(false);hideSpinner(true);hideTranslationRow(true)}function showModalError(){$("#modalError").modal()}function hideModalSpinner(a){var b=$("#modalSpinner");if(a){b.css("display","none")}else{b.css("display","block")}}function hideBootstrapTooltips(){$(".tooltip").tooltip("hide")}function addModalAlertMessage(){var a=$("#modalMessages");a.append('
×\' . $this->translate(\'Error:\') . \' An unexpected error has occurred.
');$("#modalDetails").animate({scrollTop:a.offset().top})}function showSuggestionAddEdit(h,c){var e=$("#modalContainer #suggestionAddEdit");var d=$("#modalContainer #suggestionAddEdit");var b=$("#modalContainer #suggestionAddEdit #suggestionDeleteButton");var a=null;e.find(".suggestionAddEditSubmit").data("suggestionid",h);e.find(".suggestionDelete").data("suggestionid",h);if($.type(c)==="object"){b.removeClass("disabled")}else{b.addClass("disabled")}if(suggestionType=="String"){var f="";if(($.type(c)==="object")&&($.type(c.value)==="string")){f=c.value}var g=$("#modalContainer #suggestionAddEditText");g.val(f);a=g}e.collapse("show");$("#modalDetails").animate({scrollTop:e.offset().top});if(a!==null){a.focus()}}function refreshTranslationEntry(c,b,a){hideModalSpinner(false);$.ajax({url:translationsPath+"/app/"+c+"/resource/"+b+"/entry/"+a,dataType:"json",method:"GET"}).done(function(e){if($.type(e)=="array"&&e.length==1){var d=$("#translations").DataTable();d.row("#translation-"+a).data(e[0]).draw();hideModalSpinner(true);enableBootstrapTooltips()}else{hideModalSpinner(true);showModalError()}}).fail(function(d,f,e){hideModalSpinner(true);showModalError()})}$("#showAll").on("change",function(a){var b=$("#app");b.selectpicker("deselectAll");$("option",b).remove();curApps=(a.target.checked)?appsAll:apps;curResources=(a.target.checked)?resourcesAll:resources;$.each(curApps,function(c,d){b.append('")})});$("#app").on("changed.bs.select",function(e,d,f,a){setSelectionNeededState();var c=$("#resource");$("option",c).remove();if(f){var b=$(this).val();if(b in curResources){$.each(curResources[b],function(g,h){c.append('")})}}c.selectpicker("refresh")});$("#resource").on("changed.bs.select",function(c,b,e,a){if(e){hideSelectionHint(true);hideSpinner(false);hideTranslationRow(true);var f=$("#app").val();var d=$(this).val();$.ajax({url:translationsPath+"/app/"+f+"/resource/"+d,dataType:"json",method:"GET"}).done(function(h){var g=$("#translations").DataTable();g.clear().rows.add(h).draw();hideSelectionHint(true);hideSpinner(true);hideTranslationRow(false);enableBootstrapTooltips()}).fail(function(g,i,h){setSelectionNeededState()})}else{setSelectionNeededState()}});$("#translations").on("click",".translationDetails",function(b){var d=$("#app").val();var c=$("#resource").val();var a=$(b.target).data("entryid");$.ajax({url:detailsPath+"/app/"+d+"/resource/"+c+"/entry/"+a,dataType:"json",method:"GET"}).done(function(e){if($.type(e)=="object"&&e.modal){$("#modalContainer").html(e.modal);$("#modalDetails").on("shown.bs.modal",function(f){initSuggestions();$("#modalContainer #suggestions").DataTable().rows.add(suggestionData).draw();enableBootstrapTooltips()}).on("show.bs.modal",function(f){refreshTranslation=false}).on("hidden.bs.modal",function(f){$("#modalContainer #suggestions").DataTable().destroy();if(refreshTranslation){refreshTranslationEntry(d,c,a)}enableBootstrapTooltips()}).modal()}else{showModalError()}}).fail(function(e,g,f){showModalError()})});$("#modalContainer").on("click",".suggestionVote",function(d){var c=$(this);if(c.hasClass("disabled")){return}var f=$("#app").val();var e=$("#resource").val();var a=c.data("suggestionid");var b=c.data("vote");hideBootstrapTooltips();hideModalSpinner(false);$.ajax({url:suggestionvotePath+"/app/"+f+"/resource/"+e+"/entry/"+suggestionEntryId+"/suggestion/"+a+"/vote/"+b,dataType:"json",method:"GET"}).done(function(g){if($.type(g)=="object"&&g.suggestion){$("#modalContainer #suggestions").DataTable().row("#suggestion-"+a).data(g.suggestion).draw();enableBootstrapTooltips()}else{addModalAlertMessage()}hideModalSpinner(true)}).fail(function(g,i,h){addModalAlertMessage();hideModalSpinner(true)})});$("#modalContainer").on("click",".suggestionEdit",function(d){var b=$(this);if(b.hasClass("disabled")){return}var e=0;var a=b.data("suggestion");if($.type(a)==="object"&&$.type(a.id)==="number"){e=a.id}else{a=null}hideBootstrapTooltips();var c=$("#modalContainer #suggestionAddEdit");if(c.hasClass("in")){c.one("hidden.bs.collapse",function(){showSuggestionAddEdit(e,a)}).collapse("hide")}else{showSuggestionAddEdit(e,a)}});$("#modalContainer").on("click",".suggestionAddEditSubmit",function(c){var b=$(this);if(b.hasClass("disabled")){return}var f=$("#app").val();var e=$("#resource").val();var a=b.data("suggestionid");var d={};if(suggestionType=="String"){d.value=$("#modalContainer #suggestionAddEditText").val()}hideBootstrapTooltips();hideModalSpinner(false);$.ajax({url:suggestionaddeditPath+"/app/"+f+"/resource/"+e+"/entry/"+suggestionEntryId+"/suggestion/"+a,data:d,dataType:"json",method:"POST"}).done(function(h){if($.type(h)=="object"&&h.suggestion){var g=$("#modalContainer #suggestions").DataTable();if(a==0){g.row.add(h.suggestion)}else{g.row("#suggestion-"+a).data(h.suggestion)}g.draw();$("#modalContainer #suggestionAddEdit").collapse("hide");enableBootstrapTooltips();refreshTranslation=true}else{addModalAlertMessage()}hideModalSpinner(true)}).fail(function(g,i,h){addModalAlertMessage();hideModalSpinner(true)})});$("#modalContainer").on("click",".suggestionDelete",function(c){var b=$(this);if(b.hasClass("disabled")){return}var e=$("#app").val();var d=$("#resource").val();var a=$(this).data("suggestionid");if(a==0){return}hideBootstrapTooltips();hideModalSpinner(false);$.ajax({url:suggestiondeletePath+"/app/"+e+"/resource/"+d+"/entry/"+suggestionEntryId+"/suggestion/"+a,dataType:"json",method:"GET"}).done(function(g){if(($.type(g)=="object")&&("deleted" in g)){if(g.deleted){var f=$("#modalContainer #suggestions").DataTable();f.row("#suggestion-"+a).remove();f.draw()}$("#modalContainer #suggestionAddEdit").collapse("hide")}else{addModalAlertMessage()}hideModalSpinner(true)}).fail(function(f,h,g){addModalAlertMessage();hideModalSpinner(true)})});$("#modalContainer").on("click",".suggestionAccept",function(b){var d=$("#app").val();var c=$("#resource").val();var a=$(this).data("suggestionid");hideBootstrapTooltips();hideModalSpinner(false);$.ajax({url:suggestionacceptPath+"/app/"+d+"/resource/"+c+"/entry/"+suggestionEntryId+"/suggestion/"+a,dataType:"json",method:"GET"}).done(function(e){if(($.type(e)=="object")&&("accepted" in e)){if(e.accepted){refreshTranslation=true}$("#modalDetails").modal("hide")}else{addModalAlertMessage()}hideModalSpinner(true)}).fail(function(e,g,f){addModalAlertMessage();hideModalSpinner(true)})}); \ No newline at end of file +var curResources=resources;var refreshTranslation=false;function enableBootstrapTooltips(){$(function(){$('[data-toggle="tooltip"]').tooltip({container:"body"})})}function hideSelectionHint(a){var b=$("#selectionHint");if(a){b.addClass("hidden")}else{b.removeClass("hidden")}}function hideSpinner(a){var b=$("#spinner");if(a){b.addClass("hidden")}else{b.removeClass("hidden")}}function hideTranslationRow(a){var c=$("#translationRow");if(a){c.addClass("hidden");$("translationTableBody").empty()}else{c.removeClass("hidden");var b=$("#translations").DataTable()}}function setSelectionNeededState(){hideSelectionHint(false);hideSpinner(true);hideTranslationRow(true)}function showModalError(){$("#modalError").modal()}function hideModalSpinner(a){var b=$("#modalSpinner");if(a){b.css("display","none")}else{b.css("display","block")}}function hideBootstrapTooltips(){$(".tooltip").tooltip("hide")}function addModalAlertMessage(){var a=$("#modalMessages");a.append('
×\' . $this->translate(\'Error:\') . \' An unexpected error has occurred.
');$("#modalDetails").animate({scrollTop:a.offset().top})}function showSuggestionAddEdit(h,c){var e=$("#modalContainer #suggestionAddEdit");var d=$("#modalContainer #suggestionAddEdit");var b=$("#modalContainer #suggestionAddEdit #suggestionDeleteButton");var a=null;e.find(".suggestionAddEditSubmit").data("suggestionid",h);e.find(".suggestionDelete").data("suggestionid",h);if($.type(c)==="object"){b.removeClass("disabled")}else{b.addClass("disabled")}if(suggestionType=="String"){var f="";if(($.type(c)==="object")&&($.type(c.value)==="string")){f=c.value}var g=$("#modalContainer #suggestionAddEditText");g.val(f);a=g}e.collapse("show");$("#modalDetails").animate({scrollTop:e.offset().top});if(a!==null){a.focus()}}function refreshTranslationEntry(c,b,a){hideModalSpinner(false);$.ajax({url:translationsPath+"/app/"+c+"/resource/"+b+"/entry/"+a,dataType:"json",method:"GET"}).done(function(e){if($.type(e)=="array"&&e.length==1){var d=$("#translations").DataTable();d.row("#translation-"+a).data(e[0]).draw(false);hideModalSpinner(true);enableBootstrapTooltips()}else{hideModalSpinner(true);showModalError()}}).fail(function(d,f,e){hideModalSpinner(true);showModalError()})}$("#showAll").on("change",function(a){var b=$("#app");b.selectpicker("deselectAll");$("option",b).remove();curApps=(a.target.checked)?appsAll:apps;curResources=(a.target.checked)?resourcesAll:resources;$.each(curApps,function(c,d){b.append('")})});$("#app").on("changed.bs.select",function(e,d,f,a){setSelectionNeededState();var c=$("#resource");$("option",c).remove();if(f){var b=$(this).val();if(b in curResources){$.each(curResources[b],function(g,h){c.append('")})}}c.selectpicker("refresh")});$("#resource").on("changed.bs.select",function(c,b,e,a){if(e){hideSelectionHint(true);hideSpinner(false);hideTranslationRow(true);var f=$("#app").val();var d=$(this).val();$.ajax({url:translationsPath+"/app/"+f+"/resource/"+d,dataType:"json",method:"GET"}).done(function(h){var g=$("#translations").DataTable();g.clear().rows.add(h).draw();hideSelectionHint(true);hideSpinner(true);hideTranslationRow(false);enableBootstrapTooltips()}).fail(function(g,i,h){setSelectionNeededState()})}else{setSelectionNeededState()}});$("#translations").on("click",".translationDetails",function(b){var d=$("#app").val();var c=$("#resource").val();var a=$(b.target).data("entryid");$.ajax({url:detailsPath+"/app/"+d+"/resource/"+c+"/entry/"+a,dataType:"json",method:"GET"}).done(function(e){if($.type(e)=="object"&&e.modal){$("#modalContainer").html(e.modal);$("#modalDetails").on("shown.bs.modal",function(f){initSuggestions();$("#modalContainer #suggestions").DataTable().rows.add(suggestionData).draw();enableBootstrapTooltips()}).on("show.bs.modal",function(f){refreshTranslation=false}).on("hidden.bs.modal",function(f){$("#modalContainer #suggestions").DataTable().destroy();if(refreshTranslation){refreshTranslationEntry(d,c,a)}enableBootstrapTooltips()}).modal()}else{showModalError()}}).fail(function(e,g,f){showModalError()})});$("#modalContainer").on("click",".suggestionVote",function(d){var c=$(this);if(c.hasClass("disabled")){return}var f=$("#app").val();var e=$("#resource").val();var a=c.data("suggestionid");var b=c.data("vote");hideBootstrapTooltips();hideModalSpinner(false);$.ajax({url:suggestionvotePath+"/app/"+f+"/resource/"+e+"/entry/"+suggestionEntryId+"/suggestion/"+a+"/vote/"+b,dataType:"json",method:"GET"}).done(function(g){if($.type(g)=="object"&&g.suggestion){$("#modalContainer #suggestions").DataTable().row("#suggestion-"+a).data(g.suggestion).draw(false);enableBootstrapTooltips()}else{addModalAlertMessage()}hideModalSpinner(true)}).fail(function(g,i,h){addModalAlertMessage();hideModalSpinner(true)})});$("#modalContainer").on("click",".suggestionEdit",function(d){var b=$(this);if(b.hasClass("disabled")){return}var e=0;var a=b.data("suggestion");if($.type(a)==="object"&&$.type(a.id)==="number"){e=a.id}else{a=null}hideBootstrapTooltips();var c=$("#modalContainer #suggestionAddEdit");if(c.hasClass("in")){c.one("hidden.bs.collapse",function(){showSuggestionAddEdit(e,a)}).collapse("hide")}else{showSuggestionAddEdit(e,a)}});$("#modalContainer").on("click",".suggestionAddEditSubmit",function(c){var b=$(this);if(b.hasClass("disabled")){return}var f=$("#app").val();var e=$("#resource").val();var a=b.data("suggestionid");var d={};if(suggestionType=="String"){d.value=$("#modalContainer #suggestionAddEditText").val()}hideBootstrapTooltips();hideModalSpinner(false);$.ajax({url:suggestionaddeditPath+"/app/"+f+"/resource/"+e+"/entry/"+suggestionEntryId+"/suggestion/"+a,data:d,dataType:"json",method:"POST"}).done(function(h){if($.type(h)=="object"&&h.suggestion){var g=$("#modalContainer #suggestions").DataTable();if(a==0){g.row.add(h.suggestion)}else{g.row("#suggestion-"+a).data(h.suggestion)}g.draw(false);$("#modalContainer #suggestionAddEdit").collapse("hide");enableBootstrapTooltips();refreshTranslation=true}else{addModalAlertMessage()}hideModalSpinner(true)}).fail(function(g,i,h){addModalAlertMessage();hideModalSpinner(true)})});$("#modalContainer").on("click",".suggestionDelete",function(c){var b=$(this);if(b.hasClass("disabled")){return}var e=$("#app").val();var d=$("#resource").val();var a=$(this).data("suggestionid");if(a==0){return}hideBootstrapTooltips();hideModalSpinner(false);$.ajax({url:suggestiondeletePath+"/app/"+e+"/resource/"+d+"/entry/"+suggestionEntryId+"/suggestion/"+a,dataType:"json",method:"GET"}).done(function(g){if(($.type(g)=="object")&&("deleted" in g)){if(g.deleted){var f=$("#modalContainer #suggestions").DataTable();f.row("#suggestion-"+a).remove();f.draw(false)}$("#modalContainer #suggestionAddEdit").collapse("hide");refreshTranslation=true}else{addModalAlertMessage()}hideModalSpinner(true)}).fail(function(f,h,g){addModalAlertMessage();hideModalSpinner(true)})});$("#modalContainer").on("click",".suggestionAccept",function(b){var d=$("#app").val();var c=$("#resource").val();var a=$(this).data("suggestionid");hideBootstrapTooltips();hideModalSpinner(false);$.ajax({url:suggestionacceptPath+"/app/"+d+"/resource/"+c+"/entry/"+suggestionEntryId+"/suggestion/"+a,dataType:"json",method:"GET"}).done(function(e){if(($.type(e)=="object")&&("accepted" in e)){if(e.accepted){refreshTranslation=true}$("#modalDetails").modal("hide")}else{addModalAlertMessage()}hideModalSpinner(true)}).fail(function(e,g,f){addModalAlertMessage();hideModalSpinner(true)})}); \ No newline at end of file