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

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

Adjust UI components in documents and customers package.

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