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

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

Add browser components for customers. Tests will follow.

File size: 7.2 KB
Line 
13## $Id: viewlets.py 11772 2014-07-31 04:38:23Z 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 (
27    default_primary_nav_template, default_filedisplay_template,
28    default_fileupload_template)
29from waeup.ikoba.customers.interfaces import (
30    ICustomer, ICustomersContainer)
31from waeup.ikoba.customers.browser import (
32    CustomersContainerPage, CustomersContainerManagePage,
33    CustomerBaseDisplayFormPage)
34
35grok.context(IIkobaObject) # Make IIkobaObject the default context
36grok.templatedir('browser_templates')
37
38class CustomersTab(PrimaryNavTab):
39    """Customers tab in primary navigation.
40    """
41
42    grok.context(IIkobaObject)
43    grok.order(4)
44    grok.require('waeup.viewCustomersTab')
45    grok.name('customerstab')
46
47    pnav = 4
48    tab_title = _(u'Customers')
49
50    @property
51    def link_target(self):
52        return self.view.application_url('customers')
53
54class PrimaryCustomerNavManager(grok.ViewletManager):
55    """Viewlet manager for the primary navigation tab.
56    """
57    grok.name('primary_nav_customer')
58
59class PrimaryCustomerNavTab(grok.Viewlet):
60    """Base for primary customer nav tabs.
61    """
62    grok.baseclass()
63    grok.viewletmanager(PrimaryCustomerNavManager)
64    template = default_primary_nav_template
65    grok.order(1)
66    grok.require('waeup.Authenticated')
67    pnav = 0
68    tab_title = u'Some Text'
69
70    @property
71    def link_target(self):
72        return self.view.application_url()
73
74    @property
75    def active(self):
76        view_pnav = getattr(self.view, 'pnav', 0)
77        if view_pnav == self.pnav:
78            return 'active'
79        return ''
80
81class MyCustomerDataTab(PrimaryCustomerNavTab):
82    """MyData dropdown tab in primary navigation.
83    """
84    grok.order(3)
85    grok.require('waeup.viewMyCustomerDataTab')
86    grok.template('mydatadropdowntabs')
87    grok.name('mycustomerdatatab')
88    pnav = 4
89    tab_title = _(u'My Data')
90
91    @property
92    def active(self):
93        view_pnav = getattr(self.view, 'pnav', 0)
94        if view_pnav == self.pnav:
95            return 'active dropdown'
96        return 'dropdown'
97
98    @property
99    def targets(self):
100        customer = grok.getSite()['customers'][self.request.principal.id]
101        customer_url = self.view.url(customer)
102        targets = []
103        targets += [
104            {'url':customer_url, 'title':'Base Data'},
105            {'url':customer_url + '/history', 'title':_('History')},
106            ]
107        return targets
108
109class CustomerManageSidebar(grok.ViewletManager):
110    grok.name('left_customermanage')
111
112class CustomerManageLink(grok.Viewlet):
113    """A link displayed in the customer box which shows up for CustomerNavigation
114    objects.
115
116    """
117    grok.baseclass()
118    grok.viewletmanager(CustomerManageSidebar)
119    grok.view(Interface)
120    grok.order(5)
121    grok.require('waeup.viewCustomer')
122
123    link = 'index'
124    text = _(u'Base Data')
125
126    def render(self):
127        url = self.view.url(self.context.customer, self.link)
128        # Here we know that the cookie has been set
129        lang = self.request.cookies.get('kofa.language')
130        text = translate(self.text, 'waeup.kofa',
131            target_language=lang)
132        if not self.link:
133            return ''
134        return u'<li><a href="%s">%s</a></li>' % (
135                url, text)
136
137class CustomerManageBaseLink(CustomerManageLink):
138    grok.order(2)
139    link = 'index'
140    text = _(u'Base Data')
141
142class CustomerManageHistoryLink(CustomerManageLink):
143    grok.order(8)
144    link = 'history'
145    text = _(u'History')
146
147class CustomersContainerManageActionButton(ManageActionButton):
148    grok.order(1)
149    grok.context(ICustomersContainer)
150    grok.view(CustomersContainerPage)
151    grok.require('waeup.manageCustomer')
152    text = _('Manage customer section')
153
154class CustomersContainerAddActionButton(AddActionButton):
155    grok.order(1)
156    grok.context(ICustomersContainer)
157    grok.view(CustomersContainerManagePage)
158    grok.require('waeup.manageCustomer')
159    text = _('Add customer')
160    target = 'addcustomer'
161
162class ContactActionButton(ManageActionButton):
163    grok.order(5)
164    grok.context(ICustomer)
165    grok.view(CustomerBaseDisplayFormPage)
166    grok.require('waeup.manageCustomer')
167    icon = 'actionicon_mail.png'
168    text = _('Send email')
169    target = 'contactcustomer'
170
171class CustomerBaseManageActionButton(ManageActionButton):
172    grok.order(1)
173    grok.context(ICustomer)
174    grok.view(CustomerBaseDisplayFormPage)
175    grok.require('waeup.manageCustomer')
176    text = _('Manage')
177    target = 'manage_base'
178
179class CustomerTrigTransActionButton(ManageActionButton):
180    grok.order(2)
181    grok.context(ICustomer)
182    grok.view(CustomerBaseDisplayFormPage)
183    grok.require('waeup.triggerTransition')
184    icon = 'actionicon_trigtrans.png'
185    text = _(u'Trigger transition')
186    target = 'trigtrans'
187
188class CustomerLoginAsActionButton(ManageActionButton):
189    grok.order(3)
190    grok.context(ICustomer)
191    grok.view(CustomerBaseDisplayFormPage)
192    grok.require('waeup.loginAsCustomer')
193    icon = 'actionicon_mask.png'
194    text = _(u'Login as customer')
195    target = 'loginasstep1'
196
197class CustomerDeactivateActionButton(ManageActionButton):
198    grok.order(7)
199    grok.context(ICustomer)
200    grok.view(CustomerBaseDisplayFormPage)
201    grok.require('waeup.manageCustomer')
202    text = _('Deactivate account')
203    target = 'deactivate'
204    icon = 'actionicon_traffic_lights_red.png'
205
206    @property
207    def target_url(self):
208        if self.context.suspended:
209            return ''
210        return self.view.url(self.view.context, self.target)
211
212    @property
213    def onclick(self):
214        return "return window.confirm(%s);" % _(
215            "'A history message will be added. Are you sure?'")
216
217class CustomerActivateActionButton(ManageActionButton):
218    grok.order(7)
219    grok.context(ICustomer)
220    grok.view(CustomerBaseDisplayFormPage)
221    grok.require('waeup.manageCustomer')
222    text = _('Activate account')
223    target = 'activate'
224    icon = 'actionicon_traffic_lights_green.png'
225
226    @property
227    def target_url(self):
228        if not self.context.suspended:
229            return ''
230        return self.view.url(self.view.context, self.target)
231
232    @property
233    def onclick(self):
234        return "return window.confirm(%s);" % _(
235            "'A history message will be added. Are you sure?'")
Note: See TracBrowser for help on using the repository browser.