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

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

Add view and viewlet for customer document transitions.

  • Property svn:keywords set to Id
File size: 9.6 KB
Line 
1## $Id: viewlets.py 12028 2014-11-21 13:05:56Z 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,
29    ICustomerDocumentsContainer, ICustomerDocument)
30from waeup.ikoba.customers.browser import (
31    CustomersContainerPage, CustomersContainerManagePage,
32    CustomerBaseDisplayFormPage,
33    DocumentsManageFormPage, DocumentDisplayFormPage, DocumentManageFormPage)
34
35grok.context(IIkobaObject)  # Make IIkobaObject the default context
36grok.templatedir('browser_templates')
37
38
39class CustomersTab(PrimaryNavTab):
40    """Customers tab in primary navigation.
41    """
42
43    grok.context(IIkobaObject)
44    grok.order(4)
45    grok.require('waeup.viewCustomersTab')
46    grok.name('customerstab')
47
48    pnav = 4
49    tab_title = _(u'Customers')
50
51    @property
52    def link_target(self):
53        return self.view.application_url('customers')
54
55
56class PrimaryCustomerNavManager(grok.ViewletManager):
57    """Viewlet manager for the primary navigation tab.
58    """
59    grok.name('primary_nav_customer')
60
61
62class PrimaryCustomerNavTab(grok.Viewlet):
63    """Base for primary customer nav tabs.
64    """
65    grok.baseclass()
66    grok.viewletmanager(PrimaryCustomerNavManager)
67    template = default_primary_nav_template
68    grok.order(1)
69    grok.require('waeup.Authenticated')
70    pnav = 0
71    tab_title = u'Some Text'
72
73    @property
74    def link_target(self):
75        return self.view.application_url()
76
77    @property
78    def active(self):
79        view_pnav = getattr(self.view, 'pnav', 0)
80        if view_pnav == self.pnav:
81            return 'active'
82        return ''
83
84
85class MyCustomerDataTab(PrimaryCustomerNavTab):
86    """MyData dropdown tab in primary navigation.
87    """
88    grok.order(3)
89    grok.require('waeup.viewMyCustomerDataTab')
90    grok.template('mydatadropdowntabs')
91    grok.name('mycustomerdatatab')
92    pnav = 4
93    tab_title = _(u'My Data')
94
95    @property
96    def active(self):
97        view_pnav = getattr(self.view, 'pnav', 0)
98        if view_pnav == self.pnav:
99            return 'active dropdown'
100        return 'dropdown'
101
102    @property
103    def targets(self):
104        customer = grok.getSite()['customers'][self.request.principal.id]
105        customer_url = self.view.url(customer)
106        targets = []
107        targets += [
108            {'url':customer_url, 'title':'Base Data'},
109            {'url':customer_url + '/documents', 'title':_('Documents')},
110            {'url':customer_url + '/history', 'title':_('History')},
111            ]
112        return targets
113
114
115class CustomerManageSidebar(grok.ViewletManager):
116    grok.name('left_customermanage')
117
118
119class CustomerManageLink(grok.Viewlet):
120    """A link displayed in the customer box which shows up for CustomerNavigation
121    objects.
122
123    """
124    grok.baseclass()
125    grok.viewletmanager(CustomerManageSidebar)
126    grok.view(Interface)
127    grok.order(5)
128    grok.require('waeup.viewCustomer')
129
130    link = 'index'
131    text = _(u'Base Data')
132
133    def render(self):
134        url = self.view.url(self.context.customer, self.link)
135        # Here we know that the cookie has been set
136        lang = self.request.cookies.get('ikoba.language')
137        text = translate(self.text, 'waeup.ikoba',
138            target_language=lang)
139        if not self.link:
140            return ''
141        return u'<li><a href="%s">%s</a></li>' % (
142                url, text)
143
144
145class CustomerManageBaseLink(CustomerManageLink):
146    grok.order(2)
147    link = 'index'
148    text = _(u'Base Data')
149
150class CustomerManageDocumentsLink(CustomerManageLink):
151    grok.order(3)
152    link = 'documents'
153    text = _(u'Documents')
154
155
156class CustomerManageHistoryLink(CustomerManageLink):
157    grok.order(8)
158    link = 'history'
159    text = _(u'History')
160
161
162class CustomersContainerManageActionButton(ManageActionButton):
163    grok.order(1)
164    grok.context(ICustomersContainer)
165    grok.view(CustomersContainerPage)
166    grok.require('waeup.manageCustomer')
167    text = _('Manage customer section')
168
169
170class CustomersContainerAddActionButton(AddActionButton):
171    grok.order(1)
172    grok.context(ICustomersContainer)
173    grok.view(CustomersContainerManagePage)
174    grok.require('waeup.manageCustomer')
175    text = _('Add customer')
176    target = 'addcustomer'
177
178
179class ContactActionButton(ManageActionButton):
180    grok.order(5)
181    grok.context(ICustomer)
182    grok.view(CustomerBaseDisplayFormPage)
183    grok.require('waeup.manageCustomer')
184    icon = 'actionicon_mail.png'
185    text = _('Send email')
186    target = 'contactcustomer'
187
188
189class CustomerBaseManageActionButton(ManageActionButton):
190    grok.order(1)
191    grok.context(ICustomer)
192    grok.view(CustomerBaseDisplayFormPage)
193    grok.require('waeup.manageCustomer')
194    text = _('Manage')
195    target = 'manage_base'
196
197
198class CustomerTrigTransActionButton(ManageActionButton):
199    grok.order(2)
200    grok.context(ICustomer)
201    grok.view(CustomerBaseDisplayFormPage)
202    grok.require('waeup.triggerTransition')
203    icon = 'actionicon_trigtrans.png'
204    text = _(u'Transition')
205    target = 'trigtrans'
206
207
208class CustomerLoginAsActionButton(ManageActionButton):
209    grok.order(3)
210    grok.context(ICustomer)
211    grok.view(CustomerBaseDisplayFormPage)
212    grok.require('waeup.loginAsCustomer')
213    icon = 'actionicon_mask.png'
214    text = _(u'Login as customer')
215    target = 'loginasstep1'
216
217
218class CustomerDeactivateActionButton(ManageActionButton):
219    grok.order(7)
220    grok.context(ICustomer)
221    grok.view(CustomerBaseDisplayFormPage)
222    grok.require('waeup.manageCustomer')
223    text = _('Deactivate account')
224    target = 'deactivate'
225    icon = 'actionicon_traffic_lights_red.png'
226
227    @property
228    def target_url(self):
229        if self.context.suspended:
230            return ''
231        return self.view.url(self.view.context, self.target)
232
233    @property
234    def onclick(self):
235        return "return window.confirm(%s);" % _(
236            "'A history message will be added. Are you sure?'")
237
238
239class CustomerActivateActionButton(ManageActionButton):
240    grok.order(7)
241    grok.context(ICustomer)
242    grok.view(CustomerBaseDisplayFormPage)
243    grok.require('waeup.manageCustomer')
244    text = _('Activate account')
245    target = 'activate'
246    icon = 'actionicon_traffic_lights_green.png'
247
248    @property
249    def target_url(self):
250        if not self.context.suspended:
251            return ''
252        return self.view.url(self.view.context, self.target)
253
254    @property
255    def onclick(self):
256        return "return window.confirm(%s);" % _(
257            "'A history message will be added. Are you sure?'")
258
259
260class CustomerBaseActionButton(ManageActionButton):
261    grok.order(1)
262    grok.context(ICustomer)
263    grok.view(CustomerBaseDisplayFormPage)
264    grok.require('waeup.handleCustomer')
265    text = _('Edit')
266    target = 'edit_base'
267
268
269class CustomerPasswordActionButton(ManageActionButton):
270    grok.order(2)
271    grok.context(ICustomer)
272    grok.view(CustomerBaseDisplayFormPage)
273    grok.require('waeup.handleCustomer')
274    icon = 'actionicon_key.png'
275    text = _('Change password')
276    target = 'changepassword'
277
278
279class CustomerPassportActionButton(ManageActionButton):
280    grok.order(3)
281    grok.context(ICustomer)
282    grok.view(CustomerBaseDisplayFormPage)
283    grok.require('waeup.handleCustomer')
284    icon = 'actionicon_portrait.png'
285    text = _('Change portrait')
286    target = 'change_portrait'
287
288
289# Viewlets for customer cocuments
290
291
292class AddDocumentActionButton(AddActionButton):
293    grok.order(1)
294    grok.context(ICustomerDocumentsContainer)
295    grok.view(DocumentsManageFormPage)
296    grok.require('waeup.editCustomerDocuments')
297    text = _('Add document')
298    target = 'adddoc'
299
300
301class DocumentManageActionButton(ManageActionButton):
302    grok.order(1)
303    grok.context(ICustomerDocument)
304    grok.view(DocumentDisplayFormPage)
305    grok.require('waeup.manageCustomer')
306    text = _('Manage')
307    target = 'manage'
308
309
310class DocumentEditActionButton(ManageActionButton):
311    grok.order(1)
312    grok.context(ICustomerDocument)
313    grok.view(DocumentDisplayFormPage)
314    grok.require('waeup.handleCustomer')
315    text = _('Edit')
316    target = 'edit'
317
318    @property
319    def target_url(self):
320        if not self.context.is_editable:
321            return ''
322        return self.view.url(self.view.context, self.target)
323
324
325class DocumentTrigTransActionButton(ManageActionButton):
326    grok.order(2)
327    grok.context(ICustomerDocument)
328    grok.view(DocumentDisplayFormPage)
329    grok.require('waeup.triggerTransition')
330    icon = 'actionicon_trigtrans.png'
331    text = _(u'Transition')
332    target = 'trigtrans'
333
334
335class DocumentViewActionButton(ManageActionButton):
336    grok.order(1)
337    grok.context(ICustomerDocument)
338    grok.view(DocumentManageFormPage)
339    grok.require('waeup.handleCustomer')
340    text = _('View')
341    target = 'index'
342    icon = 'actionicon_view.png'
Note: See TracBrowser for help on using the repository browser.