function wpm_ajax() { $command = $_POST['command']; $type = $_POST['type']; switch ($command) { case 'typeargs': include_once 'wpm-edit.php'; wpm_typeargs($type); break; default: echo "bad ajax command received: {$command}\n"; break; } exit; }
function wpm_item_form($action, $menuid, $item = null) { global $wpm_options; global $wpm_type_list; $menu = wpm_read_node($menuid); ?> <script type='text/javascript'> jQuery(document).ready(function($) { $("#order").change(function() { if ($("#order option:selected").val() == 0) $("#orderid").css("display", "none"); else $("#orderid").css("display", ""); }); }); </script> <script type='text/javascript'> jQuery(document).ready ( function ($) { $("#type").change ( function () { var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?> '; var typeargs = $("#typeargs"); var saveargs = $("#saveargs"); var typespinner = $("#typespinner"); var typevalue = $("#type option:selected").val(); typeargs.css ("display", "none"); saveargs.css ("display", "none"); typespinner.css ("display", ""); $.post (ajaxurl, { action: "menubar", command: "typeargs", type: typevalue }, function (data) { if (typevalue == "<?php echo $item->type; ?> ") { if (saveargs.html()) saveargs.css ("display", ""); } else if (data) { typeargs.html (data); typeargs.css ("display", ""); } typespinner.css ("display", "none"); }); return false; }); }); </script> <?php $item_list = wpm_item_list($menuid, array(), 0); if ($action == 'edit') { $heading = __('Edit Menu Item', 'wpm'); $submit_text = __('Edit Menu Item', 'wpm'); $form = '<form method="post" action="' . $wpm_options->form_action . '">'; $action = 'update'; $nonce_action = 'update_' . $item->id; $selected = key($item_list); $mincount = 1; } else { $heading = __('Add Menu Item', 'wpm'); $submit_text = __('Add Menu Item', 'wpm'); $form = '<form method="post" action="' . $wpm_options->form_action . '">'; $action = 'add'; $nonce_action = 'add'; end($item_list); $selected = key($item_list); $mincount = 0; } ?> <div class="wrap"> <h2><?php echo $heading; ?> </h2> <?php echo $form; ?> <input type="hidden" name="action" value="<?php echo $action; ?> " /> <input type="hidden" name="menuid" value="<?php echo $menuid; ?> " /> <input type="hidden" name="itemid" value="<?php echo $item->id; ?> " /> <?php wp_nonce_field($nonce_action); ?> <table class="editform"> <?php if (count($item_list) > $mincount) { wpm_order(__('Order:', 'wpm'), 'orderid', '', $item_list, $selected, $action); } ?> <?php wpm_input(__('Name:', 'wpm'), 'name', $item->name, 40, __('(e.g. Home, News)', 'wpm')); if ($menu->features['images'] == true) { wpm_input(__('Image:', 'wpm'), 'imageurl', $item->imageurl, 50, __('(optional image URL)', 'wpm')); } ?> <?php wpm_select(__('Type:', 'wpm'), 'type', $wpm_type_list, $item->type); ?> </table> <table id="saveargs" class="editform"> <?php if ($action == 'update') { wpm_typeargs($item->type, $item); } ?> </table> <table id="typeargs" class="editform" style="display: none;"> </table> <table class="editform"> <?php wpm_input(__('CSS class:', 'wpm'), 'cssclass', $item->cssclass, 30, __('(optional CSS class of this menu item)', 'wpm')); wpm_input(__('Attributes:', 'wpm'), 'attributes', $item->attributes, 30, __('(e.g. target="_blank", title="click me!")', 'wpm')); ?> </table> <p class="submit"> <input type="submit" name="submit" value="<?php echo $submit_text; ?> " /> </p> </form> </div> <?php }