Menu

Hide and set default value for UserResquest form in portal

2018-09-12
2018-09-12
  • Sébastien Potin

    Hello all,

    Do you know how to set default value for service, service subcategory, impact and urgency in the request form in the portal ?

    And then hide them ?

    I tried with this but it failed :

    <?xml version="1.0" encoding="UTF-8"?>
    <itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
      <module_designs>
        <module_design id="itop-portal" xsi:type="portal">
          <bricks>
              <brick id="services" xsi:type="Combodo\iTop\Portal\Brick\BrowseBrick">
                  <active _delta="redefine">false</active>
              </brick>
              <brick id="quick-new-user-request" xsi:type="Combodo\iTop\Portal\Brick\CreateBrick" _delta="define">
                <active>true</active>
                <rank>
                    <default>9</default>
                </rank>
                <width>6</width>
                <modal>true</modal>
                <title>
                    <default>Brick:Portal:QuickNewUserRequest:Title</default>
                </title>
                  <description>Brick:Portal:QuickNewUserRequest:Description</description>
                <visible>
                    <home>true</home>
                </visible>
                <decoration_class>
                    <default>fa fa-bolt fa-2x fa-fw</default>
                </decoration_class>
                <!-- Class that will be create created with the form -->
                <class>UserRequest</class>
                <rules>
                    <rule id="contact-to-userrequest"/>
                    <rule id="preset-service-subservice-impact-urgency"/>
                </rules>
            </brick>
          </bricks>
            <action_rules>
                <action_rule id="preset-service-subservice-impact-urgency">
                    <presets>
                        <!-- Only set() and copy() are supported for now -->
                        <preset id="1">set(service_id, 1)</preset>
                        <preset id="2">set(subcategory_id, 55)</preset>
                        <preset id="8">set(impact, 3)</preset>
                        <preset id="9">set(urgency, 4)</preset>
                    </presets>
                    <retrofits/>
                </action_rule>
            </action_rules>
        </module_design>
      </module_designs>
    </itop_design>
    

    Thanks for your reply

     
  • Guillaume Lajarige

    Hi Sebastian,

    Presetting fields
    The usage of an action rule like you deal seems good, that the proper way to preset fields when creating an object in the portal.

    The only thing that could be wrong is the subcategory_id that is not a regular field, in the standard datamodel it's servicesubcategory_id but maybe you changed your datamodel?

    How are you applying the XML delta, through an extension? Because I don't see any _delta="XXX" attributes on the nodes.

    What is your symptom exactly?

    Hidding fields
    In the portal, for a specific class you can design a form for the object creation, edition, viewing, transitions. So in your case, I think the best way would be to change the edit (and view?) form to remove the impact and urgency fields.

    In the standard datamodel there are defined in the /module_designs/module_design[@id="itop-portal"]/forms/form[@id="ticket-edit"]/twig
    If your alter this form, the changes will occurs on all the classes derivated from Ticket (UserRequest, Incident, ...). If you prefer to change only the UserRequest form, you can add a new form node dedicated to the UserRequest class.

    Guillaume

     
    • Sébastien Potin

      Hi Guillaume,

      Yes, I'm using an extension.

      I replaced subcategory_id by servicesubcategory_id and I added delta="define" like this :

      <action_rule id="preset-service-subservice-impact-urgency" _delta="define">
      

      And now it works correctly !
      Thanks you so much !

      About Hidding fields
      I understand what you explain, but I don't know from where to start ...

      Should I write it in the same XML file of my extension ?

       
  • Sébastien Potin

    Finally I found by myself :

    <?xml version="1.0" encoding="UTF-8"?>
    <itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
      <module_designs>
        <module_design id="itop-portal" xsi:type="portal">
          <bricks>
              <brick id="services" xsi:type="Combodo\iTop\Portal\Brick\BrowseBrick">
                  <active _delta="redefine">false</active>
              </brick>
              <brick id="quick-new-user-request" xsi:type="Combodo\iTop\Portal\Brick\CreateBrick" _delta="define">
                <active>true</active>
                <rank>
                    <default>9</default>
                </rank>
                <width>6</width>
                <modal>true</modal>
                <title>
                    <default>Brick:Portal:QuickNewUserRequest:Title</default>
                </title>
                  <description>Brick:Portal:QuickNewUserRequest:Description</description>
                <visible>
                    <home>true</home>
                </visible>
                <decoration_class>
                    <default>fa fa-bolt fa-2x fa-fw</default>
                </decoration_class>
                <!-- Class that will be create created with the form -->
                <class>UserRequest</class>
                <rules>
                    <rule id="contact-to-userrequest"/>
                    <rule id="preset-service-subservice-impact-urgency"/>
                </rules>
            </brick>
          </bricks>
            <action_rules>
                <action_rule id="preset-service-subservice-impact-urgency" _delta="define">
                    <presets>
                        <!-- Only set() and copy() are supported for now -->
                        <preset id="1">set(service_id, 1)</preset>
                        <preset id="2">set(servicesubcategory_id, 55)</preset>
                        <preset id="3">set(impact, 3)</preset>
                        <preset id="4">set(urgency, 4)</preset>
                    </presets>
                    <retrofits/>
                </action_rule>
            </action_rules>
            <forms>
                <form id="ticket-create" _delta="must_exist">
                    <class>Ticket</class>
                    <fields/>
                    <twig _delta="redefine">
                        <div class="row" style="display: none">
                            <div class="col-sm-6">
                                <div class="form_field" data-field-id="service_id" data-field-flags="mandatory">
                                </div>
                            </div>
                            <div class="col-sm-6">
                                <div class="form_field" data-field-id="servicesubcategory_id" data-field-flags="mandatory">
                                </div>
                            </div>
                        </div>
                        <div id="service_details_placeholder" _altered_in="itop-request-template-portal">
                            <div class="form_field" data-field-id="service_details">
                            </div>
                        </div>
                        <div class="row" style="display: none">
                            <div class="col-sm-6">
                                <div class="form_field" data-field-id="impact">
                                </div>
                            </div>
                            <div class="col-sm-6">
                                <div class="form_field" data-field-id="urgency">
                                </div>
                            </div>
                        </div>
                        <div>
                            <div class="form_field" data-field-id="title">
                            </div>
                            <div class="form_field" data-field-id="description">
                            </div>
                            <div class="form_field" data-field-id="contacts_list">
                            </div>
                        </div>
                    </twig>
                    <modes>
                        <!-- mode id can among create / edit / view -->
                        <mode id="create"/>
                    </modes>
                </form>
                <form id="ticket-edit" _delta="must_exist">
                    <class>Ticket</class>
                    <properties>
                        <!--Display mode of the form fields. "cosy" for a regular labels over values layout; "compact" for a side-by-side layout with input aligned; "dense" for a side-by-side layout with input filling all available space. You can also use a custom css class that will be used on the form as "form_xxx", as well as on the fields as "form_field_xxx".-->
                        <!--<display_mode>cosy</display_mode>-->
                        <!-- When set to false, submit button is hidden when transitions are available on the object (in edit mode only). Default is false. -->
                        <!--<always_show_submit>false</always_show_submit>-->
                    </properties>
                    <fields/>
                    <twig _delta="redefine">
                        <div class="row" style="">
                            <div class="col-sm-7">
                                <fieldset>
                                    <legend>{{'Ticket:baseinfo'|dict_s}}</legend>
                                    <div class="col-sm-6">
                                        <div class="form_field" data-field-id="title" data-field-flags="read_only"/>
                                        <div class="form_field" data-field-id="service_id" data-field-flags="read_only"/>
                                    </div>
                                    <div class="col-sm-6">
                                        <div class="form_field" data-field-id="caller_id" data-field-flags="read_only"/>
                                        <div class="form_field" data-field-id="servicesubcategory_id" data-field-flags="read_only"/>
                                    </div>
                                    <div class="col-sm-12">
                                        <div class="form_field" data-field-id="description" data-field-flags="read_only"/>
                                        <div class="form_field" data-field-id="solution" data-field-flags="read_only"/>
                                    </div>
                                    <div class="col-sm-6">
                                        <div class="form_field" data-field-id="user_satisfaction" data-field-flags="read_only"/>
                                    </div>
                                    <div class="col-sm-6">
                                        <div class="form_field" data-field-id="user_comment" data-field-flags="read_only"/>
                                    </div>
                                </fieldset>
                            </div>
                            <div class="col-sm-5">
                                <fieldset>
                                    <legend>{{'Ticket:Type'|dict_s}} &amp; {{'Ticket:date'|dict_s}}</legend>
                                    <div class="col-sm-6">
                                        <div class="form_field" data-field-id="status" data-field-flags="read_only"/>
                                        <div class="form_field" data-field-id="impact" data-field-flags="read_only"/>
                                        <div class="form_field" data-field-id="urgency" data-field-flags="read_only"/>
                                        <div class="form_field" data-field-id="priority" data-field-flags="read_only"/>
                                    </div>
                                    <div class="col-sm-6">
                                        <div class="form_field" data-field-id="start_date" data-field-flags="read_only"/>
                                        <div class="form_field" data-field-id="last_update" data-field-flags="read_only"/>
                                        <div class="form_field" data-field-id="resolution_date" data-field-flags="read_only"/>
                                        <div class="form_field" data-field-id="agent_id" data-field-flags="read_only"/>
                                    </div>
                                </fieldset>
                            </div>
                        </div>
                        <div>
                            <div class="form_field" data-field-id="contacts_list"/>
                            <div class="form_field" data-field-id="public_log"/>
                        </div>
                    </twig>
                    <modes>
                        <mode id="edit"/>
                        <mode id="view"/>
                    </modes>
                </form>
            </forms>
        </module_design>
      </module_designs>
    </itop_design>
    

    Thanks @Guillaume for your help !

     
  • Guillaume Lajarige

    Yep that is it! Keep in mind that you can either modify the Ticket form if you want the change to apply on all derivated classes or duplicate it only for the UserRequest.

    Glad it helped!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.