Slicker category adding, fixes #1882

git-svn-id: http://svn.automattic.com/wordpress/trunk@3135 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
matt 2005-11-17 10:23:35 +00:00
parent c9685b895a
commit 20660c0ffb
5 changed files with 150 additions and 63 deletions

View File

@ -110,6 +110,32 @@ tinyMCE.init({
<script type="text/javascript" src="../wp-includes/js/dbx-key.js"></script> <script type="text/javascript" src="../wp-includes/js/dbx-key.js"></script>
<?php if ( current_user_can('manage_categories') ) : ?> <?php if ( current_user_can('manage_categories') ) : ?>
<style type="text/css">
#newcat { width: 120px; margin-right: 5px; }
input#catadd { background: #a4a4a4;
border-bottom: 1px solid #898989;
border-left: 1px solid #bcbcbc;
border-right: 1px solid #898989;
border-top: 1px solid #bcbcbc;
color: #fff;
font-size: 10px;
padding: 0;
margin: 0;
font-weight: bold;
height: 20px;
margin-bottom: 2px;
text-align: center;
width: 37px; }
#howto {
font-size: 11px;
margin: 0 5px;
display: block;
}
#jaxcat {
margin: 0;
padding: 0;
}
</style>
<script type="text/javascript"> <script type="text/javascript">
var ajaxCat = new sack(); var ajaxCat = new sack();
var newcat; var newcat;
@ -129,12 +155,18 @@ function newCatAddIn() {
var newcatSub = document.createElement('input'); var newcatSub = document.createElement('input');
newcatSub.type = 'button'; newcatSub.type = 'button';
newcatSub.name = 'Button'; newcatSub.name = 'Button';
newcatSub.value = '+'; newcatSub.id = 'catadd';
newcat.onkeypress = ajaxNewCatKeyPress; newcatSub.value = '<?php _e('Add'); ?>';
newcatSub.onclick = ajaxNewCat;
ajaxcat.appendChild(newcat); ajaxcat.appendChild(newcat);
ajaxcat.appendChild(newcatSub); ajaxcat.appendChild(newcatSub);
document.getElementById('categorychecklist').parentNode.appendChild(ajaxcat); document.getElementById('jaxcat').appendChild(ajaxcat);
howto = document.createElement('span');
howto.innerHTML = '<?php _e('Separate multiple categories with commas.'); ?>';
howto.id = 'howto';
ajaxcat.appendChild(howto);
} }
addLoadEvent(newCatAddIn); addLoadEvent(newCatAddIn);
@ -143,7 +175,7 @@ function getResponseElement() {
var p = document.getElementById('ajaxcatresponse'); var p = document.getElementById('ajaxcatresponse');
if (!p) { if (!p) {
p = document.createElement('p'); p = document.createElement('p');
document.getElementById('categorydiv').appendChild(p); document.getElementById('jaxcat').appendChild(p);
p.id = 'ajaxcatresponse'; p.id = 'ajaxcatresponse';
} }
return p; return p;
@ -161,12 +193,22 @@ function newCatLoaded() {
function newCatInteractive() { function newCatInteractive() {
var p = getResponseElement(); var p = getResponseElement();
p.innerHTML = 'Processing Data...'; p.innerHTML = 'Processing Request...';
} }
function newCatCompletion() { function newCatCompletion() {
var p = getResponseElement(); var p = getResponseElement();
var id = parseInt(ajaxCat.response, 10); // alert(ajaxCat.response);
var id = 0;
var ids = new Array();
var names = new Array();
ids = myPload( ajaxCat.response );
names = myPload( newcat.value );
for ( i = 0; i < ids.length; i++ ) {
id = ids[i];
// alert(id);
if ( id == '-1' ) { if ( id == '-1' ) {
p.innerHTML = "You don't have permission to do that."; p.innerHTML = "You don't have permission to do that.";
return; return;
@ -175,8 +217,9 @@ function newCatCompletion() {
p.innerHTML = "That category name is invalid. Try something else."; p.innerHTML = "That category name is invalid. Try something else.";
return; return;
} }
p.parentNode.removeChild(p);
var exists = document.getElementById('category-' + id); var exists = document.getElementById('category-' + id);
if (exists) { if (exists) {
var moveIt = exists.parentNode; var moveIt = exists.parentNode;
var container = moveIt.parentNode; var container = moveIt.parentNode;
@ -202,7 +245,7 @@ function newCatCompletion() {
newCheck.id = 'category-' + id; newCheck.id = 'category-' + id;
newLabel.appendChild(newCheck); newLabel.appendChild(newCheck);
var newLabelText = document.createTextNode(' ' + newcat.value); var newLabelText = document.createTextNode(' ' + names[i]);
newLabel.appendChild(newLabelText); newLabel.appendChild(newLabelText);
catDiv.insertBefore(newLabel, catDiv.firstChild); catDiv.insertBefore(newLabel, catDiv.firstChild);
@ -212,6 +255,11 @@ function newCatCompletion() {
newLabel.className = 'selectit'; newLabel.className = 'selectit';
} }
newcat.value = ''; newcat.value = '';
}
p.parentNode.removeChild(p);
// var id = parseInt(ajaxCat.response, 10);
} }
function ajaxNewCatKeyPress(e) { function ajaxNewCatKeyPress(e) {
@ -232,7 +280,10 @@ function ajaxNewCatKeyPress(e) {
function ajaxNewCat() { function ajaxNewCat() {
var newcat = document.getElementById('newcat'); var newcat = document.getElementById('newcat');
var catString = 'ajaxnewcat=' + encodeURIComponent(newcat.value); var split_cats = new Array(1);
var catString = '';
catString = 'ajaxnewcat=' + encodeURIComponent(newcat.value);
ajaxCat.requestFile = 'edit-form-ajax-cat.php'; ajaxCat.requestFile = 'edit-form-ajax-cat.php';
ajaxCat.method = 'GET'; ajaxCat.method = 'GET';
ajaxCat.onLoading = newCatLoading; ajaxCat.onLoading = newCatLoading;
@ -241,6 +292,30 @@ function ajaxNewCat() {
ajaxCat.onCompletion = newCatCompletion; ajaxCat.onCompletion = newCatCompletion;
ajaxCat.runAJAX(catString); ajaxCat.runAJAX(catString);
} }
function myPload( str ) {
var fixedExplode = new Array();
var comma = new String(',');
var count = 0;
var currentElement = '';
for( x=0; x < str.length; x++) {
andy = str.charAt(x);
if ( comma.indexOf(andy) != -1 ) {
fixedExplode[count] = currentElement;
currentElement = "";
count++;
} else {
if ( ' ' != andy )
currentElement += andy;
}
}
if ( currentElement != "" )
fixedExplode[count] = currentElement;
return fixedExplode;
}
</script> </script>
<?php endif; ?> <?php endif; ?>

View File

@ -90,7 +90,9 @@ addLoadEvent(focusit);
<fieldset id="categorydiv" class="dbx-box"> <fieldset id="categorydiv" class="dbx-box">
<h3 class="dbx-handle"><?php _e('Categories') ?></h3> <h3 class="dbx-handle"><?php _e('Categories') ?></h3>
<div class="dbx-content"><div id="categorychecklist"><?php dropdown_categories(get_settings('default_category')); ?></div></div> <div class="dbx-content">
<p id="jaxcat"></p>
<div id="categorychecklist"><?php dropdown_categories(get_settings('default_category')); ?></div></div>
</fieldset> </fieldset>
<fieldset class="dbx-box"> <fieldset class="dbx-box">

View File

@ -12,13 +12,26 @@ function get_out_now() { exit; }
add_action('shutdown', 'get_out_now', -1); add_action('shutdown', 'get_out_now', -1);
$cat_name = rawurldecode($_GET['ajaxnewcat']); $names = explode(',', rawurldecode($_GET['ajaxnewcat']) );
$ids = array();
foreach ($names as $cat_name) {
$cat_name = trim( $cat_name );
if ( !$category_nicename = sanitize_title($cat_name) ) if ( !$category_nicename = sanitize_title($cat_name) )
die('0'); continue;
if ( $already = category_exists($cat_name) ) if ( $already = category_exists($cat_name) ) {
die((string) $already); $ids[] = (string) $already;
continue;
}
$new_cat_id = wp_create_category($cat_name); $new_cat_id = wp_create_category($cat_name);
die((string) $new_cat_id);
$ids[] = (string) $new_cat_id;
}
$return = join(',', $ids);
die( (string) $return );
?> ?>

View File

@ -17,9 +17,6 @@ else
$menu[40] = array(__('Options'), 'read', 'options-general.php'); $menu[40] = array(__('Options'), 'read', 'options-general.php');
$menu[45] = array(__('Import'), 'import', 'import.php'); $menu[45] = array(__('Import'), 'import', 'import.php');
if ( get_option('use_fileupload') )
$menu[50] = array(__('Upload'), 'upload_files', 'upload.php');
$submenu['post.php'][5] = array(__('Write Post'), 'edit_posts', 'post.php'); $submenu['post.php'][5] = array(__('Write Post'), 'edit_posts', 'post.php');
$submenu['post.php'][10] = array(__('Write Page'), 'edit_pages', 'page-new.php'); $submenu['post.php'][10] = array(__('Write Page'), 'edit_pages', 'page-new.php');

View File

@ -189,7 +189,7 @@ textarea, input, select {
.available-theme a.screenshot { .available-theme a.screenshot {
width: 250px; width: 250px;
height: 200px; height: 200px;
display: inline-block; display: block;
margin: auto; margin: auto;
background: #f1f1f1; background: #f1f1f1;
border: 1px solid #ccc; border: 1px solid #ccc;
@ -817,7 +817,7 @@ a.dbx-toggle, a.dbx-toggle:visited {
position: absolute; position: absolute;
top: 10px; top: 10px;
right: 14px; right: 14px;
background-repeat: none; background-repeat: no-repeat;
border-bottom: 0; border-bottom: 0;
background-position: 0 9px; background-position: 0 9px;
} }