source: main/waeup.ikoba/trunk/src/waeup/ikoba/customers/viewlets.py @ 12005

Last change on this file since 12005 was 11997, checked in by Henrik Bettermann, 10 years ago

propset svn:keywords "Id"

  • Property svn:keywords set to Id
File size: 7.9 KB
Line 
1## $Id: viewlets.py 11997 2014-11-19 17:02:48Z henrik $
2##
3## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18
19import grok
20from zope.i18n import translate
21from zope.interface import Interface
22from waeup.ikoba.interfaces import IIkobaObject
23from waeup.ikoba.interfaces import MessageFactory as _
24from waeup.ikoba.browser.viewlets import (
25    PrimaryNavTab, ManageActionButton, AddActionButton)
26from waeup.ikoba.browser.layout import default_primary_nav_template
27from waeup.ikoba.customers.interfaces import (
28    ICustomer, ICustomersContainer)
29from waeup.ikoba.customers.browser import (
30    CustomersContainerPage, CustomersContainerManagePage,
31    CustomerBaseDisplayFormPage)
32
33grok.context(IIkobaObject)  # Make IIkobaObject the default context
34grok.templatedir('browser_templates')
35
36
37class CustomersTab(PrimaryNavTab):
38    """Customers tab in primary navigation.
39    """
40
41    grok.context(IIkobaObject)
42    grok.order(4)
43    grok.require('waeup.viewCustomersTab')
44    grok.name('customerstab')
45
46    pnav = 4
47    tab_title = _(u'Customers')
48
49    @property
50    def link_target(self):
51        return self.view.application_url('customers')
52
53
54class PrimaryCustomerNavManager(grok.ViewletManager):
55    """Viewlet manager for the primary navigation tab.
56    """
57    grok.name('primary_nav_customer')
58
59
60class PrimaryCustomerNavTab(grok.Viewlet):
61    """Base for primary customer nav tabs.
62    """
63    grok.baseclass()
64    grok.viewletmanager(PrimaryCustomerNavManager)
65    template = default_primary_nav_template
66    grok.order(1)
67    grok.require('waeup.Authenticated')
68    pnav = 0
69    tab_title = u'Some Text'
70
71    @property
72    def link_target(self):
73        return self.view.application_url()
74
75    @property
76    def active(self):
77        view_pnav = getattr(self.view, 'pnav', 0)
78        if view_pnav == self.pnav:
79            return 'active'
80        return ''
81
82
83class MyCustomerDataTab(PrimaryCustomerNavTab):
84    """MyData dropdown tab in primary navigation.
85    """
86    grok.order(3)
87    grok.require('waeup.viewMyCustomerDataTab')
88    grok.template('mydatadropdowntabs')
89    grok.name('mycustomerdatatab')
90    pnav = 4
91    tab_title = _(u'My Data')
92
93    @property
94    def active(self):
95        view_pnav = getattr(self.view, 'pnav', 0)
96        if view_pnav == self.pnav:
97            return 'active dropdown'
98        return 'dropdown'
99
100    @property
101    def targets(self):
102        customer = grok.getSite()['customers'][self.request.principal.id]
103        customer_url = self.view.url(customer)
104        targets = []
105        targets += [
106            {'url':customer_url, 'title':'Base Data'},
107            {'url':customer_url + '/history', 'title':_('History')},
108            ]
109        return targets
110
111
112class CustomerManageSidebar(grok.ViewletManager):
113    grok.name('left_customermanage')
114
115
116class CustomerManageLink(grok.Viewlet):
117    """A link displayed in the customer box which shows up for CustomerNavigation
118    objects.
119
120    """
121    grok.baseclass()
122    grok.viewletmanager(CustomerManageSidebar)
123    grok.view(Interface)
124    grok.order(5)
125    grok.require('waeup.viewCustomer')
126
127    link = 'index'
128    text = _(u'Base Data')
129
130    def render(self):
131        url = self.view.url(self.context.customer, self.link)
132        # Here we know that the cookie has been set
133        lang = self.request.cookies.get('ikoba.language')
134        text = translate(self.text, 'waeup.ikoba',
135            target_language=lang)
136        if not self.link:
137            return ''
138        return u'<li><a href="%s">%s</a></li>' % (
139                url, text)
140
141
142class CustomerManageBaseLink(CustomerManageLink):
143    grok.order(2)
144    link = 'index'
145    text = _(u'Base Data')
146
147
148class CustomerManageHistoryLink(CustomerManageLink):
149    grok.order(8)
150    link = 'history'
151    text = _(u'History')
152
153
154class CustomersContainerManageActionButton(ManageActionButton):
155    grok.order(1)
156    grok.context(ICustomersContainer)
157    grok.view(CustomersContainerPage)
158    grok.require('waeup.manageCustomer')
159    text = _('Manage customer section')
160
161
162class CustomersContainerAddActionButton(AddActionButton):
163    grok.order(1)
164    grok.context(ICustomersContainer)
165    grok.view(CustomersContainerManagePage)
166    grok.require('waeup.manageCustomer')
167    text = _('Add customer')
168    target = 'addcustomer'
169
170
171class ContactActionButton(ManageActionButton):
172    grok.order(5)
173    grok.context(ICustomer)
174    grok.view(CustomerBaseDisplayFormPage)
175    grok.require('waeup.manageCustomer')
176    icon = 'actionicon_mail.png'
177    text = _('Send email')
178    target = 'contactcustomer'
179
180
181class CustomerBaseManageActionButton(ManageActionButton):
182    grok.order(1)
183    grok.context(ICustomer)
184    grok.view(CustomerBaseDisplayFormPage)
185    grok.require('waeup.manageCustomer')
186    text = _('Manage')
187    target = 'manage_base'
188
189
190class CustomerTrigTransActionButton(ManageActionButton):
191    grok.order(2)
192    grok.context(ICustomer)
193    grok.view(CustomerBaseDisplayFormPage)
194    grok.require('waeup.triggerTransition')
195    icon = 'actionicon_trigtrans.png'
196    text = _(u'Trigger transition')
197    target = 'trigtrans'
198
199
200class CustomerLoginAsActionButton(ManageActionButton):
201    grok.order(3)
202    grok.context(ICustomer)
203    grok.view(CustomerBaseDisplayFormPage)
204    grok.require('waeup.loginAsCustomer')
205    icon = 'actionicon_mask.png'
206    text = _(u'Login as customer')
207    target = 'loginasstep1'
208
209
210class CustomerDeactivateActionButton(ManageActionButton):
211    grok.order(7)
212    grok.context(ICustomer)
213    grok.view(CustomerBaseDisplayFormPage)
214    grok.require('waeup.manageCustomer')
215    text = _('Deactivate account')
216    target = 'deactivate'
217    icon = 'actionicon_traffic_lights_red.png'
218
219    @property
220    def target_url(self):
221        if self.context.suspended:
222            return ''
223        return self.view.url(self.view.context, self.target)
224
225    @property
226    def onclick(self):
227        return "return window.confirm(%s);" % _(
228            "'A history message will be added. Are you sure?'")
229
230
231class CustomerActivateActionButton(ManageActionButton):
232    grok.order(7)
233    grok.context(ICustomer)
234    grok.view(CustomerBaseDisplayFormPage)
235    grok.require('waeup.manageCustomer')
236    text = _('Activate account')
237    target = 'activate'
238    icon = 'actionicon_traffic_lights_green.png'
239
240    @property
241    def target_url(self):
242        if not self.context.suspended:
243            return ''
244        return self.view.url(self.view.context, self.target)
245
246    @property
247    def onclick(self):
248        return "return window.confirm(%s);" % _(
249            "'A history message will be added. Are you sure?'")
250
251
252class CustomerBaseActionButton(ManageActionButton):
253    grok.order(1)
254    grok.context(ICustomer)
255    grok.view(CustomerBaseDisplayFormPage)
256    grok.require('waeup.handleCustomer')
257    text = _('Edit')
258    target = 'edit_base'
259
260class CustomerPasswordActionButton(ManageActionButton):
261    grok.order(2)
262    grok.context(ICustomer)
263    grok.view(CustomerBaseDisplayFormPage)
264    grok.require('waeup.handleCustomer')
265    icon = 'actionicon_key.png'
266    text = _('Change password')
267    target = 'changepassword'
268
269class CustomerPassportActionButton(ManageActionButton):
270    grok.order(3)
271    grok.context(ICustomer)
272    grok.view(CustomerBaseDisplayFormPage)
273    grok.require('waeup.handleCustomer')
274    icon = 'actionicon_portrait.png'
275    text = _('Change portrait')
276    target = 'change_portrait'
Note: See TracBrowser for help on using the repository browser.