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

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

Customers must be able to proceed to contract submission without interaction by officers.

Show only the first 6 uid digits in breadcrumbs and in select boxes.

  • Property svn:keywords set to Id
File size: 12.6 KB
Line 
1## $Id: viewlets.py 12351 2014-12-31 12:53:13Z 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 zope.component import getUtility
23from waeup.ikoba.interfaces import IIkobaObject
24from waeup.ikoba.interfaces import MessageFactory as _
25from waeup.ikoba.browser.viewlets import (
26    PrimaryNavTab, ManageActionButton, AddActionButton)
27from waeup.ikoba.browser.layout import default_primary_nav_template
28from waeup.ikoba.customers.interfaces import (
29    ICustomer, ICustomersContainer,
30    ICustomerDocumentsContainer, ICustomerDocument,
31    IContractsContainer, IContract, ICustomersUtils)
32from waeup.ikoba.customers.browser import (
33    CustomersContainerPage, CustomersContainerManagePage,
34    CustomerBaseDisplayFormPage,
35    DocumentsManageFormPage, DocumentDisplayFormPage, DocumentManageFormPage,
36    ContractsFormPage, ContractDisplayFormPage,
37    ContractManageFormPage)
38
39grok.context(IIkobaObject)  # Make IIkobaObject the default context
40grok.templatedir('browser_templates')
41
42
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):
57        return self.view.application_url('customers')
58
59
60class PrimaryCustomerNavManager(grok.ViewletManager):
61    """Viewlet manager for the primary navigation tab.
62    """
63    grok.name('primary_nav_customer')
64
65
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
88
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'},
113            {'url':customer_url + '/contracts', 'title':_('My Contracts')},
114            {'url':customer_url + '/documents', 'title':_('My Documents')},
115            {'url':customer_url + '/history', 'title':_('History')},
116            ]
117        return targets
118
119
120class CustomerManageSidebar(grok.ViewletManager):
121    grok.name('left_customermanage')
122
123
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
141        lang = self.request.cookies.get('ikoba.language')
142        text = translate(self.text, 'waeup.ikoba',
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
149
150class CustomerManageBaseLink(CustomerManageLink):
151    grok.order(2)
152    link = 'index'
153    text = _(u'Base Data')
154
155
156class CustomerManageContractsLink(CustomerManageLink):
157    grok.order(3)
158    link = 'contracts'
159    text = _(u'Contracts')
160
161
162class CustomerManageDocumentsLink(CustomerManageLink):
163    grok.order(4)
164    link = 'documents'
165    text = _(u'Documents')
166
167
168class CustomerManageHistoryLink(CustomerManageLink):
169    grok.order(8)
170    link = 'history'
171    text = _(u'History')
172
173
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
181
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
190
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
200
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
209
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'
216    text = _(u'Transition')
217    target = 'trigtrans'
218
219
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
229
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
250
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);" % _(
269            "'A history message will be added. Are you sure?'")
270
271
272class CustomerBaseActionButton(ManageActionButton):
273    grok.order(1)
274    grok.context(ICustomer)
275    grok.view(CustomerBaseDisplayFormPage)
276    grok.require('waeup.handleCustomer')
277    target = 'edit_base'
278
279    @property
280    def text(self):
281        if self.view.is_requestable:
282            return _('Edit and request registration')
283        return _('Edit')
284
285
286class CustomerPasswordActionButton(ManageActionButton):
287    grok.order(2)
288    grok.context(ICustomer)
289    grok.view(CustomerBaseDisplayFormPage)
290    grok.require('waeup.handleCustomer')
291    icon = 'actionicon_key.png'
292    text = _('Change password')
293    target = 'changepassword'
294
295
296class CustomerPassportActionButton(ManageActionButton):
297    grok.order(3)
298    grok.context(ICustomer)
299    grok.view(CustomerBaseDisplayFormPage)
300    grok.require('waeup.handleCustomer')
301    icon = 'actionicon_portrait.png'
302    text = _('Change portrait')
303    target = 'change_portrait'
304
305    @property
306    def target_url(self):
307        CUSTMANAGE_STATES = getUtility(
308            ICustomersUtils).CUSTMANAGE_CUSTOMER_STATES
309        if self.context.state not in CUSTMANAGE_STATES:
310            return ''
311        return self.view.url(self.view.context, self.target)
312
313
314# Viewlets for customer documents
315
316class PDFDocumentOverviewActionButton(ManageActionButton):
317    grok.order(2)
318    grok.context(ICustomerDocumentsContainer)
319    grok.view(DocumentsManageFormPage)
320    grok.require('waeup.viewCustomer')
321    icon = 'actionicon_pdf.png'
322    text = _('Download documents overview')
323    target = 'documents_overview_slip.pdf'
324
325
326class DocumentManageActionButton(ManageActionButton):
327    grok.order(1)
328    grok.context(ICustomerDocument)
329    grok.view(DocumentDisplayFormPage)
330    grok.require('waeup.manageCustomer')
331    text = _('Manage')
332    target = 'manage'
333
334    @property
335    def target_url(self):
336        if not self.context.is_editable_by_manager:
337            return ''
338        return self.view.url(self.view.context, self.target)
339
340
341class DocumentEditActionButton(ManageActionButton):
342    grok.order(1)
343    grok.context(ICustomerDocument)
344    grok.view(DocumentDisplayFormPage)
345    grok.require('waeup.handleCustomer')
346    text = _('Edit')
347    target = 'edit'
348
349    @property
350    def target_url(self):
351        if not self.context.is_editable_by_customer:
352            return ''
353        return self.view.url(self.view.context, self.target)
354
355
356class DocumentTrigTransActionButton(ManageActionButton):
357    grok.order(2)
358    grok.context(ICustomerDocument)
359    grok.view(DocumentDisplayFormPage)
360    grok.require('waeup.triggerTransition')
361    icon = 'actionicon_trigtrans.png'
362    text = _(u'Transition')
363    target = 'trigtrans'
364
365
366class DocumentViewActionButton(ManageActionButton):
367    grok.order(1)
368    grok.context(ICustomerDocument)
369    grok.view(DocumentManageFormPage)
370    grok.require('waeup.handleCustomer')
371    text = _('View')
372    target = 'index'
373    icon = 'actionicon_view.png'
374
375
376class PDFDocumentSlipActionButton(ManageActionButton):
377    grok.order(3)
378    grok.context(ICustomerDocument)
379    grok.view(DocumentDisplayFormPage)
380    grok.require('waeup.viewCustomer')
381    icon = 'actionicon_pdf.png'
382    text = _('Download document slip')
383    target = 'document_slip.pdf'
384
385
386# Viewlets for customer contracts
387
388class PDFContractOverviewActionButton(ManageActionButton):
389    grok.order(2)
390    grok.context(IContractsContainer)
391    grok.view(ContractsFormPage)
392    grok.require('waeup.viewCustomer')
393    icon = 'actionicon_pdf.png'
394    text = _('Download contracts overview')
395    target = 'contracts_overview_slip.pdf'
396
397
398class ContractManageActionButton(ManageActionButton):
399    grok.order(1)
400    grok.context(IContract)
401    grok.view(ContractDisplayFormPage)
402    grok.require('waeup.manageCustomer')
403    text = _('Manage')
404    target = 'manage'
405
406
407class ContractEditActionButton(ManageActionButton):
408    grok.order(1)
409    grok.context(IContract)
410    grok.view(ContractDisplayFormPage)
411    grok.require('waeup.handleCustomer')
412    text = _('Edit')
413    target = 'edit'
414
415    @property
416    def target_url(self):
417        if not self.context.is_editable:
418            return ''
419        return self.view.url(self.view.context, self.target)
420
421
422class ContractTrigTransActionButton(ManageActionButton):
423    grok.order(2)
424    grok.context(IContract)
425    grok.view(ContractDisplayFormPage)
426    grok.require('waeup.triggerTransition')
427    icon = 'actionicon_trigtrans.png'
428    text = _(u'Transition')
429    target = 'trigtrans'
430
431
432class ContractViewActionButton(ManageActionButton):
433    grok.order(1)
434    grok.context(IContract)
435    grok.view(ContractManageFormPage)
436    grok.require('waeup.handleCustomer')
437    text = _('View')
438    target = 'index'
439    icon = 'actionicon_view.png'
440
441
442class PDFContractSlipActionButton(ManageActionButton):
443    grok.order(3)
444    grok.context(IContract)
445    grok.view(ContractDisplayFormPage)
446    grok.require('waeup.viewCustomer')
447    icon = 'actionicon_pdf.png'
448    text = _('Download contract slip')
449    target = 'contract_slip.pdf'
450
Note: See TracBrowser for help on using the repository browser.