From 547e8c6c07e8249a9960e60043b0c6b6442bc9da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Wed, 11 May 2016 13:28:15 -0500 Subject: [PATCH] Disable Next Or Previous Button while the item position is First or Last - Refs #11192 --- app/Resources/public/css/scorm.css | 2 +- main/inc/ajax/lp.ajax.php | 10 +++++++++ main/newscorm/learnpath.class.php | 5 ++--- main/newscorm/scorm_api.php | 28 ++++++++++++++++++++++++ main/template/default/learnpath/view.tpl | 1 + 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/app/Resources/public/css/scorm.css b/app/Resources/public/css/scorm.css index 3a97984abf..c51b04bc75 100644 --- a/app/Resources/public/css/scorm.css +++ b/app/Resources/public/css/scorm.css @@ -445,7 +445,7 @@ See https://support.chamilo.org/issues/6976 .icon-toolbar{ border-radius: 100%; width: 35px; - display: inline-block !important; + display: inline-block; margin: 0px 5px 5px 0px; color: #fff; diff --git a/main/inc/ajax/lp.ajax.php b/main/inc/ajax/lp.ajax.php index 97103f9c93..c31b1283ca 100755 --- a/main/inc/ajax/lp.ajax.php +++ b/main/inc/ajax/lp.ajax.php @@ -280,6 +280,16 @@ switch ($action) { } echo json_encode($jsonGamification); + break; + case 'check_item_position': + $lp = isset($_SESSION['oLP']) ? $_SESSION['oLP'] : null; + $lpItemId = isset($_GET['lp_item']) ? intval($_GET['lp_item']) : 0; + if ($lp) { + $position = $_SESSION['oLP']->isFirstOrLastItem($lpItemId); + } + + echo json_encode($position); + break; default: echo ''; diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index a1aa514338..302114d98a 100755 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -11118,16 +11118,16 @@ EOD; /** * Check if the current lp item is first, both, last or none from lp list * + * @param int $currentItemId * @return string */ - public function isFirstOrLastItem() + public function isFirstOrLastItem($currentItemId) { if ($this->debug > 0) { error_log('New LP - In learnpath::isFirstOrLastItem', 0); } $lpItemId = []; - $currentItemId = $this->get_current_item_id(); $typeListNotToVerify = self::getChapterTypes(); foreach ($this->items as $item) { @@ -11136,7 +11136,6 @@ EOD; } } - $answer = ''; $lastLpItemIndex = count($lpItemId) - 1; $position = array_search($currentItemId, $lpItemId); diff --git a/main/newscorm/scorm_api.php b/main/newscorm/scorm_api.php index e7baf570f9..b833e41589 100755 --- a/main/newscorm/scorm_api.php +++ b/main/newscorm/scorm_api.php @@ -1664,10 +1664,38 @@ function switch_item(current_item, next_item){ olms.switch_finished = 0; //only changed back once LMSInitialize() happens loadForumThead(olms.lms_lp_id, next_item); + checkCurrentItemPosition(olms.lms_item_id); return true; } +/** + * Hide or show the navigation buttons if the current item is the First or Last + */ +var checkCurrentItemPosition = function(lpItemId) { + var currentItem = $.getJSON('lp.ajax.php', { + a: 'check_item_position', + lp_item: lpItemId + } + ).done(function(parsedResponse,statusText,jqXhr) { + var position = jqXhr.responseJSON; + if (position == 'first') { + $("#scorm-previous").hide(); + $("#scorm-next").show(); + } else if (position == 'none') { + $("#scorm-previous").show(); + $("#scorm-next").show(); + } else if (position == 'last') { + $("#scorm-previous").show(); + $("#scorm-next").hide(); + } else if (position == 'both') { + $("#scorm-previous").hide(); + $("#scorm-next").hide(); + } + }); + +} + /** * Get a forum info when the learning path item has a associated forum */ diff --git a/main/template/default/learnpath/view.tpl b/main/template/default/learnpath/view.tpl index 07c1ab0fbe..257d9b1f6b 100644 --- a/main/template/default/learnpath/view.tpl +++ b/main/template/default/learnpath/view.tpl @@ -215,6 +215,7 @@ }); loadForumThead({{ lp_id }}, {{ lp_current_item_id }}); + checkCurrentItemPosition({{ lp_current_item_id }}); {% if glossary_extra_tools in glossary_tool_availables %} // Loads the glossary library.