[12015] | 1 | ## $Id: viewlets.py 12097 2014-11-30 20:49:22Z 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, |
---|
[12090] | 29 | ICustomerDocumentsContainer, ICustomerDocument, |
---|
[12097] | 30 | IContractsContainer, IContract) |
---|
[11967] | 31 | from waeup.ikoba.customers.browser import ( |
---|
| 32 | CustomersContainerPage, CustomersContainerManagePage, |
---|
[12015] | 33 | CustomerBaseDisplayFormPage, |
---|
[12090] | 34 | DocumentsManageFormPage, DocumentDisplayFormPage, DocumentManageFormPage, |
---|
[12097] | 35 | ContractsManageFormPage, ContractDisplayFormPage, |
---|
| 36 | ContractManageFormPage) |
---|
[11958] | 37 | |
---|
[11985] | 38 | grok.context(IIkobaObject) # Make IIkobaObject the default context |
---|
[11964] | 39 | grok.templatedir('browser_templates') |
---|
| 40 | |
---|
[11985] | 41 | |
---|
[11958] | 42 | class 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): |
---|
[11964] | 56 | return self.view.application_url('customers') |
---|
| 57 | |
---|
[11985] | 58 | |
---|
[11964] | 59 | class PrimaryCustomerNavManager(grok.ViewletManager): |
---|
| 60 | """Viewlet manager for the primary navigation tab. |
---|
| 61 | """ |
---|
| 62 | grok.name('primary_nav_customer') |
---|
| 63 | |
---|
[11985] | 64 | |
---|
[11964] | 65 | class 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 | |
---|
[11985] | 87 | |
---|
[11964] | 88 | class 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'}, |
---|
[12097] | 112 | {'url':customer_url + '/contracts', 'title':_('My Contracts')}, |
---|
[12090] | 113 | {'url':customer_url + '/documents', 'title':_('My Documents')}, |
---|
[11964] | 114 | {'url':customer_url + '/history', 'title':_('History')}, |
---|
| 115 | ] |
---|
[11967] | 116 | return targets |
---|
| 117 | |
---|
[11985] | 118 | |
---|
[11967] | 119 | class CustomerManageSidebar(grok.ViewletManager): |
---|
| 120 | grok.name('left_customermanage') |
---|
| 121 | |
---|
[11985] | 122 | |
---|
[11967] | 123 | class 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 |
---|
[11979] | 140 | lang = self.request.cookies.get('ikoba.language') |
---|
| 141 | text = translate(self.text, 'waeup.ikoba', |
---|
[11967] | 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 | |
---|
[11985] | 148 | |
---|
[11967] | 149 | class CustomerManageBaseLink(CustomerManageLink): |
---|
| 150 | grok.order(2) |
---|
| 151 | link = 'index' |
---|
| 152 | text = _(u'Base Data') |
---|
| 153 | |
---|
[12090] | 154 | |
---|
[12097] | 155 | class CustomerManageContractsLink(CustomerManageLink): |
---|
[12090] | 156 | grok.order(3) |
---|
[12097] | 157 | link = 'contracts' |
---|
| 158 | text = _(u'Contracts') |
---|
[12090] | 159 | |
---|
| 160 | |
---|
[12015] | 161 | class CustomerManageDocumentsLink(CustomerManageLink): |
---|
[12090] | 162 | grok.order(4) |
---|
[12015] | 163 | link = 'documents' |
---|
| 164 | text = _(u'Documents') |
---|
[11985] | 165 | |
---|
[12015] | 166 | |
---|
[11967] | 167 | class CustomerManageHistoryLink(CustomerManageLink): |
---|
| 168 | grok.order(8) |
---|
| 169 | link = 'history' |
---|
| 170 | text = _(u'History') |
---|
| 171 | |
---|
[11985] | 172 | |
---|
[11967] | 173 | class 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 | |
---|
[11985] | 180 | |
---|
[11967] | 181 | class 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 | |
---|
[11985] | 189 | |
---|
[11967] | 190 | class 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 | |
---|
[11985] | 199 | |
---|
[11967] | 200 | class 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 | |
---|
[11985] | 208 | |
---|
[11967] | 209 | class CustomerTrigTransActionButton(ManageActionButton): |
---|
| 210 | grok.order(2) |
---|
| 211 | grok.context(ICustomer) |
---|
| 212 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 213 | grok.require('waeup.triggerTransition') |
---|
| 214 | icon = 'actionicon_trigtrans.png' |
---|
[12028] | 215 | text = _(u'Transition') |
---|
[11967] | 216 | target = 'trigtrans' |
---|
| 217 | |
---|
[11985] | 218 | |
---|
[11967] | 219 | class 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 | |
---|
[11985] | 228 | |
---|
[11967] | 229 | class 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 | |
---|
[11985] | 249 | |
---|
[11967] | 250 | class 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);" % _( |
---|
[11977] | 268 | "'A history message will be added. Are you sure?'") |
---|
| 269 | |
---|
[11985] | 270 | |
---|
[11986] | 271 | class 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 | |
---|
[12016] | 279 | |
---|
[11977] | 280 | class 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') |
---|
[11985] | 287 | target = 'changepassword' |
---|
[11986] | 288 | |
---|
[12016] | 289 | |
---|
[11986] | 290 | class 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' |
---|
[12015] | 298 | |
---|
| 299 | |
---|
[12059] | 300 | # Viewlets for customer documents |
---|
[12015] | 301 | |
---|
| 302 | class 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' |
---|
[12016] | 309 | |
---|
| 310 | |
---|
[12090] | 311 | class PDFDocumentOverviewActionButton(ManageActionButton): |
---|
[12059] | 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') |
---|
[12091] | 318 | target = 'documents_overview_slip.pdf' |
---|
[12059] | 319 | |
---|
| 320 | |
---|
[12016] | 321 | class 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 | |
---|
[12018] | 329 | |
---|
| 330 | class DocumentEditActionButton(ManageActionButton): |
---|
| 331 | grok.order(1) |
---|
| 332 | grok.context(ICustomerDocument) |
---|
| 333 | grok.view(DocumentDisplayFormPage) |
---|
| 334 | grok.require('waeup.handleCustomer') |
---|
| 335 | text = _('Edit') |
---|
| 336 | target = 'edit' |
---|
| 337 | |
---|
| 338 | @property |
---|
| 339 | def target_url(self): |
---|
| 340 | if not self.context.is_editable: |
---|
| 341 | return '' |
---|
| 342 | return self.view.url(self.view.context, self.target) |
---|
| 343 | |
---|
| 344 | |
---|
[12028] | 345 | class DocumentTrigTransActionButton(ManageActionButton): |
---|
| 346 | grok.order(2) |
---|
| 347 | grok.context(ICustomerDocument) |
---|
| 348 | grok.view(DocumentDisplayFormPage) |
---|
| 349 | grok.require('waeup.triggerTransition') |
---|
| 350 | icon = 'actionicon_trigtrans.png' |
---|
| 351 | text = _(u'Transition') |
---|
| 352 | target = 'trigtrans' |
---|
| 353 | |
---|
| 354 | |
---|
[12016] | 355 | class DocumentViewActionButton(ManageActionButton): |
---|
| 356 | grok.order(1) |
---|
| 357 | grok.context(ICustomerDocument) |
---|
| 358 | grok.view(DocumentManageFormPage) |
---|
[12018] | 359 | grok.require('waeup.handleCustomer') |
---|
[12016] | 360 | text = _('View') |
---|
| 361 | target = 'index' |
---|
| 362 | icon = 'actionicon_view.png' |
---|
[12062] | 363 | |
---|
[12090] | 364 | |
---|
| 365 | class PDFDocumentSlipActionButton(ManageActionButton): |
---|
[12062] | 366 | grok.order(3) |
---|
| 367 | grok.context(ICustomerDocument) |
---|
| 368 | grok.view(DocumentDisplayFormPage) |
---|
| 369 | grok.require('waeup.viewCustomer') |
---|
| 370 | icon = 'actionicon_pdf.png' |
---|
| 371 | text = _('Download document slip') |
---|
| 372 | target = 'document_slip.pdf' |
---|
[12090] | 373 | |
---|
[12097] | 374 | # Viewlets for customer contracts |
---|
[12090] | 375 | |
---|
[12097] | 376 | class AddContractActionButton(AddActionButton): |
---|
[12090] | 377 | grok.order(1) |
---|
[12097] | 378 | grok.context(IContractsContainer) |
---|
| 379 | grok.view(ContractsManageFormPage) |
---|
| 380 | grok.require('waeup.editContracts') |
---|
| 381 | text = _('Add contract') |
---|
[12090] | 382 | target = 'addapp' |
---|
| 383 | |
---|
| 384 | |
---|
[12097] | 385 | class PDFContractOverviewActionButton(ManageActionButton): |
---|
[12090] | 386 | grok.order(2) |
---|
[12097] | 387 | grok.context(IContractsContainer) |
---|
| 388 | grok.view(ContractsManageFormPage) |
---|
[12090] | 389 | grok.require('waeup.viewCustomer') |
---|
| 390 | icon = 'actionicon_pdf.png' |
---|
[12097] | 391 | text = _('Download contracts overview') |
---|
| 392 | target = 'contracts_overview_slip.pdf' |
---|
[12090] | 393 | |
---|
| 394 | |
---|
[12097] | 395 | class ContractManageActionButton(ManageActionButton): |
---|
[12090] | 396 | grok.order(1) |
---|
[12097] | 397 | grok.context(IContract) |
---|
| 398 | grok.view(ContractDisplayFormPage) |
---|
[12090] | 399 | grok.require('waeup.manageCustomer') |
---|
| 400 | text = _('Manage') |
---|
| 401 | target = 'manage' |
---|
| 402 | |
---|
| 403 | |
---|
[12097] | 404 | class ContractEditActionButton(ManageActionButton): |
---|
[12090] | 405 | grok.order(1) |
---|
[12097] | 406 | grok.context(IContract) |
---|
| 407 | grok.view(ContractDisplayFormPage) |
---|
[12090] | 408 | grok.require('waeup.handleCustomer') |
---|
| 409 | text = _('Edit') |
---|
| 410 | target = 'edit' |
---|
| 411 | |
---|
| 412 | @property |
---|
| 413 | def target_url(self): |
---|
| 414 | if not self.context.is_editable: |
---|
| 415 | return '' |
---|
| 416 | return self.view.url(self.view.context, self.target) |
---|
| 417 | |
---|
| 418 | |
---|
[12097] | 419 | class ContractTrigTransActionButton(ManageActionButton): |
---|
[12090] | 420 | grok.order(2) |
---|
[12097] | 421 | grok.context(IContract) |
---|
| 422 | grok.view(ContractDisplayFormPage) |
---|
[12090] | 423 | grok.require('waeup.triggerTransition') |
---|
| 424 | icon = 'actionicon_trigtrans.png' |
---|
| 425 | text = _(u'Transition') |
---|
| 426 | target = 'trigtrans' |
---|
| 427 | |
---|
| 428 | |
---|
[12097] | 429 | class ContractViewActionButton(ManageActionButton): |
---|
[12090] | 430 | grok.order(1) |
---|
[12097] | 431 | grok.context(IContract) |
---|
| 432 | grok.view(ContractManageFormPage) |
---|
[12090] | 433 | grok.require('waeup.handleCustomer') |
---|
| 434 | text = _('View') |
---|
| 435 | target = 'index' |
---|
| 436 | icon = 'actionicon_view.png' |
---|
| 437 | |
---|
| 438 | |
---|
[12097] | 439 | class PDFContractSlipActionButton(ManageActionButton): |
---|
[12090] | 440 | grok.order(3) |
---|
[12097] | 441 | grok.context(IContract) |
---|
| 442 | grok.view(ContractDisplayFormPage) |
---|
[12090] | 443 | grok.require('waeup.viewCustomer') |
---|
| 444 | icon = 'actionicon_pdf.png' |
---|
[12097] | 445 | text = _('Download contract slip') |
---|
| 446 | target = 'contract_slip.pdf' |
---|
[12090] | 447 | |
---|