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

dev #48349 : previous / next buttons

parent d1f5ce76
Branches
Tags
2 merge requests!2334Master,!2104Dev#48349 ux versionning
Pipeline #928 failed with stage
in 1 minute and 30 seconds
......@@ -57,6 +57,16 @@ class Class_Version extends Class_Entity {
}
public function previous() {
return static::getPersistence()->previousOf($this);
}
public function next() {
return static::getPersistence()->nextOf($this);
}
public function save() {
static::getPersistence()->save($this);
}
......
......@@ -77,6 +77,46 @@ class Class_Version_FilePersistence extends Class_Entity {
}
public function previousOf($version) {
if (!$version->getName() || !$version->getKey()
|| (!$id = $version->getId()))
return;
if (!$all = $this->findAllOf($version))
return;
$found = false;
foreach($all as $one) {
if ($id == $one->getId()) {
$found = true;
continue;
}
if ($found)
return $one;
}
}
public function nextOf($version) {
if (!$version->getName() || !$version->getKey()
|| (!$id = $version->getId()))
return;
if (!$all = $this->findAllOf($version))
return;
$found = false;
$next = null;
foreach($all as $one) {
if ($id == $one->getId())
return $next;
$next = $one;
}
}
public function save($version) {
if (!$version->getName() || !$version->getKey() || !$version->getData())
return;
......
......@@ -47,6 +47,53 @@ class ZendAfi_View_Helper_Admin_RenderVersionForm
protected function _buttonsFor($form, $buttons) {
return $this
->_renderDefaultButtons($form,
[$this->view->Button_Back($this->_getBackUrl($form))]);
[$this->_prevButton(),
$this->_nextButton(),
$this->_listButton($form)]);
}
protected function _prevButton() {
$back = (new Class_Entity())
->setText($this->_('Précédente'))
->setAttribs(['disabled' => 'disabled',
'title' => $this->_('Pas de version précédente')]);
if ($previous = $this->_version->previous())
$back
->setUrl($this->view->url(['key' => $previous->getId()]))
->setAttribs([]);
return $this->view->Button_Back($back);
}
protected function _nextButton() {
$forward = (new Class_Entity())
->setText($this->_('Suivante'))
->setImage($this->view->tagImg(Class_Admin_Skin::current()
->renderIconUrlOn('buttons',
'back'),
['style' => 'transform: scaleX(-1);']))
->setAttribs(['disabled' => 'disabled',
'title' => $this->_('Pas de version suivante')]);
if ($next = $this->_version->next())
$forward
->setUrl($this->view->url(['key' => $next->getId()]))
->setAttribs([]);
return $this->view->Button($forward);
}
protected function _listButton($form) {
return $this->view
->Button($this->_getBackUrl($form)
->setText($this->_('Liste complète'))
->setImage($this->view->tagImg(Class_Admin_Skin::current()
->renderIconUrlOn('actions',
'liste'),
['style' => 'filter: invert();'])));
}
}
\ No newline at end of file
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