[12015] | 1 | ## $Id: viewlets.py 12762 2015-03-14 13:49:29Z 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 |
---|
[12346] | 22 | from zope.component import getUtility |
---|
[11958] | 23 | from waeup.ikoba.interfaces import IIkobaObject |
---|
| 24 | from waeup.ikoba.interfaces import MessageFactory as _ |
---|
| 25 | from waeup.ikoba.browser.viewlets import ( |
---|
| 26 | PrimaryNavTab, ManageActionButton, AddActionButton) |
---|
[11987] | 27 | from waeup.ikoba.browser.layout import default_primary_nav_template |
---|
[11967] | 28 | from waeup.ikoba.customers.interfaces import ( |
---|
[12015] | 29 | ICustomer, ICustomersContainer, |
---|
[12090] | 30 | ICustomerDocumentsContainer, ICustomerDocument, |
---|
[12346] | 31 | IContractsContainer, IContract, ICustomersUtils) |
---|
[11967] | 32 | from waeup.ikoba.customers.browser import ( |
---|
| 33 | CustomersContainerPage, CustomersContainerManagePage, |
---|
[12015] | 34 | CustomerBaseDisplayFormPage, |
---|
[12090] | 35 | DocumentsManageFormPage, DocumentDisplayFormPage, DocumentManageFormPage, |
---|
[12337] | 36 | ContractsFormPage, ContractDisplayFormPage, |
---|
[12500] | 37 | ContractManageFormPage, |
---|
| 38 | ContractOfficialUsePage) |
---|
[11958] | 39 | |
---|
[11985] | 40 | grok.context(IIkobaObject) # Make IIkobaObject the default context |
---|
[11964] | 41 | grok.templatedir('browser_templates') |
---|
| 42 | |
---|
[11985] | 43 | |
---|
[11958] | 44 | class 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): |
---|
[11964] | 58 | return self.view.application_url('customers') |
---|
| 59 | |
---|
[11985] | 60 | |
---|
[11964] | 61 | class PrimaryCustomerNavManager(grok.ViewletManager): |
---|
| 62 | """Viewlet manager for the primary navigation tab. |
---|
| 63 | """ |
---|
| 64 | grok.name('primary_nav_customer') |
---|
| 65 | |
---|
[11985] | 66 | |
---|
[11964] | 67 | class 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 | |
---|
[11985] | 89 | |
---|
[11964] | 90 | class 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'}, |
---|
[12097] | 114 | {'url':customer_url + '/contracts', 'title':_('My Contracts')}, |
---|
[12090] | 115 | {'url':customer_url + '/documents', 'title':_('My Documents')}, |
---|
[11964] | 116 | {'url':customer_url + '/history', 'title':_('History')}, |
---|
| 117 | ] |
---|
[11967] | 118 | return targets |
---|
| 119 | |
---|
[11985] | 120 | |
---|
[11967] | 121 | class CustomerManageSidebar(grok.ViewletManager): |
---|
| 122 | grok.name('left_customermanage') |
---|
| 123 | |
---|
[11985] | 124 | |
---|
[11967] | 125 | class 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 |
---|
[11979] | 142 | lang = self.request.cookies.get('ikoba.language') |
---|
| 143 | text = translate(self.text, 'waeup.ikoba', |
---|
[11967] | 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 | |
---|
[11985] | 150 | |
---|
[11967] | 151 | class CustomerManageBaseLink(CustomerManageLink): |
---|
| 152 | grok.order(2) |
---|
| 153 | link = 'index' |
---|
| 154 | text = _(u'Base Data') |
---|
| 155 | |
---|
[12090] | 156 | |
---|
[12097] | 157 | class CustomerManageContractsLink(CustomerManageLink): |
---|
[12090] | 158 | grok.order(3) |
---|
[12097] | 159 | link = 'contracts' |
---|
| 160 | text = _(u'Contracts') |
---|
[12090] | 161 | |
---|
| 162 | |
---|
[12015] | 163 | class CustomerManageDocumentsLink(CustomerManageLink): |
---|
[12090] | 164 | grok.order(4) |
---|
[12015] | 165 | link = 'documents' |
---|
| 166 | text = _(u'Documents') |
---|
[11985] | 167 | |
---|
[12762] | 168 | |
---|
[12757] | 169 | class CustomerManagePaymentsLink(CustomerManageLink): |
---|
| 170 | grok.order(5) |
---|
| 171 | link = 'payments' |
---|
| 172 | text = _(u'Payments') |
---|
[12015] | 173 | |
---|
[12757] | 174 | |
---|
[11967] | 175 | class CustomerManageHistoryLink(CustomerManageLink): |
---|
| 176 | grok.order(8) |
---|
| 177 | link = 'history' |
---|
| 178 | text = _(u'History') |
---|
| 179 | |
---|
[11985] | 180 | |
---|
[11967] | 181 | class 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 | |
---|
[11985] | 188 | |
---|
[11967] | 189 | class 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 | |
---|
[11985] | 197 | |
---|
[11967] | 198 | class 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 | |
---|
[11985] | 207 | |
---|
[11967] | 208 | class 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 | |
---|
[11985] | 216 | |
---|
[11967] | 217 | class CustomerTrigTransActionButton(ManageActionButton): |
---|
| 218 | grok.order(2) |
---|
| 219 | grok.context(ICustomer) |
---|
| 220 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 221 | grok.require('waeup.triggerTransition') |
---|
| 222 | icon = 'actionicon_trigtrans.png' |
---|
[12028] | 223 | text = _(u'Transition') |
---|
[11967] | 224 | target = 'trigtrans' |
---|
| 225 | |
---|
[11985] | 226 | |
---|
[11967] | 227 | class 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 | |
---|
[11985] | 236 | |
---|
[11967] | 237 | class 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 | |
---|
[11985] | 257 | |
---|
[11967] | 258 | class 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);" % _( |
---|
[11977] | 276 | "'A history message will be added. Are you sure?'") |
---|
| 277 | |
---|
[11985] | 278 | |
---|
[11986] | 279 | class CustomerBaseActionButton(ManageActionButton): |
---|
| 280 | grok.order(1) |
---|
| 281 | grok.context(ICustomer) |
---|
| 282 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 283 | grok.require('waeup.handleCustomer') |
---|
| 284 | target = 'edit_base' |
---|
| 285 | |
---|
[12351] | 286 | @property |
---|
| 287 | def text(self): |
---|
| 288 | if self.view.is_requestable: |
---|
| 289 | return _('Edit and request registration') |
---|
| 290 | return _('Edit') |
---|
[12016] | 291 | |
---|
[12351] | 292 | |
---|
[11977] | 293 | class 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') |
---|
[11985] | 300 | target = 'changepassword' |
---|
[11986] | 301 | |
---|
[12016] | 302 | |
---|
[11986] | 303 | class CustomerPassportActionButton(ManageActionButton): |
---|
| 304 | grok.order(3) |
---|
| 305 | grok.context(ICustomer) |
---|
| 306 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 307 | grok.require('waeup.handleCustomer') |
---|
[12527] | 308 | icon = 'actionicon_up.png' |
---|
| 309 | text = _('Upload files') |
---|
| 310 | target = 'upload_files' |
---|
[12015] | 311 | |
---|
[12346] | 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) |
---|
[12015] | 319 | |
---|
[12346] | 320 | |
---|
[12059] | 321 | # Viewlets for customer documents |
---|
[12015] | 322 | |
---|
[12090] | 323 | class PDFDocumentOverviewActionButton(ManageActionButton): |
---|
[12059] | 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') |
---|
[12091] | 330 | target = 'documents_overview_slip.pdf' |
---|
[12059] | 331 | |
---|
| 332 | |
---|
[12016] | 333 | class 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 | |
---|
[12166] | 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) |
---|
[12018] | 346 | |
---|
[12166] | 347 | |
---|
[12018] | 348 | class 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): |
---|
[12166] | 358 | if not self.context.is_editable_by_customer: |
---|
[12018] | 359 | return '' |
---|
| 360 | return self.view.url(self.view.context, self.target) |
---|
| 361 | |
---|
| 362 | |
---|
[12028] | 363 | class 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 | |
---|
[12016] | 373 | class DocumentViewActionButton(ManageActionButton): |
---|
| 374 | grok.order(1) |
---|
| 375 | grok.context(ICustomerDocument) |
---|
| 376 | grok.view(DocumentManageFormPage) |
---|
[12018] | 377 | grok.require('waeup.handleCustomer') |
---|
[12016] | 378 | text = _('View') |
---|
| 379 | target = 'index' |
---|
| 380 | icon = 'actionicon_view.png' |
---|
[12062] | 381 | |
---|
[12090] | 382 | |
---|
| 383 | class PDFDocumentSlipActionButton(ManageActionButton): |
---|
[12062] | 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' |
---|
[12090] | 391 | |
---|
[12214] | 392 | |
---|
[12097] | 393 | # Viewlets for customer contracts |
---|
[12090] | 394 | |
---|
[12097] | 395 | class PDFContractOverviewActionButton(ManageActionButton): |
---|
[12090] | 396 | grok.order(2) |
---|
[12097] | 397 | grok.context(IContractsContainer) |
---|
[12337] | 398 | grok.view(ContractsFormPage) |
---|
[12090] | 399 | grok.require('waeup.viewCustomer') |
---|
| 400 | icon = 'actionicon_pdf.png' |
---|
[12097] | 401 | text = _('Download contracts overview') |
---|
| 402 | target = 'contracts_overview_slip.pdf' |
---|
[12090] | 403 | |
---|
| 404 | |
---|
[12097] | 405 | class ContractManageActionButton(ManageActionButton): |
---|
[12090] | 406 | grok.order(1) |
---|
[12097] | 407 | grok.context(IContract) |
---|
| 408 | grok.view(ContractDisplayFormPage) |
---|
[12090] | 409 | grok.require('waeup.manageCustomer') |
---|
| 410 | text = _('Manage') |
---|
| 411 | target = 'manage' |
---|
| 412 | |
---|
| 413 | |
---|
[12500] | 414 | class 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 | |
---|
[12097] | 423 | class ContractEditActionButton(ManageActionButton): |
---|
[12090] | 424 | grok.order(1) |
---|
[12097] | 425 | grok.context(IContract) |
---|
| 426 | grok.view(ContractDisplayFormPage) |
---|
[12090] | 427 | grok.require('waeup.handleCustomer') |
---|
| 428 | text = _('Edit') |
---|
| 429 | target = 'edit' |
---|
| 430 | |
---|
| 431 | @property |
---|
| 432 | def target_url(self): |
---|
[12337] | 433 | if not self.context.is_editable: |
---|
[12090] | 434 | return '' |
---|
| 435 | return self.view.url(self.view.context, self.target) |
---|
| 436 | |
---|
| 437 | |
---|
[12097] | 438 | class ContractTrigTransActionButton(ManageActionButton): |
---|
[12500] | 439 | grok.order(3) |
---|
[12097] | 440 | grok.context(IContract) |
---|
| 441 | grok.view(ContractDisplayFormPage) |
---|
[12090] | 442 | grok.require('waeup.triggerTransition') |
---|
| 443 | icon = 'actionicon_trigtrans.png' |
---|
| 444 | text = _(u'Transition') |
---|
| 445 | target = 'trigtrans' |
---|
| 446 | |
---|
| 447 | |
---|
[12097] | 448 | class ContractViewActionButton(ManageActionButton): |
---|
[12090] | 449 | grok.order(1) |
---|
[12097] | 450 | grok.context(IContract) |
---|
| 451 | grok.view(ContractManageFormPage) |
---|
[12090] | 452 | grok.require('waeup.handleCustomer') |
---|
| 453 | text = _('View') |
---|
| 454 | target = 'index' |
---|
| 455 | icon = 'actionicon_view.png' |
---|
| 456 | |
---|
| 457 | |
---|
[12500] | 458 | class ContractViewActionButton2(ContractViewActionButton): |
---|
| 459 | grok.view(ContractOfficialUsePage) |
---|
| 460 | |
---|
| 461 | |
---|
[12097] | 462 | class PDFContractSlipActionButton(ManageActionButton): |
---|
[12500] | 463 | grok.order(4) |
---|
[12097] | 464 | grok.context(IContract) |
---|
| 465 | grok.view(ContractDisplayFormPage) |
---|
[12090] | 466 | grok.require('waeup.viewCustomer') |
---|
| 467 | icon = 'actionicon_pdf.png' |
---|
[12097] | 468 | text = _('Download contract slip') |
---|
| 469 | target = 'contract_slip.pdf' |
---|
[12090] | 470 | |
---|