1var ajaxutils = {}; 2 3ajaxutils.showAskModal = function(message, ajax, action, parameters, callback, templateSelector) { 4 if($(templateSelector).length !== 0) { 5 ajaxutils.showStoreModal($(templateSelector), ajax, message); 6 return false; 7 } 8 9 ajaxutils.showModal('Alerta', message, ajax, true, action, parameters, callback); 10 return false; 11} 12 13ajaxutils.showCustomModal = function(html) { 14 var randomName = 'modal' + $.now(); 15 var modal = 16 `<div id="${randomName}" class="modal checkout fade"> 17 <div class="modal-dialog modal-add-product-cart"> 18 ${html} 19 </div> 20 </div>`; 21 22 if ($('.ajax-modal-content').length == 0) { 23 $('body').append('<div class="ajax-modal-content">'); 24 } 25 26 $('.ajax-modal-content').html(modal); 27 $('#' + randomName).modal('show'); 28} 29 30ajaxutils.showModal = function(title, content, ajax, small, action, parameters, callback) { 31 small = typeof small !== "undefined" ? small : false; 32 33 var additionalClass = small ? "modal-sm" : ""; 34 var randomName = "modal" + $.now(); 35 var html = ajaxutils.getModalTemplate(title, content, ajax, action, parameters, callback); 36 var modalContent = "<div class=\"" + additionalClass + " modal-dialog\">" + html + "</div>"; 37 var modal = "<div id=\"" + randomName + "\" class=\"modal fade checkout\">" + modalContent + "</div>"; 38 39 if ($(".ajax-modal-content").length == 0) { 40 $("body").append('<div class="ajax-modal-content">'); 41 } 42 $(".ajax-modal-content").html(modal); 43 44 $("#" + randomName).modal("show"); 45 46 return false; 47} 48 49ajaxutils.getModalTemplate = function(title, content, ajax, action, parameters, callback) { 50 var _action = action || null; 51 var _parameters = parameters || null; 52 var _callback = callback || null; 53 var template = "<div class=\"modal-content\">"; 54 template += "<div class=\"modal-header\">"; 55 template += "<button type=\"button\" class=\"close\" data-dismiss=\"modal\">"; 56 template += "<span aria-hidden=\"true\">×</span>"; 57 template += "<span class=\"sr-only\">Close</span>"; 58 template += "</button>"; 59 template += "<h4 class=\"modal-title\">" + title + "</h4>"; 60 template += "</div>"; 61 template += "<div class=\"modal-body\">"; 62 template += "<span class=\"modal-ask\">" + content + "</span>"; 63 template += "</div>"; 64 65 if (typeof ajax !== "undefined" && ajax != null && _action == null && _parameters == null) { 66 template += "<div class=\"modal-footer justify-content-between\">"; 67 template += "<button class=\"pull-left btn btn-secondary\" data-dismiss=\"modal\">Cancelar</button>"; 68 if (_callback == null) { 69 template += "<button data-href=\"" + ajax + "\" class=\"pull-right btn btn-primary\">Confirmar</button>"; 70 } else { 71 template += "<button data-href=\"" + ajax + "\" data-callback=\"" + _callback + "\" class=\"pull-right btn btn-primary\">Confirmar</button>"; 72 } 73 template += "</div>"; 74 } else if (_action !== null && _parameters !== null) { 75 var params = JSON.parse(_parameters) || null; 76 if (_callback == null) { 77 template += "<form method=\"post\" data-action=\"" + ajax + "\">"; 78 } else { 79 template += "<form method=\"post\" data-action=\"" + ajax + "\" data-callback=\"" + _callback + "\">"; 80 } 81 template += "<input type=\"hidden\" name=\"act\" value=\"" + _action + "\">"; 82 template += "<input type=\"hidden\" name=\"isModal\" value=\"" + true + "\">"; 83 if (params) { 84 $.each(params, function (key, value) { 85 template += "<input type=\"hidden\" name=\"" + key + "\" value=\"" + value + "\">"; 86 }); 87 } 88 template += "<div class=\"modal-footer justify-content-between\">"; 89 template += "<button class=\"pull-left btn btn-secondary\" data-dismiss=\"modal\">Cancelar</button>"; 90 template += "<button data-submit type=\"button\" class=\"pull-right btn btn-primary\">Confirmar</button>"; 91 template += "</div>"; 92 template += "</form>"; 93 } 94 95 template += "</div>"; 96 97 return template; 98} 99 100ajaxutils.showStoreModal = function(template, url, message) { 101 if (template.length == 0) { 102 template = ajaxutils.getAskTemplate(); 103 } else { 104 template = template.html(); 105 } 106 107 var randomName = "modal" + $.now(); 108 var modal = "<div id=\"" + randomName + "\" class=\"modal fade\"><div class=\"modal-sm modal-dialog\">" + template + "</div></div>"; 109 modal = modal.replace("{TemplateAjax}", url); 110 modal = modal.replace("{TemplateMessage}", message); 111 112 $("body").append(modal); 113 $("#" + randomName).modal("show"); 114 115 return false;
116} 117 118ajaxutils.getAskTemplate = function() { 119 var template = "<div class=\"modal-content\">"; 120 template += "<div class=\"modal-header\">"; 121 template += "<button type=\"button\" class=\"close\" data-dismiss=\"modal\">"; 122 template += "<span aria-hidden=\"true\">×</span>"; 123 template += "<span class=\"sr-only\">Close</span>"; 124 template += "</button>"; 125 template += "<h4 class=\"modal-title\">Alerta</h4>"; 126 template += "</div>"; 127 template += "<div class=\"modal-body\">"; 128 template += "<span class=\"modal-ask\">{TemplateMessage}</span>"; 129 template += "</div>"; 130 template += "<div class=\"modal-footer\">"; 131 template += "<button class=\"pull-left btn btn-default\" data-dismiss=\"modal\">Cancelar</button>"; 132 template += "<button data-href=\"{TemplateAjax}\" class=\"pull-right btn btn-primary\">Confirmar</button>"; 133 template += "</div>"; 134 template += "</div>"; 135 136 return template; 137} 138 139ajaxutils.showAlertModal = function(title, text, header, backdrop, closeButton) { 140 if (typeof closeButton === 'undefined' || typeof closeButton === 'null' || closeButton.length == 0) { 141 closeButton = true 142 } 143 144 var tplData = { 145 title: title, 146 text: text, 147 header: header || null, 148 backdrop: backdrop ? "data-backdrop='static'" : false, 149 closeButton: closeButton 150 }; 151 152 var tpl = template.getTemplate('root/modalalerta', tplData); 153 154 if ($(".alert-modal-content").length == 0) { 155 $("body").append('<div class="alert-modal-content">'); 156 } 157 158 $(".alert-modal-content").html(tpl); 159 $('#alert-modal').modal('show'); 160} 161 162ajaxutils.getFormData = function(formSelector, remove) { 163 if ($(formSelector).length == 0) { 164 return null; 165 } 166 167 var data = $(formSelector).serialize(); 168 data = decodeURIComponent(data); 169 170 if (remove) { 171 remove = remove.split(","); 172 173 if (remove.length == 0) { 174 return data; 175 } 176 177 remove.forEach(function(value) { 178 data = ajaxutils.removeQueryParam(value, data); 179 }); 180 } 181 182 return data; 183}; 184 185ajaxutils.removeQueryParam = function(key, sourceUrl) { 186 var rtn = sourceUrl.split("&"); 187 var i = 0; 188 189 rtn.forEach(function(value) { 190 var param = value.split("=")[0]; 191 192 if (param === key) { 193 rtn.splice(i, 1); 194 } 195 196 i++; 197 }); 198 199 rtn = rtn.join("&"); 200 return rtn; 201}; 202 203ajaxutils.executeFunctionByName = function(functionName, context, args) { 204 if (functionName == null || context == null || typeof context === "undefined") { 205 return false; 206 } 207 208 var namespaces = functionName.split("."); 209 var functionContext = namespaces; 210 211 if (namespaces.length > 1) { 212 functionContext = namespaces.pop(); 213 214 for (var i = 0; i < namespaces.length; i++) { 215 if (typeof context[namespaces[i]] === "undefined") { 216 return false; 217 } 218 219 context = context[namespaces[i]]; 220 } 221 } 222 223 if (args != null) { 224 args = Array.prototype.slice.call(arguments, 2); 225 } 226 227 context[functionContext].apply(context, args); 228}; 229 230ajaxutils.getAskModalHtml = function(title, text, confirmButton, cancelButton, confirmButtonSelector, modalContentSelector = '') { 231 var template = 232 `<div ${modalContentSelector} class=\"modal-content\"> 233 <div class=\"modal-header\"> 234 <button type=\"button\" class=\"close\" data-dismiss=\"modal\"> 235 <span aria-hidden=\"true\">×</span> 236 <span class=\"sr-only\">Close</span> 237 </button> 238 <h4 class=\"modal-title\">${title}</h4> 239 </div> 240 <div class=\"modal-body\"> 241 <span class=\"modal-ask\">${text}</span> 242 </div> 243 <div class=\"modal-footer\"> 244 <button class=\"pull-left btn btn-default\" data-dismiss=\"modal\">${cancelButton}</button> 245 <button ${confirmButtonSelector} data-dismiss=\"modal\" class=\"pull-right btn btn-primary\">${confirmButton}</button> 246 </div> 247 </div>`; 248 249 return template; 250} 251 252ajaxutils.redirectPost = function(location, inputs) 253{ 254 var form = ''; 255 256 inputs.each(function(key, element) { 257 form += `<input type="hidden" name="${element.name}" value="${element.value}">`; 258 }); 259 260 $(`<form action="${location}" method="POST">${form}</form>`).appendTo($(document.body)).submit(); 261}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.