Separate AJAX cat adder into post and link flavors. see #4189

git-svn-id: http://svn.automattic.com/wordpress/trunk@5637 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2007-06-02 02:53:09 +00:00
parent 9828d17066
commit 4214428322
9 changed files with 45 additions and 6 deletions

View File

@ -125,6 +125,28 @@ case 'add-category' : // On the Fly
}
$x->send();
break;
case 'add-link-category' : // On the Fly
if ( !current_user_can( 'manage_categories' ) )
die('-1');
$names = explode(',', $_POST['newcat']);
$x = new WP_Ajax_Response();
foreach ( $names as $cat_name ) {
$cat_name = trim($cat_name);
if ( !$slug = sanitize_title($cat_name) )
die('0');
if ( !$cat_id = category_exists( $cat_name ) ) {
$cat_id = wp_insert_term( $cat_name, 'link_category' );
$cat_id = $cat_id['term_id'];
}
$cat_name = wp_specialchars(stripslashes($cat_name));
$x->add( array(
'what' => 'link-category',
'id' => $cat_id,
'data' => "<li id='link-category-$cat_id'><label for='in-link-category-$cat_id' class='selectit'><input value='$cat_id' type='checkbox' checked='checked' name='link_category[]' id='in-link-category-$cat_id'/> $cat_name</label></li>"
) );
}
$x->send();
break;
case 'add-cat' : // From Manage->Categories
if ( !current_user_can( 'manage_categories' ) )
die('-1');

View File

@ -43,7 +43,7 @@ function xfn_check($class, $value = '', $type = 'check') {
<h3 class="dbx-handle"><?php _e('Categories') ?></h3>
<div class="dbx-content">
<p id="jaxcat"></p>
<ul id="categorychecklist"><?php dropdown_link_categories(get_option('default_link_category')); ?></ul>
<ul id="linkcategorychecklist"><?php dropdown_link_categories(get_option('default_link_category')); ?></ul>
</div>
</fieldset>

View File

@ -13,7 +13,6 @@ function edit_link( $link_id = '' ) {
$_POST['link_name'] = wp_specialchars( $_POST['link_name'] );
$_POST['link_image'] = wp_specialchars( $_POST['link_image'] );
$_POST['link_rss'] = clean_url($_POST['link_rss']);
$_POST['link_category'] = $_POST['post_category'];
if ( !empty( $link_id ) ) {
$_POST['link_id'] = $link_id;

View File

@ -5,7 +5,10 @@
//
function category_exists($cat_name) {
return is_term($cat_name, 'category');
$id = is_term($cat_name, 'category');
if ( is_array($id) )
$id = $id['term_id'];
return $id;
}
function get_category_to_edit( $id ) {

View File

@ -157,7 +157,7 @@ function dropdown_link_categories( $default = 0 ) {
$cat_id = $category->term_id;
$name = wp_specialchars( apply_filters('the_category', $category->name));
$checked = in_array( $cat_id, $checked_categories );
echo '<li id="category-', $cat_id, '"><label for="in-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="post_category[]" id="in-category-', $cat_id, '"', ($checked ? ' checked="checked"' : "" ), '/> ', $name, "</label></li>";
echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', ($checked ? ' checked="checked"' : "" ), '/> ', $name, "</label></li>";
}
}

10
wp-admin/js/link-cat.js Normal file
View File

@ -0,0 +1,10 @@
addLoadEvent(function(){linkcatList=new listMan('linkcategorychecklist');linkcatList.ajaxRespEl='jaxcat';linkcatList.topAdder=1;linkcatList.alt=0;linkcatList.showLink=0;});
addLoadEvent(newLinkCatAddIn);
function newLinkCatAddIn() {
var jaxcat = $('jaxcat');
if ( !jaxcat )
return false;
Element.update(jaxcat,'<span id="ajaxcat"><input type="text" name="newcat" id="newcat" size="16" autocomplete="off"/><input type="button" name="Button" id="catadd" value="' + linkcatL10n.add + '"/><input type="hidden"/><span id="howto">' + linkcatL10n.how + '</span></span>');
$('newcat').onkeypress = function(e) { return killSubmit("linkcatList.ajaxAdder('link-category','jaxcat');", e); };
$('catadd').onclick = function() { linkcatList.ajaxAdder('link-category', 'jaxcat'); };
}

View File

@ -13,7 +13,7 @@ wp_reset_vars(array('action', 'cat_id', 'linkurl', 'name', 'image',
wp_enqueue_script( array('xfn', 'dbx-admin-key?pagenow=link.php') );
if ( current_user_can( 'manage_categories' ) )
wp_enqueue_script( 'ajaxcat' );
wp_enqueue_script( 'ajaxlinkcat' );
require('admin-header.php');
?>

View File

@ -93,7 +93,7 @@ switch ($action) {
case 'edit' :
wp_enqueue_script( array('xfn', 'dbx-admin-key?pagenow=link.php') );
if ( current_user_can( 'manage_categories' ) )
wp_enqueue_script( 'ajaxcat' );
wp_enqueue_script( 'ajaxlinkcat' );
$parent_file = 'link-manager.php';
$submenu_file = 'link-manager.php';
$title = __('Edit Link');

View File

@ -109,6 +109,11 @@ class WP_Scripts {
'add' => attribute_escape(__('Add')),
'how' => __('Separate multiple categories with commas.')
) );
$this->add( 'ajaxlinkcat', '/wp-admin/js/link-cat.js', array('listman'), '200700601' );
$this->localize( 'ajaxlinkcat', 'linkcatL10n', array(
'add' => attribute_escape(__('Add')),
'how' => __('Separate multiple categories with commas.')
) );
$this->add( 'admin-categories', '/wp-admin/js/categories.js', array('listman'), '3684' );
$this->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('listman'), '3733' );
$this->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('listman'), '20070327' );