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

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

Add interface and page for editing official use data. Adjust exporter.

  • Property svn:keywords set to Id
File size: 13.0 KB
Line 
1## $Id: viewlets.py 12500 2015-01-20 17:31:11Z 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    ContractOfficialUsePage)
39
40grok.context(IIkobaObject)  # Make IIkobaObject the default context
41grok.templatedir('browser_templates')
42
43
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):
58        return self.view.application_url('customers')
59
60
61class PrimaryCustomerNavManager(grok.ViewletManager):
62    """Viewlet manager for the primary navigation tab.
63    """
64    grok.name('primary_nav_customer')
65
66
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
89
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'},
114            {'url':customer_url + '/contracts', 'title':_('My Contracts')},
115            {'url':customer_url + '/documents', 'title':_('My Documents')},
116            {'url':customer_url + '/history', 'title':_('History')},
117            ]
118        return targets
119
120
121class CustomerManageSidebar(grok.ViewletManager):
122    grok.name('left_customermanage')
123
124
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
142        lang = self.request.cookies.get('ikoba.language')
143        text = translate(self.text, 'waeup.ikoba',
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
150
151class CustomerManageBaseLink(CustomerManageLink):
152    grok.order(2)
153    link = 'index'
154    text = _(u'Base Data')
155
156
157class CustomerManageContractsLink(CustomerManageLink):
158    grok.order(3)
159    link = 'contracts'
160    text = _(u'Contracts')
161
162
163class CustomerManageDocumentsLink(CustomerManageLink):
164    grok.order(4)
165    link = 'documents'
166    text = _(u'Documents')
167
168
169class CustomerManageHistoryLink(CustomerManageLink):
170    grok.order(8)
171    link = 'history'
172    text = _(u'History')
173
174
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
182
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
191
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
201
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
210
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'
217    text = _(u'Transition')
218    target = 'trigtrans'
219
220
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
230
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
251
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);" % _(
270            "'A history message will be added. Are you sure?'")
271
272
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
280    @property
281    def text(self):
282        if self.view.is_requestable:
283            return _('Edit and request registration')
284        return _('Edit')
285
286
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')
294    target = 'changepassword'
295
296
297class CustomerPassportActionButton(ManageActionButton):
298    grok.order(3)
299    grok.context(ICustomer)
300    grok.view(CustomerBaseDisplayFormPage)
301    grok.require('waeup.handleCustomer')
302    icon = 'actionicon_portrait.png'
303    text = _('Change portrait')
304    target = 'change_portrait'
305
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)
313
314
315# Viewlets for customer documents
316
317class PDFDocumentOverviewActionButton(ManageActionButton):
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')
324    target = 'documents_overview_slip.pdf'
325
326
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
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)
340
341
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):
352        if not self.context.is_editable_by_customer:
353            return ''
354        return self.view.url(self.view.context, self.target)
355
356
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
367class DocumentViewActionButton(ManageActionButton):
368    grok.order(1)
369    grok.context(ICustomerDocument)
370    grok.view(DocumentManageFormPage)
371    grok.require('waeup.handleCustomer')
372    text = _('View')
373    target = 'index'
374    icon = 'actionicon_view.png'
375
376
377class PDFDocumentSlipActionButton(ManageActionButton):
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'
385
386
387# Viewlets for customer contracts
388
389class PDFContractOverviewActionButton(ManageActionButton):
390    grok.order(2)
391    grok.context(IContractsContainer)
392    grok.view(ContractsFormPage)
393    grok.require('waeup.viewCustomer')
394    icon = 'actionicon_pdf.png'
395    text = _('Download contracts overview')
396    target = 'contracts_overview_slip.pdf'
397
398
399class ContractManageActionButton(ManageActionButton):
400    grok.order(1)
401    grok.context(IContract)
402    grok.view(ContractDisplayFormPage)
403    grok.require('waeup.manageCustomer')
404    text = _('Manage')
405    target = 'manage'
406
407
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
417class ContractEditActionButton(ManageActionButton):
418    grok.order(1)
419    grok.context(IContract)
420    grok.view(ContractDisplayFormPage)
421    grok.require('waeup.handleCustomer')
422    text = _('Edit')
423    target = 'edit'
424
425    @property
426    def target_url(self):
427        if not self.context.is_editable:
428            return ''
429        return self.view.url(self.view.context, self.target)
430
431
432class ContractTrigTransActionButton(ManageActionButton):
433    grok.order(3)
434    grok.context(IContract)
435    grok.view(ContractDisplayFormPage)
436    grok.require('waeup.triggerTransition')
437    icon = 'actionicon_trigtrans.png'
438    text = _(u'Transition')
439    target = 'trigtrans'
440
441
442class ContractViewActionButton(ManageActionButton):
443    grok.order(1)
444    grok.context(IContract)
445    grok.view(ContractManageFormPage)
446    grok.require('waeup.handleCustomer')
447    text = _('View')
448    target = 'index'
449    icon = 'actionicon_view.png'
450
451
452class ContractViewActionButton2(ContractViewActionButton):
453    grok.view(ContractOfficialUsePage)
454
455
456class PDFContractSlipActionButton(ManageActionButton):
457    grok.order(4)
458    grok.context(IContract)
459    grok.view(ContractDisplayFormPage)
460    grok.require('waeup.viewCustomer')
461    icon = 'actionicon_pdf.png'
462    text = _('Download contract slip')
463    target = 'contract_slip.pdf'
464
Note: See TracBrowser for help on using the repository browser.