/** * @copyright 2021 Double Bastion LLC * * @author Double Bastion LLC * * @license GNU AGPL version 3 or any later version * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * License as published by the Free Software Foundation; either * version 3 of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU Affero General Public * License along with this program. If not, see . * */ $(document).ready(function() { var userid = ""; var parseddata = null; var sentparseddata = null; // Set the default number of messages per page var messagesperpage = 100; // Get the number of messages per page from the database var getNoPerPageUrl = OC.generateUrl("/apps/sms_relentless/user/getmessagesperpage"); $.ajax({ url: getNoPerPageUrl + '/' + userid, method: 'GET', success: function(mesperpagedb) { messagesperpage = parseInt(mesperpagedb); }, error: function(mesperpagedb) { alert("An error occurred. Please check your settings!"); } }); // List received messages $("#receivedsmstable").on("click", function(event) { $('#smstables').empty(); var getReceivedUrl = OC.generateUrl("/apps/sms_relentless/user/getreceivedtable"); $('#smstables').addClass('icon-loading'); $.ajax({ url: getReceivedUrl + '/' + userid, method: 'GET', dataType:'text', success: function(recdatafromdb) { parseddata = $.parseJSON(recdatafromdb); $('#smstables').append("
Pages
"); $('#smstables').append("
"); $('#recSmsTable').append(""); $('#recSmsTable').append("DB
IDUser IDMessage IDDateFromToReceived Message"); $('#recfiltersrow').hide(); for (var i = 0; i < parseddata.length; i++) { $("#recSmsTable").append(""+parseddata[i].id+""+parseddata[i].user_id+""+parseddata[i].message_id+""+parseddata[i].date+""+parseddata[i].from+""+parseddata[i].to+""+parseddata[i].message+""); } $('#smstables').append("
Total displayed messages: " + parseddata.length + "
"); $('#smstables').removeClass('icon-loading'); $('#recarrow').css({"background-image" : "url('img/arrowDown.svg')", "background-repeat" : "no-repeat", "background-position" : "center center"}); // Add pagination var rowsShown = messagesperpage; var rowsTotal = $("#recSmsTable tr").length; var numPages = (rowsTotal - 2) / rowsShown; for (i = 0; i < numPages; i++) { var pageNum = i + 1; $('#paginationrec').append('' + pageNum + ' '); } $('#paginationrec').children(":first").addClass('active'); $(".receivedrowsbody").hide(); $('#paginationrec a:first').addClass('active'); // Show table page when clicking a page number $('.recpages a').bind('click', function() { $('#paginationrec').children().removeClass('active'); $(this).addClass('active'); var currentPageNo = $(this).text(); $('#paginationrec a').each(function() { if ($(this).text() == currentPageNo) { $(this).addClass('active'); } }); // Sort table rows var rows = $('#recSmsTable tr').get(); rows.sort(function(a, b) { var A = parseInt($('td.dbidcolumnrec', a).text()); var B = parseInt($('td.dbidcolumnrec', b).text()); if (A < B) { return -1; } if (A > B) { return 1; } return 0; }); $.each(rows, function(index, row) { $('#recSmsTable').append(row); }); var currPage = $(this).attr('rel'); var startItem = currPage * rowsShown; var endItem = startItem + rowsShown; $(".receivedrowsbody").hide().slice(startItem, endItem).css('display', 'table-row'); $('#totalrecmessages').remove(); $('#smstables').append("
Total displayed messages: " + parseddata.length + "
"); }); $('#paginationrec').children(":last").trigger('click'); // Select all records $('#selectAllChckbx').change(function() { if ($(this).is(':checked')) { $(".indivchckbx").prop("checked", true); } else { $(".indivchckbx").prop("checked", false); } }); function reorderRecRows() { var currenttext = $(".filterbuttonsrec").closest('[class="filterbuttonsrec"]').find('[class="indivfilterrec"]').text(); if (currenttext == '') { $('tr').sort(function (a, b) { return parseInt($('td.dbidcolumnrec', b).text()) < parseInt($('td.dbidcolumnrec', a).text()); }).appendTo("#recSmsTable"); } } // Filter rows $("#databaseidfilter").on("click", function(event) { var databaseId = $("#dbidtextrec").val(); var msgrowsNo = 0; $(".receivedrowsbody").each(function() { var checkrecEmpty1 = 0; $(".indivfilterrec").not("#dbidtextrec").each(function() { if ($(this).val() != '') { checkrecEmpty1 = 1; } }); if (checkrecEmpty1 == 0) { $(this).show(); } if (databaseId != '') { if ($(this).find('[class="dbidcolumnrec"]').text() == databaseId) { $("#recSmsTable").append(this); if ($(this).is(":visible")) { msgrowsNo++; } } else { $(this).hide(); } } else { $(this).show(); msgrowsNo++; } }); reorderRecRows(); $('#totalrecmessages').remove(); $('#smstables').append("
Total filtered messages: " + msgrowsNo + "
"); }); $("#useridfilter").on("click", function(event) { var useridtxt = $("#useridtextrec").val().toLowerCase(); var msgrowsNo = 0; $(".receivedrowsbody").each(function() { var checkrecEmpty2 = 0; $(".indivfilterrec").not("#useridtextrec").each(function() { if ($(this).val() != '') { checkrecEmpty2 = 1; } }); if (checkrecEmpty2 == 0) { $(this).show(); } if (useridtxt != '') { var useridfound = $(this).find('[class="useridcolrec"]').text().toLowerCase(); if(useridfound.indexOf(useridtxt) != -1) { $("#recSmsTable").append(this); if ($(this).is(":visible")) { msgrowsNo++; } } else { $(this).hide(); } } else { $(this).show(); msgrowsNo++; } }); reorderRecRows(); $('#totalrecmessages').remove(); $('#smstables').append("
Total filtered messages: " + msgrowsNo + "
"); }); $("#messageidfilter").on("click", function(event) { var messageidtxt = $("#messageidtextrec").val().toLowerCase(); var msgrowsNo = 0; $(".receivedrowsbody").each(function() { var checkrecEmpty3 = 0; $(".indivfilterrec").not("#messageidtextrec").each(function() { if ($(this).val() != '') { checkrecEmpty3 = 1; } }); if (checkrecEmpty3 == 0) { $(this).show(); } if (messageidtxt != '') { var foundtdmssgid = $(this).find('[class="messageidcolrec"]').text().toLowerCase(); if (foundtdmssgid.indexOf(messageidtxt) != -1) { $("#recSmsTable").append(this); if ($(this).is(":visible")) { msgrowsNo++; } } else { $(this).hide(); } } else { $(this).show(); msgrowsNo++; } }); reorderRecRows(); $('#totalrecmessages').remove(); $('#smstables').append("
Total filtered messages: " + msgrowsNo + "
"); }); $("#datefilter").on("click", function(event) { var datetxtvr = $("#datetextrec").val().toLowerCase(); var msgrowsNo = 0; $(".receivedrowsbody").each(function() { var checkrecEmpty4 = 0; $(".indivfilterrec").not("#datetextrec").each(function() { if ($(this).val() != '') { checkrecEmpty4 = 1; } }); if (checkrecEmpty4 == 0) { $(this).show(); } if (datetxtvr != '') { var founddate = $(this).find('[class="datecolrec"]').text().toLowerCase(); if (founddate.indexOf(datetxtvr) != -1) { $("#recSmsTable").append(this); if ($(this).is(":visible")) { msgrowsNo++; } } else { $(this).hide(); } } else { $(this).show(); msgrowsNo++; } }); reorderRecRows(); $('#totalrecmessages').remove(); $('#smstables').append("
Total filtered messages: " + msgrowsNo + "
"); }); $("#fromfilter").on("click", function(event) { var fromtxtvr = $("#fromtextrec").val().toLowerCase(); var msgrowsNo = 0; $(".receivedrowsbody").each(function() { var checkrecEmpty5 = 0; $(".indivfilterrec").not("#fromtextrec").each(function() { if ($(this).val() != '') { checkrecEmpty5 = 1; } }); if (checkrecEmpty5 == 0) { $(this).show(); } if (fromtxtvr != '') { var foundfrom = $(this).find('[class="fromcolumnrec"]').text().toLowerCase(); if (foundfrom.indexOf(fromtxtvr) != -1) { $("#recSmsTable").append(this); if ($(this).is(":visible")) { msgrowsNo++; } } else { $(this).hide(); } } else { $(this).show(); msgrowsNo++; } }); reorderRecRows(); $('#totalrecmessages').remove(); $('#smstables').append("
Total filtered messages: " + msgrowsNo + "
"); }); $("#tofilter").on("click", function(event) { var totxtvr = $("#totextrec").val().toLowerCase(); var msgrowsNo = 0; $(".receivedrowsbody").each(function() { var checkrecEmpty6 = 0; $(".indivfilterrec").not("#totextrec").each(function() { if ($(this).val() != '') { checkrecEmpty6 = 1; } }); if (checkrecEmpty6 == 0) { $(this).show(); } if (totxtvr != '') { var foundto = $(this).find('[class="tocolrec"]').text().toLowerCase(); if (foundto.indexOf(totxtvr) != -1) { $("#recSmsTable").append(this); if ($(this).is(":visible")) { msgrowsNo++; } } else { $(this).hide(); } } else { $(this).show(); msgrowsNo++; } }); reorderRecRows(); $('#totalrecmessages').remove(); $('#smstables').append("
Total filtered messages: " + msgrowsNo + "
"); }); $("#messagefilter").on("click", function(event) { var messagetxtvr = $("#messagetextrec").val().toLowerCase(); var msgrowsNo = 0; $(".receivedrowsbody").each(function() { var checkrecEmpty7 = 0; $(".indivfilterrec").not("#messagetextrec").each(function() { if ($(this).val() != '') { checkrecEmpty7 = 1; } }); if (checkrecEmpty7 == 0) { $(this).show(); } if (messagetxtvr != '') { var foundmessage = $(this).find('[class="messagecolumnrec"]').text().toLowerCase(); if (foundmessage.indexOf(messagetxtvr) != -1) { $("#recSmsTable").append(this); if ($(this).is(":visible")) { msgrowsNo++; } } else { $(this).hide(); } } else { $(this).show(); msgrowsNo++; } }); reorderRecRows(); $('#totalrecmessages').remove(); $('#smstables').append("
Total filtered messages: " + msgrowsNo + "
"); }); // Clear all filters $("#clearrecfilters").on("click", function(event) { $(".receivedrowsbody").each(function() { $(this).show(); }); $(".indivfilterrec").val(""); $('#totalrecmessages').remove(); $('#smstables').append("
Total displayed messages: " + parseddata.length + "
"); }); // Delete selected rows from the database $("#deleterecrows").on("click", function() { var checkcheckbx = jQuery("#recSmsTable input[type=checkbox]:checked").length; if (checkcheckbx == 0) { alert("Please select the row(s) to permanently delete from the database !"); } else { var checkboxIds = []; $(".receivedrowsbody").each(function() { var rowcheckbx = $(this).find('input[type="checkbox"]'); if (rowcheckbx.is(":checked")) { var dbrowid = $(this).find('[class="dbidcolumnrec"]').text(); checkboxIds.push(dbrowid); } }); if (confirm("Please note that the row(s) you selected will be permanently deleted from the database, without being saved before removal. This action cannot be undone ! If you really want to permanently delete the selected row(s) press 'OK'.")) { var deleterecRowsUrl = OC.generateUrl("/apps/sms_relentless/user/removerecrows"); $('#smstables').addClass('icon-loading'); $.ajax({ url: deleterecRowsUrl + '/' + userid, method: "POST", dataType:'text', data: {recmessagedbIDs: checkboxIds}, success: function() { alert("The row(s) have been deleted successfully !"); $('#smstables').removeClass('icon-loading'); $('#receivedsmstable').click(); }, error: function() { alert("There was an error while deleting the selected row(s) !"); $('#smstables').removeClass('icon-loading'); } }); } } }); // Show/Hide filter row $('#recarrow').on('click', function() { if ($('#recfiltersrow').is(':visible')) { $('#recfiltersrow').hide(); $('#recheaderrow').css('top', '0px'); $('#recarrow').css({"background-image" : "url('img/arrowDown.svg')", "background-repeat" : "no-repeat", "background-position" : "center center"}); } else { $('#recfiltersrow').show(); $('#recheaderrow').css('top', '158px'); $('#recarrow').css({"background-image" : "url('img/arrowUp.svg')", "background-repeat" : "no-repeat", "background-position" : "center center"}); } }); }, error: function(recdatafromdb) { alert("An error occurred. Please check your settings!"); $('#smstables').removeClass('icon-loading'); } }); }); // List sent messages $("#sentsmstable").on("click", function(event) { $('#smstables').empty(); var getSentUrl = OC.generateUrl("/apps/sms_relentless/user/getsenttable"); $('#smstables').addClass('icon-loading'); $.ajax({ url: getSentUrl + '/' + userid, method: "GET", dataType:'text', success: function(sentdatafromdb) { sentparseddata = $.parseJSON(sentdatafromdb); $('#smstables').append("
Pages
"); $('#smstables').append("
"); $('#sentSmsTable').append(""); $('#sentSmsTable').append("DB
IDUser IDMessage IDDateFromToNetworkPriceStatusDelivery
ReceitSent Message"); $('#sentfiltersrow').hide(); for (var i = 0; i < sentparseddata.length; i++) { $('#sentSmsTable').append(""+sentparseddata[i].id+""+sentparseddata[i].user_id+""+sentparseddata[i].message_id+""+sentparseddata[i].date+""+sentparseddata[i].from+""+sentparseddata[i].to+""+sentparseddata[i].network+""+sentparseddata[i].price+""+sentparseddata[i].status+""+sentparseddata[i].deliveryreceipt+""+sentparseddata[i].message+""); } $('#smstables').append("
Total displayed messages: " + sentparseddata.length + "
"); $('#smstables').removeClass('icon-loading'); $('#sentarrow').css({"background-image" : "url('img/arrowDown.svg')", "background-repeat" : "no-repeat", "background-position" : "center center"}); // Add pagination var rowsShown = messagesperpage; var rowsTotal = $("#sentSmsTable tr").length; var numPages = (rowsTotal - 2) / rowsShown; for (i = 0; i < numPages; i++) { var pageNum = i + 1; $('#paginationsent').append('' + pageNum + ' '); } $('#paginationsent').children(":first").addClass('active'); $(".sentrowsbody").hide(); $('#paginationsent a:first').addClass('active'); // Show table page when clicking on page number $('.pages a').bind('click', function () { $('#paginationsent').children().removeClass('active'); $(this).addClass('active'); var currentsentPgNo = $(this).text(); $('#paginationsent a').each(function() { if ($(this).text() == currentsentPgNo) { $(this).addClass('active'); } }); // Sort table rows var rows = $('#sentSmsTable tr').get(); rows.sort(function(a, b) { var A = parseInt($('td.sentdbidcolumn', a).text()); var B = parseInt($('td.sentdbidcolumn', b).text()); if (A < B) { return -1; } if (A > B) { return 1; } return 0; }); $.each(rows, function(index, row) { $('#sentSmsTable').append(row); }); var currPage = $(this).attr('rel'); var startItem = currPage * rowsShown; var endItem = startItem + rowsShown; $('.sentrowsbody').hide().slice(startItem, endItem).css('display', 'table-row'); $('#totalsentmessages').remove(); $('#smstables').append("
Total displayed messages: " + sentparseddata.length + "
"); }); $('#paginationsent').children(":last").trigger('click'); // Select all records $('#selectAllChckbx').change(function() { if ($(this).is(':checked')) { $(".indivchckbx").prop("checked", true); } else { $(".indivchckbx").prop("checked", false); } }); function reorderSentRows() { var currenttext = $(".filterbuttonsent").closest('[class="filterbuttonsent"]').find('[class="indivfiltersent"]').text(); if (currenttext == '') { $('tr').sort(function (a, b) { return parseInt($('td.sentdbidcolumn', b).text()) < parseInt($('td.sentdbidcolumn', a).text()); }).appendTo("#sentSmsTable"); } } // Filter rows $("#databaseidfilter").on("click", function(event) { var databaseId = $("#dbidtextsent").val(); var msgrowsNo = 0; $(".sentrowsbody").each(function() { var checkEmpty = 0; $(".indivfiltersent").not("#dbidtextsent").each(function() { if ($(this).val() != '') { checkEmpty = 1; } }); if (checkEmpty == 0) { $(this).show(); } if (databaseId != '') { if ($(this).find('[class="sentdbidcolumn"]').text() == databaseId) { $("#sentSmsTable").append(this); if ($(this).is(":visible")) { msgrowsNo++; } } else { $(this).hide(); } } else { $(this).show(); msgrowsNo++; } }); reorderSentRows(); $('#totalsentmessages').remove(); $('#smstables').append("
Total filtered messages: " + msgrowsNo + "
"); }); $("#useridfilter").on("click", function(event) { var useridtxt = $("#useridtext").val().toLowerCase(); var msgrowsNo = 0; $(".sentrowsbody").each(function() { var checkEmpty1 = 0; $(".indivfiltersent").not("#useridtext").each(function() { if ($(this).val() != '') { checkEmpty1 = 1; } }); if (checkEmpty1 == 0) { $(this).show(); } if (useridtxt != '') { var founduserid = $(this).find('[class="useridcolsent"]').text().toLowerCase(); if (founduserid.indexOf(useridtxt) != -1) { $("#sentSmsTable").append(this); if ($(this).is(":visible")) { msgrowsNo++; } } else { $(this).hide(); } } else { $(this).show(); msgrowsNo++; } }); reorderSentRows(); $('#totalsentmessages').remove(); $('#smstables').append("
Total filtered messages: " + msgrowsNo + "
"); }); $("#messageidfilter").on("click", function(event) { var messageidtxt = $("#messageidtext").val().toLowerCase(); var msgrowsNo = 0; $(".sentrowsbody").each(function() { var checkEmpty2 = 0; $(".indivfiltersent").not("#messageidtext").each(function() { if ($(this).val() != '') { checkEmpty2 = 1; } }); if (checkEmpty2 == 0) { $(this).show(); } if (messageidtxt != '') { var foundtdmssgid = $(this).find('[class="messageidcolsent"]').text().toLowerCase(); if (foundtdmssgid.indexOf(messageidtxt) != -1) { $("#sentSmsTable").append(this); if ($(this).is(":visible")) { msgrowsNo++; } } else { $(this).hide(); } } else { $(this).show(); msgrowsNo++; } }); reorderSentRows(); $('#totalsentmessages').remove(); $('#smstables').append("
Total filtered messages: " + msgrowsNo + "
"); }); $("#datefilter").on("click", function(event) { var datetxtvr = $("#datetext").val().toLowerCase(); var msgrowsNo = 0; $(".sentrowsbody").each(function() { var checkEmpty3 = 0; $(".indivfiltersent").not("#datetext").each(function() { if ($(this).val() != '') { checkEmpty3 = 1; } }); if (checkEmpty3 == 0) { $(this).show(); } if (datetxtvr != '') { var founddate = $(this).find('[class="datecolsent"]').text().toLowerCase(); if (founddate.indexOf(datetxtvr) != -1) { $("#sentSmsTable").append(this); if ($(this).is(":visible")) { msgrowsNo++; } } else { $(this).hide(); } } else { $(this).show(); msgrowsNo++; } }); reorderSentRows(); $('#totalsentmessages').remove(); $('#smstables').append("
Total filtered messages: " + msgrowsNo + "
"); }); $("#fromfilter").on("click", function(event) { var fromtxtvr = $("#fromtext").val().toLowerCase(); var msgrowsNo = 0; $(".sentrowsbody").each(function() { var checkEmpty4 = 0; $(".indivfiltersent").not("#fromtext").each(function() { if ($(this).val() != '') { checkEmpty4 = 1; } }); if (checkEmpty4 == 0) { $(this).show(); } if (fromtxtvr != '') { var foundfrom = $(this).find('[class="fromcolumnsent"]').text().toLowerCase(); if (foundfrom.indexOf(fromtxtvr) != -1) { $("#sentSmsTable").append(this); if ($(this).is(":visible")) { msgrowsNo++; } } else { $(this).hide(); } } else { $(this).show(); msgrowsNo++; } }); reorderSentRows(); $('#totalsentmessages').remove(); $('#smstables').append("
Total filtered messages: " + msgrowsNo + "
"); }); $("#tofilter").on("click", function(event) { var totxtvr = $("#totext").val().toLowerCase(); var msgrowsNo = 0; $(".sentrowsbody").each(function() { var checkEmpty5 = 0; $(".indivfiltersent").not("#totext").each(function() { if ($(this).val() != '') { checkEmpty5 = 1; } }); if (checkEmpty5 == 0) { $(this).show(); } if (totxtvr != '') { var foundto = $(this).find('[class="tocolumnsent"]').text().toLowerCase(); if (foundto.indexOf(totxtvr) != -1) { $("#sentSmsTable").append(this); if ($(this).is(":visible")) { msgrowsNo++; } } else { $(this).hide(); } } else { $(this).show(); msgrowsNo++; } }); reorderSentRows(); $('#totalsentmessages').remove(); $('#smstables').append("
Total filtered messages: " + msgrowsNo + "
"); }); $("#networkfilter").on("click", function(event) { var networktxtvr = $("#networktext").val().toLowerCase(); var msgrowsNo = 0; $(".sentrowsbody").each(function() { var checkEmpty6 = 0; $(".indivfiltersent").not("#networktext").each(function() { if ($(this).val() != '') { checkEmpty6 = 1; } }); if (checkEmpty6 == 0) { $(this).show(); } if (networktxtvr != '') { var foundnetwork = $(this).find('[class="networkcolumnsent"]').text().toLowerCase(); if (foundnetwork.indexOf(networktxtvr) != -1) { $("#sentSmsTable").append(this); if ($(this).is(":visible")) { msgrowsNo++; } } else { $(this).hide(); } } else { $(this).show(); msgrowsNo++; } }); reorderSentRows(); $('#totalsentmessages').remove(); $('#smstables').append("
Total filtered messages: " + msgrowsNo + "
"); }); $("#pricefilter").on("click", function(event) { var pricetxtvr = $("#pricetext").val().toLowerCase(); var msgrowsNo = 0; $(".sentrowsbody").each(function() { var checkEmpty7 = 0; $(".indivfiltersent").not("#pricetext").each(function() { if ($(this).val() != '') { checkEmpty7 = 1; } }); if (checkEmpty7 == 0) { $(this).show(); } if (pricetxtvr != '') { var foundprice = $(this).find('[class="pricecolumnsent"]').text().toLowerCase(); if (foundprice.indexOf(pricetxtvr) != -1) { $("#sentSmsTable").append(this); if ($(this).is(":visible")) { msgrowsNo++; } } else { $(this).hide(); } } else { $(this).show(); msgrowsNo++; } }); reorderSentRows(); $('#totalsentmessages').remove(); $('#smstables').append("
Total filtered messages: " + msgrowsNo + "
"); }); $("#statusfilter").on("click", function(event) { var statustxtvr = $("#statustext").val().toLowerCase(); var msgrowsNo = 0; $(".sentrowsbody").each(function() { var checkEmpty8 = 0; $(".indivfiltersent").not("#statustext").each(function() { if ($(this).val() != '') { checkEmpty8 = 1; } }); if (checkEmpty8 == 0) { $(this).show(); } if (statustxtvr != '') { var foundstatus = $(this).find('[class="statuscolumnsent"]').text().toLowerCase(); if (foundstatus.indexOf(statustxtvr) != -1) { $("#sentSmsTable").append(this); if ($(this).is(":visible")) { msgrowsNo++; } } else { $(this).hide(); } } else { $(this).show(); msgrowsNo++; } }); reorderSentRows(); $('#totalsentmessages').remove(); $('#smstables').append("
Total filtered messages: " + msgrowsNo + "
"); }); $("#deliveryrecfilter").on("click", function(event) { var deliverytxtvr = $("#deliveryrcpttext").val().toLowerCase(); var msgrowsNo = 0; $(".sentrowsbody").each(function() { var checkEmpty9 = 0; $(".indivfiltersent").not("#deliveryrcpttext").each(function() { if ($(this).val() != '') { checkEmpty9 = 1; } }); if (checkEmpty9 == 0) { $(this).show(); } if (deliverytxtvr != '') { var founddeliveryrcpt = $(this).find('[class="deliveryrcptcolsent"]').text().toLowerCase(); if (founddeliveryrcpt.indexOf(deliverytxtvr) != -1) { $("#sentSmsTable").append(this); if ($(this).is(":visible")) { msgrowsNo++; } } else { $(this).hide(); } } else { $(this).show(); msgrowsNo++; } }); reorderSentRows(); $('#totalsentmessages').remove(); $('#smstables').append("
Total filtered messages: " + msgrowsNo + "
"); }); $("#messagefilter").on("click", function(event) { var messagetxtvr = $("#messagetext").val().toLowerCase(); var msgrowsNo = 0; $(".sentrowsbody").each(function() { var checkEmpty10 = 0; $(".indivfiltersent").not("#messagetext").each(function() { if ($(this).val() != '') { checkEmpty10 = 1; } }); if (checkEmpty10 == 0) { $(this).show(); } if (messagetxtvr != '') { var foundmessage = $(this).find('[class="messagecolumnsent"]').text().toLowerCase(); if (foundmessage.indexOf(messagetxtvr) != -1) { $("#sentSmsTable").append(this); if ($(this).is(":visible")) { msgrowsNo++; } } else { $(this).hide(); } } else { $(this).show(); msgrowsNo++; } }); reorderSentRows(); $('#totalsentmessages').remove(); $('#smstables').append("
Total filtered messages: " + msgrowsNo + "
"); }); // Clear all filters $("#clearsentfilters").on("click", function(event) { $(".sentrowsbody").each(function() { $(this).show(); }); $(".indivfiltersent").val(""); $('#totalsentmessages').remove(); $('#smstables').append("
Total displayed messages: " + sentparseddata.length + "
"); }); // Delete selected rows from the database $("#deletesentrows").on("click", function() { var checkcheckbx = jQuery("#sentSmsTable input[type=checkbox]:checked").length; if (checkcheckbx == 0) { alert("Please select the row(s) to permanently delete from the database !"); } else { var sentcheckboxIds = []; $(".sentrowsbody").each(function() { var sentrowcheckbx = $(this).find('input[type="checkbox"]'); if (sentrowcheckbx.is(":checked")) { var dbrowid = $(this).find('[class="sentdbidcolumn"]').text(); sentcheckboxIds.push(dbrowid); } }); if (confirm("Please note that the row(s) you selected will be permanently deleted from the database, without being saved before removal. This action cannot be undone ! If you really want to permanently delete the selected row(s) press 'OK'.")) { var deletesentRowsUrl = OC.generateUrl("/apps/sms_relentless/user/removesentrows"); $('#smstables').addClass('icon-loading'); $.ajax({ url: deletesentRowsUrl + '/' + userid, method: "POST", dataType:'text', data: {sentmessagedbIDs: sentcheckboxIds}, success: function() { alert("The row(s) have been deleted successfully !"); $('#smstables').removeClass('icon-loading'); $('#sentsmstable').click(); }, error: function() { alert("There was an error while deleting the selected row(s) !"); $('#smstables').removeClass('icon-loading'); } }); } } }); // Show/Hide filter row $('#sentarrow').on('click', function() { if ($('#sentfiltersrow').is(':visible')) { $('#sentfiltersrow').hide(); $('#sentheaderrow').css('top', '0px'); $('#sentarrow').css({"background-image" : "url('img/arrowDown.svg')", "background-repeat" : "no-repeat", "background-position" : "center center"}); } else { $('#sentfiltersrow').show(); $('#sentheaderrow').css('top', '158px'); $('#sentarrow').css({"background-image" : "url('img/arrowUp.svg')", "background-repeat" : "no-repeat", "background-position" : "center center"}); } }); }, error: function(sentdatafromdb) { alert("An error occurred!"); $('#smstables').removeClass('icon-loading'); } }); }); });