Dotclear

Changeset 3833:ea88f004549f for admin


Ignore:
Timestamp:
08/30/18 16:26:16 (7 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Mainly every areas on the dashboard are now sortable

Location:
admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • admin/index.php

    r3781 r3833  
    115115if ($core->auth->user_prefs->dashboard->doclinks) { 
    116116    if (!empty($__resources['doc'])) { 
    117         $doc_links = '<div class="box small dc-box"><h3>' . __('Documentation and support') . '</h3><ul>'; 
     117        $doc_links = '<div class="box small dc-box" id="doc-and-support"><h3>' . __('Documentation and support') . '</h3><ul>'; 
    118118 
    119119        foreach ($__resources['doc'] as $k => $v) { 
     
    150150-------------------------------------------------------- */ 
    151151dcPage::open(__('Dashboard'), 
     152    dcPage::jsLoad('js/jquery/jquery-ui.custom.js') . 
     153    dcPage::jsLoad('js/jquery/jquery.ui.touch-punch.js') . 
    152154    dcPage::jsLoad('js/_index.js') . 
    153155    $admin_post_behavior . 
     
    244246} 
    245247 
    246 # Dashboard items and contents (processed first, as we need to know the result before displaying the icons.) 
    247 $dashboardItems = ''; 
    248 foreach ($__dashboard_items as $i) { 
    249     foreach ($i as $v) { 
    250         $dashboardItems .= $v; 
    251     } 
    252 } 
    253 $dashboardContents = ''; 
    254 foreach ($__dashboard_contents as $i) { 
    255     foreach ($i as $v) { 
    256         $dashboardContents .= $v; 
    257     } 
    258 } 
    259  
    260 # Dashboard elements: icons then boxes (items then contents) 
    261 echo '<div id="dashboard-main">'; 
    262  
     248# Get current main orders 
     249$main_order = $core->auth->user_prefs->dashboard->main_order; 
     250$main_order = ($main_order != '' ? explode(',', $main_order) : array()); 
     251 
     252# Get current boxes orders 
     253$boxes_order = $core->auth->user_prefs->dashboard->boxes_order; 
     254$boxes_order = ($boxes_order != '' ? explode(',', $boxes_order) : array()); 
     255 
     256# Get current boxes items orders 
     257$boxes_items_order = $core->auth->user_prefs->dashboard->boxes_items_order; 
     258$boxes_items_order = ($boxes_items_order != '' ? explode(',', $boxes_items_order) : array()); 
     259 
     260# Get current boxes contents orders 
     261$boxes_contents_order = $core->auth->user_prefs->dashboard->boxes_contents_order; 
     262$boxes_contents_order = ($boxes_contents_order != '' ? explode(',', $boxes_contents_order) : array()); 
     263 
     264$composeItems = function ($list, $blocks, $flat = false) { 
     265 
     266    $ret   = array(); 
     267    $items = array(); 
     268 
     269    if ($flat) { 
     270        $items = $blocks; 
     271    } else { 
     272        foreach ($blocks as $i) { 
     273            foreach ($i as $v) { 
     274                $items[] = $v; 
     275            } 
     276        } 
     277    } 
     278 
     279    # First loop to find ordered indexes 
     280    $order = array(); 
     281    $index = 0; 
     282    foreach ($items as $v) { 
     283        if (preg_match('/<div.*?id="([^"].*?)".*?>/ms', $v, $match)) { 
     284            $id       = $match[1]; 
     285            $position = array_search($id, $list, true); 
     286            if ($position !== false) { 
     287                $order[$position] = $index; 
     288            } 
     289        } 
     290        $index++; 
     291    } 
     292 
     293    # Second loop to combine ordered items 
     294    $index = 0; 
     295    foreach ($items as $v) { 
     296        $position = array_search($index, $order, true); 
     297        if ($position !== false) { 
     298            $ret[$position] = $v; 
     299        } 
     300        $index++; 
     301    } 
     302    # Reorder items on their position (key) 
     303    ksort($ret); 
     304 
     305    # Third loop to combine unordered items 
     306    $index = 0; 
     307    foreach ($items as $v) { 
     308        $position = array_search($index, $order, true); 
     309        if ($position === false) { 
     310            $ret[count($ret)] = $v; 
     311        } 
     312        $index++; 
     313    } 
     314 
     315    return join('', $ret); 
     316}; 
     317 
     318# Compose dashboard items (doc, …) 
     319$dashboardItems = $composeItems($boxes_items_order, $__dashboard_items); 
     320# Compose dashboard contents (plugin's modules) 
     321$dashboardContents = $composeItems($boxes_contents_order, $__dashboard_contents); 
     322 
     323$__dashboard_boxes = array(); 
     324if ($dashboardItems != '') { 
     325    $__dashboard_boxes[] = '<div class="db-items" id="db-items">' . $dashboardItems . '</div>'; 
     326} 
     327if ($dashboardContents != '') { 
     328    $__dashboard_boxes[] = '<div class="db-contents" id="db-contents">' . $dashboardContents . '</div>'; 
     329} 
     330$dashboardBoxes = $composeItems($boxes_order, $__dashboard_boxes, true); 
     331 
     332# Compose main area 
     333$__dashboard_main = array(); 
    263334if (!$core->auth->user_prefs->dashboard->nofavicons) { 
    264335    # Dashboard icons 
    265     echo '<div id="icons">'; 
     336    $dashboardIcons = '<div id="icons">'; 
    266337    foreach ($__dashboard_icons as $i) { 
    267         echo 
    268         '<p><a href="' . $i[1] . '"><img src="' . dc_admin_icon_url($i[2]) . '" alt="" />' . 
     338        $dashboardIcons .= '<p><a href="' . $i[1] . '"><img src="' . dc_admin_icon_url($i[2]) . '" alt="" />' . 
    269339            '<br /><span class="db-icon-title">' . $i[0] . '</span></a></p>'; 
    270340    } 
    271     echo '</div>'; 
    272 } 
    273  
     341    $dashboardIcons .= '</div>'; 
     342    $__dashboard_main[] = $dashboardIcons; 
     343} 
    274344if ($core->auth->user_prefs->dashboard->quickentry) { 
    275345    if ($core->auth->check('usage,contentadmin', $core->blog->id)) { 
     
    279349        ); 
    280350 
    281         echo 
     351        $dashboardQuickEntry = 
    282352        '<div id="quick">' . 
    283353        '<h3>' . __('Quick entry') . sprintf(' &rsaquo; %s', $core->auth->getOption('post_format')) . '</h3>' . 
     
    320390            '</form>' . 
    321391            '</div>'; 
    322     } 
    323 } 
    324  
    325 if ($dashboardContents != '' || $dashboardItems != '') { 
    326     echo 
    327         '<div id="dashboard-boxes">' . 
    328         ($dashboardItems != '' ? '<div class="db-items">' . $dashboardItems . '</div>' : '') . 
    329         ($dashboardContents != '' ? '<div class="db-contents">' . $dashboardContents . '</div>' : '') . 
    330         '</div>'; 
    331 } 
    332  
    333 echo '</div>'; #end dashboard-main 
     392        $__dashboard_main[] = $dashboardQuickEntry; 
     393    } 
     394} 
     395if ($dashboardBoxes != '') { 
     396    $__dashboard_main[] = '<div id="dashboard-boxes">' . $dashboardBoxes . '</div>'; 
     397} 
     398$dashboardMain = $composeItems($main_order, $__dashboard_main, true); 
     399 
     400# Dashboard elements 
     401echo '<div id="dashboard-main">' . $dashboardMain . '</div>'; 
     402 
    334403dcPage::helpBlock('core_dashboard'); 
    335404dcPage::close(); 
  • admin/js/_index.js

    r3820 r3833  
    199199  } 
    200200  // Posts 
    201   var icon_com = $('#dashboard-main #icons p a[href="posts.php"]'); 
    202   if (icon_com.length) { 
     201  var icon_post = $('#dashboard-main #icons p a[href="posts.php"]'); 
     202  if (icon_post.length) { 
    203203    // Icon exists on dashboard 
    204204    // First pass 
     
    207207    dotclear.dbPostsCount_Timer = setInterval(dotclear.dbCommentsPost, 600 * 1000); 
    208208  } 
     209 
     210  // Dashboard boxes and their children are sortable 
     211  var set_positions = function(sel, id) { 
     212    var list = $(sel).sortable("toArray").join(); 
     213    // Save positions (via services) for id 
     214    var params = { 
     215      f: 'setDashboardPositions', 
     216      xd_check: dotclear.nonce, 
     217      id: id, 
     218      list: list 
     219    }; 
     220    $.post('services.php', params, function() {}); 
     221  }; 
     222  // Wait 5 seconds before activating ordering capabilities on dashboard 
     223  setTimeout(function() { 
     224    $('#dashboard-main').sortable({ 
     225      cursor: 'move', 
     226      opacity: 0.5, 
     227      tolerance: "pointer", 
     228      update: function() { 
     229        set_positions(this, 'main_order'); 
     230      } 
     231    }); 
     232    $('#dashboard-boxes').sortable({ 
     233      cursor: 'move', 
     234      opacity: 0.5, 
     235      tolerance: "pointer", 
     236      update: function() { 
     237        set_positions(this, 'boxes_order'); 
     238      } 
     239    }); 
     240    $('#db-items').sortable({ 
     241      cursor: 'move', 
     242      opacity: 0.5, 
     243      tolerance: "pointer", 
     244      update: function() { 
     245        set_positions(this, 'boxes_items_order'); 
     246      } 
     247    }); 
     248    $('#db-contents').sortable({ 
     249      cursor: 'move', 
     250      opacity: 0.5, 
     251      tolerance: "pointer", 
     252      update: function() { 
     253        set_positions(this, 'boxes_contents_order'); 
     254      } 
     255    }); 
     256  }, 5000); 
     257 
    209258}); 
  • admin/services.php

    r3819 r3833  
    2525$core->rest->addFunction('setSectionFold', array('dcRestMethods', 'setSectionFold')); 
    2626$core->rest->addFunction('getModuleById', array('dcRestMethods', 'getModuleById')); 
     27$core->rest->addFunction('setDashboardPositions', array('dcRestMethods', 'setDashboardPositions')); 
    2728 
    2829$core->rest->serve(); 
     
    566567    } 
    567568 
     569    public static function setDashboardPositions($core, $get, $post) 
     570    { 
     571        if (empty($post['id'])) { 
     572            throw new Exception('No zone name'); 
     573        } 
     574        if (empty($post['list'])) { 
     575            throw new Exception('No sorted list of id'); 
     576        } 
     577 
     578        if ($core->auth->user_prefs->dashboard === null) { 
     579            $core->auth->user_prefs->addWorkspace('dashboard'); 
     580        } 
     581 
     582        $zone  = $post['id']; 
     583        $order = $post['list']; 
     584 
     585        $core->auth->user_prefs->dashboard->put($zone, $order); 
     586        return true; 
     587    } 
     588 
    568589    public static function getModuleById($core, $get, $post) 
    569590    { 
Note: See TracChangeset for help on using the changeset viewer.

Sites map