// Bloque 1 (js_tableeditor) window.addEventListener('DOMContentLoaded', function() { $(document).ready(function() { $('.filterFields').change(function(){ var campo = $(this).attr('id'); var valor = ($('#' + $(this).attr('id') + ' option:selected').val()); location.href = updateQueryString(location.href,campo,valor); }); }); }); function updateQueryString(url, key, value) { if (!url) url = window.location.href; var re = new RegExp('([?|&])' + key + '=.*?(&|#|$)(.*)', 'gi'); if (re.test(url)) { if (value) return url.replace(re, '$1' + key + '=' + value + '$2$3'); else { return url.replace(re, '$1$3').replace(/(&|\?)$/, ''); } } else { if (value) { var separator = url.indexOf('?') !== -1 ? '&' : '?', hash = url.split('#'); url = hash[0] + separator + key + '=' + value; if (hash[1]) url += '#' + hash[1]; return url; } else return url; } } // Bloque 2 (js_tableeditor) /** * Adds an extra criteria row to the search form */ function addCriteria() { var tableObj = document.getElementById('searchCriteriaTable'); var trObj = document.getElementById('searchCriteriaRow'); var lastRow = document.getElementById('searchCriteriaTable_lastRow'); // Insert new row var insertedRow = lastRow.parentNode.insertBefore(trObj.cloneNode(true), lastRow); // Lose the button from the top row var buttonObj = trObj.getElementsByTagName('button')[0]; buttonObj.parentNode.removeChild(buttonObj); // Move the id trObj.id = ''; insertedRow.id = 'searchCriteriaRow'; // Reset values on the newly inserted row (needed when modifying a search) inputs = insertedRow.getElementsByTagName('input'); inputs[0].value = ''; selects = insertedRow.getElementsByTagName('select'); selects[0].selectedIndex = 0; selects[1].selectedIndex = 0; return false; } /** * Performs the search */ function search() { var selects = document.getElementsByTagName('select'); var inputs = document.getElementsByTagName('input'); var fields = []; var operators = []; var values = []; // Separate field names from operators for (var i=0; i 1) { alert('Debes seleccionar sólo un registro para ver'); return; } else { view = 'view=' + encodeURIComponent(selectedRows[0]); } location.href = location.href + (location.search.length ? '&' : '?') + view; } /** * Handles redirecting for deleting rows */ function row_delete() { var selectedRows = getSelectedRows(); var deletes = new Array(); if (selectedRows.length == 0) { alert('Debes seleccionar uno o varios registros para borrar!'); return; } for (var i=0; i 1 ? '\nATENCION: Has seleccionado varios registros!' : ''))) { location.href = location.href + (location.search.length ? '&' : '?') + deletes.join('&'); } } function send_newsletter() { var selectedRows = getSelectedRows(); var view = ''; if (selectedRows.length == 0) { alert('Debes seleccionar un registro para ver!'); return; } if (selectedRows.length > 1) { alert('Debes seleccionar sólo un registro para ver'); return; } else { if (confirm("¡Atención!. Si acepta se enviará esta newsletter a todos los usuarios registrados. ¿Desea continuar?")) { jQuery.ajax({ contentType: "application/x-www-form-urlencoded", type: "POST", url: "send_newsletter.php", data: 'newsletter=' + encodeURIComponent(selectedRows[0]), success: function(datos){ //jQuery("#box_carrito").html(aDatos[0]); alert(datos); } }); } } } /** * Handles redirecting for editing rows */ function row_edit() { var selectedRows = getSelectedRows(); var edit = ''; if (selectedRows.length == 0) { alert('Debes seleccionar un registro para editar!'); return; } if (selectedRows.length > 1) { alert('Sólo puedes seleccionar un registro para editar'); return; } else { edit = 'edit=' + encodeURIComponent(selectedRows[0]); } location.href = location.href + (location.search.length ? '&' : '?') + edit; } /** * Handles redirecting for copying a row */ function row_copy() { var selectedRows = getSelectedRows(); var copy = ''; if (selectedRows.length == 0) { alert('Debes seleccionar un registro para copiar!'); return; } if (selectedRows.length > 1) { alert('Sólo puedes copiar un registro a la vez'); return; } else { copy = 'copy=' + encodeURIComponent(selectedRows[0]); } location.href = location.href + (location.search.length ? '&' : '?') + copy; } /** * Handles redirecting for adding a row */ function row_add() { location.href = location.href + (location.search.length ? '&' : '?') + 'add=1'; } /** * Handles the search button */ function search() { var searchStr = document.getElementById('searchInput').value; location.href = location.href + (location.search.length ? '&' : '?') + 'search=' + (searchStr); } /** * Handles ordering links */ function orderBy(field) { location.href = location.href + (location.search.length ? '&' : '?') + 'orderby=' + encodeURIComponent(field); } /** * Enables the apply button on the edit form */ function enableApply() { document.forms[0].elements['action'][2].disabled = false; } /** * Returns the current date and time in ISO8660 format (YYYY-MM-DD HH:MM:SS) */ function currentDateTime() { return currentDate() + ' ' + currentTime(); } /** * Returns the current date in ISO8660 format */ function currentDate() { var d = new Date(); var date = d.getDate() > 9 ? d.getDate() : '0' + String(d.getDate()); var month = (d.getMonth() + 1) > 9 ? (d.getMonth() + 1) : '0' + (d.getMonth() + 1); var year = d.getFullYear(); return year + '-' + month + '-' + date; } /** * Returns the current time in ISO8660 format */ function currentTime() { var d = new Date(); var hours = d.getHours() > 9 ? d.getHours() : '0' + d.getHours(); var minutes = d.getMinutes() > 9 ? d.getMinutes() : '0' + d.getMinutes(); var seconds = d.getSeconds() > 9 ? d.getSeconds() : '0' + d.getSeconds(); return hours + ':' + minutes + ':' + seconds; } /////////////////////////////////////////////////////////////////////// // This fade library was designed by Erik Arvidsson for WebFX // // // // For more info and examples see: http://webfx.eae.net // // or contact Erik at http://webfx.eae.net/contact.html#erik // // // // Feel free to use this code as lomg as this disclaimer is // // intact. // /////////////////////////////////////////////////////////////////////// var __fadeArray = new Array(); // Needed to keep track of wich elements are animating ////////////////// fade //////////////////////////////////////////////////////////// // // // parameter: fadeIn // // description: A boolean value. If true the element fades in, otherwise fades out // // The steps and msec are optional. If not provided the default // // values are used // // // ////////////////////////////////////////////////////////////////////////////////////// function Fade(el, fadeIn, steps, msec) { if (steps == null) steps = 4; if (msec == null) msec = 25; if (el.fadeIndex == null) { el.fadeIndex = __fadeArray.length; } __fadeArray[el.fadeIndex] = el; if (el.fadeStepNumber == null) { if (el.style.visibility == "hidden") { el.fadeStepNumber = 0; } else { el.fadeStepNumber = steps; } if (fadeIn) { el.style.filter = "Alpha(Opacity=0)"; el.style.MozOpacity = '0'; } else { el.style.filter = "Alpha(Opacity=100)"; el.style.MozOpacity = '1'; } } window.setTimeout("RepeatFade(" + fadeIn + "," + el.fadeIndex + "," + steps + "," + msec + ")", msec); } ////////////////////////////////////////////////////////////////////////////////////// // Used to iterate the fading // ////////////////////////////////////////////////////////////////////////////////////// function RepeatFade(fadeIn, index, steps, msec) { el = __fadeArray[index]; c = el.fadeStepNumber; if (el.fadeTimer != null) { window.clearTimeout(el.fadeTimer); } if ((c == 0) && (!fadeIn)) { // Done fading out! el.style.visibility = "hidden"; // If the platform doesn't support filter it will hide anyway // el.style.filter = ""; return; } else if ((c==steps) && (fadeIn)) { //Done fading in! el.style.filter = ""; el.style.MozOpacity = '1'; el.style.visibility = "visible"; return; } else { (fadeIn) ? c++ : c--; el.style.visibility = "visible"; el.style.filter = "Alpha(Opacity=" + 100*c/steps + ")"; el.style.MozOpacity = c/steps; el.fadeStepNumber = c; el.fadeTimer = window.setTimeout("RepeatFade(" + fadeIn + "," + index + "," + steps + "," + msec + ")", msec); } }