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

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

Rename contract property attribute to be more in line with documents.

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