[Update] Editing a datenset from a "contentSelect" function

Peter_Jodeleit
Crownpeak employee
Crownpeak employee
0 0 639

Last week we got the request how to edit a dataset when using the FirstSpirit template function "contenSelect".

The Template was roughly this:

<CMS_FUNCTION name="contentSelect" resultname=“set_blogs">

</CMS_FUNCTION>

$CMS_FOR(_blog, set_blogs)$

                ???

$CMS_END_FOR$

The problem for datasets (type de.espirit.or.schema.Entity) is, that there is no direct form relation, and that there could be multiple forms for a dataset. Therefore the standard previewId way isn't working.


[UPDATE 6/15/2018]

Since FirstSpirit update 2018-06 there is a much easier way than initially described below.

Just use the following template snippet to create preview ids for the entities:

<CMS_FUNCTION name="contentSelect" resultname=“set_blogs">

  …

</CMS_FUNCTION>

{

   $CMS_FOR(_blog, set_blogs)${

      "_previewId" : $CMS_VALUE(previewId(element:ref(template:"<uid of table template>").getDataset(_blog)).toJSON)$

   }$CMS_VALUE(if(!#for.isLast, ","))$$CMS_END_FOR$

}

Use these preview ids for the default edit function of the TPP_API.


[Below you find the initial content of this post]


The solution consists of providing the form (TableTemplate) and the Entity to a project script, which in turn uses these information to open the edit dialog.

Step 1:
Create a project script (uid = "edit_dataset")

// TPP: open edit dialog for dataset

// params:

// * template:    uid of table template

// * entityId:    entity id

import com.espirit.tpp.api.action.EditAction;

import com.espirit.tpp.api.action.RenderAction;

import de.espirit.firstspirit.agency.StoreAgent;

import de.espirit.firstspirit.access.store.templatestore.TableTemplate;

import de.espirit.firstspirit.access.store.Store;

PreviewIdDescriptor(dataset) {

    getLanguage() {

        return context.getProject().getMasterLanguage();

    }

    getElement() {

        return dataset;

    }

    return this;

}

storeAgent = context.requireSpecialist(StoreAgent.TYPE);

ttemplate = storeAgent.getStore(Store.Type.TEMPLATESTORE).getStoreElement(template, TableTemplate.UID_TYPE);

entity = ttemplate.getSchema().getSession().find(ttemplate.getEntityType().getName(), entityId);

dataset = ttemplate.getDataset(entity);

descriptor = PreviewIdDescriptor(dataset);

changed = EditAction.perform(context, descriptor);

if (changed) {

    return RenderAction.perform(context, descriptor);

} else {

    return null;

}

Step 2:
Writing the properties of the dataset in the template output channel

$CMS_FOR(_blog, set_blogs)$

     { "dataset" : {

          "template": "<uid>",

          "entityId": $CMS_VALUE(_blog.identifier.getValue(0))$,

          ...}

     }

$CMS_END_FOR$

Schritt 3:

Usage in the front end code

TPP_API.Common.execute("script:edit_dataset", { "template": template, "entityId": entityId });

Version history
Last update:
‎06-17-2018 11:38 PM
Updated by: