web/views/editforms.py
changeset 2675 f84ba1a66abb
parent 2672 c66f52d44394
parent 2661 f8df42c9da6b
child 2678 0308dc159b96
equal deleted inserted replaced
2674:ff6114c2c416 2675:f84ba1a66abb
    60         done = set()
    60         done = set()
    61         for entity in self.rset.entities():
    61         for entity in self.rset.entities():
    62             if entity.eid in done:
    62             if entity.eid in done:
    63                 continue
    63                 continue
    64             done.add(entity.eid)
    64             done.add(entity.eid)
    65             subform = self.vreg.select('forms', 'base', self.req, entity=entity,
    65             subform = self.vreg['forms'].select('base', self.req, entity=entity,
    66                                        mainform=False)
    66                                                 mainform=False)
    67             self.form_add_subform(subform)
    67             self.form_add_subform(subform)
    68 
    68 
    69 
    69 
    70 class DeleteConfFormView(FormViewMixIn, EntityView):
    70 class DeleteConfFormView(FormViewMixIn, EntityView):
    71     """form used to confirm deletion of some entities"""
    71     """form used to confirm deletion of some entities"""
    81         _ = req._
    81         _ = req._
    82         w(u'<script type="text/javascript">updateMessage(\'%s\');</script>\n'
    82         w(u'<script type="text/javascript">updateMessage(\'%s\');</script>\n'
    83           % _('this action is not reversible!'))
    83           % _('this action is not reversible!'))
    84         # XXX above message should have style of a warning
    84         # XXX above message should have style of a warning
    85         w(u'<h4>%s</h4>\n' % _('Do you want to delete the following element(s) ?'))
    85         w(u'<h4>%s</h4>\n' % _('Do you want to delete the following element(s) ?'))
    86         form = self.vreg.select('forms', self.id, req, rset=self.rset,
    86         form = self.vreg['forms'].select(self.id, req, rset=self.rset,
    87                                 onsubmit=onsubmit)
    87                                          onsubmit=onsubmit)
    88         w(u'<ul>\n')
    88         w(u'<ul>\n')
    89         for entity in self.rset.entities():
    89         for entity in self.rset.entities():
    90             # don't use outofcontext view or any other that may contain inline edition form
    90             # don't use outofcontext view or any other that may contain inline edition form
    91             w(u'<li>%s</li>' % tags.a(entity.view('textoutofcontext'),
    91             w(u'<li>%s</li>' % tags.a(entity.view('textoutofcontext'),
    92                                       href=entity.absolute_url()))
    92                                       href=entity.absolute_url()))
   125 
   125 
   126     def _build_landing_zone(self, lzone):
   126     def _build_landing_zone(self, lzone):
   127         return lzone or self._defaultlandingzone % {'msg' : xml_escape(self.req._(self._landingzonemsg))}
   127         return lzone or self._defaultlandingzone % {'msg' : xml_escape(self.req._(self._landingzonemsg))}
   128 
   128 
   129     def _build_renderer(self, entity, rtype, role):
   129     def _build_renderer(self, entity, rtype, role):
   130         return self.vreg.select_object('formrenderers', 'base', self.req,
   130         return self.vreg['formrenderers'].select(
   131                                        entity=entity,
   131             'base', self.req, entity=entity, display_label=False,
   132                                        display_label=False, display_help=False,
   132             display_help=False, display_fields=[(rtype, role)], table_class='',
   133                                        display_fields=[(rtype, role)],
   133             button_bar_class='buttonbar', display_progress_div=False)
   134                                        table_class='', button_bar_class='buttonbar',
       
   135                                        display_progress_div=False)
       
   136 
   134 
   137     def cell_call(self, row, col, rtype=None, role='subject',
   135     def cell_call(self, row, col, rtype=None, role='subject',
   138                   reload=False,      # controls reloading the whole page after change
   136                   reload=False,      # controls reloading the whole page after change
   139                   rvid=None,         # vid to be applied to other side of rtype
   137                   rvid=None,         # vid to be applied to other side of rtype
   140                   default=None,      # default value
   138                   default=None,      # default value
   205         onsubmit = ("return inlineValidateRelationForm('%(rtype)s', '%(role)s', '%(eid)s', "
   203         onsubmit = ("return inlineValidateRelationForm('%(rtype)s', '%(role)s', '%(eid)s', "
   206                     "'%(divid)s', %(reload)s, '%(vid)s', '%(default)s', '%(lzone)s');"
   204                     "'%(divid)s', %(reload)s, '%(vid)s', '%(default)s', '%(lzone)s');"
   207                     % event_data)
   205                     % event_data)
   208         cancelclick = "hideInlineEdit(%s,\'%s\',\'%s\')" % (
   206         cancelclick = "hideInlineEdit(%s,\'%s\',\'%s\')" % (
   209             entity.eid, rtype, divid)
   207             entity.eid, rtype, divid)
   210         form = self.vreg.select('forms', 'base', self.req, entity=entity,
   208         form = self.vreg['forms'].select('base', self.req, entity=entity,
   211                                 domid='%s-form' % divid, cssstyle='display: none',
   209                                          domid='%s-form' % divid, cssstyle='display: none',
   212                                 onsubmit=onsubmit, action='#',
   210                                          onsubmit=onsubmit, action='#',
   213                                 form_buttons=[SubmitButton(),
   211                                          form_buttons=[SubmitButton(),
   214                                               Button(stdmsgs.BUTTON_CANCEL,
   212                                                        Button(stdmsgs.BUTTON_CANCEL,
   215                                                      onclick=cancelclick)])
   213                                                               onclick=cancelclick)])
   216         field = guess_field(entity.e_schema, entity.schema.rschema(rtype), role)
   214         field = guess_field(entity.e_schema, entity.schema.rschema(rtype), role)
   217         form.append_field(field)
   215         form.append_field(field)
   218         w = self.w
   216         w = self.w
   219         w(u'<div id="%s-reledit" class="field">' % divid)
   217         w(u'<div id="%s-reledit" class="field">' % divid)
   220         w(tags.div(lzone, klass='editableField', id=divid,
   218         w(tags.div(lzone, klass='editableField', id=divid,
   241                     "%(reload)s, '%(default)s');")
   239                     "%(reload)s, '%(default)s');")
   242         buttons = [SubmitButton(stdmsgs.BUTTON_OK),
   240         buttons = [SubmitButton(stdmsgs.BUTTON_OK),
   243                    Button(stdmsgs.BUTTON_CANCEL,
   241                    Button(stdmsgs.BUTTON_CANCEL,
   244                           onclick="hideInlineEdit(%s,\'%s\',\'%s\')" % (
   242                           onclick="hideInlineEdit(%s,\'%s\',\'%s\')" % (
   245                               eid, rtype, divid))]
   243                               eid, rtype, divid))]
   246         form = self.vreg.select('forms', 'edition', self.req, rset=self.rset,
   244         form = self.vreg['forms'].select('edition', self.req, rset=self.rset,
   247                                 row=row, col=col, form_buttons=buttons,
   245                                          row=row, col=col, form_buttons=buttons,
   248                                 attrcategories=self.attrcategories,
   246                                          attrcategories=self.attrcategories,
   249                                 domid='%s-form' % divid, action='#',
   247                                          domid='%s-form' % divid, action='#',
   250                                 cssstyle='display: none',
   248                                          cssstyle='display: none',
   251                                 onsubmit=onsubmit % event_data)
   249                                          onsubmit=onsubmit % event_data)
   252         try:
   250         try:
   253             field = form.field_by_name(rtype, role)
   251             field = form.field_by_name(rtype, role)
   254         except FieldNotFound:
   252         except FieldNotFound:
   255             self.w(value)
   253             self.w(value)
   256             return
   254             return
   281         self.render_form(entity)
   279         self.render_form(entity)
   282 
   280 
   283     def render_form(self, entity):
   281     def render_form(self, entity):
   284         """fetch and render the form"""
   282         """fetch and render the form"""
   285         self.form_title(entity)
   283         self.form_title(entity)
   286         form = self.vreg.select('forms', 'edition', self.req, rset=entity.rset,
   284         form = self.vreg['forms'].select('edition', self.req, rset=entity.rset,
   287                                 row=entity.row, col=entity.col, entity=entity,
   285                                          row=entity.row, col=entity.col, entity=entity,
   288                                 submitmsg=self.submited_message())
   286                                          submitmsg=self.submited_message())
   289         self.init_form(form, entity)
   287         self.init_form(form, entity)
   290         self.w(form.form_render(formvid=u'edition'))
   288         self.w(form.form_render(formvid=u'edition'))
   291 
   289 
   292     def init_form(self, form, entity):
   290     def init_form(self, form, entity):
   293         """customize your form before rendering here"""
   291         """customize your form before rendering here"""
   313 
   311 
   314     def call(self, **kwargs):
   312     def call(self, **kwargs):
   315         """creation view for an entity"""
   313         """creation view for an entity"""
   316         etype = kwargs.pop('etype', self.req.form.get('etype'))
   314         etype = kwargs.pop('etype', self.req.form.get('etype'))
   317         try:
   315         try:
   318             entity = self.vreg.etype_class(etype)(self.req)
   316             entity = self.vreg['etypes'].etype_class(etype)(self.req)
   319         except:
   317         except:
   320             self.w(self.req._('no such entity type %s') % etype)
   318             self.w(self.req._('no such entity type %s') % etype)
   321         else:
   319         else:
   322             self.initialize_varmaker()
   320             self.initialize_varmaker()
   323             entity.eid = self.varmaker.next()
   321             entity.eid = self.varmaker.next()
   400 
   398 
   401     def __init__(self, req, rset, **kwargs):
   399     def __init__(self, req, rset, **kwargs):
   402         kwargs.setdefault('__redirectrql', rset.printable_rql())
   400         kwargs.setdefault('__redirectrql', rset.printable_rql())
   403         super(TableEditForm, self).__init__(req, rset, **kwargs)
   401         super(TableEditForm, self).__init__(req, rset, **kwargs)
   404         for row in xrange(len(self.rset)):
   402         for row in xrange(len(self.rset)):
   405             form = self.vreg.select('forms', 'edition', self.req, rset=self.rset,
   403             form = self.vreg['forms'].select('edition', self.req,
   406                                     row=row, attrcategories=('primary',),
   404                                              rset=self.rset, row=row,
   407                                     mainform=False)
   405                                              attrcategories=('primary',),
       
   406                                              mainform=False)
   408             # XXX rely on the EntityCompositeFormRenderer to put the eid input
   407             # XXX rely on the EntityCompositeFormRenderer to put the eid input
   409             form.remove_field(form.field_by_name('eid'))
   408             form.remove_field(form.field_by_name('eid'))
   410             self.form_add_subform(form)
   409             self.form_add_subform(form)
   411 
   410 
   412 
   411 
   418     def call(self, **kwargs):
   417     def call(self, **kwargs):
   419         """a view to edit multiple entities of the same type the first column
   418         """a view to edit multiple entities of the same type the first column
   420         should be the eid
   419         should be the eid
   421         """
   420         """
   422         #self.form_title(entity)
   421         #self.form_title(entity)
   423         form = self.vreg.select('forms', self.id, self.req, rset=self.rset)
   422         form = self.vreg['forms'].select(self.id, self.req, rset=self.rset)
   424         self.w(form.form_render())
   423         self.w(form.form_render())
   425 
   424 
   426 
   425 
   427 class InlineEntityEditionFormView(FormViewMixIn, EntityView):
   426 class InlineEntityEditionFormView(FormViewMixIn, EntityView):
   428     id = 'inline-edition'
   427     id = 'inline-edition'
   449                                                                  entity.eid)
   448                                                                  entity.eid)
   450         self.render_form(entity, peid, rtype, role, divonclick=divonclick)
   449         self.render_form(entity, peid, rtype, role, divonclick=divonclick)
   451 
   450 
   452     def render_form(self, entity, peid, rtype, role, **kwargs):
   451     def render_form(self, entity, peid, rtype, role, **kwargs):
   453         """fetch and render the form"""
   452         """fetch and render the form"""
   454         form = self.vreg.select('forms', 'edition', self.req, entity=entity,
   453         form = self.vreg['forms'].select('edition', self.req, entity=entity,
   455                                 form_renderer_id='inline', mainform=False,
   454                                          form_renderer_id='inline',
   456                                 copy_nav_params=False)
   455                                          mainform=False, copy_nav_params=False)
   457         self.add_hiddens(form, entity, peid, rtype, role)
   456         self.add_hiddens(form, entity, peid, rtype, role)
   458         divid = '%s-%s-%s' % (peid, rtype, entity.eid)
   457         divid = '%s-%s-%s' % (peid, rtype, entity.eid)
   459         title = self.schema.rschema(rtype).display_name(self.req, role)
   458         title = self.schema.rschema(rtype).display_name(self.req, role)
   460         removejs = self.removejs % (peid, rtype,entity.eid)
   459         removejs = self.removejs % (peid, rtype,entity.eid)
   461         countkey = '%s_count' % rtype
   460         countkey = '%s_count' % rtype
   501         :param peid: the parent entity's eid hosting the inline form
   500         :param peid: the parent entity's eid hosting the inline form
   502         :param rtype: the relation bridging `etype` and `peid`
   501         :param rtype: the relation bridging `etype` and `peid`
   503         :param role: the role played by the `peid` in the relation
   502         :param role: the role played by the `peid` in the relation
   504         """
   503         """
   505         try:
   504         try:
   506             entity = self.vreg.etype_class(etype)(self.req, None, None)
   505             entity = self.vreg['etypes'].etype_class(etype)(self.req, None, None)
   507         except:
   506         except:
   508             self.w(self.req._('no such entity type %s') % etype)
   507             self.w(self.req._('no such entity type %s') % etype)
   509             return
   508             return
   510         self.initialize_varmaker()
   509         self.initialize_varmaker()
   511         entity.eid = self.varmaker.next()
   510         entity.eid = self.varmaker.next()