## $Id: viewlets.py 11772 2014-07-31 04:38:23Z henrik $ ## ## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## import grok from zope.i18n import translate from zope.interface import Interface from waeup.ikoba.interfaces import IIkobaObject from waeup.ikoba.interfaces import MessageFactory as _ from waeup.ikoba.browser.viewlets import ( PrimaryNavTab, ManageActionButton, AddActionButton) from waeup.ikoba.browser.layout import default_primary_nav_template from waeup.ikoba.customers.interfaces import ( ICustomer, ICustomersContainer) from waeup.ikoba.customers.browser import ( CustomersContainerPage, CustomersContainerManagePage, CustomerBaseDisplayFormPage) grok.context(IIkobaObject) # Make IIkobaObject the default context grok.templatedir('browser_templates') class CustomersTab(PrimaryNavTab): """Customers tab in primary navigation. """ grok.context(IIkobaObject) grok.order(4) grok.require('waeup.viewCustomersTab') grok.name('customerstab') pnav = 4 tab_title = _(u'Customers') @property def link_target(self): return self.view.application_url('customers') class PrimaryCustomerNavManager(grok.ViewletManager): """Viewlet manager for the primary navigation tab. """ grok.name('primary_nav_customer') class PrimaryCustomerNavTab(grok.Viewlet): """Base for primary customer nav tabs. """ grok.baseclass() grok.viewletmanager(PrimaryCustomerNavManager) template = default_primary_nav_template grok.order(1) grok.require('waeup.Authenticated') pnav = 0 tab_title = u'Some Text' @property def link_target(self): return self.view.application_url() @property def active(self): view_pnav = getattr(self.view, 'pnav', 0) if view_pnav == self.pnav: return 'active' return '' class MyCustomerDataTab(PrimaryCustomerNavTab): """MyData dropdown tab in primary navigation. """ grok.order(3) grok.require('waeup.viewMyCustomerDataTab') grok.template('mydatadropdowntabs') grok.name('mycustomerdatatab') pnav = 4 tab_title = _(u'My Data') @property def active(self): view_pnav = getattr(self.view, 'pnav', 0) if view_pnav == self.pnav: return 'active dropdown' return 'dropdown' @property def targets(self): customer = grok.getSite()['customers'][self.request.principal.id] customer_url = self.view.url(customer) targets = [] targets += [ {'url':customer_url, 'title':'Base Data'}, {'url':customer_url + '/history', 'title':_('History')}, ] return targets class CustomerManageSidebar(grok.ViewletManager): grok.name('left_customermanage') class CustomerManageLink(grok.Viewlet): """A link displayed in the customer box which shows up for CustomerNavigation objects. """ grok.baseclass() grok.viewletmanager(CustomerManageSidebar) grok.view(Interface) grok.order(5) grok.require('waeup.viewCustomer') link = 'index' text = _(u'Base Data') def render(self): url = self.view.url(self.context.customer, self.link) # Here we know that the cookie has been set lang = self.request.cookies.get('ikoba.language') text = translate(self.text, 'waeup.ikoba', target_language=lang) if not self.link: return '' return u'