Changeset 12067 for main


Ignore:
Timestamp:
27 Nov 2014, 07:11:36 (10 years ago)
Author:
Henrik Bettermann
Message:

Upgrade manage form pages.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba/products
Files:
4 added
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/products/browser.py

    r12065 r12067  
    4141    FriendlyDatetimeDisplayWidget)
    4242from waeup.ikoba.browser.breadcrumbs import Breadcrumb
     43from waeup.ikoba.browser.pages import (
     44    delSubobjects, add_local_role, del_local_roles, msave,
     45    LocalRoleAssignmentUtilityView)
    4346
    4447from waeup.ikoba.products.interfaces import (
     
    7174    grok.name('index')
    7275    grok.require('waeup.Public')
    73     #grok.template('containerpage')
     76    grok.template('containerpage')
    7477    pnav = 1
    7578    label = _('Products')
    7679
    7780
    78 class ProductsContainerManageFormPage(IkobaEditFormPage):
     81class ProductsContainerManageFormPage(IkobaEditFormPage,
     82                                      LocalRoleAssignmentUtilityView):
    7983    """The manage page for customer containers.
    8084    """
     
    8286    grok.name('manage')
    8387    grok.require('waeup.manageProducts')
    84     #grok.template('containermanagepage')
     88    grok.template('containermanagepage')
    8589    pnav = 1
    8690    label = _('Manage product section')
     91
     92    taboneactions = [_('Save'),_('Cancel')]
     93    tabtwoactions = [_('Add product'), _('Remove selected'),_('Cancel')]
     94    tabthreeactions1 = [_('Remove selected local roles')]
     95    tabthreeactions2 = [_('Add local role')]
     96
     97    @jsaction(_('Remove selected'))
     98    def delDepartments(self, **data):
     99        if not checkPermission('waeup.managePortal', self.context):
     100            self.flash(_('You are not allowed to remove products.'),
     101                       type='danger')
     102            return
     103        delSubobjects(self, redirect='@@manage', tab='2')
     104        return
     105
     106    @action(_('Save'), style='primary')
     107    def save(self, **data):
     108        return msave(self, **data)
     109
     110    @action(_('Cancel'), validator=NullValidator)
     111    def cancel(self, **data):
     112        self.redirect(self.url(self.context))
     113        return
     114
     115    @action(_('Add product'), validator=NullValidator)
     116    def addSubunit(self, **data):
     117        self.redirect(self.url(self.context, '@@addproduct'))
     118        return
     119
     120    @action(_('Add local role'), validator=NullValidator)
     121    def addLocalRole(self, **data):
     122        return add_local_role(self,3,**data)
     123
     124    @action(_('Remove selected local roles'))
     125    def delLocalRoles(self, **data):
     126        return del_local_roles(self,3,**data)
    87127
    88128
     
    101141        product = createObject(u'waeup.Product')
    102142        self.applyData(product, **data)
    103         self.context.addProduct(product)
    104         self.flash(_('Product created.'))
    105         self.redirect(self.url(self.context[product.product_id], 'index'))
     143        try:
     144            self.context.addProduct(product)
     145        except KeyError:
     146            self.flash(_('The Id chosen already exists.'),
     147                       type='danger')
     148            return
     149        self.flash(
     150            _("Product ${a} added.", mapping = {'a':data['product_id']}))
     151        ob_class = self.__implemented__.__name__.replace('waeup.ikoba.','')
     152        self.context.__parent__.logger.info(
     153            '%s - added: %s' % (ob_class, data['product_id']))
     154        self.redirect(self.url(self.context, u'@@manage')+'#tab2')
    106155        return
    107156
     
    122171
    123172
    124 class ProductManageFormPage(IkobaEditFormPage):
     173class ProductManageFormPage(IkobaEditFormPage,
     174                            LocalRoleAssignmentUtilityView):
    125175    """ View to manage product data
    126176    """
     
    128178    grok.name('manage')
    129179    grok.require('waeup.manageProducts')
    130     form_fields = grok.AutoFields(IProduct)
    131     #grok.template('basemanagepage')
    132     label = _('Manage product')
    133     pnav = 1
     180    form_fields = grok.AutoFields(IProduct).omit('product_id')
     181    grok.template('productmanagepage')
     182    pnav = 1
     183
     184    taboneactions = [_('Save'),_('Cancel')]
     185    tabtwoactions1 = [_('Remove selected local roles')]
     186    tabtwoactions2 = [_('Add local role')]
     187
     188    def label(self):
     189        return _('Manage product ') + self.context.product_id
     190
     191    @action(_('Save'), style='primary')
     192    def save(self, **data):
     193        return msave(self, **data)
     194
     195    @action(_('Cancel'), validator=NullValidator)
     196    def cancel(self, **data):
     197        self.redirect(self.url(self.context))
     198        return
     199
     200    @action(_('Add local role'), validator=NullValidator)
     201    def addLocalRole(self, **data):
     202        return add_local_role(self,2,**data)
     203
     204    @action(_('Remove selected local roles'))
     205    def delLocalRoles(self, **data):
     206        return del_local_roles(self,2,**data)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/products/viewlets.py

    r12065 r12067  
    6262
    6363
    64 class AddProductActionButton(AddActionButton):
    65     grok.order(1)
    66     grok.context(IProductsContainer)
    67     grok.view(ProductsContainerManageFormPage)
    68     grok.require('waeup.manageProducts')
    69     text = _('Add product')
    70     target = 'addproduct'
    71 
    72 
    7364class ProductViewActionButton(ManageActionButton):
    7465    grok.order(1)
Note: See TracChangeset for help on using the changeset viewer.