web/views/editforms.py
changeset 3890 d7a270f50f54
parent 3777 3ef8cdb5fb1c
parent 3880 88fc53eb5b5f
child 3998 94cc7cad3d2d
equal deleted inserted replaced
3810:5b75fd66c80e 3890:d7a270f50f54
    49     __regid__ = 'deleteconf'
    49     __regid__ = 'deleteconf'
    50     __select__ = non_final_entity()
    50     __select__ = non_final_entity()
    51 
    51 
    52     domid = 'deleteconf'
    52     domid = 'deleteconf'
    53     copy_nav_params = True
    53     copy_nav_params = True
    54     form_buttons = [Button(stdmsgs.YES, cwaction='delete'),
    54     form_buttons = [Button(stdmsgs.BUTTON_DELETE, cwaction='delete'),
    55                     Button(stdmsgs.NO, cwaction='cancel')]
    55                     Button(stdmsgs.BUTTON_CANCEL, cwaction='cancel')]
    56     @property
    56     @property
    57     def action(self):
    57     def action(self):
    58         return self._cw.build_url('edit')
    58         return self._cw.build_url('edit')
    59 
    59 
    60     def __init__(self, *args, **kwargs):
    60     def __init__(self, *args, **kwargs):
   111 
   111 
   112     _onclick = u"showInlineEditionForm(%(eid)s, '%(rtype)s', '%(divid)s')"
   112     _onclick = u"showInlineEditionForm(%(eid)s, '%(rtype)s', '%(divid)s')"
   113     _onsubmit = ("return inlineValidateRelationForm('%(rtype)s', '%(role)s', '%(eid)s', "
   113     _onsubmit = ("return inlineValidateRelationForm('%(rtype)s', '%(role)s', '%(eid)s', "
   114                  "'%(divid)s', %(reload)s, '%(vid)s', '%(default)s', '%(lzone)s');")
   114                  "'%(divid)s', %(reload)s, '%(vid)s', '%(default)s', '%(lzone)s');")
   115     _cancelclick = "hideInlineEdit(%s,\'%s\',\'%s\')"
   115     _cancelclick = "hideInlineEdit(%s,\'%s\',\'%s\')"
   116     _defaultlandingzone = (u'<img title="%(msg)s" src="data/file.gif" '
   116     _defaultlandingzone = (u'<img title="%(msg)s" src="data/pen_icon.png" '
   117                            'alt="%(msg)s"/>')
   117                            'alt="%(msg)s"/>')
   118     _landingzonemsg = _('click to edit this field')
   118     _landingzonemsg = _('click to edit this field')
   119     # default relation vids according to cardinality
   119     # default relation vids according to cardinality
   120     _one_rvid = 'incontext'
   120     _one_rvid = 'incontext'
   121     _many_rvid = 'csv'
   121     _many_rvid = 'csv'
   195               +-xxx-value div
   195               +-xxx-value div
   196               +-xxx-form div
   196               +-xxx-form div
   197         """
   197         """
   198         w = self.w
   198         w = self.w
   199         divid = form.event_args['divid']
   199         divid = form.event_args['divid']
   200         w(u'<div id="%s-reledit" class="field">' % form.event_args['divid'])
   200         w(u'<div id="%s-reledit" class="field" '
   201         w(u'<div id="%s" class="editableField" onclick="%s" title="%s">' % (
   201           u'onmouseout="addElementClass(jQuery(\'#%s\'), \'hidden\')" '
       
   202           u'onmouseover="removeElementClass(jQuery(\'#%s\'), \'hidden\')">'
       
   203           % (divid, divid, divid))
       
   204         w(u'<div id="%s-value" class="editableFieldValue">%s</div>' % (divid, value))
       
   205         w(form.form_render(renderer=renderer))
       
   206         w(u'<div id="%s" class="editableField hidden" onclick="%s" title="%s">' % (
   202                 divid, xml_escape(self._onclick % form.event_args),
   207                 divid, xml_escape(self._onclick % form.event_args),
   203                 self.req._(self._landingzonemsg)))
   208                 self.req._(self._landingzonemsg)))
   204         w(lzone)
   209         w(lzone)
   205         w(u'</div>')
   210         w(u'</div>')
   206         w(u'<div id="%s-value" class="editableFieldValue">%s</div>' % (divid, value))
       
   207         w(form.form_render(renderer=renderer))
       
   208         w(u'</div>')
   211         w(u'</div>')
   209 
   212 
   210     def _compute_best_vid(self, eschema, rschema, role):
   213     def _compute_best_vid(self, eschema, rschema, role):
   211         if eschema.cardinality(rschema, role) in '+*':
   214         if eschema.cardinality(rschema, role) in '+*':
   212             return self._many_rvid
   215             return self._many_rvid
   267         rtype = str(rschema)
   270         rtype = str(rschema)
   268         # XXX check autoform_section. what if 'generic'?
   271         # XXX check autoform_section. what if 'generic'?
   269         dispctrl = uicfg.primaryview_display_ctrl.etype_get(eschema, rtype, role)
   272         dispctrl = uicfg.primaryview_display_ctrl.etype_get(eschema, rtype, role)
   270         vid = dispctrl.get('vid', 'reledit')
   273         vid = dispctrl.get('vid', 'reledit')
   271         if vid != 'reledit': # reledit explicitly disabled
   274         if vid != 'reledit': # reledit explicitly disabled
   272             self.wview(vid, entity.related(rtype, role), 'null')
       
   273             return False
   275             return False
   274         if eschema.role_rproperty(role, rschema, 'composite') == role:
   276         if eschema.role_rproperty(role, rschema, 'composite') == role:
   275             self.wview(rvid, entity.related(rtype, role), 'null')
       
   276             return False
   277             return False
   277         return super(AutoClickAndEditFormView, self).should_edit_relation(
   278         return super(AutoClickAndEditFormView, self).should_edit_relation(
   278             entity, rschema, role, rvid)
   279             entity, rschema, role, rvid)
   279 
   280 
   280     def _build_form(self, entity, rtype, role, formid, default, reload, lzone,
   281     def _build_form(self, entity, rtype, role, formid, default, reload, lzone,
   424         super(TableEditForm, self).__init__(req, rset=rset, **kwargs)
   425         super(TableEditForm, self).__init__(req, rset=rset, **kwargs)
   425         for row in xrange(len(self.cw_rset)):
   426         for row in xrange(len(self.cw_rset)):
   426             form = self._cw.vreg['forms'].select('edition', self._cw,
   427             form = self._cw.vreg['forms'].select('edition', self._cw,
   427                                                  rset=self.cw_rset, row=row,
   428                                                  rset=self.cw_rset, row=row,
   428                                                  formtype='muledit',
   429                                                  formtype='muledit',
       
   430                                                  copy_nav_params=False,
   429                                                  mainform=False)
   431                                                  mainform=False)
   430             # XXX rely on the EntityCompositeFormRenderer to put the eid input
   432             # XXX rely on the EntityCompositeFormRenderer to put the eid input
   431             form.remove_field(form.field_by_name('eid'))
   433             form.remove_field(form.field_by_name('eid'))
   432             self.add_subform(form)
   434             self.add_subform(form)
   433 
   435 
   440     def call(self, **kwargs):
   442     def call(self, **kwargs):
   441         """a view to edit multiple entities of the same type the first column
   443         """a view to edit multiple entities of the same type the first column
   442         should be the eid
   444         should be the eid
   443         """
   445         """
   444         #self.form_title(entity)
   446         #self.form_title(entity)
   445         form = self._cw.vreg['forms'].select(self.__regid__, self._cw, rset=self.cw_rset)
   447         form = self._cw.vreg['forms'].select(self.__regid__, self._cw,
       
   448                                              rset=self.cw_rset,
       
   449                                              copy_nav_params=True)
   446         self.w(form.form_render())
   450         self.w(form.form_render())
   447 
   451 
   448 
   452 
   449 class InlineEntityEditionFormView(FormViewMixIn, EntityView):
   453 class InlineEntityEditionFormView(FormViewMixIn, EntityView):
   450     """
   454     """
   575             js = "toggleVisibility('%s'); %s" % (divid, js)
   579             js = "toggleVisibility('%s'); %s" % (divid, js)
   576         __ = self.req.pgettext
   580         __ = self.req.pgettext
   577         self.w(u'<a class="addEntity" id="add%s:%slink" href="javascript: %s" >+ %s.</a>'
   581         self.w(u'<a class="addEntity" id="add%s:%slink" href="javascript: %s" >+ %s.</a>'
   578           % (self.rtype, self.peid, js, __(i18nctx, 'add a %s' % self.etype)))
   582           % (self.rtype, self.peid, js, __(i18nctx, 'add a %s' % self.etype)))
   579         self.w(u'</div>')
   583         self.w(u'</div>')
   580         self.w(u'<div class="trame_grise">&#160;</div>')