doc/book/en/devweb/edition/editcontroller.rst
branchstable
changeset 5459 6e561796804c
child 5475 b44bad36e609
equal deleted inserted replaced
5458:a5b96b98242c 5459:6e561796804c
       
     1 .. _edit_controller:
       
     2 
       
     3 The `edit controller`
       
     4 +++++++++++++++++++++
       
     5 
       
     6 It can be found in (:mod:`cubicweb.web.views.editcontroller`).
       
     7 
       
     8 Editing control
       
     9 ~~~~~~~~~~~~~~~~
       
    10 
       
    11 .. XXX this look obsolete
       
    12 
       
    13 The parameters related to entities to edit are specified as follows ::
       
    14 
       
    15   <field name>:<entity eid>
       
    16 
       
    17 where entity eid could be a letter in case of an entity to create. We
       
    18 name those parameters as *qualified*.
       
    19 
       
    20 1. Retrieval of entities to edit by looking for the forms parameters
       
    21    starting by `eid:` and also having a parameter `__type` associated
       
    22    (also *qualified* by eid)
       
    23 
       
    24 2. For all the attributes and the relations of an entity to edit:
       
    25 
       
    26    1. search for a parameter `edits-<relation name>` or `edito-<relation name>`
       
    27       qualified in the case of a relation where the entity is object
       
    28    2. if found, the value returned is considered as the initial value
       
    29       for this relaiton and we then look for the new value(s)  in the parameter
       
    30       <relation name> (qualified)
       
    31    3. if the value returned is different from the initial value, an database update
       
    32       request is done
       
    33 
       
    34 3. For each entity to edit:
       
    35 
       
    36    1. if a qualified parameter `__linkto` is specified, its value has to be
       
    37       a string (or a list of string) such as: ::
       
    38 
       
    39         <relation type>:<eids>:<target>
       
    40 
       
    41       where <target> is either `subject` or `object` and each eid could be
       
    42       separated from the others by a `_`. Target specifies if the *edited entity*
       
    43       is subject or object of the relation and each relation specified will
       
    44       be inserted.
       
    45 
       
    46     2. if a qualified parameter `__clone_eid` is specified for an entity, the
       
    47        relations of the specified entity passed as value of this parameter are
       
    48        copied on the edited entity.
       
    49 
       
    50     3. if a qualified parameter `__delete` is specified, its value must be
       
    51        a string or a list of string such as follows: ::
       
    52 
       
    53           <ssubjects eids>:<relation type>:<objects eids>
       
    54 
       
    55        where each eid subject or object can be seperated from the other
       
    56        by `_`. Each relation specified will be deleted.
       
    57 
       
    58     4. if a qualified parameter `__insert` is specified, its value should
       
    59        follow the same pattern as `__delete`, but each relation specified is
       
    60        inserted.
       
    61 
       
    62 4. If the parameters `__insert` and/or `__delete` are found not qualified,
       
    63    they are interpreted as explained above (independantly from the number
       
    64    of entities edited).
       
    65 
       
    66 5. If no entity is edited but the form contains the parameters `__linkto`
       
    67    and `eid`, this one is interpreted by using the value specified for `eid`
       
    68    to designate the entity on which to add the relations.
       
    69 
       
    70 
       
    71 .. note::
       
    72 
       
    73    * if the parameter `__action_delete` is found, all the entities specified
       
    74      as to be edited will be deleted.
       
    75 
       
    76    * if the parameter `__action_cancel` is found, no action is completed.
       
    77 
       
    78    * if the parameter `__action_apply` is found, the editing is
       
    79      applied normally but the redirection is done on the form (see
       
    80      :ref:`RedirectionControl`).
       
    81 
       
    82    * if no entity is found to be edited and if there is no parameter
       
    83      `__action_delete`, `__action_cancel`, `__linkto`, `__delete` or
       
    84      `__insert`, an error is raised.
       
    85 
       
    86    * using the parameter `__message` in the form will allow to use its value
       
    87      as a message to provide the user once the editing is completed.
       
    88 
       
    89 
       
    90 .. _RedirectionControl:
       
    91 
       
    92 Redirection control
       
    93 ~~~~~~~~~~~~~~~~~~~
       
    94 Once editing is completed, there is still an issue left: where should we go
       
    95 now? If nothing is specified, the controller will do his job but it does not
       
    96 mean we will be happy with the result. We can control that by using the
       
    97 following parameters:
       
    98 
       
    99 * `__redirectpath`: path of the URL (relative to the root URL of the site,
       
   100   no form parameters
       
   101 
       
   102 * `__redirectparams`: forms parameters to add to the path
       
   103 
       
   104 * `__redirectrql`: redirection RQL request
       
   105 
       
   106 * `__redirectvid`: redirection view identifier
       
   107 
       
   108 * `__errorurl`: initial form URL, used for redirecting in case a validation
       
   109   error is raised during editing. If this one is not specified, an error page
       
   110   is displayed instead of going back to the form (which is, if necessary,
       
   111   responsible for displaying the errors)
       
   112 
       
   113 * `__form_id`: initial view form identifier, used if `__action_apply` is
       
   114   found
       
   115 
       
   116 In general we use either `__redirectpath` and `__redirectparams` or
       
   117 `__redirectrql` and `__redirectvid`.