web/views/editforms.py
changeset 3396 fb261afd49cd
parent 3388 b8be8fc77c27
parent 3377 dd9d292b6a6d
child 3451 6b46d73823f5
equal deleted inserted replaced
3395:405f393bcac0 3396:fb261afd49cd
    43     return u'[<a class="handle" href="%s" id="handle%s">%s</a>]' % (
    43     return u'[<a class="handle" href="%s" id="handle%s">%s</a>]' % (
    44         js, nodeid, label)
    44         js, nodeid, label)
    45 
    45 
    46 
    46 
    47 class DeleteConfForm(forms.CompositeForm):
    47 class DeleteConfForm(forms.CompositeForm):
    48     id = 'deleteconf'
    48     __regid__ = 'deleteconf'
    49     __select__ = non_final_entity()
    49     __select__ = non_final_entity()
    50 
    50 
    51     domid = 'deleteconf'
    51     domid = 'deleteconf'
    52     copy_nav_params = True
    52     copy_nav_params = True
    53     form_buttons = [Button(stdmsgs.YES, cwaction='delete'),
    53     form_buttons = [Button(stdmsgs.YES, cwaction='delete'),
    68             self.form_add_subform(subform)
    68             self.form_add_subform(subform)
    69 
    69 
    70 
    70 
    71 class DeleteConfFormView(FormViewMixIn, EntityView):
    71 class DeleteConfFormView(FormViewMixIn, EntityView):
    72     """form used to confirm deletion of some entities"""
    72     """form used to confirm deletion of some entities"""
    73     id = 'deleteconf'
    73     __regid__ = 'deleteconf'
    74     title = _('delete')
    74     title = _('delete')
    75     # don't use navigation, all entities asked to be deleted should be displayed
    75     # don't use navigation, all entities asked to be deleted should be displayed
    76     # else we will only delete the displayed page
    76     # else we will only delete the displayed page
    77     need_navigation = False
    77     need_navigation = False
    78 
    78 
    99     """form used to permit ajax edition of a relation or attribute of an entity
    99     """form used to permit ajax edition of a relation or attribute of an entity
   100     in a view, if logged user have the permission to edit it.
   100     in a view, if logged user have the permission to edit it.
   101 
   101 
   102     (double-click on the field to see an appropriate edition widget).
   102     (double-click on the field to see an appropriate edition widget).
   103     """
   103     """
   104     id = 'doreledit'
   104     __regid__ = 'doreledit'
   105     __select__ = non_final_entity() & match_kwargs('rtype')
   105     __select__ = non_final_entity() & match_kwargs('rtype')
   106     # FIXME editableField class could be toggleable from userprefs
   106     # FIXME editableField class could be toggleable from userprefs
   107 
   107 
   108     # add metadata to allow edition of metadata attributes (not considered by
   108     # add metadata to allow edition of metadata attributes (not considered by
   109     # edition form by default)
   109     # edition form by default)
   260 
   260 
   261 class AutoClickAndEditFormView(ClickAndEditFormView):
   261 class AutoClickAndEditFormView(ClickAndEditFormView):
   262     """same as ClickAndEditFormView but checking if the view *should* be applied
   262     """same as ClickAndEditFormView but checking if the view *should* be applied
   263     by checking uicfg configuration and composite relation property.
   263     by checking uicfg configuration and composite relation property.
   264     """
   264     """
   265     id = 'reledit'
   265     __regid__ = 'reledit'
   266 
   266 
   267     def should_edit_relation(self, entity, rschema, role, rvid):
   267     def should_edit_relation(self, entity, rschema, role, rvid):
   268         eschema = entity.e_schema
   268         eschema = entity.e_schema
   269         rtype = str(rschema)
   269         rtype = str(rschema)
   270         # XXX check autoform_section. what if 'generic'?
   270         # XXX check autoform_section. what if 'generic'?
   280             entity, rschema, role, rvid)
   280             entity, rschema, role, rvid)
   281 
   281 
   282 
   282 
   283 class EditionFormView(FormViewMixIn, EntityView):
   283 class EditionFormView(FormViewMixIn, EntityView):
   284     """display primary entity edition form"""
   284     """display primary entity edition form"""
   285     id = 'edition'
   285     __regid__ = 'edition'
   286     # add yes() so it takes precedence over deprecated views in baseforms,
   286     # add yes() so it takes precedence over deprecated views in baseforms,
   287     # though not baseforms based customized view
   287     # though not baseforms based customized view
   288     __select__ = one_line_rset() & non_final_entity() & yes()
   288     __select__ = one_line_rset() & non_final_entity() & yes()
   289 
   289 
   290     title = _('edition')
   290     title = _('edition')
   317         return self.req._('entity edited')
   317         return self.req._('entity edited')
   318 
   318 
   319 
   319 
   320 class CreationFormView(EditionFormView):
   320 class CreationFormView(EditionFormView):
   321     """display primary entity creation form"""
   321     """display primary entity creation form"""
   322     id = 'creation'
   322     __regid__ = 'creation'
   323     __select__ = specified_etype_implements('Any') & yes()
   323     __select__ = specified_etype_implements('Any') & yes()
   324 
   324 
   325     title = _('creation')
   325     title = _('creation')
   326 
   326 
   327     def call(self, **kwargs):
   327     def call(self, **kwargs):
   367 
   367 
   368 class CopyFormView(EditionFormView):
   368 class CopyFormView(EditionFormView):
   369     """display primary entity creation form initialized with values from another
   369     """display primary entity creation form initialized with values from another
   370     entity
   370     entity
   371     """
   371     """
   372     id = 'copy'
   372     __regid__ = 'copy'
   373     warning_message = _('Please note that this is only a shallow copy')
   373     warning_message = _('Please note that this is only a shallow copy')
   374 
   374 
   375     def render_form(self, entity):
   375     def render_form(self, entity):
   376         """fetch and render the form"""
   376         """fetch and render the form"""
   377         # make a copy of entity to avoid altering the entity in the
   377         # make a copy of entity to avoid altering the entity in the
   403         """return the message that will be displayed on successful edition"""
   403         """return the message that will be displayed on successful edition"""
   404         return self.req._('entity copied')
   404         return self.req._('entity copied')
   405 
   405 
   406 
   406 
   407 class TableEditForm(forms.CompositeForm):
   407 class TableEditForm(forms.CompositeForm):
   408     id = 'muledit'
   408     __regid__ = 'muledit'
   409     domid = 'entityForm'
   409     domid = 'entityForm'
   410     onsubmit = "return validateForm('%s', null);" % domid
   410     onsubmit = "return validateForm('%s', null);" % domid
   411     form_buttons = [SubmitButton(_('validate modifications on selected items')),
   411     form_buttons = [SubmitButton(_('validate modifications on selected items')),
   412                     ResetButton(_('revert changes'))]
   412                     ResetButton(_('revert changes'))]
   413 
   413 
   423             form.remove_field(form.field_by_name('eid'))
   423             form.remove_field(form.field_by_name('eid'))
   424             self.form_add_subform(form)
   424             self.form_add_subform(form)
   425 
   425 
   426 
   426 
   427 class TableEditFormView(FormViewMixIn, EntityView):
   427 class TableEditFormView(FormViewMixIn, EntityView):
   428     id = 'muledit'
   428     __regid__ = 'muledit'
   429     __select__ = EntityView.__select__ & yes()
   429     __select__ = EntityView.__select__ & yes()
   430     title = _('multiple edit')
   430     title = _('multiple edit')
   431 
   431 
   432     def call(self, **kwargs):
   432     def call(self, **kwargs):
   433         """a view to edit multiple entities of the same type the first column
   433         """a view to edit multiple entities of the same type the first column
   437         form = self.vreg['forms'].select(self.id, self.req, rset=self.rset)
   437         form = self.vreg['forms'].select(self.id, self.req, rset=self.rset)
   438         self.w(form.form_render())
   438         self.w(form.form_render())
   439 
   439 
   440 
   440 
   441 class InlineEntityEditionFormView(FormViewMixIn, EntityView):
   441 class InlineEntityEditionFormView(FormViewMixIn, EntityView):
   442     id = 'inline-edition'
   442     __regid__ = 'inline-edition'
   443     __select__ = non_final_entity() & match_kwargs('peid', 'rtype')
   443     __select__ = non_final_entity() & match_kwargs('peid', 'rtype')
   444     removejs = "removeInlinedEntity('%s', '%s', '%s')"
   444     removejs = "removeInlinedEntity('%s', '%s', '%s')"
   445 
   445 
   446     def call(self, **kwargs):
   446     def call(self, **kwargs):
   447         """redefine default call() method to avoid automatic
   447         """redefine default call() method to avoid automatic
   498                 return False
   498                 return False
   499         return True
   499         return True
   500 
   500 
   501 
   501 
   502 class InlineEntityCreationFormView(InlineEntityEditionFormView):
   502 class InlineEntityCreationFormView(InlineEntityEditionFormView):
   503     id = 'inline-creation'
   503     __regid__ = 'inline-creation'
   504     __select__ = (match_kwargs('peid', 'rtype')
   504     __select__ = (match_kwargs('peid', 'rtype')
   505                   & specified_etype_implements('Any'))
   505                   & specified_etype_implements('Any'))
   506     removejs = "removeInlineForm('%s', '%s', '%s')"
   506     removejs = "removeInlineForm('%s', '%s', '%s')"
   507 
   507 
   508     def call(self, etype, peid, rtype, role, i18nctx, **kwargs):
   508     def call(self, etype, peid, rtype, role, i18nctx, **kwargs):