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

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

Add PaymentsPage? (work in progress).

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