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

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

Add PaymentsContainerPage? to search for and list payments (work in progress, completely untested).

  • Property svn:keywords set to Id
File size: 13.1 KB
Line 
1## $Id: viewlets.py 12762 2015-03-14 13:49:29Z 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 CustomerManagePaymentsLink(CustomerManageLink):
170    grok.order(5)
171    link = 'payments'
172    text = _(u'Payments')
173
174
175class CustomerManageHistoryLink(CustomerManageLink):
176    grok.order(8)
177    link = 'history'
178    text = _(u'History')
179
180
181class CustomersContainerManageActionButton(ManageActionButton):
182    grok.order(1)
183    grok.context(ICustomersContainer)
184    grok.view(CustomersContainerPage)
185    grok.require('waeup.manageCustomer')
186    text = _('Manage customer section')
187
188
189class CustomersContainerAddActionButton(AddActionButton):
190    grok.order(1)
191    grok.context(ICustomersContainer)
192    grok.view(CustomersContainerManagePage)
193    grok.require('waeup.manageCustomer')
194    text = _('Add customer')
195    target = 'addcustomer'
196
197
198class ContactActionButton(ManageActionButton):
199    grok.order(5)
200    grok.context(ICustomer)
201    grok.view(CustomerBaseDisplayFormPage)
202    grok.require('waeup.manageCustomer')
203    icon = 'actionicon_mail.png'
204    text = _('Send email')
205    target = 'contactcustomer'
206
207
208class CustomerBaseManageActionButton(ManageActionButton):
209    grok.order(1)
210    grok.context(ICustomer)
211    grok.view(CustomerBaseDisplayFormPage)
212    grok.require('waeup.manageCustomer')
213    text = _('Manage')
214    target = 'manage_base'
215
216
217class CustomerTrigTransActionButton(ManageActionButton):
218    grok.order(2)
219    grok.context(ICustomer)
220    grok.view(CustomerBaseDisplayFormPage)
221    grok.require('waeup.triggerTransition')
222    icon = 'actionicon_trigtrans.png'
223    text = _(u'Transition')
224    target = 'trigtrans'
225
226
227class CustomerLoginAsActionButton(ManageActionButton):
228    grok.order(3)
229    grok.context(ICustomer)
230    grok.view(CustomerBaseDisplayFormPage)
231    grok.require('waeup.loginAsCustomer')
232    icon = 'actionicon_mask.png'
233    text = _(u'Login as customer')
234    target = 'loginasstep1'
235
236
237class CustomerDeactivateActionButton(ManageActionButton):
238    grok.order(7)
239    grok.context(ICustomer)
240    grok.view(CustomerBaseDisplayFormPage)
241    grok.require('waeup.manageCustomer')
242    text = _('Deactivate account')
243    target = 'deactivate'
244    icon = 'actionicon_traffic_lights_red.png'
245
246    @property
247    def target_url(self):
248        if self.context.suspended:
249            return ''
250        return self.view.url(self.view.context, self.target)
251
252    @property
253    def onclick(self):
254        return "return window.confirm(%s);" % _(
255            "'A history message will be added. Are you sure?'")
256
257
258class CustomerActivateActionButton(ManageActionButton):
259    grok.order(7)
260    grok.context(ICustomer)
261    grok.view(CustomerBaseDisplayFormPage)
262    grok.require('waeup.manageCustomer')
263    text = _('Activate account')
264    target = 'activate'
265    icon = 'actionicon_traffic_lights_green.png'
266
267    @property
268    def target_url(self):
269        if not self.context.suspended:
270            return ''
271        return self.view.url(self.view.context, self.target)
272
273    @property
274    def onclick(self):
275        return "return window.confirm(%s);" % _(
276            "'A history message will be added. Are you sure?'")
277
278
279class CustomerBaseActionButton(ManageActionButton):
280    grok.order(1)
281    grok.context(ICustomer)
282    grok.view(CustomerBaseDisplayFormPage)
283    grok.require('waeup.handleCustomer')
284    target = 'edit_base'
285
286    @property
287    def text(self):
288        if self.view.is_requestable:
289            return _('Edit and request registration')
290        return _('Edit')
291
292
293class CustomerPasswordActionButton(ManageActionButton):
294    grok.order(2)
295    grok.context(ICustomer)
296    grok.view(CustomerBaseDisplayFormPage)
297    grok.require('waeup.handleCustomer')
298    icon = 'actionicon_key.png'
299    text = _('Change password')
300    target = 'changepassword'
301
302
303class CustomerPassportActionButton(ManageActionButton):
304    grok.order(3)
305    grok.context(ICustomer)
306    grok.view(CustomerBaseDisplayFormPage)
307    grok.require('waeup.handleCustomer')
308    icon = 'actionicon_up.png'
309    text = _('Upload files')
310    target = 'upload_files'
311
312    @property
313    def target_url(self):
314        CUSTMANAGE_STATES = getUtility(
315            ICustomersUtils).CUSTMANAGE_CUSTOMER_STATES
316        if self.context.state not in CUSTMANAGE_STATES:
317            return ''
318        return self.view.url(self.view.context, self.target)
319
320
321# Viewlets for customer documents
322
323class PDFDocumentOverviewActionButton(ManageActionButton):
324    grok.order(2)
325    grok.context(ICustomerDocumentsContainer)
326    grok.view(DocumentsManageFormPage)
327    grok.require('waeup.viewCustomer')
328    icon = 'actionicon_pdf.png'
329    text = _('Download documents overview')
330    target = 'documents_overview_slip.pdf'
331
332
333class DocumentManageActionButton(ManageActionButton):
334    grok.order(1)
335    grok.context(ICustomerDocument)
336    grok.view(DocumentDisplayFormPage)
337    grok.require('waeup.manageCustomer')
338    text = _('Manage')
339    target = 'manage'
340
341    @property
342    def target_url(self):
343        if not self.context.is_editable_by_manager:
344            return ''
345        return self.view.url(self.view.context, self.target)
346
347
348class DocumentEditActionButton(ManageActionButton):
349    grok.order(1)
350    grok.context(ICustomerDocument)
351    grok.view(DocumentDisplayFormPage)
352    grok.require('waeup.handleCustomer')
353    text = _('Edit')
354    target = 'edit'
355
356    @property
357    def target_url(self):
358        if not self.context.is_editable_by_customer:
359            return ''
360        return self.view.url(self.view.context, self.target)
361
362
363class DocumentTrigTransActionButton(ManageActionButton):
364    grok.order(2)
365    grok.context(ICustomerDocument)
366    grok.view(DocumentDisplayFormPage)
367    grok.require('waeup.triggerTransition')
368    icon = 'actionicon_trigtrans.png'
369    text = _(u'Transition')
370    target = 'trigtrans'
371
372
373class DocumentViewActionButton(ManageActionButton):
374    grok.order(1)
375    grok.context(ICustomerDocument)
376    grok.view(DocumentManageFormPage)
377    grok.require('waeup.handleCustomer')
378    text = _('View')
379    target = 'index'
380    icon = 'actionicon_view.png'
381
382
383class PDFDocumentSlipActionButton(ManageActionButton):
384    grok.order(3)
385    grok.context(ICustomerDocument)
386    grok.view(DocumentDisplayFormPage)
387    grok.require('waeup.viewCustomer')
388    icon = 'actionicon_pdf.png'
389    text = _('Download document slip')
390    target = 'document_slip.pdf'
391
392
393# Viewlets for customer contracts
394
395class PDFContractOverviewActionButton(ManageActionButton):
396    grok.order(2)
397    grok.context(IContractsContainer)
398    grok.view(ContractsFormPage)
399    grok.require('waeup.viewCustomer')
400    icon = 'actionicon_pdf.png'
401    text = _('Download contracts overview')
402    target = 'contracts_overview_slip.pdf'
403
404
405class ContractManageActionButton(ManageActionButton):
406    grok.order(1)
407    grok.context(IContract)
408    grok.view(ContractDisplayFormPage)
409    grok.require('waeup.manageCustomer')
410    text = _('Manage')
411    target = 'manage'
412
413
414class ContractOUActionButton(ManageActionButton):
415    grok.order(2)
416    grok.context(IContract)
417    grok.view(ContractDisplayFormPage)
418    grok.require('waeup.manageCustomer')
419    text = _('Manage official data')
420    target = 'official_use'
421
422
423class ContractEditActionButton(ManageActionButton):
424    grok.order(1)
425    grok.context(IContract)
426    grok.view(ContractDisplayFormPage)
427    grok.require('waeup.handleCustomer')
428    text = _('Edit')
429    target = 'edit'
430
431    @property
432    def target_url(self):
433        if not self.context.is_editable:
434            return ''
435        return self.view.url(self.view.context, self.target)
436
437
438class ContractTrigTransActionButton(ManageActionButton):
439    grok.order(3)
440    grok.context(IContract)
441    grok.view(ContractDisplayFormPage)
442    grok.require('waeup.triggerTransition')
443    icon = 'actionicon_trigtrans.png'
444    text = _(u'Transition')
445    target = 'trigtrans'
446
447
448class ContractViewActionButton(ManageActionButton):
449    grok.order(1)
450    grok.context(IContract)
451    grok.view(ContractManageFormPage)
452    grok.require('waeup.handleCustomer')
453    text = _('View')
454    target = 'index'
455    icon = 'actionicon_view.png'
456
457
458class ContractViewActionButton2(ContractViewActionButton):
459    grok.view(ContractOfficialUsePage)
460
461
462class PDFContractSlipActionButton(ManageActionButton):
463    grok.order(4)
464    grok.context(IContract)
465    grok.view(ContractDisplayFormPage)
466    grok.require('waeup.viewCustomer')
467    icon = 'actionicon_pdf.png'
468    text = _('Download contract slip')
469    target = 'contract_slip.pdf'
470
Note: See TracBrowser for help on using the repository browser.