/* * isEmptyJSON() * FUNCIÓN: Indicará si un objeto JSON es vacío o no */ $.fn.isEmptyJSON = function(obj) { for(var i in obj) { return false; } return true; } /* * createTree() * FUNCIÓN: Crea un árbol jquery con el plugin jstree * PARAMS: idTree - del BOTÓN para el que se van a activar los campos * node - */ $.fn.createTree = function(options) { var defaults = $.extend({ idTree: '', node: '', multiple: 'false', url: '', claseM: '', destino: '', actualizaA: '', idForm: '' },options); gvh.showConsoleMsg('log',defaults.idTree); if (defaults.multiple == "true") multiple = true; else multiple = false; // Comprobar si existe la variable gvh.datosJSON raizJSON = gvh.datosJSON[defaults.claseM][defaults.panel]; var data = []; if (raizJSON['gvhJSON'] == 'false') { data = JSON.stringify($("#"+defaults.idForm).serialize()); url = defaults.url; } else { data = gvh.datosJSON; url = defaults.url+"&gvhcache=true&claseManejadora="+defaults.claseM+"&gvhpanel="+defaults.panel; } gvh.showConsoleMsg('log',data); $('#'+defaults.idTree).jstree({ "types" : { "default" : { "icon" : "glyphicon glyphicon-flash" }, "root" : { "icon" : "fa fa-chevron-down" }, "users" : { "icon" : "fa fa-users" }, "volley" : { "icon" : "fa fa-anchor" }, "ciclismo" : { "icon" : "fa fa-bicycle" }, "child" : { "icon" : "fa fa-child" } }, "core" : { "multiple": multiple, "checkbox": true, "ajax": true, "worker": true, "data": { "url": url, //"url": "phrame.php?action=TreeSelector__treeAjax", "data": function(data) { gvh.showConsoleMsg('log','data '+data); return data;//{ "id" : node.id, "nodo": node }; }, "beforeSend": function(node) { gvh.showConsoleMsg('log','beforeSend '+node); }, "error": function(node) { gvh.showConsoleMsg('log','error '+node); }, "success": function (node) { gvh.showConsoleMsg('log','success '+node); if ($(this).isEmptyJSON(node)) { gvh.showConsoleMsg('log',"NO DATA!"); gvh.showMessage('gvhlang_NoData','alert'); } }, "search": { "case_insensitive": true, "ajax" : { "url": "phrame.php?action=TreeSelector__treeAjax&value=search", 'dataType': 'json', 'type': 'POST', "data": function (node) { gvh.showConsoleMsg('log','search '+node.id) return { "id": node.id }; } } }, }, "themes": { 'name': 'proton', 'responsive': true }, }, "plugins" : [ "types", "wholerow", "search", "themes", "html_data", "checkbox", "sort", "ui" ] }); }