[PATCH 2 of 3 sherpa V2] Add a contextual component replacing the standard actions box

Sylvain Thénault sylvain.thenault at logilab.fr
Fri Feb 24 09:52:07 CET 2017



Le 24/02/2017 à 09:49, Sylvain Thenault a écrit :
> # HG changeset patch
> # User Sylvain Thénault <sylvain.thenault at logilab.fr>
> # Date 1487924313 -3600
> #      Fri Feb 24 09:18:33 2017 +0100
> # Node ID bfaa0c10092d1aced8d64fe76f2ce5daa92f9bf2
> # Parent  712aa8b2d0d12c90e78ee1cdd026b7c0465500e5
> Add a contextual component replacing the standard actions box
>
> diff --git a/cubicweb_sherpa/views/components.py b/cubicweb_sherpa/views/components.py
> --- a/cubicweb_sherpa/views/components.py
> +++ b/cubicweb_sherpa/views/components.py
> @@ -14,13 +14,15 @@
>  # You should have received a copy of the GNU Lesser General Public License along
>  # with this program. If not, see <http://www.gnu.org/licenses/>.
>  """cubicweb-sherpa components, originaly copied from the saem_ref cube."""
>  
>  from cubicweb import _, tags
> -from cubicweb.predicates import multi_lines_rset, has_permission, is_instance
> +from cubicweb.predicates import multi_lines_rset, has_permission, is_instance, non_final_entity
>  from cubicweb.web import component
>  
> +from . import jinja_render
> +
>  
>  def add_etype_link(req, etype, text=u'', klass='icon-plus-circled pull-right',
>                     **urlparams):
>      """Return an HTML link to add an entity of type 'etype'."""
>      vreg = req.vreg
> @@ -92,5 +94,27 @@ class SKOSImportComponent(ImportEntityCo
>      _('Import ConceptScheme')  # generate message used by the import component
>  
>      @property
>      def import_url(self):
>          return self._cw.build_url('add/skossource')
> +
> +
> +class ActionsComponent(component.CtxComponent):
> +    """Contextual component replacing the actions box (`cubicweb.web.views.boxes.EditBox`)."""
> +
> +    __regid__ = 'sherpa.actions'
> +    __select__ = component.CtxComponent.__select__ & non_final_entity()
> +    context = 'navtop'
> +
> +    def render_body(self, w):
> +        allactions = self._cw.vreg['actions'].possible_actions(
> +            self._cw, self.cw_rset, view=self.cw_extra_kwargs['view'])
> +        actions = allactions.get('mainactions', []) + allactions.get('moreactions', [])
> +        if actions:
> +            w(jinja_render('menu', actions=actions, _=self._cw._))
> +
> +
> +def registration_callback(vreg):
> +    vreg.register_all(globals().values(), __name__)
> +
> +    from cubicweb.web.views import boxes
> +    vreg.unregister(boxes.EditBox)
> diff --git a/cubicweb_sherpa/views/templates/menu.jinja2.html b/cubicweb_sherpa/views/templates/menu.jinja2.html
> new file mode 100644
> --- /dev/null
> +++ b/cubicweb_sherpa/views/templates/menu.jinja2.html
> @@ -0,0 +1,11 @@
> +<div class="btn-group pull-right">
> +  <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" \
> +aria-haspopup="true" aria-expanded="false">

pushed a new version of this cset in the repo that drop this undesired \

> +    <span class="glyphicon glyphicon-menu-hamburger"/>
> +  </button>
> +  <ul class="dropdown-menu">
> +    {% for action in actions %}
> +    <li><a href='{{ action.url() }}'> {{ _(action.title) }}</a></li>
> +    {% endfor %}
> +  </ul>
> +</div>
>

-- 
Sylvain Thénault, LOGILAB, Paris (01.45.32.03.12) - Toulouse (05.62.17.16.42)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
CubicWeb, the semantic web framework:    http://www.cubicweb.org



More information about the saem-devel mailing list