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

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

First batch of UI improvements.

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