Ignore:
Timestamp:
13 Dec 2014, 15:46:41 (10 years ago)
Author:
Henrik Bettermann
Message:

Adjust UI components in documents and customers package.

File:
1 edited

Legend:

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

    r12213 r12214  
    4646
    4747from waeup.ikoba.documents.interfaces import (
    48     IDocumentsContainer, IDocument)
     48    IDocumentsContainer, IPublicDocument, IDocumentsUtils)
    4949
    5050grok.context(IIkobaObject) # Make IKofaObject the default context
     
    6262    """A breadcrumb for the customer container.
    6363    """
    64     grok.context(IDocument)
     64    grok.context(IPublicDocument)
    6565
    6666    def title(self):
     
    9090    label = _('Manage document section')
    9191
    92     taboneactions = [_('Save'),_('Cancel')]
    93     tabtwoactions = [_('Add document'), _('Remove selected'),_('Cancel')]
     92    @action(_('Add document'), validator=NullValidator, style='primary')
     93    def addSubunit(self, **data):
     94        self.redirect(self.url(self.context, 'adddoc'))
     95        return
    9496
    95     @jsaction(_('Remove selected'))
     97    @jsaction(_('Remove selected documents'))
    9698    def delDocuments(self, **data):
    9799        delSubobjects(self, redirect='manage', tab='2')
    98100        return
    99101
    100     @action(_('Save'), style='primary')
    101     def save(self, **data):
    102         return msave(self, **data)
    103 
    104102    @action(_('Cancel'), validator=NullValidator)
    105103    def cancel(self, **data):
    106104        self.redirect(self.url(self.context))
    107         return
    108 
    109     @action(_('Add document'), validator=NullValidator)
    110     def addSubunit(self, **data):
    111         self.redirect(self.url(self.context, 'adddocument'))
    112105        return
    113106
     
    118111    grok.context(IDocumentsContainer)
    119112    grok.require('waeup.manageDocuments')
    120     grok.name('adddocument')
    121     form_fields = grok.AutoFields(IDocument).omit('document_id')
     113    grok.name('adddoc')
     114    grok.template('documentaddform')
    122115    label = _('Add document')
    123116    pnav = 2
    124117
     118    @property
     119    def selectable_doctypes(self):
     120        doctypes = getUtility(IDocumentsUtils).SELECTABLE_DOCTYPES_DICT
     121        return sorted(doctypes.items())
     122
    125123    @action(_('Create document'), style='primary')
    126     def addDocument(self, **data):
    127         document = createObject(u'waeup.PublicDocument')
     124    def createDocument(self, **data):
     125        form = self.request.form
     126        doctype = form.get('doctype', None)
     127        # Here we can create various instances of PublicDocument derived
     128        # classes depending on the doctype parameter given in form.
     129        document = createObject('waeup.%s' % doctype)
    128130        self.applyData(document, **data)
    129         try:
    130             self.context.addDocument(document)
    131         except KeyError:
    132             self.flash(_('The Id chosen already exists.'),
    133                        type='danger')
    134             return
    135         self.flash(
    136             _("Document ${a} added.", mapping = {'a':document.document_id}))
     131        self.context.addDocument(document)
     132        doctype = getUtility(IDocumentsUtils).SELECTABLE_DOCTYPES_DICT[doctype]
     133        self.flash(_('${a} added.', mapping = {'a': doctype}))
    137134        ob_class = self.__implemented__.__name__.replace('waeup.ikoba.','')
    138135        self.context.__parent__.logger.info(
    139             '%s - added: %s' % (ob_class, document.document_id))
    140         self.redirect(self.url(self.context, u'manage')+'#tab2')
     136            '%s - added: %s %s' % (ob_class, doctype, document.document_id))
     137        self.redirect(self.url(self.context))
    141138        return
     139
     140    @action(_('Cancel'), validator=NullValidator)
     141    def cancel(self, **data):
     142        self.redirect(self.url(self.context))
    142143
    143144
     
    145146    """ Page to display document data
    146147    """
    147     grok.context(IDocument)
     148    grok.context(IPublicDocument)
    148149    grok.name('index')
    149150    grok.require('waeup.viewDocuments')
    150151    #grok.template('basepage')
    151     form_fields = grok.AutoFields(IDocument)
    152152    pnav = 2
     153
     154    @property
     155    def form_fields(self):
     156        return grok.AutoFields(self.context.form_fields_interface)
    153157
    154158    @property
     
    161165    """ View to manage document data
    162166    """
    163     grok.context(IDocument)
     167    grok.context(IPublicDocument)
    164168    grok.name('manage')
    165169    grok.require('waeup.manageDocuments')
    166     form_fields = grok.AutoFields(IDocument).omit('document_id')
    167170    grok.template('documentmanagepage')
    168171    pnav = 2
     
    171174    tabtwoactions1 = [_('Remove selected local roles')]
    172175    tabtwoactions2 = [_('Add local role')]
     176
     177    @property
     178    def form_fields(self):
     179        return grok.AutoFields(self.context.form_fields_interface)
    173180
    174181    def label(self):
Note: See TracChangeset for help on using the changeset viewer.