Browse Source

Add up/down arrows in LP item list see BT#15967

Julio Montoya 5 years ago
parent
commit
196a2fa171
3 changed files with 93 additions and 9 deletions
  1. 0 2
      main/inc/ajax/lp.ajax.php
  2. 58 7
      main/lp/learnpath.class.php
  3. 35 0
      main/lp/lp_controller.php

+ 0 - 2
main/inc/ajax/lp.ajax.php

@@ -80,8 +80,6 @@ switch ($action) {
         if (api_is_allowed_to_edit(null, true)) {
             $new_order = $_POST['new_order'];
             $sections = explode('^', $new_order);
-            $new_array = [];
-
             // We have to update parent_item_id, previous_item_id, next_item_id, display_order in the database
             $itemList = new LpItemOrderList();
             foreach ($sections as $items) {

+ 58 - 7
main/lp/learnpath.class.php

@@ -6215,13 +6215,41 @@ class learnpath
         $return_audio = null;
         $iconPath = api_get_path(SYS_CODE_PATH).'img/';
         $mainUrl = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq();
+        $countItems = count($arrLP);
 
-        for ($i = 0; $i < count($arrLP); $i++) {
+        $upIcon = Display::return_icon(
+            'up.png',
+            get_lang('Up'),
+            [],
+            ICON_SIZE_TINY
+        );
+
+        $disableUpIcon = Display::return_icon(
+            'up_na.png',
+            get_lang('Up'),
+            [],
+            ICON_SIZE_TINY
+        );
+
+        $downIcon = Display::return_icon(
+            'down.png',
+            get_lang('Down'),
+            [],
+            ICON_SIZE_TINY
+        );
+
+        $disableDownIcon = Display::return_icon(
+            'down_na.png',
+            get_lang('Down'),
+            [],
+            ICON_SIZE_TINY
+        );
+        for ($i = 0; $i < $countItems; $i++) {
+            $parent_id = $arrLP[$i]['parent_item_id'];
             $title = $arrLP[$i]['title'];
             $title_cut = cut($arrLP[$i]['title'], self::MAX_LP_ITEM_TITLE_LENGTH);
-
             // Link for the documents
-            if ($arrLP[$i]['item_type'] == 'document' || $arrLP[$i]['item_type'] == TOOL_READOUT_TEXT) {
+            if ($arrLP[$i]['item_type'] === 'document' || $arrLP[$i]['item_type'] == TOOL_READOUT_TEXT) {
                 $url = $mainUrl.'&action=view_item&mode=preview_document&id='.$arrLP[$i]['id'].'&lp_id='.$this->lp_id;
                 $title_cut = Display::url(
                     $title_cut,
@@ -6239,10 +6267,9 @@ class learnpath
                 Session::write('pathItem', $arrLP[$i]['path']);
             }
 
+            $oddClass = 'row_even';
             if (($i % 2) == 0) {
                 $oddClass = 'row_odd';
-            } else {
-                $oddClass = 'row_even';
             }
             $return_audio .= '<tr id ="lp_item_'.$arrLP[$i]['id'].'" class="'.$oddClass.'">';
             $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
@@ -6295,6 +6322,7 @@ class learnpath
             $forumIcon = '';
             $previewIcon = '';
             $pluginCalendarIcon = '';
+            $orderIcons = '';
 
             $pluginCalendar = api_get_plugin_setting('learning_calendar', 'enabled') === 'true';
             $plugin = null;
@@ -6398,7 +6426,6 @@ class learnpath
                 if ($pluginCalendar) {
                     $pluginLink = $pluginUrl.
                         '&action=toggle_visibility&lp_item_id='.$arrLP[$i]['id'].'&lp_id='.$this->lp_id;
-
                     $iconCalendar = Display::return_icon('agenda_na.png', get_lang('OneDay'), [], ICON_SIZE_TINY);
                     $itemInfo = $plugin->getItemVisibility($arrLP[$i]['id']);
                     if ($itemInfo && $itemInfo['value'] == 1) {
@@ -6411,6 +6438,30 @@ class learnpath
                     );
                 }
 
+                    /*if ($isFirst) {
+                        $orderIcons = Display::url($disableUpIcon, '#', ['class' => 'btn btn-default']);
+                    } else {
+                    }*/
+                    $orderIcons = Display::url(
+                        $upIcon,
+                        'javascript:void(0)',
+                        ['class' => 'btn btn-default order_items', 'data-dir' => 'up', 'data-id' => $arrLP[$i]['id']]
+                    );
+
+                    /*if ($isLast) {
+                        $orderIcons .= Display::url($disableDownIcon, '#', ['class' => 'btn btn-default']);
+                    } else {
+
+                    }*/
+                    $orderIcons .= Display::url(
+                        $downIcon,
+                        'javascript:void(0)',
+                        ['class' => 'btn btn-default order_items', 'data-dir' => 'down', 'data-id' => $arrLP[$i]['id']]
+                    );
+
+
+
+
                 $delete_icon .= ' <a 
                     href="'.$mainUrl.'&action=delete_item&id='.$arrLP[$i]['id'].'&lp_id='.$this->lp_id.'" 
                     onclick="return confirmation(\''.addslashes($title).'\');" 
@@ -6535,6 +6586,7 @@ class learnpath
                                     $prerequisities_icon 
                                     $move_item_icon 
                                     $audio_icon 
+                                    $orderIcons
                                     $delete_icon
                                 </div>",
                         ['class' => 'btn-toolbar button_actions']
@@ -6545,7 +6597,6 @@ class learnpath
                     Display::span($audio, ['class' => 'button_actions']);
             }
 
-            $parent_id = $arrLP[$i]['parent_item_id'];
             $default_data[$arrLP[$i]['id']] = $row;
             $default_content[$arrLP[$i]['id']] = $arrLP[$i];
 

+ 35 - 0
main/lp/lp_controller.php

@@ -95,6 +95,41 @@ $htmlHeadXtra[] = '
                 $(ui.item).css("width", "100%");
             }
         });
+        
+        
+        $(".li_container .order_items").click(function(e) {            
+            var dir = $(this).data("dir");
+            var itemId = $(this).data("id");             
+            var jItems = $("#lp_item_list li.li_container");            
+            var jItem = $("#"+ itemId);          
+            var index = jItems.index(jItem);
+                                    
+            switch (dir) {
+                case "up":
+                    if (index != 0) {
+                        var item = jItem.detach().insertBefore(jItems[index - 1]);
+                    }
+                    break;
+                case "down":
+                     if (index != jItems.length - 1) {
+                        var item = jItem.detach().insertAfter(jItems[index + 1]);                        
+                     }
+                     break;
+            }   
+            
+            buildLPtree($("#lp_item_list"), 0);
+            
+            var order = "new_order="+ newOrderData + "&a=update_lp_item_order";
+            $.post(
+                "'.$ajax_url.'",
+                order,
+                function(reponse) {
+                    $("#message").html(reponse);
+                    order = "";
+                    newOrderData = "";
+                }
+            );            
+        });
 
         $("#lp_item_list").sortable({
             items: "li",