web/views/editforms.py
branchstable
changeset 2482 dead2d56f711
parent 2392 4f6bfffbfb80
child 2538 6f8ffaa2a700
equal deleted inserted replaced
2432:986718a355fa 2482:dead2d56f711
   102                                role) in '+*':
   102                                role) in '+*':
   103             return self._many_rvid
   103             return self._many_rvid
   104         return self._one_rvid
   104         return self._one_rvid
   105 
   105 
   106     def _build_landing_zone(self, lzone):
   106     def _build_landing_zone(self, lzone):
   107         return lzone or self._defaultlandingzone % {'msg' : self.req._(self._landingzonemsg)}
   107         return lzone or self._defaultlandingzone % {'msg' : xml_escape(self.req._(self._landingzonemsg))}
   108 
   108 
   109     def _build_renderer(self, entity, rtype, role):
   109     def _build_renderer(self, entity, rtype, role):
   110         return self.vreg.select_object('formrenderers', 'base', self.req,
   110         return self.vreg.select_object('formrenderers', 'base', self.req,
   111                                        entity=entity,
   111                                        entity=entity,
   112                                        display_label=False, display_help=False,
   112                                        display_label=False, display_help=False,
   126         assert role in ('subject', 'object')
   126         assert role in ('subject', 'object')
   127         if default is None:
   127         if default is None:
   128             default = xml_escape(self.req._('<no value>'))
   128             default = xml_escape(self.req._('<no value>'))
   129         entity = self.entity(row, col)
   129         entity = self.entity(row, col)
   130         rschema = entity.schema.rschema(rtype)
   130         rschema = entity.schema.rschema(rtype)
       
   131         lzone = self._build_landing_zone(landing_zone)
   131         # compute value, checking perms, build form
   132         # compute value, checking perms, build form
   132         if rschema.is_final():
   133         if rschema.is_final():
   133             value = entity.printable_value(rtype) or default
   134             value = entity.printable_value(rtype) or default
   134             if not entity.has_perm('update'):
   135             if not entity.has_perm('update'):
   135                 self.w(value)
   136                 self.w(value)
   136                 return
   137                 return
   137             self._attribute_form(entity, value, rtype, role, reload,
   138             self._attribute_form(entity, value, rtype, role, reload,
   138                                  row, col, default, landing_zone)
   139                                  row, col, default, lzone)
   139         else:
   140         else:
   140             dispctrl = uicfg.primaryview_display_ctrl.etype_get(entity.e_schema,
   141             dispctrl = uicfg.primaryview_display_ctrl.etype_get(entity.e_schema,
   141                                                                 rtype, role)
   142                                                                 rtype, role)
   142             vid = dispctrl.get('vid', 'reledit')
   143             vid = dispctrl.get('vid', 'reledit')
   143             if vid != 'reledit': # reledit explicitly disabled
   144             if vid != 'reledit': # reledit explicitly disabled
   157             elif get_schema_property(entity.e_schema, rschema,
   158             elif get_schema_property(entity.e_schema, rschema,
   158                                      role, 'composite') == role:
   159                                      role, 'composite') == role:
   159                 self.warning('reledit cannot be applied : (... %s %s [composite])'
   160                 self.warning('reledit cannot be applied : (... %s %s [composite])'
   160                              % (rtype, entity.e_schema))
   161                              % (rtype, entity.e_schema))
   161                 return self.w(value)
   162                 return self.w(value)
   162             self._relation_form(entity, value, rtype, role, reload, row, col,
   163             self._relation_form(entity, value, rtype, role, reload, rvid,
   163                                 rvid, default, landing_zone)
   164                                 default, lzone)
   164 
   165 
   165 
   166 
   166     def _relation_form(self, entity, value, rtype, role, row, col, reload, rvid, default, lzone):
   167     def _relation_form(self, entity, value, rtype, role, reload, rvid, default, lzone):
   167         lzone = self._build_landing_zone(lzone)
   168         """xxx-reledit div (class=field)
       
   169               +-xxx div (class="editableField")
       
   170               |   +-landing zone
       
   171               +-value
       
   172               +-form-xxx div
       
   173         """
   168         divid = 'd%s' % make_uid('%s-%s' % (rtype, entity.eid))
   174         divid = 'd%s' % make_uid('%s-%s' % (rtype, entity.eid))
   169         event_data = {'divid' : divid, 'eid' : entity.eid, 'rtype' : rtype, 'vid' : rvid,
   175         event_data = {'divid' : divid, 'eid' : entity.eid, 'rtype' : rtype, 'vid' : rvid,
   170                       'reload' : reload, 'default' : default, 'role' : role,
   176                       'reload' : dumps(reload), 'default' : default, 'role' : role,
   171                       'lzone' : lzone}
   177                       'lzone' : lzone}
   172         onsubmit = ("return inlineValidateRelationForm('%(rtype)s', '%(role)s', '%(eid)s', "
   178         onsubmit = ("return inlineValidateRelationForm('%(rtype)s', '%(role)s', '%(eid)s', "
   173                     "'%(divid)s', %(reload)s, '%(vid)s', '%(default)s', '%(lzone)s');"
   179                     "'%(divid)s', %(reload)s, '%(vid)s', '%(default)s', '%(lzone)s');"
   174                     % event_data)
   180                     % event_data)
   175         cancelclick = "hideInlineEdit(%s,\'%s\',\'%s\')" % (
   181         cancelclick = "hideInlineEdit(%s,\'%s\',\'%s\')" % (
   180                                        form_buttons=[SubmitButton(),
   186                                        form_buttons=[SubmitButton(),
   181                                                      Button(stdmsgs.BUTTON_CANCEL,
   187                                                      Button(stdmsgs.BUTTON_CANCEL,
   182                                                             onclick=cancelclick)])
   188                                                             onclick=cancelclick)])
   183         field = guess_field(entity.e_schema, entity.schema.rschema(rtype), role)
   189         field = guess_field(entity.e_schema, entity.schema.rschema(rtype), role)
   184         form.append_field(field)
   190         form.append_field(field)
   185         self.w(u'<div id="%s-reledit" class="field">' % divid)
   191         w = self.w
   186         self.w(tags.div(lzone, klass='editableField', id=divid,
   192         w(u'<div id="%s-reledit" class="field">' % divid)
   187                         onclick=self._onclick % event_data))
   193         w(tags.div(lzone, klass='editableField', id=divid,
   188         self.w(value)
   194                    onclick=self._onclick % event_data))
       
   195         w(value)
   189         renderer = self._build_renderer(entity, rtype, role)
   196         renderer = self._build_renderer(entity, rtype, role)
   190         self.w(form.form_render(renderer=renderer))
   197         w(form.form_render(renderer=renderer))
   191         self.w(u'</div>')
   198         w(u'</div>')
   192 
   199 
   193     def _attribute_form(self, entity, value, rtype, role, reload, row, col, default, lzone):
   200     def _attribute_form(self, entity, value, rtype, role, reload, row, col, default, lzone):
       
   201         """div (class=field)
       
   202               +-xxx div
       
   203               |  +-xxx div (class=editableField)
       
   204               |  |  +-landing zone
       
   205               |  +-value-xxx div
       
   206               |     +-value
       
   207               +-form-xxx div
       
   208         """
   194         eid = entity.eid
   209         eid = entity.eid
   195         divid = 'd%s' % make_uid('%s-%s' % (rtype, eid))
   210         divid = 'd%s' % make_uid('%s-%s' % (rtype, eid))
   196         event_data = {'divid' : divid, 'eid' : eid, 'rtype' : rtype,
   211         event_data = {'divid' : divid, 'eid' : eid, 'rtype' : rtype,
   197                       'reload' : dumps(reload), 'default' : default, 'lzone' : lzone}
   212                       'reload' : dumps(reload), 'default' : default}
   198         onsubmit = ("return inlineValidateAttributeForm('%(rtype)s', '%(eid)s', '%(divid)s', "
   213         onsubmit = ("return inlineValidateAttributeForm('%(rtype)s', '%(eid)s', '%(divid)s', "
   199                     "%(reload)s, '%(default)s', '%(lzone)s');")
   214                     "%(reload)s, '%(default)s');")
   200         buttons = [SubmitButton(stdmsgs.BUTTON_OK),
   215         buttons = [SubmitButton(stdmsgs.BUTTON_OK),
   201                    Button(stdmsgs.BUTTON_CANCEL,
   216                    Button(stdmsgs.BUTTON_CANCEL,
   202                           onclick="hideInlineEdit(%s,\'%s\',\'%s\')" % (
   217                           onclick="hideInlineEdit(%s,\'%s\',\'%s\')" % (
   203                               eid, rtype, divid))]
   218                               eid, rtype, divid))]
   204         form = self.vreg.select_object('forms', 'edition', self.req, self.rset,
   219         form = self.vreg.select_object('forms', 'edition', self.req, self.rset,
   205                                        row=row, col=col, form_buttons=buttons,
   220                                        row=row, col=col, form_buttons=buttons,
   206                                        domid='%s-form' % divid, action='#',
   221                                        domid='%s-form' % divid, action='#',
   207                                        cssstyle='display: none',
   222                                        cssstyle='display: none',
   208                                        onsubmit=onsubmit % event_data)
   223                                        onsubmit=onsubmit % event_data)
   209         self.w(tags.div(value, klass='editableField', id=divid,
   224         w = self.w
   210                         onclick=self._onclick % event_data))
   225         w(u'<div class="field">')
       
   226         w(u'<div id="%s" style="display: inline">' % divid)
       
   227         w(tags.div(lzone, klass='editableField',
       
   228                    onclick=self._onclick % event_data))
       
   229         w(u'<div id="value-%s" style="display: inline">%s</div>' %
       
   230                (divid, value))
       
   231         w(u'</div>')
   211         renderer = self._build_renderer(entity, rtype, role)
   232         renderer = self._build_renderer(entity, rtype, role)
   212         self.w(form.form_render(renderer=renderer))
   233         w(form.form_render(renderer=renderer))
       
   234         w(u'</div>')
   213 
   235 
   214 
   236 
   215 class EditionFormView(FormViewMixIn, EntityView):
   237 class EditionFormView(FormViewMixIn, EntityView):
   216     """display primary entity edition form"""
   238     """display primary entity edition form"""
   217     id = 'edition'
   239     id = 'edition'