[12015] | 1 | ## $Id: viewlets.py 12062 2014-11-26 13:03:56Z henrik $ |
---|
[11958] | 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 | |
---|
| 19 | import grok |
---|
[11967] | 20 | from zope.i18n import translate |
---|
| 21 | from zope.interface import Interface |
---|
[11958] | 22 | from waeup.ikoba.interfaces import IIkobaObject |
---|
| 23 | from waeup.ikoba.interfaces import MessageFactory as _ |
---|
| 24 | from waeup.ikoba.browser.viewlets import ( |
---|
| 25 | PrimaryNavTab, ManageActionButton, AddActionButton) |
---|
[11987] | 26 | from waeup.ikoba.browser.layout import default_primary_nav_template |
---|
[11967] | 27 | from waeup.ikoba.customers.interfaces import ( |
---|
[12015] | 28 | ICustomer, ICustomersContainer, |
---|
[12016] | 29 | ICustomerDocumentsContainer, ICustomerDocument) |
---|
[11967] | 30 | from waeup.ikoba.customers.browser import ( |
---|
| 31 | CustomersContainerPage, CustomersContainerManagePage, |
---|
[12015] | 32 | CustomerBaseDisplayFormPage, |
---|
[12016] | 33 | DocumentsManageFormPage, DocumentDisplayFormPage, DocumentManageFormPage) |
---|
[11958] | 34 | |
---|
[11985] | 35 | grok.context(IIkobaObject) # Make IIkobaObject the default context |
---|
[11964] | 36 | grok.templatedir('browser_templates') |
---|
| 37 | |
---|
[11985] | 38 | |
---|
[11958] | 39 | class CustomersTab(PrimaryNavTab): |
---|
| 40 | """Customers tab in primary navigation. |
---|
| 41 | """ |
---|
| 42 | |
---|
| 43 | grok.context(IIkobaObject) |
---|
| 44 | grok.order(4) |
---|
| 45 | grok.require('waeup.viewCustomersTab') |
---|
| 46 | grok.name('customerstab') |
---|
| 47 | |
---|
| 48 | pnav = 4 |
---|
| 49 | tab_title = _(u'Customers') |
---|
| 50 | |
---|
| 51 | @property |
---|
| 52 | def link_target(self): |
---|
[11964] | 53 | return self.view.application_url('customers') |
---|
| 54 | |
---|
[11985] | 55 | |
---|
[11964] | 56 | class PrimaryCustomerNavManager(grok.ViewletManager): |
---|
| 57 | """Viewlet manager for the primary navigation tab. |
---|
| 58 | """ |
---|
| 59 | grok.name('primary_nav_customer') |
---|
| 60 | |
---|
[11985] | 61 | |
---|
[11964] | 62 | class PrimaryCustomerNavTab(grok.Viewlet): |
---|
| 63 | """Base for primary customer nav tabs. |
---|
| 64 | """ |
---|
| 65 | grok.baseclass() |
---|
| 66 | grok.viewletmanager(PrimaryCustomerNavManager) |
---|
| 67 | template = default_primary_nav_template |
---|
| 68 | grok.order(1) |
---|
| 69 | grok.require('waeup.Authenticated') |
---|
| 70 | pnav = 0 |
---|
| 71 | tab_title = u'Some Text' |
---|
| 72 | |
---|
| 73 | @property |
---|
| 74 | def link_target(self): |
---|
| 75 | return self.view.application_url() |
---|
| 76 | |
---|
| 77 | @property |
---|
| 78 | def active(self): |
---|
| 79 | view_pnav = getattr(self.view, 'pnav', 0) |
---|
| 80 | if view_pnav == self.pnav: |
---|
| 81 | return 'active' |
---|
| 82 | return '' |
---|
| 83 | |
---|
[11985] | 84 | |
---|
[11964] | 85 | class MyCustomerDataTab(PrimaryCustomerNavTab): |
---|
| 86 | """MyData dropdown tab in primary navigation. |
---|
| 87 | """ |
---|
| 88 | grok.order(3) |
---|
| 89 | grok.require('waeup.viewMyCustomerDataTab') |
---|
| 90 | grok.template('mydatadropdowntabs') |
---|
| 91 | grok.name('mycustomerdatatab') |
---|
| 92 | pnav = 4 |
---|
| 93 | tab_title = _(u'My Data') |
---|
| 94 | |
---|
| 95 | @property |
---|
| 96 | def active(self): |
---|
| 97 | view_pnav = getattr(self.view, 'pnav', 0) |
---|
| 98 | if view_pnav == self.pnav: |
---|
| 99 | return 'active dropdown' |
---|
| 100 | return 'dropdown' |
---|
| 101 | |
---|
| 102 | @property |
---|
| 103 | def targets(self): |
---|
| 104 | customer = grok.getSite()['customers'][self.request.principal.id] |
---|
| 105 | customer_url = self.view.url(customer) |
---|
| 106 | targets = [] |
---|
| 107 | targets += [ |
---|
| 108 | {'url':customer_url, 'title':'Base Data'}, |
---|
[12015] | 109 | {'url':customer_url + '/documents', 'title':_('Documents')}, |
---|
[11964] | 110 | {'url':customer_url + '/history', 'title':_('History')}, |
---|
| 111 | ] |
---|
[11967] | 112 | return targets |
---|
| 113 | |
---|
[11985] | 114 | |
---|
[11967] | 115 | class CustomerManageSidebar(grok.ViewletManager): |
---|
| 116 | grok.name('left_customermanage') |
---|
| 117 | |
---|
[11985] | 118 | |
---|
[11967] | 119 | class CustomerManageLink(grok.Viewlet): |
---|
| 120 | """A link displayed in the customer box which shows up for CustomerNavigation |
---|
| 121 | objects. |
---|
| 122 | |
---|
| 123 | """ |
---|
| 124 | grok.baseclass() |
---|
| 125 | grok.viewletmanager(CustomerManageSidebar) |
---|
| 126 | grok.view(Interface) |
---|
| 127 | grok.order(5) |
---|
| 128 | grok.require('waeup.viewCustomer') |
---|
| 129 | |
---|
| 130 | link = 'index' |
---|
| 131 | text = _(u'Base Data') |
---|
| 132 | |
---|
| 133 | def render(self): |
---|
| 134 | url = self.view.url(self.context.customer, self.link) |
---|
| 135 | # Here we know that the cookie has been set |
---|
[11979] | 136 | lang = self.request.cookies.get('ikoba.language') |
---|
| 137 | text = translate(self.text, 'waeup.ikoba', |
---|
[11967] | 138 | target_language=lang) |
---|
| 139 | if not self.link: |
---|
| 140 | return '' |
---|
| 141 | return u'<li><a href="%s">%s</a></li>' % ( |
---|
| 142 | url, text) |
---|
| 143 | |
---|
[11985] | 144 | |
---|
[11967] | 145 | class CustomerManageBaseLink(CustomerManageLink): |
---|
| 146 | grok.order(2) |
---|
| 147 | link = 'index' |
---|
| 148 | text = _(u'Base Data') |
---|
| 149 | |
---|
[12015] | 150 | class CustomerManageDocumentsLink(CustomerManageLink): |
---|
| 151 | grok.order(3) |
---|
| 152 | link = 'documents' |
---|
| 153 | text = _(u'Documents') |
---|
[11985] | 154 | |
---|
[12015] | 155 | |
---|
[11967] | 156 | class CustomerManageHistoryLink(CustomerManageLink): |
---|
| 157 | grok.order(8) |
---|
| 158 | link = 'history' |
---|
| 159 | text = _(u'History') |
---|
| 160 | |
---|
[11985] | 161 | |
---|
[11967] | 162 | class CustomersContainerManageActionButton(ManageActionButton): |
---|
| 163 | grok.order(1) |
---|
| 164 | grok.context(ICustomersContainer) |
---|
| 165 | grok.view(CustomersContainerPage) |
---|
| 166 | grok.require('waeup.manageCustomer') |
---|
| 167 | text = _('Manage customer section') |
---|
| 168 | |
---|
[11985] | 169 | |
---|
[11967] | 170 | class CustomersContainerAddActionButton(AddActionButton): |
---|
| 171 | grok.order(1) |
---|
| 172 | grok.context(ICustomersContainer) |
---|
| 173 | grok.view(CustomersContainerManagePage) |
---|
| 174 | grok.require('waeup.manageCustomer') |
---|
| 175 | text = _('Add customer') |
---|
| 176 | target = 'addcustomer' |
---|
| 177 | |
---|
[11985] | 178 | |
---|
[11967] | 179 | class ContactActionButton(ManageActionButton): |
---|
| 180 | grok.order(5) |
---|
| 181 | grok.context(ICustomer) |
---|
| 182 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 183 | grok.require('waeup.manageCustomer') |
---|
| 184 | icon = 'actionicon_mail.png' |
---|
| 185 | text = _('Send email') |
---|
| 186 | target = 'contactcustomer' |
---|
| 187 | |
---|
[11985] | 188 | |
---|
[11967] | 189 | class CustomerBaseManageActionButton(ManageActionButton): |
---|
| 190 | grok.order(1) |
---|
| 191 | grok.context(ICustomer) |
---|
| 192 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 193 | grok.require('waeup.manageCustomer') |
---|
| 194 | text = _('Manage') |
---|
| 195 | target = 'manage_base' |
---|
| 196 | |
---|
[11985] | 197 | |
---|
[11967] | 198 | class CustomerTrigTransActionButton(ManageActionButton): |
---|
| 199 | grok.order(2) |
---|
| 200 | grok.context(ICustomer) |
---|
| 201 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 202 | grok.require('waeup.triggerTransition') |
---|
| 203 | icon = 'actionicon_trigtrans.png' |
---|
[12028] | 204 | text = _(u'Transition') |
---|
[11967] | 205 | target = 'trigtrans' |
---|
| 206 | |
---|
[11985] | 207 | |
---|
[11967] | 208 | class CustomerLoginAsActionButton(ManageActionButton): |
---|
| 209 | grok.order(3) |
---|
| 210 | grok.context(ICustomer) |
---|
| 211 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 212 | grok.require('waeup.loginAsCustomer') |
---|
| 213 | icon = 'actionicon_mask.png' |
---|
| 214 | text = _(u'Login as customer') |
---|
| 215 | target = 'loginasstep1' |
---|
| 216 | |
---|
[11985] | 217 | |
---|
[11967] | 218 | class CustomerDeactivateActionButton(ManageActionButton): |
---|
| 219 | grok.order(7) |
---|
| 220 | grok.context(ICustomer) |
---|
| 221 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 222 | grok.require('waeup.manageCustomer') |
---|
| 223 | text = _('Deactivate account') |
---|
| 224 | target = 'deactivate' |
---|
| 225 | icon = 'actionicon_traffic_lights_red.png' |
---|
| 226 | |
---|
| 227 | @property |
---|
| 228 | def target_url(self): |
---|
| 229 | if self.context.suspended: |
---|
| 230 | return '' |
---|
| 231 | return self.view.url(self.view.context, self.target) |
---|
| 232 | |
---|
| 233 | @property |
---|
| 234 | def onclick(self): |
---|
| 235 | return "return window.confirm(%s);" % _( |
---|
| 236 | "'A history message will be added. Are you sure?'") |
---|
| 237 | |
---|
[11985] | 238 | |
---|
[11967] | 239 | class CustomerActivateActionButton(ManageActionButton): |
---|
| 240 | grok.order(7) |
---|
| 241 | grok.context(ICustomer) |
---|
| 242 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 243 | grok.require('waeup.manageCustomer') |
---|
| 244 | text = _('Activate account') |
---|
| 245 | target = 'activate' |
---|
| 246 | icon = 'actionicon_traffic_lights_green.png' |
---|
| 247 | |
---|
| 248 | @property |
---|
| 249 | def target_url(self): |
---|
| 250 | if not self.context.suspended: |
---|
| 251 | return '' |
---|
| 252 | return self.view.url(self.view.context, self.target) |
---|
| 253 | |
---|
| 254 | @property |
---|
| 255 | def onclick(self): |
---|
| 256 | return "return window.confirm(%s);" % _( |
---|
[11977] | 257 | "'A history message will be added. Are you sure?'") |
---|
| 258 | |
---|
[11985] | 259 | |
---|
[11986] | 260 | class CustomerBaseActionButton(ManageActionButton): |
---|
| 261 | grok.order(1) |
---|
| 262 | grok.context(ICustomer) |
---|
| 263 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 264 | grok.require('waeup.handleCustomer') |
---|
| 265 | text = _('Edit') |
---|
| 266 | target = 'edit_base' |
---|
| 267 | |
---|
[12016] | 268 | |
---|
[11977] | 269 | class CustomerPasswordActionButton(ManageActionButton): |
---|
| 270 | grok.order(2) |
---|
| 271 | grok.context(ICustomer) |
---|
| 272 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 273 | grok.require('waeup.handleCustomer') |
---|
| 274 | icon = 'actionicon_key.png' |
---|
| 275 | text = _('Change password') |
---|
[11985] | 276 | target = 'changepassword' |
---|
[11986] | 277 | |
---|
[12016] | 278 | |
---|
[11986] | 279 | class CustomerPassportActionButton(ManageActionButton): |
---|
| 280 | grok.order(3) |
---|
| 281 | grok.context(ICustomer) |
---|
| 282 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 283 | grok.require('waeup.handleCustomer') |
---|
| 284 | icon = 'actionicon_portrait.png' |
---|
| 285 | text = _('Change portrait') |
---|
| 286 | target = 'change_portrait' |
---|
[12015] | 287 | |
---|
| 288 | |
---|
[12059] | 289 | # Viewlets for customer documents |
---|
[12015] | 290 | |
---|
| 291 | class AddDocumentActionButton(AddActionButton): |
---|
| 292 | grok.order(1) |
---|
| 293 | grok.context(ICustomerDocumentsContainer) |
---|
| 294 | grok.view(DocumentsManageFormPage) |
---|
| 295 | grok.require('waeup.editCustomerDocuments') |
---|
| 296 | text = _('Add document') |
---|
| 297 | target = 'adddoc' |
---|
[12016] | 298 | |
---|
| 299 | |
---|
[12062] | 300 | class PDFOverviewActionButton(ManageActionButton): |
---|
[12059] | 301 | grok.order(2) |
---|
| 302 | grok.context(ICustomerDocumentsContainer) |
---|
| 303 | grok.view(DocumentsManageFormPage) |
---|
| 304 | grok.require('waeup.viewCustomer') |
---|
| 305 | icon = 'actionicon_pdf.png' |
---|
| 306 | text = _('Download documents overview') |
---|
| 307 | target = 'overview_slip.pdf' |
---|
| 308 | |
---|
| 309 | |
---|
[12016] | 310 | class DocumentManageActionButton(ManageActionButton): |
---|
| 311 | grok.order(1) |
---|
| 312 | grok.context(ICustomerDocument) |
---|
| 313 | grok.view(DocumentDisplayFormPage) |
---|
| 314 | grok.require('waeup.manageCustomer') |
---|
| 315 | text = _('Manage') |
---|
| 316 | target = 'manage' |
---|
| 317 | |
---|
[12018] | 318 | |
---|
| 319 | class DocumentEditActionButton(ManageActionButton): |
---|
| 320 | grok.order(1) |
---|
| 321 | grok.context(ICustomerDocument) |
---|
| 322 | grok.view(DocumentDisplayFormPage) |
---|
| 323 | grok.require('waeup.handleCustomer') |
---|
| 324 | text = _('Edit') |
---|
| 325 | target = 'edit' |
---|
| 326 | |
---|
| 327 | @property |
---|
| 328 | def target_url(self): |
---|
| 329 | if not self.context.is_editable: |
---|
| 330 | return '' |
---|
| 331 | return self.view.url(self.view.context, self.target) |
---|
| 332 | |
---|
| 333 | |
---|
[12028] | 334 | class DocumentTrigTransActionButton(ManageActionButton): |
---|
| 335 | grok.order(2) |
---|
| 336 | grok.context(ICustomerDocument) |
---|
| 337 | grok.view(DocumentDisplayFormPage) |
---|
| 338 | grok.require('waeup.triggerTransition') |
---|
| 339 | icon = 'actionicon_trigtrans.png' |
---|
| 340 | text = _(u'Transition') |
---|
| 341 | target = 'trigtrans' |
---|
| 342 | |
---|
| 343 | |
---|
[12016] | 344 | class DocumentViewActionButton(ManageActionButton): |
---|
| 345 | grok.order(1) |
---|
| 346 | grok.context(ICustomerDocument) |
---|
| 347 | grok.view(DocumentManageFormPage) |
---|
[12018] | 348 | grok.require('waeup.handleCustomer') |
---|
[12016] | 349 | text = _('View') |
---|
| 350 | target = 'index' |
---|
| 351 | icon = 'actionicon_view.png' |
---|
[12062] | 352 | |
---|
| 353 | class PDFSlipActionButton(ManageActionButton): |
---|
| 354 | grok.order(3) |
---|
| 355 | grok.context(ICustomerDocument) |
---|
| 356 | grok.view(DocumentDisplayFormPage) |
---|
| 357 | grok.require('waeup.viewCustomer') |
---|
| 358 | icon = 'actionicon_pdf.png' |
---|
| 359 | text = _('Download document slip') |
---|
| 360 | target = 'document_slip.pdf' |
---|