11from pyramid_formalchemy .i18n import TranslationStringFactory
22from pyramid_formalchemy import actions
33from pyramid_formalchemy .actions import Actions
4- from pyramid_formalchemy .actions import action ; action
54from webhelpers .html import literal
65
76_ = TranslationStringFactory ('fa_bootstrap' )
87
98
9+ class RealButton (actions .Action ):
10+ body = '<button class="${_class}" tal:attributes="%(attributes)s">' \
11+ '<span tal:condition="action.icon" class="${action.icon}"></span> ${content}</button>'
12+
13+ @property
14+ def icon (self ):
15+ return self .rcontext .get ('icon' , None )
16+
17+
1018class UIButton (actions .UIButton ):
1119 """Overwrite default pyramid_formalchemy action to support bootstrap style."""
1220
13- body = '''<a class="${_class}" tal:attributes="%(attributes)s"><i tal:condition="action.icon" class="${action.icon}"></i> ${content}</a>'''
21+ body = '<a class="${_class}" tal:attributes="%(attributes)s">' \
22+ '<span tal:condition="action.icon" class="${action.icon}"></span> ${content}</a>'
1423
1524 @property
1625 def icon (self ):
1726 return self .rcontext .get ('icon' , None )
1827
1928
20-
2129class TabAction (actions .Action ):
2230 """New action type - comaptible with boostrap style."""
23- body = u'<li tal:attributes="class action.isActive(request) and \' active\' or \' \' "><a tal:attributes="%(attributes)s">${content}</a></li>'
31+ body = u"<li tal:attributes=\" class action.is_active(request) and 'active' or ''\" >" \
32+ u'<a tal:attributes="%(attributes)s">${content}</a></li>'
2433
25- def isActive (self , request ):
34+ def is_active (self , request ):
2635 for _id in self .rcontext .get ('children' , ()):
2736 if _id in request .matchdict .get ('traverse' ):
2837 return True
2938 return request .path_url .strip ('/' ) == eval (self .attrs ['href' ]).strip ('/' )
3039
3140
3241class BreadcrumbAction (TabAction ):
33- body = u'''<li tal:attributes="class action.isActive (request) and \' active\' or \' \' ">
34- <a tal:condition="not action.isActive (request)" tal:attributes="%(attributes)s">${content}</a>
35- <span tal:condition="action.isActive (request)" tal:omit-tag="">${content}</span>
36- <span tal:condition="not action.isActive (request)" class="divider">/</span>
42+ body = u'''<li tal:attributes="class action.is_active (request) and \' active\' or \' \' ">
43+ <a tal:condition="not action.is_active (request)" tal:attributes="%(attributes)s">${content}</a>
44+ <span tal:condition="action.is_active (request)" tal:omit-tag="">${content}</span>
45+ <span tal:condition="not action.is_active (request)" class="divider">/</span>
3746 </li>'''
3847
3948
4049class TabsActions (Actions , actions .Action ):
41- body = '''<ul class="nav nav-tabs">${items}</ul>'''
50+ body = '''<ul class="nav nav-tabs">${items}</ul>'''
4251
4352 def __init__ (self , * args , ** kwargs ):
4453 Actions .__init__ (self , * args , ** kwargs )
@@ -51,7 +60,7 @@ def render(self, request, **kwargs):
5160
5261
5362class PillsActions (TabsActions ):
54- body = '''<ul class="nav nav-pills">${items}</ul>'''
63+ body = '''<ul class="nav nav-pills">${items}</ul>'''
5564
5665
5766class DropdownActions (Actions , actions .Action ):
@@ -74,70 +83,69 @@ def render(self, request, **kwargs):
7483
7584
7685new = UIButton (
77- id = 'new' ,
78- content = _ ('New ${model_label}' ),
79- permission = 'new' ,
80- _class = 'btn btn-primary' ,
81- icon = 'icon-white icon-plus' ,
82- attrs = dict (href = "request.fa_url(request.model_name, 'new')" ),
83- )
84-
85-
86- save = UIButton (
87- id = 'save' ,
88- content = _ ('Save' ),
89- permission = 'edit' ,
90- _class = 'btn btn-success' ,
91- icon = 'icon-white icon-ok' ,
92- attrs = dict (onclick = "jQuery(this).parents('form').submit();" ),
93- )
86+ id = 'new' ,
87+ content = _ ('New ${model_label}' ),
88+ permission = 'new' ,
89+ _class = 'btn btn-primary' ,
90+ icon = 'glyphicon glyphicon-plus' ,
91+ attrs = dict (href = "request.fa_url(request.model_name, 'new')" ),
92+ )
93+
94+ save = RealButton (
95+ id = 'save' ,
96+ type = 'submit' ,
97+ content = _ ('Save' ),
98+ permission = 'edit' ,
99+ _class = 'btn btn-success' ,
100+ icon = 'glyphicon glyphicon-ok' ,
101+ )
94102
95103save_and_add_another = UIButton (
96- id = 'save_and_add_another' ,
97- content = _ ('Save and add another' ),
98- permission = 'edit' ,
99- _class = 'btn btn-success' ,
100- icon = 'icon-white icon -plus' ,
101- attrs = dict (onclick = ("var f = jQuery(this).parents('form');"
102- "jQuery('#next', f).val(window.location.href);"
103- "f.submit();" )),
104- )
104+ id = 'save_and_add_another' ,
105+ content = _ ('Save and add another' ),
106+ permission = 'edit' ,
107+ _class = 'btn btn-success' ,
108+ icon = 'glyphicon glyphicon -plus' ,
109+ attrs = dict (onclick = ("var f = jQuery(this).parents('form');"
110+ "jQuery('#next', f).val(window.location.href);"
111+ "f.submit();" )),
112+ )
105113
106114edit = UIButton (
107- id = 'edit' ,
108- content = _ ('Edit' ),
109- permission = 'edit' ,
110- _class = 'btn btn-info' ,
111- icon = 'icon-white icon -edit' ,
112- attrs = dict (href = "request.fa_url(request.model_name, request.model_id, 'edit')" ),
113- )
115+ id = 'edit' ,
116+ content = _ ('Edit' ),
117+ permission = 'edit' ,
118+ _class = 'btn btn-info' ,
119+ icon = 'glyphicon glyphicon -edit' ,
120+ attrs = dict (href = "request.fa_url(request.model_name, request.model_id, 'edit')" ),
121+ )
114122
115123back = UIButton (
116- id = 'back' ,
117- content = _ ('Back' ),
118- _class = 'btn' ,
119- attrs = dict (href = "request.fa_url(request.model_name)" ),
120- )
124+ id = 'back' ,
125+ content = _ ('Back' ),
126+ _class = 'btn btn-default ' ,
127+ attrs = dict (href = "request.fa_url(request.model_name)" ),
128+ )
121129
122130delete = UIButton (
123- id = 'delete' ,
124- content = _ ('Delete' ),
125- permission = 'delete' ,
126- _class = 'btn btn-danger' ,
127- icon = 'icon-white icon -trash' ,
128- attrs = dict (onclick = ("var f = jQuery(this).parents('form');"
129- "f.attr('action', window.location.href.replace('/edit', '/delete'));"
130- "f.submit();" )),
131- )
131+ id = 'delete' ,
132+ content = _ ('Delete' ),
133+ permission = 'delete' ,
134+ _class = 'btn btn-danger' ,
135+ icon = 'glyphicon glyphicon -trash' ,
136+ attrs = dict (onclick = ("var f = jQuery(this).parents('form');"
137+ "f.attr('action', window.location.href.replace('/edit', '/delete'));"
138+ "f.submit();" )),
139+ )
132140
133141cancel = UIButton (
134- id = 'cancel' ,
135- content = _ ('Cancel' ),
136- permission = 'view' ,
137- _class = 'btn' ,
138- icon = 'icon -remove' ,
139- attrs = dict (href = "request.fa_url(request.model_name)" ),
140- )
142+ id = 'cancel' ,
143+ content = _ ('Cancel' ),
144+ permission = 'view' ,
145+ _class = 'btn btn-default ' ,
146+ icon = 'glyphicon glyphicon -remove' ,
147+ attrs = dict (href = "request.fa_url(request.model_name)" ),
148+ )
141149
142150defaults_actions = actions .defaults_actions .copy ()
143151defaults_actions ['listing_buttons' ] = Actions (new )
0 commit comments