Skip to content
Snippets Groups Projects
Commit 55759043 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

Merge branch 'dev#24865_pnb_ergonomie_interface_emprunt' into 'master'

Dev#24865 pnb ergonomie interface emprunt

See merge request !1177
parents d72dbf9f 96cd343b
Branches
Tags
No related merge requests found
Showing
with 270 additions and 19 deletions
- ticket #24865 : PNB: Ergonomie interface emprunt
\ No newline at end of file
......@@ -255,11 +255,6 @@ class BibNumeriqueController extends ZendAfi_Controller_Action {
}
public function consultBookAjaxAction() {
if (!$this->_redirectToLogin())
$this->_redirect($this->view->url(['action' => 'consult-book', 'render' =>null]),
['prependBase' => false]);
}
protected function _redirectToLogin() {
if (!$this->_user = Class_Users::getLoader()->getIdentity()) {
......@@ -270,11 +265,100 @@ class BibNumeriqueController extends ZendAfi_Controller_Action {
}
protected function _redirectToPopupLogin($url) {
if (!$this->_user = Class_Users::getLoader()->getIdentity()) {
$this->_forward('popup-login', 'auth', 'opac', ['redirect' => $url]);
return true;
}
return false;
}
protected function _userShouldBeRedirect() {
if($this->_redirectToPopupLogin($this->view->url()))
return true;
if (!$this->_user->hasRightAccessDilicom())
return $this->_ajaxRedirectToNotice();
if(!$this->view->album = Class_Album::find($this->_getParam('id')))
return $this->_ajaxRedirectToNotice();
return false;
}
public function loanBookAjaxAction() {
if ($this->_redirectToLogin())
return ;
$this->_redirect($this->view->url(['action' => 'loan-book', 'render' => null]), ['prependBase' => false]);
return true;
if($this->_userShouldBeRedirect())
return;
return $this->renderPopupResult($this->_('Emrpunter le livre au format EPUB'),
$this->view->render('bib-numerique/loan-book.phtml'));
}
public function consultBookAjaxAction() {
if($this->_userShouldBeRedirect())
return;
return $this->renderPopupResult($this->_('Consulter le livre en ligne'),
$this->view->render('bib-numerique/consult-book.phtml'));
}
public function consultBookOpenAjaxAction() {
if($this->_userShouldBeRedirect())
return;
$client_ip = (new Class_RemoteClient($this->_request))->getIpAddress();
$response = (new Class_WebService_BibNumerique_Dilicom_Hub())->consultBook($this->view->album,
$client_ip,
$this->_user);
return $this->_withContentDo(json_decode($response),
function($url)
{
$this->view->open_url = $url;
$this->renderPopupResult($this->_('Consultation'),
$this->view->render('bib-numerique/consult-book-open.phtml'));
});
}
protected function _withContentDo($content, $closure) {
if(!$content)
return $this->_ajaxRedirectToNotice();
if ($content->returnMessage) {
$this->_helper->notify(implode(',', $content->returnMessage));
return $this->_ajaxRedirectToNotice();
}
$closure($content->link->url);
}
public function downloadLoanBookAjaxAction() {
if($this->_userShouldBeRedirect())
return;
$content = (new Class_WebService_BibNumerique_Dilicom_Hub())->loanBook(Class_Album::find($this->_getParam('id')));
return $this->_withContentDo($content,
function($url)
{
$this->view->download_url = $url;
$this->renderPopupResult($this->_('Téléchargement'), $this->view->render('bib-numerique/download-book.phtml'));
});
}
protected function _ajaxRedirectToNotice() {
$this->view->redirect_url = $this->view->url(['controller' => 'recherche',
'action' => 'viewnotice',
'render' => 'false']);
return $this->renderPopupResult('', $this->view->render('bib-numerique/redirect.phtml'));
}
......@@ -293,8 +377,7 @@ class BibNumeriqueController extends ZendAfi_Controller_Action {
$content = json_decode($response);
if ($content->returnMessage) {
$this->_helper->notify(implode(',', $content->returnMessage));
$this->_redirectToNotice();
return;
return $this->_redirectToNotice();
}
$this->_redirect($content->link->url);
......
<?php
echo '<div class="popup-content">';
echo $this->tagAnchor($this->open_url, $this->_('Lire en ligne'),
['target' => '_blank',
'class' => 'button blue',
'onclick' => 'opacDialogClose();']);
echo '</div>';
?>
<?php
echo '<div class="popup-content">';
echo $this->tag('p', $this->_('Etes vous sur de vouloir consulter ce document ?'));
echo $this->tagAnchor($this->url(['action' => 'consult-book-open-ajax']), $this->_('oui'), ['data-popup' => 'true',
'class' => 'button blue']);
echo $this->tagAnchor('', $this->_('non'), ['onclick' => 'opacDialogClose();return false',
'class' => 'button red']);
echo '</div>';
?>
<?php
echo '<div class="popup-content">';
echo $this->tagAnchor( $this->download_url, $this->_('Télécharger'),
['class' => 'button blue',
'onclick' => 'opacDialogClose();']);
echo '</div>';
?>
<?php
echo '<div class="popup-content">';
echo $this->tag('p', $this->_('Etes vous sur de vouloir emprunter ce document ?'));
echo $this->tagAnchor($this->url(['action' => 'download-loan-book-ajax']), $this->_('oui'), ['data-popup' => 'true',
'class' => 'button blue']);
echo $this->tagAnchor('', $this->_('non'), ['onclick' => 'opacDialogClose();return false',
'class' => 'button red']);
echo $this->tag('p', 'Votre compte sera mis à jour dans un délai de 15 minutes après le retour anticipé du document.');
echo '</div>';
?>
<?php
echo $this->tag('script', 'window.open("'.$this->redirect_url.'")');
echo $this->tag('script', 'opacDialogClose();');
?>
......@@ -53,7 +53,7 @@ class ZendAfi_View_Helper_TagDilicomWidget extends Zend_View_Helper_HtmlElement
'action' => 'consult-book-ajax',
'id' => $this->_album->getId()],
$this->view->_('Consulter le livre en ligne'),
[ 'target'=> '_blank' ]);
['data-popup' => 'true']);
}
......@@ -61,8 +61,8 @@ class ZendAfi_View_Helper_TagDilicomWidget extends Zend_View_Helper_HtmlElement
return $this->getDilicomAnchor(['controller' => 'bib-numerique',
'action' => 'loan-book-ajax',
'id' => $this->_album->getId()],
$this->view->_('Emprunter le livre au format EPUB')
);
$this->view->_('Emprunter le livre au format EPUB'),
['data-popup' => 'true']);
}
......
......@@ -64,6 +64,8 @@ a[data-popup="true"].image-loading-status {
background:url(../images/patience.gif) no-repeat center;
width: 16px;
height: 16px;
overflow: hidden;
font-size: 0;
}
......
......@@ -3101,4 +3101,50 @@ a.loan-export {
.boite.library p.closed {
background: url(../images/buttons/ledred.png) no-repeat left center;
}
#opac-dialog a.button {
display: inline-block;
text-align: center;
padding: 2px 5px;
border-radius: 5px;
line-height: 2em;
margin: 5px;
font-size: 1.2em;
font-weight: bold;
min-width: 60px;
text-transform: uppercase;
text-shadow: 0px -1px 1px rgba(0, 0, 0, 0.25);
cursor: pointer;
color: #FFF;
white-space: nowrap;
}
#opac-dialog a.button.blue {
background: #008CFF;
}
#opac-dialog a.button.red {
background: #DF1B1B;
}
#opac-dialog a.button.blue:hover {
background: #004F8F;
}
#opac-dialog a.button.red:hover {
background: #8F1111;
}
#opac-dialog div.popup-content {
padding: 5px;
}
#opac-dialog div.popup-content,
#opac-dialog div.popup-content * {
vertical-align: middle;
}
\ No newline at end of file
......@@ -106,18 +106,99 @@ abstract class BibNumeriqueContollerDilicomTestCase extends AbstractControllerTe
class BibNumeriqueContollerDilicomAjaxRedirectBookActionTest extends BibNumeriqueContollerDilicomTestCase {
class BibNumeriqueContollerDilicomAjaxPopupBookActionTest extends BibNumeriqueContollerDilicomTestCase {
/** @test */
public function redirectShouldBeConsultBook() {
public function popupConsultBookShouldContainsLinkToOpenAjax() {
$this->_http
->whenCalled('open_url')
->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/consultBook?glnContractor=123456789&orderLineId=x321&accessMedium=STREAMING&localization=IN_SITU&consultEndDate=2014-05-02T15%3A14%3A14%2B0200&ean13=435465&ipAddress=127.0.0.1&glnColl=afi-bib&loanerColl=2345889&loanId=n4y4nq63')
->answers(DilicomFixtures::loanBookResponse())
->beStrict();
$this->dispatch('/bib-numerique/consult-book-ajax/id/3', true);
$this->assertRedirectTo('/bib-numerique/consult-book/id/3', $this->getResponseLocation());
$this->assertContains('"<div class=\"popup-content\"><p>Etes vous sur de vouloir consulter ce document ?<\/p><a href=\"\/bib-numerique\/consult-book-open-ajax\/id\/3\" data-popup=\"true\" class=\"button blue\">oui<\/a><a href=\"\" onclick=\"opacDialogClose();return false\" class=\"button red\">non<\/a><\/div>"', $this->_response->getBody());
}
/** @test */
public function redirectShouldBeLoanBook() {
public function popupConsultBookOpenShouldContainsLinkToOpenPnbUrl() {
$this->_http
->whenCalled('open_url')
->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/consultBook?glnContractor=123456789&orderLineId=x321&accessMedium=STREAMING&localization=IN_SITU&consultEndDate=2014-05-02T15%3A14%3A14%2B0200&ean13=435465&ipAddress=127.0.0.1&glnColl=afi-bib&loanerColl=2345889&loanId=n4y4nq63')
->answers(DilicomFixtures::loanBookResponse())
->beStrict();
$this->dispatch('/bib-numerique/consult-book-open-ajax/id/3', true);
$this->assertContains('<div class=\"popup-content\"><a href=\"https:\/\/pnb-dilicom.centprod.com\/v2\/\/link\/3025594195810\/LOAN\/WIKI001\/9782021153057-NUMOIY0785CYO0IGCV83DE9DOAOC1Y1O.do\" target=\"_blank\" class=\"button blue\" onclick=\"opacDialogClose();\">Lire en ligne<\/a><\/div>"', $this->_response->getBody());
}
/** @test */
public function popupLoanBookOpenAjaxWithPnbErrorShouldContainsScriptToReloadPage() {
$this->_http
->whenCalled('open_url')
->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/consultBook?glnContractor=123456789&orderLineId=x321&accessMedium=STREAMING&localization=IN_SITU&consultEndDate=2014-05-02T15%3A14%3A14%2B0200&ean13=435465&ipAddress=127.0.0.1&glnColl=afi-bib&loanerColl=2345889&loanId=n4y4nq63')
->answers(DilicomFixtures::loanBookErrorResponse())
->beStrict();
$this->dispatch('/bib-numerique/consult-book-open-ajax/id/3', true);
$this->assertContains('<script>window.open(\"\/recherche\/viewnotice\/id\/3\/render\/false\")<\/script>', $this->_response->getBody());
}
/** @test */
public function loanBookPopupShouldContainsQuestion() {
$this->dispatch('/bib-numerique/loan-book-ajax/id/3', true);
$this->assertRedirectTo('/bib-numerique/loan-book/id/3', $this->getResponseLocation());
$this->assertContains('<p>Etes vous sur de vouloir emprunter ce document ?<\/p>', $this->_response->getBody());
}
/** @test */
public function loanBookPopupShouldContainsLinkToDownload() {
$this->dispatch('/bib-numerique/loan-book-ajax/id/3', true);
$this->assertContains('<a href=\"\/bib-numerique\/download-loan-book-ajax\/id\/3\" data-popup=\"true\" class=\"button blue\">oui<\/a>', $this->_response->getBody());
}
/** @test */
public function loanBookPopupShouldContainsAnswerYes() {
$this->dispatch('/bib-numerique/loan-book-ajax/id/3', true);
$this->assertContains('<a href=\"\/bib-numerique\/download-loan-book-ajax\/id\/3\" data-popup=\"true\" class=\"button blue\">oui<\/a>', $this->_response->getBody());
}
/** @test */
public function downloadLinkShouldAnswersDilicomLink() {
$this->_http
->whenCalled('open_url')
->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/loanBook?glnContractor=123456789&orderLineId=x321&accessMedium=DOWNLOAD&glnColl=afi-bib&loanerColl=2345889&localization=EX_SITU&loanEndDate=2014-08-10T14%3A14%3A14%2B0200&ean13=435465&loanId=1')
->answers(DilicomFixtures::loanBookResponse())
->beStrict();
$this->dispatch('bib-numerique/download-loan-book-ajax/id/3', true);
$this->assertContains('"<div class=\"popup-content\"><a href=\"https:\/\/pnb-dilicom.centprod.com\/v2\/\/link\/3025594195810\/LOAN\/WIKI001\/9782021153057-NUMOIY0785CYO0IGCV83DE9DOAOC1Y1O.do\" class=\"button blue\" onclick=\"opacDialogClose();\">T\u00e9l\u00e9charger<\/a><\/div>"', $this->_response->getBody());
}
/** @test */
public function downloadLinkWithPnbErrorShouldConstainsScriptToReloadPage() {
$this->_http
->whenCalled('open_url')
->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/loanBook?glnContractor=123456789&orderLineId=x321&accessMedium=DOWNLOAD&glnColl=afi-bib&loanerColl=2345889&localization=EX_SITU&loanEndDate=2014-08-10T14%3A14%3A14%2B0200&ean13=435465&loanId=1')
->answers(DilicomFixtures::loanBookErrorResponse())
->beStrict();
$this->dispatch('bib-numerique/download-loan-book-ajax/id/3', true);
$this->assertContains('<script>window.open(\"\/recherche\/viewnotice\/id\/3\/render\/false\")<\/script>', $this->_response->getBody());
}
/** @test */
public function downloadLinkWithNoConnectedUserShouldRenderLoginPopup() {
ZendAfi_Auth::getInstance()->clearIdentity();
$this->dispatch('bib-numerique/download-loan-book-ajax/id/3', true);
$this->assertContains('"title":"Authentification"', $this->_response->getBody());
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment