Make WordPress Core

Changeset 3135


Ignore:
Timestamp:
11/17/2005 10:23:35 AM (20 years ago)
Author:
matt
Message:

Slicker category adding, fixes #1882

Location:
trunk/wp-admin
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-header.php

    r3112 r3135  
    111111
    112112<?php if ( current_user_can('manage_categories') ) : ?>
     113<style type="text/css">
     114#newcat { width: 120px; margin-right: 5px; }
     115input#catadd {  background: #a4a4a4;
     116    border-bottom: 1px solid #898989;
     117    border-left: 1px solid #bcbcbc;
     118    border-right: 1px solid #898989;
     119    border-top: 1px solid #bcbcbc;
     120    color: #fff;
     121    font-size: 10px;
     122    padding: 0;
     123    margin: 0;
     124    font-weight: bold;
     125    height: 20px;
     126    margin-bottom: 2px;
     127    text-align: center;
     128    width: 37px; }
     129#howto {
     130    font-size: 11px;
     131    margin: 0 5px;
     132    display: block;
     133}
     134#jaxcat {
     135    margin: 0;
     136    padding: 0;
     137}
     138</style>
    113139<script type="text/javascript">
    114140var ajaxCat = new sack();
     
    130156    newcatSub.type = 'button';
    131157    newcatSub.name = 'Button';
    132     newcatSub.value = '+';
    133     newcat.onkeypress = ajaxNewCatKeyPress;
     158    newcatSub.id = 'catadd';
     159    newcatSub.value = '<?php _e('Add'); ?>';
     160    newcatSub.onclick = ajaxNewCat;
    134161
    135162    ajaxcat.appendChild(newcat);
    136163    ajaxcat.appendChild(newcatSub);
    137     document.getElementById('categorychecklist').parentNode.appendChild(ajaxcat);
     164    document.getElementById('jaxcat').appendChild(ajaxcat);
     165
     166    howto = document.createElement('span');
     167    howto.innerHTML = '<?php _e('Separate multiple categories with commas.'); ?>';
     168    howto.id = 'howto';
     169    ajaxcat.appendChild(howto);
    138170}
    139171
     
    144176    if (!p) {
    145177        p = document.createElement('p');
    146         document.getElementById('categorydiv').appendChild(p);
     178        document.getElementById('jaxcat').appendChild(p);
    147179        p.id = 'ajaxcatresponse';
    148180    }
     
    162194function newCatInteractive() {
    163195    var p = getResponseElement();
    164     p.innerHTML = 'Processing Data...';
     196    p.innerHTML = 'Processing Request...';
    165197}
    166198
    167199function newCatCompletion() {
    168200    var p = getResponseElement();
    169     var id = parseInt(ajaxCat.response, 10);
    170     if ( id == '-1' ) {
    171         p.innerHTML = "You don't have permission to do that.";
    172         return;
    173     }
    174     if ( id == '0' ) {
    175         p.innerHTML = "That category name is invalid.  Try something else.";
    176         return;
     201//  alert(ajaxCat.response);
     202    var id    = 0;
     203    var ids   = new Array();
     204    var names = new Array();
     205   
     206    ids   = myPload( ajaxCat.response );
     207    names = myPload( newcat.value );
     208
     209    for ( i = 0; i < ids.length; i++ ) {
     210        id = ids[i];
     211//      alert(id);
     212        if ( id == '-1' ) {
     213            p.innerHTML = "You don't have permission to do that.";
     214            return;
     215        }
     216        if ( id == '0' ) {
     217            p.innerHTML = "That category name is invalid.  Try something else.";
     218            return;
     219        }
     220       
     221        var exists = document.getElementById('category-' + id);
     222       
     223        if (exists) {
     224            var moveIt = exists.parentNode;
     225            var container = moveIt.parentNode;
     226            container.removeChild(moveIt);
     227            container.insertBefore(moveIt, container.firstChild);
     228            moveIt.id = 'new-category-' + id;
     229            exists.checked = 'checked';
     230            var nowClass = moveIt.className;
     231            moveIt.className = nowClass + ' fade';
     232            Fat.fade_all();
     233            moveIt.className = nowClass;
     234        } else {
     235            var catDiv = document.getElementById('categorychecklist');
     236            var newLabel = document.createElement('label');
     237            newLabel.setAttribute('for', 'category-' + id);
     238            newLabel.id = 'new-category-' + id;
     239            newLabel.className = 'selectit fade';
     240   
     241            var newCheck = document.createElement('input');
     242            newCheck.type = 'checkbox';
     243            newCheck.value = id;
     244            newCheck.name = 'post_category[]';
     245            newCheck.id = 'category-' + id;
     246            newLabel.appendChild(newCheck);
     247   
     248            var newLabelText = document.createTextNode(' ' + names[i]);
     249            newLabel.appendChild(newLabelText);
     250   
     251            catDiv.insertBefore(newLabel, catDiv.firstChild);
     252            newCheck.checked = 'checked';
     253   
     254            Fat.fade_all();
     255            newLabel.className = 'selectit';
     256        }
     257        newcat.value = '';
    177258    }
    178259    p.parentNode.removeChild(p);
    179     var exists = document.getElementById('category-' + id);
    180     if (exists) {
    181         var moveIt = exists.parentNode;
    182         var container = moveIt.parentNode;
    183         container.removeChild(moveIt);
    184         container.insertBefore(moveIt, container.firstChild);
    185         moveIt.id = 'new-category-' + id;
    186         exists.checked = 'checked';
    187         var nowClass = moveIt.className;
    188         moveIt.className = nowClass + ' fade';
    189         Fat.fade_all();
    190         moveIt.className = nowClass;
    191     } else {
    192         var catDiv = document.getElementById('categorychecklist');
    193         var newLabel = document.createElement('label');
    194         newLabel.setAttribute('for', 'category-' + id);
    195         newLabel.id = 'new-category-' + id;
    196         newLabel.className = 'selectit fade';
    197 
    198         var newCheck = document.createElement('input');
    199         newCheck.type = 'checkbox';
    200         newCheck.value = id;
    201         newCheck.name = 'post_category[]';
    202         newCheck.id = 'category-' + id;
    203         newLabel.appendChild(newCheck);
    204 
    205         var newLabelText = document.createTextNode(' ' + newcat.value);
    206         newLabel.appendChild(newLabelText);
    207 
    208         catDiv.insertBefore(newLabel, catDiv.firstChild);
    209         newCheck.checked = 'checked';
    210 
    211         Fat.fade_all();
    212         newLabel.className = 'selectit';
    213     }
    214     newcat.value = '';
     260//  var id = parseInt(ajaxCat.response, 10);
     261
     262
    215263}
    216264
     
    233281function ajaxNewCat() {
    234282    var newcat = document.getElementById('newcat');
    235     var catString = 'ajaxnewcat=' + encodeURIComponent(newcat.value);
     283    var split_cats = new Array(1);
     284    var catString = '';
     285
     286    catString = 'ajaxnewcat=' + encodeURIComponent(newcat.value);
    236287    ajaxCat.requestFile = 'edit-form-ajax-cat.php';
    237288    ajaxCat.method = 'GET';
     
    242293    ajaxCat.runAJAX(catString);
    243294}
     295
     296function myPload( str ) {
     297    var fixedExplode = new Array();
     298    var comma = new String(',');
     299    var count = 0;
     300    var currentElement = '';
     301
     302    for( x=0; x < str.length; x++) {
     303        andy = str.charAt(x);
     304        if ( comma.indexOf(andy) != -1 ) {
     305            fixedExplode[count] = currentElement;
     306            currentElement = "";
     307            count++;
     308        } else {
     309            if ( ' ' != andy )
     310                currentElement += andy;
     311        }
     312    }
     313
     314    if ( currentElement != "" )
     315        fixedExplode[count] = currentElement;
     316    return fixedExplode;
     317}
     318
    244319</script>
    245320<?php endif; ?>
  • trunk/wp-admin/edit-form-advanced.php

    r3127 r3135  
    9090
    9191<fieldset id="categorydiv" class="dbx-box">
    92 <h3 class="dbx-handle"><?php _e('Categories') ?></h3>
    93 <div class="dbx-content"><div id="categorychecklist"><?php dropdown_categories(get_settings('default_category')); ?></div></div>
     92<h3 class="dbx-handle"><?php _e('Categories') ?></h3>
     93<div class="dbx-content">
     94<p id="jaxcat"></p>
     95<div id="categorychecklist"><?php dropdown_categories(get_settings('default_category')); ?></div></div>
    9496</fieldset>
    9597
  • trunk/wp-admin/edit-form-ajax-cat.php

    r3061 r3135  
    1313add_action('shutdown', 'get_out_now', -1);
    1414
    15 $cat_name = rawurldecode($_GET['ajaxnewcat']);
     15$names = explode(',', rawurldecode($_GET['ajaxnewcat']) );
     16$ids   = array();
    1617
    17 if ( !$category_nicename = sanitize_title($cat_name) )
    18     die('0');
    19 if ( $already = category_exists($cat_name) )
    20     die((string) $already);
     18foreach ($names as $cat_name) {
     19    $cat_name = trim( $cat_name );
     20   
     21    if ( !$category_nicename = sanitize_title($cat_name) )
     22        continue;
     23    if ( $already = category_exists($cat_name) ) {
     24        $ids[] = (string) $already;
     25        continue;
     26    }
     27   
     28    $new_cat_id = wp_create_category($cat_name);
     29   
     30    $ids[] = (string) $new_cat_id;
     31}
    2132
    22 $new_cat_id = wp_create_category($cat_name);
    23 die((string) $new_cat_id);
     33$return = join(',', $ids);
     34
     35die( (string) $return );
     36
    2437?>
  • trunk/wp-admin/menu.php

    r3112 r3135  
    1717$menu[40] = array(__('Options'), 'read', 'options-general.php');
    1818$menu[45] = array(__('Import'), 'import', 'import.php');
    19 
    20 if ( get_option('use_fileupload') )
    21     $menu[50] = array(__('Upload'), 'upload_files', 'upload.php');
    2219
    2320$submenu['post.php'][5] = array(__('Write Post'), 'edit_posts', 'post.php');
  • trunk/wp-admin/wp-admin.css

    r3133 r3135  
    190190    width: 250px;
    191191    height: 200px;
    192     display: inline-block;
     192    display: block;
    193193    margin: auto;
    194194    background: #f1f1f1;
     
    818818    top: 10px;
    819819    right: 14px;
    820     background-repeat: none;
     820    background-repeat: no-repeat;
    821821    border-bottom: 0;
    822822    background-position: 0 9px;
Note: See TracChangeset for help on using the changeset viewer.