本文整理汇总了PHP中Ajax::commonDropdownUpdateItem方法的典型用法代码示例。如果您正苦于以下问题:PHP Ajax::commonDropdownUpdateItem方法的具体用法?PHP Ajax::commonDropdownUpdateItem怎么用?PHP Ajax::commonDropdownUpdateItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ajax
的用法示例。
在下文中一共展示了Ajax::commonDropdownUpdateItem方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __
$search = Search::makeTextSearch($_POST['searchText']);
$query .= " AND `gr`.`name` " . $search;
}
$query .= "ORDER BY `gr`.`name` ASC";
if ($result = $DB->query($query)) {
if ($_POST['searchText'] != $CFG_GLPI["ajax_wildcard"] && $DB->numrows($result) == $NBMAX) {
echo "<option value='0'>--" . __("Limited view") . "--</option>";
} else {
if (!isset($_POST['display_emptychoice']) || $_POST['display_emptychoice']) {
echo "<option value='0'>" . $_POST["emptylabel"] . "</option>";
}
}
foreach ($DB->request($query) as $data) {
echo "<option value='" . $data["id"] . "'>" . $data['name'];
if ($data['reference_code']) {
echo " (" . $data['reference_code'] . ")";
}
echo "</option>\n";
}
}
echo "</select>";
if (isset($_POST["comment"]) && $_POST["comment"]) {
$paramscomment = array('value' => '__VALUE__', 'table' => $table);
Ajax::updateItemOnSelectEvent("dropdown_" . $_POST["myname"] . $_POST["rand"], "comment_" . $_POST["myname"] . $_POST["rand"], $CFG_GLPI["root_doc"] . "/ajax/comments.php", $paramscomment);
}
if (isset($_POST["action"]) && $_POST["action"]) {
$params = array($_POST['myname'] => '__VALUE__', 'entity_restrict' => $_POST['entity_restrict'], 'suppliers_id' => $_POST["suppliers_id"], 'rand' => $_POST['rand'], 'itemtype' => $_POST['itemtype']);
Ajax::updateItemOnSelectEvent("dropdown_" . $_POST["myname"] . $_POST["rand"], $_POST['span'], $_POST['action'], $params);
}
Ajax::commonDropdownUpdateItem($_POST);
示例2: dropdown
//.........这里部分代码省略.........
* (need value_fieldname, to_update, url
* (see Ajax::updateItemOnSelectEvent for information)
* and may have moreparams)
* - used : array / Already used items ID: not to display in dropdown (default empty)
* - ldap_import
* - on_change : string / value to transmit to "onChange"
* - display : boolean / display or get string (default true)
* - width : specific width needed (default 80%)
* - specific_tags : array of HTML5 tags to add the the field
* - url : url of the ajax php code which should return the json data to show in
* the dropdown (default /ajax/getDropdownUsers.php)
*
* @return rand value if displayed / string if not
**/
static function dropdown($options = array())
{
global $DB, $CFG_GLPI;
// Default values
$p['name'] = 'users_id';
$p['value'] = '';
$p['right'] = 'id';
$p['all'] = 0;
$p['on_change'] = '';
$p['comments'] = 1;
$p['width'] = '80%';
$p['entity'] = -1;
$p['entity_sons'] = false;
$p['used'] = array();
$p['ldap_import'] = false;
$p['toupdate'] = '';
$p['rand'] = mt_rand();
$p['display'] = true;
$p['_user_index'] = 0;
$p['specific_tags'] = array();
$p['url'] = $CFG_GLPI['root_doc'] . "/ajax/getDropdownUsers.php";
if (is_array($options) && count($options)) {
foreach ($options as $key => $val) {
$p[$key] = $val;
}
}
// check default value (in case of multiple observers)
if (is_array($p['value'])) {
$p['value'] = $p['value'][$p['_user_index']];
}
// Check default value for dropdown : need to be a numeric
if (strlen($p['value']) == 0 || !is_numeric($p['value'])) {
$p['value'] = 0;
}
$output = '';
if (!($p['entity'] < 0) && $p['entity_sons']) {
if (is_array($p['entity'])) {
$output .= "entity_sons options is not available with array of entity";
} else {
$p['entity'] = getSonsOf('glpi_entities', $p['entity']);
}
}
// Make a select box with all glpi users
$user = getUserName($p['value'], 2);
$view_users = self::canView();
if (!empty($p['value']) && $p['value'] > 0) {
$default = $user["name"];
} else {
if ($p['all']) {
$default = __('All');
} else {
$default = Dropdown::EMPTY_VALUE;
}
}
$field_id = Html::cleanId("dropdown_" . $p['name'] . $p['rand']);
$param = array('value' => $p['value'], 'valuename' => $default, 'width' => $p['width'], 'all' => $p['all'], 'right' => $p['right'], 'on_change' => $p['on_change'], 'used' => $p['used'], 'entity_restrict' => $p['entity'], 'specific_tags' => $p['specific_tags']);
$output = Html::jsAjaxDropdown($p['name'], $field_id, $p['url'], $param);
// Display comment
if ($p['comments']) {
$comment_id = Html::cleanId("comment_" . $p['name'] . $p['rand']);
$link_id = Html::cleanId("comment_link_" . $p["name"] . $p['rand']);
if (!$view_users) {
$user["link"] = '';
} else {
if (empty($user["link"])) {
$user["link"] = $CFG_GLPI['root_doc'] . "/front/user.php";
}
}
$output .= " " . Html::showToolTip($user["comment"], array('contentid' => $comment_id, 'display' => false, 'link' => $user["link"], 'linkid' => $link_id));
$paramscomment = array('value' => '__VALUE__', 'table' => "glpi_users");
if ($view_users) {
$paramscomment['withlink'] = $link_id;
}
$output .= Ajax::updateItemOnSelectEvent($field_id, $comment_id, $CFG_GLPI["root_doc"] . "/ajax/comments.php", $paramscomment, false);
}
$output .= Ajax::commonDropdownUpdateItem($p, false);
if (Session::haveRight('user', self::IMPORTEXTAUTHUSERS) && $p['ldap_import'] && Entity::isEntityDirectoryConfigured($_SESSION['glpiactive_entity'])) {
$output .= "<img alt='' title=\"" . __s('Import a user') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png' style='cursor:pointer; margin-left:2px;'\n onClick=\"" . Html::jsGetElementbyID('userimport' . $p['rand']) . ".dialog('open');\">";
$output .= Ajax::createIframeModalWindow('userimport' . $p['rand'], $CFG_GLPI["root_doc"] . "/front/ldap.import.php?entity=" . $_SESSION['glpiactive_entity'], array('title' => __('Import a user'), 'display' => false));
}
if ($p['display']) {
echo $output;
return $p['rand'];
}
return $output;
}
示例3: showFromArray
//.........这里部分代码省略.........
$max_option_size = 0;
foreach ($elements as $key => $val) {
// optgroup management
if (is_array($val)) {
$opt_goup = Html::entities_deep($key);
if ($max_option_size < strlen($opt_goup)) {
$max_option_size = strlen($opt_goup);
}
$output .= "<optgroup label=\"{$opt_goup}\"";
$optgroup_tooltips = false;
if (isset($param['option_tooltips'][$key])) {
if (is_array($param['option_tooltips'][$key])) {
if (isset($param['option_tooltips'][$key]['__optgroup_label'])) {
$output .= ' title="' . $param['option_tooltips'][$key]['__optgroup_label'] . '"';
}
$optgroup_tooltips = $param['option_tooltips'][$key];
} else {
$output .= ' title="' . $param['option_tooltips'][$key] . '"';
}
}
$output .= ">";
foreach ($val as $key2 => $val2) {
if (!isset($param['used'][$key2])) {
$output .= "<option value='" . $key2 . "'";
// Do not use in_array : trouble with 0 and empty value
foreach ($param['values'] as $value) {
if (strcmp($key2, $value) === 0) {
$output .= " selected";
break;
}
}
if ($optgroup_tooltips && isset($optgroup_tooltips[$key2])) {
$output .= ' title="' . $optgroup_tooltips[$key2] . '"';
}
$output .= ">" . $val2 . "</option>";
if ($max_option_size < strlen($val2)) {
$max_option_size = strlen($val2);
}
}
}
$output .= "</optgroup>";
} else {
if (!isset($param['used'][$key])) {
$output .= "<option value='" . $key . "'";
// Do not use in_array : trouble with 0 and empty value
foreach ($param['values'] as $value) {
if (strcmp($key, $value) === 0) {
$output .= " selected";
break;
}
}
if (isset($param['option_tooltips'][$key])) {
$output .= ' title="' . $param['option_tooltips'][$key] . '"';
}
$output .= ">" . $val . "</option>";
if ($max_option_size < strlen($val)) {
$max_option_size = strlen($val);
}
}
}
}
if ($param['other'] !== false) {
$output .= "<option value='{$other_select_option}'";
if (is_string($param['other'])) {
$output .= " selected";
}
$output .= ">" . __('Other...') . "</option>";
}
$output .= "</select>";
if ($param['other'] !== false) {
$output .= "<input name='{$other_select_option}' id='{$other_select_option}' type='text'";
if (is_string($param['other'])) {
$output .= " value=\"" . $param['other'] . "\"";
} else {
$output .= " style=\"display: none\"";
}
$output .= ">";
}
}
// Width set on select
$output .= Html::jsAdaptDropdown($field_id, array('width' => $param["width"]));
if ($param["multiple"]) {
// Hack for All / None because select2 does not provide it
$select = __('All');
$deselect = __('None');
$output .= "<div class='invisible' id='selectallbuttons_{$field_id}'>";
$output .= "<div class='select2-actionable-menu'>";
$output .= "<a class='vsubmit floatleft' " . "onclick=\"selectAll('{$field_id}');\$('#{$field_id}').select2('close');\">{$select}" . "</a> ";
$output .= "<a class='vsubmit floatright' onclick=\"deselectAll('{$field_id}');\">{$deselect}" . "</a>";
$output .= "</div></div>";
$js = "\n var multichecksappend{$field_id} = false;\n \$('#{$field_id}').on('select2-open', function() {\n if (!multichecksappend{$field_id}) {\n \$('#select2-drop').append(\$('#selectallbuttons_{$field_id}').html());\n multichecksappend{$field_id} = true;\n }\n });";
$output .= Html::scriptBlock($js);
}
$output .= Ajax::commonDropdownUpdateItem($param, false);
if ($param['display']) {
echo $output;
return $param['rand'];
}
return $output;
}