-1) {
var s = source.toLowerCase().indexOf("", e);
// Add to scripts array
var sc = source.substring(s_e + 1, e).replace('\t', '').replace('\n', '');
if (typeof sc !== 'undefined' && sc !== '') {
scripts.push(sc);
}
// Strip from source
source = source.substring(0, s) + source.substring(e_e + 1);
}
return scripts;
}
}
if (!exist_function("create_formData")) {
function create_formData(tigger) {
let data = new FormData();
$jq($jq(tigger).serializeArray()).each((o, e) => {
if (e.value !== '') {
data.append(e.name, e.value);
}
});
return data;
}
}
if (!exist_function("destroid_modal")) {
function destroid_modal(target) {
let element = $(target);
if (element.length == 0) {
console.log("target modal no encontrado : " + target);
return;
}
let modal = bootstrap.Modal.getInstance(element[0]);
if (modal === null) {
console.log("el target no contiene instancia de modal : " + target);
return;
}
modal.dispose();
element.parent().html("");
}
}
function evalInScope(js, contextAsScope) {
return new Function(`with (this) { ${js} }`).call(contextAsScope);
}
if (!exist_function("execute_script")) {
function execute_script(array_script) {
for (let i = 0; i < array_script.length; i++) {
let script = array_script[i].replace('\t', ' ').replace('\n', ' ');
try {
if (script !== '' && typeof script !== "undefined") {
// console.log(script);
/* window.eval*/$jq.globalEval('try{ ' + script + ' } ' +
'catch(error) {' +
'console.log("===============================ERROR=============================");' +
'console.error(error);' +
'}');
} else {
console.log("script no encontrado");
}
} catch (e) {
// do what you want here when a script fails
// window.alert('Script failed to run - '+scripts[i]);
if (e instanceof SyntaxError) {
console.log(e.message + ' - ' + scripts);
} else {
console.log(e.message + ' - ' + scripts);
}
}
}
}
}
if (!exist_function("remove_script")) {
function remove_script(_source) {
return _source.replace(/([\w\W\d\D\s\S\0\n\f\r\t\v\b\B]*?)<\/script>/gi, '');
}
}
if (!exist_function("isFunction")) {
function isFunction(x) {
if (typeof x === "function") {
return true;
}
return false;
}
}
if (!exist_function("refresh_all_tables")) {
function refresh_all_tables() {
$("button[name='refresh'].btn").trigger('click');
}
}
if (!exist_function("hide_popup")) {
function hide_popup(target) {
const truck_modal = document.querySelector(target);
const modal = new bootstrap.Modal(truck_modal, {
backdrop: 'static'
});
modal.hide();
destroid_modal(target);
}
}
if (!exist_function("refresh_all_iframe")) {
function refresh_all_iframe() {
$('iframe').attr('src', function (i, val) {
return val;
});
}
}
if (!exist_function("ajax")) {
function ajax(url, data, func) {
$jq.ajax({
method: "POST",
url: url,
data: data
}).done(function (data) {
if (isFunction(func)) {
func(data);
}
});
}
}
function create_appendGrid(var_global, url, parametros, postload_data, structura) {
window[var_global] = new AppendGrid(structura);
json__(url, parametros, (dat) => {
window[var_global].appendRow(dat);
if (isFunction(postload_data)) {
postload_data();
}
});
}
if (!exist_function("json__")) {
function json__(url, data, func) {
$jq.ajax({
dataType: "json",
method: "POST",
url: url,
data: data,
async: false,
}).done((data) => {
if (isFunction(func)) {
func(data);
}
});
}
}
if (!exist_function(calcHeight)) {
function calcHeight(value) {
let numberOfLineBreaks = (value.match(/\n/g) || []).length;
// min-height + lines x line-height + padding + border
let newHeight = 20 + numberOfLineBreaks * 20 + 12 + 2;
return newHeight;
}
}
if (!exist_function("html__")) {
function html__(url, data, target) {
if ($jq(target).length === 0) {
console.error("target no encontrado: " + target);
return 0;
}
$jq.ajax({
cache: false,
url: url,
method: "POST",
data: data
}).done(function (html) {
let scripts = get_script(html);
if (scripts === undefined) {
console.log(html);
throw "error";
return false;
}
$jq(target).html($jq(remove_script(html))[0]);
setTimeout(() => {
execute_script(scripts.reverse());
}, 100);
});
}
}
if (!exist_function("popup__")) {
function popup__(url, data, target) {
$jq.ajax({
cache: false,
url: url,
method: "POST",
data: data
}).done(function (html) {
let scripts = get_script(html);
if (scripts === undefined) {
console.log(html);
throw "error";
}
$jq(target).html();
const element = document.querySelector(target);
if (element ) {
const clone = element.cloneNode(true);
element.replaceWith(clone);
}
$jq(target).html($jq(remove_script(html))[0]);
setTimeout(() => {
execute_script(scripts.reverse());
}, 100);
});
}
}
function isElement(element) {
return element instanceof Element || element instanceof HTMLDocument;
}
function isString(x) {
return Object.prototype.toString.call(x) === "[object String]"
}
function to_jquery_element(target_form) {
if (typeof target_form === "object" && target_form != null && target_form.jquery != null && target_form.length > 0) {
return target_form;
}
if (isElement(target_form)) {
return $jq(target_form);
}
//@todo algunas veces no ve el elemento en el dom cuando viene por ajax
let e =null;
if (isString(target_form)) {
e = document.querySelector(target_form);
}
if (isElement(e)) {
return $jq(e);
}
e = $jq(target_form);
if (typeof e === "object" && e != null && e.jquery != null && e.length > 0) {
return e;
}
throw new Error("not found target " + target_form);
}
function get_form_data(target_form) {
let $objct = to_jquery_element(target_form);
//let unindexed_array = $objct.serializeArray();
let unindexed_array = $objct.find(':input').not('.exclude').serializeArray();
if (!Array.isArray(unindexed_array)) {
console.log("fomulario " + target_form + " not data");
}
let indexed_array = {};
$jq.map(unindexed_array, function (n, i) {
indexed_array[n['name']] = n['value'];
});
return indexed_array;
}
function verific_dimanic_grid(target) {
let arr = window[target + "_agrid"].getAllValue();
for (item of arr) {
if (item.medicamento === '') {
continue;
}
for (const [key, value] of Object.entries(item)) {
if (value === '' || typeof value === 'undefined') {
return {'key': key, 'value': value};
}
}
}
return true;
}
function get_data_dinamic_grid(target) {
let arr = window[target + "_agrid"].getAllValue();
let arr2 = [];
for (item of arr) {
if (item.medicamento === '') {
continue;
}
arr2.push(item);
}
return arr2;
}
function guardar_form_info_group(target, callback) {
let data = {'form': btoa(JSON.stringify(get_form_data(target)))};
ajax("https://sistema.uejavier.com/consultoriouej/index.php?doctor/process_form_group", data, (dat) => {
if (isFunction(callback)) {
callback(dat);
}
alertbox.show(dat.msg);
});
}
if (!exist_function("guardar_form_info")) {
function guardar_form_info(target, callback) {
let data = {'form': btoa(JSON.stringify(get_form_data(target)))};
ajax("https://sistema.uejavier.com/consultoriouej/index.php?doctor/process_form", data, (dat) => {
if (isFunction(callback)) {
callback(dat);
}
alertbox.show(dat.msg);
});
}
}
function submit_form(target) {
$jq(target).find(':submit').click();
}
function $_GET(param) {
let vars = {};
window.location.href.replace(location.hash, '').replace(/[?&]+([^=&]+)=?([^&]*)?/gi, // regexp
function (m, key, value) { // callback
vars[key] = value !== undefined ? value : '';
});
if (param) {
return vars[param] ? vars[param] : null;
}
return vars;
}
if (!exist_function("change_element")) {
function change_element(target, func) {
return $jq(target).replaceWith(func);
}
}
if (!exist_function("copy_attribute")) {
function copy_attribute(origen, target, exception_) {
let $target = $jq(target);
$jq.each(document.querySelector(origen).attributes, (index, attribute) => {
if (!in_array(attribute.name, exception_)) {
$target.attr(attribute.name, attribute.value);
}
});
}
}
function verify_data_form(target, includes) {
let status = true;
$jq($jq(target).serializeArray()).each(
(i, e) => {
if (in_array(e.name, includes) && e.value != '') {
return false;
}
});
return true;
}
function get_data_form(target, includes) {
let arr = [];
$jq($jq(target).serializeArray()).each(
(i, e) => {
if (in_array(e.name, includes)) {
arr.push(e);
}
});
return arr;
}
if (!exist_function("in_array")) {
function in_array(value, arr) {
if (Array.isArray(arr)) {
return arr.includes(value);
}
return false;
}
}
if (!exist_function("on_change_element")) {
function on_change_element(target, func) {
const t = document.querySelector(target);
if (t) {
const observer = new MutationObserver((mutations) => {
mutations.forEach(function (mutation) {
let newNodes = mutation.addedNodes;
if (newNodes !== null) {
let $nodes = $jq(newNodes);
$nodes.each(() => {
let $node = $jq(this);
if (isFunction(func)) {
func($node, mutation);
}
});
}
});
});
observer.observe(t, {
attributes: true,
childList: true,
characterData: true
});
return observer;
} else {
console.error("onChangeElement: Invalid Selector " + target);
}
// Later, you can stop observing
//observer.disconnect();
}
}
if (!exist_function("is_form_empty")) {
function is_form_empty(tigger) {
let content = [];
$jq($jq(tigger).serializeArray()).each(
(o, e) => {
if (e.value !== '' && e.value !== 0) {
content.push(e);
}
});
return content.length === 0;
}
}
/*multimodal solucion*/
$jq(document).on('show.bs.modal', '.modal', function () {
const zIndex = 1040 + 10 * $jq('.modal:visible').length;
$jq(this).css('z-index', zIndex);
setTimeout(() => $jq('.modal-backdrop').not('.modal-stack').css('z-index', zIndex - 1).addClass('modal-stack'));
//$jq(document.querySelector(this)).css('z-index', uniqueId());
});
Ingreso | uejavier