Skip to content

Commit

Permalink
Rewritten account subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed Jan 17, 2022
1 parent 2259b73 commit 43699be
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function data( \Aimeos\MW\View\Iface $view, array &$tags = [], string &$e
}
}

$view->detailItem = $item;
$view->subscriptionItem = $item;
$view->summaryBasket = $basket;
$view->summaryTaxRates = $this->getTaxRates( $basket );
$view->summaryNamedTaxes = $this->getNamedTaxes( $basket );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
* @copyright Aimeos (aimeos.org), 2018-2022
*/

/* Available data:
* - subscriptionItem : Subscription item
* - summaryBasket : Basket
* - summaryTaxRates : Prices by tax rates
* - summaryNamedTaxes : Prices by tax names
* - summaryCostsDelivery : Delivery costs
* - summaryCostsPayment : Payment costs
*/


$enc = $this->encoder();


Expand Down Expand Up @@ -97,12 +107,12 @@


<div class="button-group">
<a class="btn btn-close" href="<?= $enc->attr( $this->link( 'client/html/account/subscription/url' ) ) ?>">
<a class="btn btn-secondary close" href="<?= $enc->attr( $this->link( 'client/html/account/subscription/url' ) ) ?>">
<?= $enc->html( $this->translate( 'client', 'Close' ), $enc::TRUST ) ?>
</a>
<?php if( $this->detailItem->getDateEnd() == null ) : ?>
<?php $params = ['sub_action' => 'cancel', 'sub_id' => $this->detailItem->getId()] ?>
<a class="btn btn-primary" href="<?= $enc->attr( $this->link( 'client/html/account/subscription/url', $params ) ) ?>">
<?php if( $this->subscriptionItem->getDateEnd() == null ) : ?>
<?php $params = ['sub_action' => 'cancel', 'sub_id' => $this->subscriptionItem->getId()] ?>
<a class="btn btn-primary" href="<?= $enc->attr( $this->link( 'client/html/account/subscription/url', $params, ['account-subscription'] ) ) ?>">
<?= $enc->html( $this->translate( 'client', 'Cancel' ), $enc::TRUST ) ?>
</a>
<?php endif ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,15 @@

<?php if( !$this->get( 'listsItems', map() )->isEmpty() ) : ?>

<div class="account-subscription-list">
<div id="account-subscription" class="account-subscription-list">
<h1 class="header"><?= $enc->html( $this->translate( 'client', 'Subscriptions' ), $enc::TRUST ) ?></h1>

<div class="subscription-list">

<?php foreach( $this->get( 'listsItems', [] ) as $id => $item ) : ?>

<div class="subscription-item row">
<div class="subscription-item row"
data-url="<?= $enc->attr( $this->link( 'client/html/account/subscription/url', ['sub_action' => 'detail', 'sub_id' => $id] ) ) ?>">

<div class="col-12">
<h2 class="subscription-basic">
Expand Down Expand Up @@ -161,10 +162,8 @@
</div>

<div class="action col-md-2">
<?php $params = ['sub_action' => 'detail', 'sub_id' => $id] ?>
<a class="btn btn-outline" href="<?= $enc->attr( $this->link( 'client/html/account/subscription/url', $params ) ) ?>">
<?= $enc->html( $this->translate( 'client', 'Show' ) ) ?>
</a>
<a class="btn btn-secondary show" href="#"><?= $enc->html( $this->translate( 'client', 'Show' ) ) ?></a>
<a class="btn btn-secondary close hidden" href="#"><?= $enc->html( $this->translate( 'client', 'Close' ) ) ?></a>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testBody()

$output = $this->object->body();

$this->assertStringContainsString( '<div class="account-subscription-list">', $output );
$this->assertStringContainsString( '<div id="account-subscription" class="account-subscription-list">', $output );
$this->assertRegExp( '#<div class="subscription-item#', $output );
$this->assertRegExp( '#<h2 class="subscription-basic.*<span class="value[^<]+</span>.*</h2>#smU', $output );
$this->assertRegExp( '#<div class="subscription-interval.*<span class="value[^<]+</span>.*</div>#smU', $output );
Expand Down
12 changes: 1 addition & 11 deletions client/html/themes/default/account-subscription.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
border: 1px solid #D0D0D0;
border-color: var(--ai-light, #D0D0D0);
padding: 1rem;
margin: 1rem 0;
margin: 1rem;
}

.account-subscription-list .name:after {
Expand Down Expand Up @@ -54,15 +54,6 @@
text-decoration: underline;
}

.account-subscription-detail .modify {
float: right;
margin: 0 1rem;
}

[dir="rtl"] .account-subscription-detail .modify {
float: left;
}

.account-subscription-detail h2 {
margin: 0.5rem 0;
}
Expand All @@ -73,7 +64,6 @@
margin: 0;
}


.account-subscription-detail .attr-item .name,
.account-subscription-detail .attr-item .value {
min-width: 0;
Expand Down
50 changes: 19 additions & 31 deletions client/html/themes/default/account-subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,35 @@ AimeosAccountSubscription = {
/**
* Shows subscription details without page reload
*/
setupDetailShow: function() {
onToggleDetail() {

$(".account-subscription .subscription-item").on("click", function() {
$(".account-subscription").on("click", ".subscription-item .btn.show, .subscription-item .btn.close", (ev) => {

var target = $(this).parents(".subscription-item");
var details = $(".account-subscription-detail", target);
const target = $(ev.currentTarget).closest(".subscription-item");
const details = $(".account-subscription-detail", target);

if(details.length === 0) {

fetch($(this).find('.action a.btn').attr("href")).then(response => {
fetch(target.data("url")).then(response => {
return response.text();
}).then(data => {
var doc = document.createElement("html");
doc.innerHTML = data;

var node = $(".account-subscription-detail", doc);
node.css("display", "none");
target.append(node);
slideDown(node.get(0), 300);
const doc = $("<html/>").html(data);
const node = $(".account-subscription-detail", doc);

if(node.length) {
node.css("display", "none");
target.append(node);
slideDown(node[0], 300);
}
});

} else {
slideToggle(details.get(0), 300);
slideToggle(details[0], 300);
}

return false;
});
},

$(".btn.show", target).toggleClass('hidden');
$(".btn.close", target).toggleClass('hidden');

/**
* Closes the order details without page reload
*/
setupDetailClose: function() {

$(".account-subscription .subscription-item").on("click", ".btn-close", function() {
$(".account-subscription-detail", $(this).parents(".subscription-item")).each(function() {
slideUp(this, 300);
});
return false;
});
},
Expand All @@ -53,14 +43,12 @@ AimeosAccountSubscription = {
/**
* Initializes the account subscription actions
*/
init: function() {

this.setupDetailShow();
this.setupDetailClose();
init() {
this.onToggleDetail();
}
};


$(function() {
$(() => {
AimeosAccountSubscription.init();
});
6 changes: 5 additions & 1 deletion client/html/themes/default/aimeos.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/


@font-face {
@font-face {
font-family: 'Roboto Condensed';
font-style: normal;
font-weight: 400;
Expand Down Expand Up @@ -102,6 +102,10 @@ img {
text-align: start;
}

.aimeos .hidden {
display: none !important;
}

.aimeos .content-block {
margin: 4rem 0;
}
Expand Down

0 comments on commit 43699be

Please sign in to comment.