Dotclear

Changeset 1417:c13469e071ea


Ignore:
Timestamp:
08/16/13 20:35:03 (11 years ago)
Author:
Denis Jean-Christian <contact@…>
Branch:
2.5
Message:

Enhance categories combo and other fix, step 4, addresses #1424

Location:
admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • admin/js/_post.js

    r1256 r1417  
    123123               hide: $('#post_notes').val() == '' 
    124124          }); 
     125          $('#new_cat').toggleWithLegend( 
     126               $('#new_cat').parent().children().not('#new_cat'), 
     127               {} // no cookie on new category as we don't use this every day 
     128          ); 
    125129          $('#post_lang').parent().toggleWithLegend($('#post_lang'),{ 
    126130               cookie: 'dcx_post_lang' 
  • admin/post.php

    r1288 r1417  
    4949     $post_status = -2; 
    5050} 
    51  
    52 # Getting categories 
    53 $categories_combo = array('&nbsp;' => ''); 
    54 try { 
    55      $categories = $core->blog->getCategories(array('post_type'=>'post')); 
    56      while ($categories->fetch()) { 
    57           $categories_combo[] = new formSelectOption( 
    58                str_repeat('&nbsp;&nbsp;',$categories->level-1).($categories->level-1 == 0 ? '' : '&bull; ').html::escapeHTML($categories->cat_title), 
    59                $categories->cat_id 
    60           ); 
    61      } 
    62 } catch (Exception $e) { } 
    6351 
    6452# Status combo 
     
    218206if (!empty($_POST) && !empty($_POST['save']) && $can_edit_post && !$bad_dt) 
    219207{ 
     208     # Create category 
     209     if (!empty($_POST['new_cat_title']) && $core->auth->check('categories', $core->blog->id)) { 
     210      
     211          $cur_cat = $core->con->openCursor($core->prefix.'category'); 
     212          $cur_cat->cat_title = $_POST['new_cat_title']; 
     213          $cur_cat->cat_url = ''; 
     214           
     215          $parent_cat = !empty($_POST['new_cat_parent']) ? $_POST['new_cat_parent'] : ''; 
     216           
     217          # --BEHAVIOR-- adminBeforeCategoryCreate 
     218          $core->callBehavior('adminBeforeCategoryCreate', $cur_cat); 
     219           
     220          $cat_id = $core->blog->addCategory($cur_cat, (integer) $parent_cat); 
     221           
     222          # --BEHAVIOR-- adminAfterCategoryCreate 
     223          $core->callBehavior('adminAfterCategoryCreate', $cur_cat, $cat_id); 
     224     } 
     225      
    220226     $cur = $core->con->openCursor($core->prefix.'post'); 
    221227      
     
    283289     } 
    284290} 
     291 
     292# Getting categories 
     293$categories_combo = array(__('(No cat)') => ''); 
     294try { 
     295     $categories = $core->blog->getCategories(array('post_type'=>'post')); 
     296     if (!$categories->isEmpty()) { 
     297          $l = $categories->level; 
     298          $full_name = array($categories->cat_title); 
     299 
     300          while ($categories->fetch()) { 
     301               if ($categories->level < $l) { 
     302                    $full_name = array(); 
     303               } elseif ($categories->level == $l) { 
     304                    array_pop($full_name); 
     305               } 
     306               $full_name[] = html::escapeHTML($categories->cat_title); 
     307               $categories_combo[implode(' / ',$full_name)] = $categories->cat_id; 
     308               $l = $categories->level; 
     309          } 
     310     } 
     311} catch (Exception $e) { } 
    285312 
    286313/* DISPLAY 
     
    443470     '</label></p>'. 
    444471      
     472     ($core->auth->check('categories', $core->blog->id) ? 
     473          '<div>'. 
     474          '<p id="new_cat">'.__('Add a new category').'</p>'. 
     475          '<p><label for="new_cat_title">'.__('Title:').' '. 
     476          form::field('new_cat_title',30,255,'','maximal').'</label></p>'. 
     477          '<p><label for="new_cat_parent">'.__('Parent:').' '. 
     478          form::combo('new_cat_parent',$categories_combo,'','maximal'). 
     479          '</label></p>'. 
     480          '</div>' 
     481     : ''). 
     482      
    445483     '<p><label for="post_status">'.__('Entry status:'). 
    446484     form::combo('post_status',$status_combo,$post_status,'','',!$can_publish). 
Note: See TracChangeset for help on using the changeset viewer.

Sites map