Commit cd517f9b authored by Patrick Barroca's avatar Patrick Barroca Committed by Patrick Barroca

rel #20351 : new browsing mode proof of concept

Conflicts:
	library/ZendAfi/View/Helper/TreeView.php
parent 69074e7d
......@@ -74,6 +74,9 @@ class Admin_CmsController extends ZendAfi_Controller_Action {
['href' => $this->view->url($url_params,
null, true)])];
$this->view->categorieActions = $this->_getTreeViewContainerActions();
$this->view->articleActions = $this->_getTreeViewItemActions();
if (($id_cat = $this->_getParam('id_cat'))
&& ($category = Class_ArticleCategorie::find($id_cat))
&& ($current_bib = $category->getBib() ?
......@@ -90,7 +93,7 @@ class Admin_CmsController extends ZendAfi_Controller_Action {
null, true)]);
};
$items_by_page = 5;
$items_by_page = 25;
$page = $this->_getParam('page', 0);
array_walk($category->getParentsAndSelf(), $render_cats);
......
......@@ -35,20 +35,26 @@ $label = function($model, $attrib) {
null, true)]);
};
echo $this
->tagModelTable($this->categories,
[$this->_('Catégories')],
['libelle'],
[],
'cms-categories',
null,
['libelle' => $label]);
echo $this->tagModelTable(
$this->categories,
[$this->_('Catégories')],
['libelle'],
[function($model) {
return $this->modelActions($model, $this->categorieActions);
}],
'cms-categories',
null,
['libelle' => $label]);
if ($this->articles) {
echo $this->tagModelTable($this->articles,
[$this->_('Articles')],
['libelle'],
[],
'cms-articles');
echo $this->tagModelTable(
$this->articles,
[$this->_('Articles')],
['libelle'],
[function($model) {
return $this->modelActions($model, $this->articleActions);
}],
'cms-articles');
echo $this->paginationControl($this->art_paginator);
}
......@@ -2,7 +2,7 @@
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
......@@ -16,12 +16,12 @@
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
require('includes.php');
try {
try {
if (isUserAgentBotAndNotAllowed())
exit;
......
<?php
/**
* Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class ZendAfi_View_Helper_ModelActions extends Zend_View_Helper_Abstract {
public function modelActions($model, $actions) {
if (!$model || !$actions)
return '';
foreach ($actions as $action)
$html .= (new ZendAfi_View_Helper_ModelAction($action, $this->view))
->render($model);
return $this->view->tag('div', $html,
['class' => 'actions']);
}
}
class ZendAfi_View_Helper_ModelAction {
const CONDITION = 'condition';
const CAPTION = 'caption';
const ICON = 'icon';
const LABEL = 'label';
const ANCHOR_OPTIONS = 'anchorOptions';
const URL = 'url';
protected $_view, $_conf;
public function __construct($config, $view) {
$this->_view = $view;
$this->_conf = $config;
}
/**
* @param $model Storm_Model_Abstract
* @return string
*/
public function render($model) {
if (!$this->_meetsRequirements($model))
return '';
$caption = array_key_exists(self::CAPTION, $this->_conf) ?
$model->{$this->_conf[self::CAPTION]}() : '';
$url = sprintf($this->_conf[self::URL], $model->getId());
$icon = $this->_initIcon($model);
$anchorOptions = $this->_initAnchorOptions();
$content = $this->_view->tagImg(URL_ADMIN_IMG . $icon,
['alt' => $this->_conf[self::LABEL],
'title' => $this->_conf[self::LABEL],
'class' => 'ico'])
. $caption;
return $this->_view->tagAnchor($url, $content, $anchorOptions);
}
protected function _meetsRequirements($model) {
if (!array_key_exists(self::CONDITION, $this->_conf))
return true;
$condition = $this->_conf[self::CONDITION];
if (is_string($condition) && is_callable([$model, $condition]))
return $model->{$condition}();
return is_callable($condition) ? $condition($model) : true;
}
protected function _initIcon($model) {
if (!array_key_exists(self::ICON, $this->_conf))
return null;
return is_a($this->_conf[self::ICON], 'Closure') ?
$this->_conf[self::ICON]($model) : $this->_conf[self::ICON];
}
protected function _initAnchorOptions() {
return array_key_exists(self::ANCHOR_OPTIONS, $this->_conf) ?
$this->_conf[self::ANCHOR_OPTIONS] : [];
}
}
?>
\ No newline at end of file
......@@ -200,53 +200,7 @@ class ZendAfi_View_Helper_TreeView extends Zend_View_Helper_Abstract {
* @return string
*/
protected function _renderActions($type, $model) {
$html = '';
foreach ($this->{'_' . $type . 'Actions'} as $key => $action) {
if (array_key_exists('condition', $action)){
if (is_string($action['condition'])
&& is_callable([$model, $action['condition']])
&& !$model->{$action['condition']}())
continue;
if (is_callable($action['condition']) && !$action['condition']($model))
continue;
}
if (array_key_exists('caption', $action)) {
$action['caption'] = $model->{$action['caption']}();
}
$action['url'] = sprintf($action['url'], $model->getId());
if (isset($action['icon']) && is_a($action['icon'], 'Closure'))
$action['icon'] = $action['icon']($model);
$html .= $this->_renderAction($action);
}
return '<div class="actions">' . $html . '</div>';
}
/**
* @param array $options
* @return string
*/
protected function _renderAction(array $options) {
$anchorOptions = array();
if (array_key_exists('anchorOptions', $options)) {
$anchorOptions = array_merge($anchorOptions, $options['anchorOptions']);
}
$content = $this->view->tagImg(URL_ADMIN_IMG . $options['icon'],
['alt' => $options['label'],
'title' => $options['label'],
'class' => 'ico']);
if (array_key_exists('caption', $options))
$content .= $options['caption'];
return $this->view->tagAnchor($options['url'], $content, $anchorOptions);
return $this->view->modelActions($model, $this->{'_' . $type . 'Actions'});
}
}
......
Markdown is supported
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