Aller au contenu principal

How to update the CMS_INPUT_COMBOBOX from script template?

Commentaires

13 commentaires

  • Zendesk API User
    Author: felix_reinhold - 4/10/2019 7:41

    HI Kavin,

    I think you have to provide some more details:

    When do you want the script to be executed and what exactly does the script? Do you want to change the selected entry in the combobox or do you want to create options for the combobox dynamically? Is it a combobox which shows datasets or manually created options?

    Maybe you can provide the definition of the combobox and the scripts (or relevant parts of it)

    Best regards

    Felix

    0
  • Zendesk API User
    Author: kavin - 4/11/2019 7:33

    Hi Felix,

    Thanks for your reply.

    We want to create the options in the combo box dynamically which needs to load all the Groups which is associated with that project.

    It would be fine, if it can be achieved without script templates.

    Best regards,

    Kavin

    0
  • Zendesk API User
    Author: felix_reinhold - 4/11/2019 10:52

    HI Kavin,

    for this you have to create a HotSpot (public component) in a module, that provides the groups of the project. (FirstSpirit Online Documentation - CMS_INCLUDE_OPTIONS: Type PUBLIC ).

    If you need help with this let me know.

    Best regards

    Felix

    0
  • Zendesk API User
    Author: felix_reinhold - 4/11/2019 12:16

    Hi Kavin,

    I quickly added the solution to a github project:

    GitHub - freinhold/firstspirit: FirstSpirit Extensions

    See com.reinhold.fs.hotspot.ProjectGroupsHotspot.

    Just add it to one of your modules (or create a new one) and define it as public-component in module.xml:

    <public>

         <name>ProjectGroupsHotspot</name>

         <class>com.reinhold.fs.hotspot.ProjectGroupsHotspot</class>

    </public>

    Then you can use it in comboboxes:

      <CMS_INPUT_COMBOBOX name="st_group" useLanguages="no">

        <CMS_INCLUDE_OPTIONS type="public">

          <LABELS>

            <LABEL lang="*">#item.name</LABEL>

          </LABELS>

          <NAME>ProjectGroupsHotspot</NAME>

        </CMS_INCLUDE_OPTIONS>

        <LANGINFOS>

          <LANGINFO lang="*" label="Groups"/>

        </LANGINFOS>

      </CMS_INPUT_COMBOBOX>

    HTML-Output:

    $CMS_VALUE(st_group.getValue())$              // Get the Java Group-Instance

    $CMS_VALUE(st_group.getValue().getName())$    // Get name of group

    best regards

    Felix

    0
  • Zendesk API User
    Author: mbergmann - 4/11/2019 21:38

    Hi Felix,

    great that you share your examples!

    One thought (without having tested it): I‘m not that sure if the group‘s numeric id is an ideal candidate for the key when you think of stuff like project export/import or content transport - the name might be a better choice.

    Best regards

    Michael

    0
  • Zendesk API User
    Author: kavin - 4/12/2019 7:35

    Hi Felix,

    Thank you so much for sharing the code.

    Best regards,

    Kavin

    0
  • Zendesk API User
    Author: felix_reinhold - 4/12/2019 9:13

    HI Michael,

    thanks, that's a good point - I adjusted it in the repo.

    kavin​ you should use the adjusted version of the code then.

    Best regards

    Felix

    0
  • Zendesk API User
    Author: kavin - 4/12/2019 12:13

    Hi felix.reinhold​,

    Is it possible to load the groups in  CMS_INPUT_PERMISSION component?

    Thank you!

    0
  • Zendesk API User
    Author: felix_reinhold - 4/12/2019 12:42

    HI kavin,

    you want to...

    (1)...load the groups that are available in CMS_INPUT_PERMISSION into the CMS_INPUT_COMBOBOX

              or

    (2)...use the project editor-groups in CMS_INPUT_PERMISSION?

    For (1) you would have to adjust the hotspot and get the groups from the PermissionService (or parse the config manually).

    For (2) you would have to sync the groups into a xml-file that is provided to the PermissionService

    Best regards

    Felix

    0
  • Zendesk API User
    Author: vasanth - 4/17/2019 12:29

    Hello Guys,

    It worked very well.  Thank you felix.reinhold for share the code.

    0
  • Zendesk API User
    Author: vasanth - 4/17/2019 12:35

    felix.reinhold​  We are using the Permission Service in the meta data. please refer the below screenshot

    If I change the Permission  Service's data for the group ?? then will affect other permission service in the meta data too ??

    It would very helpful if you have any sample code.

    0
  • Zendesk API User
    Author: felix_reinhold - 4/17/2019 12:49

    Hello,

    if you're using the same group-File for different usages of the CMS_INPUT_PERMISSION component then a change in the groups-file would affect all of those usages of course. If you want different groups in the CMS_INPUT_PERMISSION then you'd have to create multiple group-files in the permission service. To sync the groups to the file you could just create a server-schedule-entry that runs automatically every x minutes/hours/days to sync the groups to the file. In the schedule entry just get the xml-Files from the service and update them by adding all groups of the project. Something like this (untested):

    final String XML_DOCUMENT_INFO = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";

    Path projectPath= new File("conf/modules/System.PermissionService/editorgroups.xml").toPath();

    // Write groups to file

    StringBuffer xmlOut = new StringBuffer(XML_DOCUMENT_INFO);

    xmlOut.append("<GROUPS name=\"editorgroups\" version=\"1\">\n");

    for (Group group : project.getGroups()) {

         String uid = group.getName().toLowerCase().replaceAll(" ","_");

         xmlOut.append("\t<GROUP id=\"").append(uid).append("\" name=\"").append(group.getName()).append("\"/>\n");

    }

    xmlOut.append("</GROUPS>\n");

    Files.write(projectPath, xmlOut.toString().getBytes(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);

    I think you can get the conf-path of the service from the service directly instead of adding it hardcoded. And of course there are better ways to write the xml-markup instead of hardcoded strings.

    Maybe you have to always increase the version by 1 to make the service recognize the change - Maybe you could use a timestamp as version or sth. like that.

    best regards

    Felix

    0
  • Zendesk API User
    Author: vasanth - 4/19/2019 8:26

    felix.reinhold​ Thank you for sharing the code felix but my scenario doesn't allow me to change the usage. So i think about other possibilities.

    0

Vous devez vous connecter pour laisser un commentaire.