Dotclear

Changeset 1953:c3e851963891


Ignore:
Timestamp:
09/18/13 22:48:53 (12 years ago)
Author:
Nicolas <nikrou77@…>
Branch:
default
Message:

Improve and simplify categories page

Location:
admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • admin/categories.php

    r1760 r1953  
    1616 
    1717# Remove a categories 
    18 if (!empty($_POST['categories']) && !empty($_POST['delete'])) { 
     18if (!empty($_POST['delete'])) { 
     19     $keys = array_keys($_POST['delete']); 
     20     $cat_id = (int) $keys[0]; 
     21 
     22     # Check if category to delete exists 
     23     $c = $core->blog->getCategory((integer) $cat_id); 
     24     if ($c->isEmpty()) { 
     25          http::redirect('categories.php?unknown=1'); 
     26     } 
     27     unset($c); 
     28 
     29     try { 
     30          # Delete category 
     31          $core->blog->delCategory($cat_id); 
     32          http::redirect('categories.php?del=1'); 
     33     } catch (Exception $e) { 
     34          $core->error->add($e->getMessage()); 
     35     } 
     36} 
     37 
     38# move post into a category 
     39if (!empty($_POST['mov']) && !empty($_POST['mov_cat'])) { 
    1940     try { 
    2041          # Check if category where to move posts exists 
    21           $mov_cat = (int) $_POST['mov_cat']; 
     42          $keys = array_keys($_POST['mov']); 
     43          $cat_id = (int) $keys[0]; 
     44          $mov_cat = (int) $_POST['mov_cat'][$cat_id]; 
     45           
    2246          $mov_cat = $mov_cat ? $mov_cat : null; 
    2347          if ($mov_cat !== null) { 
     
    2751               } 
    2852               unset($c); 
    29  
    30                if (in_array($mov_cat, $_POST['categories'])) { 
    31                     throw new Exception(__('The entries cannot be moved to the category you choose to delete.')); 
    32                } 
    33           } 
    34  
    35           foreach ($_POST['categories'] as $cat_id) { 
    36                # Check if category to delete exists 
    37                $c = $core->blog->getCategory((integer) $cat_id); 
    38                if ($c->isEmpty()) { 
    39                     continue; 
    40                } 
    41                unset($c); 
    42  
    43                # Move posts 
    44                if ($mov_cat != $cat_id) { 
    45                        $core->blog->changePostsCategory($cat_id,$mov_cat); 
    46                } 
    47  
    48                # Delete category 
    49                $core->blog->delCategory($cat_id); 
    50           } 
    51           http::redirect('categories.php?del='.count($_POST['categories'])); 
     53          } 
     54          # Move posts 
     55          if ($mov_cat != $cat_id) { 
     56               $core->blog->changePostsCategory($cat_id,$mov_cat); 
     57          } 
     58          http::redirect('categories.php?move=1'); 
    5259     } catch (Exception $e) { 
    5360          $core->error->add($e->getMessage()); 
     
    105112 
    106113if (!empty($_GET['del'])) { 
    107         dcPage::success(__('The category has been successfully removed.', 
    108                   'The categories have been successfully removed.', 
    109                   (int) $_GET['del'] 
    110                   ) 
    111                ); 
     114     dcPage::success(__('The category has been successfully removed.')); 
    112115} 
    113116if (!empty($_GET['reord'])) { 
    114117     dcPage::success(__('Categories have been successfully reordered.')); 
    115118} 
     119if (!empty($_GET['unknown'])) { 
     120     dcPage::success(__('This category does not exist.')); 
     121} 
     122if (!empty($_GET['move'])) { 
     123     dcPage::success(__('Entries have been successfully moved to the category you choose.')); 
     124} 
     125 
    116126$categories_combo = dcAdminCombos::getCategoriesCombo($rs); 
    117127 
     
    147157 
    148158          echo 
    149           '<p>'. 
    150           form::checkbox(array('categories[]','cat-'.$rs->cat_id),$rs->cat_id,null,$rs->nb_total>0?'notempty':''). 
     159          '<p>'.        
    151160          '<label class="classic" for="cat-'.$rs->cat_id.'"><a href="category.php?id='.$rs->cat_id.'">'.html::escapeHTML($rs->cat_title).'</a></label>'. 
    152161          ' (<a href="posts.php?cat_id='.$rs->cat_id.'">'. 
    153162          sprintf(($rs->nb_post > 1 ? __('%d entries') : __('%d entry') ),$rs->nb_post).'</a>'. 
    154163          ', '.__('total:').' '.$rs->nb_total.') '. 
    155           '<span class="cat-url">'.__('URL:').' <code>'.html::escapeHTML($rs->cat_url).'</code></span></p>'; 
     164               '<span class="cat-url">'.__('URL:').' <code>'.html::escapeHTML($rs->cat_url).'</code></span>'; 
     165 
     166          if ($rs->nb_total>0) { 
     167               // remove current category 
     168               echo  
     169               form::combo('mov_cat['.$rs->cat_id.']',array_filter($categories_combo, function($cat) use ($rs) {return ($cat->value!=$rs->cat_id);}),'',''). 
     170               '<input type="submit" class="" name="mov['.$rs->cat_id.']" value="'.__('Ok').'"/>'; 
     171              
     172               $attr_disabled = ' disabled="disabled"'; 
     173               $input_class = 'disabled '; 
     174          } else { 
     175               $attr_disabled = ''; 
     176               $input_class = ''; 
     177          } 
     178          echo  
     179          '<input type="submit"'.$attr_disabled.' class="'.$input_class.'delete" name="delete['.$rs->cat_id.']" value="'.__('Delete category').'"/>'. 
     180          '</p>'; 
    156181 
    157182          $level = $rs->level; 
     
    162187     } 
    163188     echo 
    164      '</div>'; 
    165  
    166      echo 
    167      '<div class="two-cols">'. 
    168      '<p class="col checkboxes-helpers"></p>'. 
    169      '<p class="col right" id="mov-cat">'. 
    170      '<label for="mov_cat" class="classic">'.__('Category where entries of deleted categories will be moved:').'</label> '. 
    171      form::combo('mov_cat',$categories_combo,'',''). 
    172      '</p>'. 
    173      '<p class="right">'. 
    174      '<input type="submit" class="delete" name="delete" value="'.__('Delete selected categories').'"/>'. 
    175      '</p>'. 
    176189     '</div>'; 
    177190 
  • admin/js/_categories.js

    r1595 r1953  
    1414     } 
    1515 
    16      $('.checkboxes-helpers').each(function() { 
    17           dotclear.checkboxesHelpers(this); 
    18      }); 
    19  
    20      $('input[name="delete"]').click(function() { 
    21           var nb_ckecked = $('input[name="categories[]"]:checked').length; 
    22           if (nb_ckecked==0) { 
    23                return false; 
    24           } 
    25  
    26           return window.confirm(dotclear.msg.confirm_delete_categories.replace('%s',nb_ckecked)); 
     16     $('input[name^="delete"]').click(function() { 
     17          return window.confirm(dotclear.msg.confirm_delete_category.replace('%s',$(this).parent().find('label a').text())); 
    2718     }); 
    2819 
Note: See TracChangeset for help on using the changeset viewer.

Sites map