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

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

Rearrange some pages for customers.

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