Html::jsGetDropdownValue PHP Method

jsGetDropdownValue() static public method

Get item value
static public jsGetDropdownValue ( $id ) : string
$id string id of the dom element
return string
    static function jsGetDropdownValue($id)
    {
        return self::jsGetElementbyID($id) . ".val()";
    }

Usage Example

Example #1
0
 /**
  * Display entities of the loaded profile
  *
  * @param $target target for entity change action
  * @param $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>";
 }
Html