Entity::showSelector PHP Method

showSelector() static public method

Display entities of the loaded profile
static public showSelector ( $target, $myname )
$target target for entity change action
$myname select name
    static function showSelector($target, $myname)
    {
        global $CFG_GLPI;
        $rand = mt_rand();
        echo "<div class='center'>";
        echo "<span class='b'>" . __('Select the desired entity') . "<br>( <img src='" . $CFG_GLPI["root_doc"] . "/pics/entity_all.png' alt=''> " . __s('to see the entity and its sub-entities') . ")</span>" . "<br>";
        echo "<a style='font-size:14px;' href='" . $target . "?active_entity=all' title=\"" . __s('Show all') . "\">" . str_replace(" ", "&nbsp;", __('Show all')) . "</a></div>";
        echo "<div class='left' style='width:100%'>";
        echo "<form id='entsearchform'>";
        echo Html::input('entsearchtext', array('id' => 'entsearchtext'));
        echo Html::submit(__('Search'), array('id' => 'entsearch'));
        echo "</form>";
        echo "<script type='text/javascript'>";
        echo Html::jsGetElementbyID("tree_projectcategory{$rand}") . "\n         // call `.jstree` with the options object\n         .jstree({\n            // the `plugins` array allows you to configure the active plugins on this instance\n            'plugins' : ['themes','json_data', 'search'],\n            'core': {\n               'load_open': true,\n               'html_titles': true,\n               'animation': 0\n            },\n            'themes': {\n               'theme': 'classic',\n               'url'  : '" . $CFG_GLPI["root_doc"] . "/css/jstree/style.css'\n            },\n            'search': {\n               'case_insensitive': true,\n               'show_only_matches': true,\n               'ajax': {\n                  'type': 'POST',\n                 'url': '" . $CFG_GLPI["root_doc"] . "/ajax/entitytreesearch.php'\n               }\n            },\n            'json_data': {\n               'ajax': {\n                  'type': 'POST',\n                  'url': function (node) {\n                     var nodeId = '';\n                     var url = '';\n                     if (node == -1) {\n                         url = '" . $CFG_GLPI["root_doc"] . "/ajax/entitytreesons.php?node=-1';\n                     }\n                     else {\n                         nodeId = node.attr('id');\n                         url = '" . $CFG_GLPI["root_doc"] . "/ajax/entitytreesons.php?node='+nodeId;\n                     }\n\n                     return url;\n                  },\n                  'success': function (new_data) {\n                      //where new_data = node children\n                      //e.g.: [{'data':'Hardware','attr':{'id':'child2'}},\n                      //         {'data':'Software','attr':{'id':'child3'}}]\n                      return new_data;\n                  },\n                  'progressive_render' : true\n               }\n            }\n         }).bind('select_node.jstree', function (e, data) {\n            document.location.href = data.rslt.obj.children('a').attr('href');\n         });\n\n         var searchTree = function() {\n            " . Html::jsGetElementbyID("tree_projectcategory{$rand}") . ".jstree('close_all');;\n            " . Html::jsGetElementbyID("tree_projectcategory{$rand}") . ".jstree('search'," . Html::jsGetDropdownValue('entsearchtext') . ");\n         }\n\n         \$('#entsearchform').submit(function( event ) {\n            // cancel submit of entity search form\n            event.preventDefault();\n\n            // search\n            searchTree();\n         });\n\n         // delay function who reinit timer on each call\n         var typewatch = (function(){\n            var timer = 0;\n            return function(callback, ms){\n               clearTimeout (timer);\n               timer = setTimeout(callback, ms);\n            };\n         })();\n\n         // autosearch on keypress (delayed and with min length)\n         \$('#entsearchtext').keyup(function () {\n            var inputsearch = \$(this);\n            typewatch(function () {\n               if (inputsearch.val().length >= 3) {\n                  searchTree();\n               }\n            }, 500);\n         })\n         .focus();\n     ";
        echo "</script>";
        echo "<div id='tree_projectcategory{$rand}' ></div>";
        echo "</div>";
    }

Usage Example

LICENSE

This file is part of GLPI.

GLPI is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

GLPI 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
$AJAX_INCLUDE = 1;
include '../inc/includes.php';
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkLoginUser();
if (!isset($_POST['target'])) {
    $_POST['target'] = $CFG_GLPI['root_doc'] . "/front/central.php";
}
Entity::showSelector($_POST['target'], "activeentity");
Html::ajaxFooter();