Suppose you want to add custom radio button field to webapp create page. Say the custom radio button field name is "App Category".
First, Let's see how to add a custom field to UI (Jaggery APIs).
- Modify <APPM_HOME>/repository/resources/rxt/webapp.rxt.
- Login to Management console and navigate to Home > Extensions > Configure > Artifact Types and delete "webapp.rxt"
- Add below code snippet to the required place of <APPM_HOME>repository/deployment/server/jageeryapps/publisher/themes/appm/partials/add-asset.hbs
- Add below code snippet to <APPM_HOME>/repository/deployment/server/jaggeryapps/publisher/themes/appm/partials/edit-asset.hbs.
- To save selected radio button value in registry, you need to add below function inside $(document ).ready(function() {} of <APPM_HOME>/repository/deployment/server/jaggeryapps/publisher/themes/appm/js/resource-add.js
- To preview the selected radio button value in app edit page, add below code snippet inside $(document ).ready(function() {} of <APPM_HOME>/repository/deployment/server/jaggeryapps/publisher/themes/appm/js/resource-edit.js.
- When you create a new version of an existing webapp, to copy the selected radio button value to the new version, add below line to<APPM_HOME>/repository/deployment/server/jaggeryapps/publisher/themes/appm/partials/copy-app.hbs
- Go to Main -> Browse -> in Management console and navigate to /_system/governance/appmgt/applicationdata/custom-property-definitions/webapp.json and click on "Edit As Text". Add the custom fields which you want to add.
- Restart App Manager.
- Web app create page with the newly added radio button will be shown as below.
Note : If you don't want add the custom field as mandatory, required="true" part is not necessary.
<field type="text" required="true"> <name>App Category</name> </field>
<div class="form-group"> <label class="control-label col-sm-2">App Category: </label> <div class="col-sm-10"> <div class="radio"> <label> <input type="radio" data-value="free" class="appCategoryRadio" name="appCategoryRadio"> Free </label> </div> <div class="radio"> <label> <input type="radio" data-value="premium" class="appCategoryRadio" name="appCategoryRadio"> Premium </label> </div> </div> </div> <input type="hidden" class="col-lg-6 col-sm-12 col-xs-12" name="overview_appCategory" id="overview_appCategory">
<div class="form-group"> <label class="control-label col-sm-2">App Category: </label> <div class="col-sm-10"> <div class="radio"> <label> <input type="radio" data-value="free" class="appCategoryRadio" name="appCategoryRadio"> Free </label> </div> <div class="radio"> <label> <input type="radio" data-value="premium" class="appCategoryRadio" name="appCategoryRadio"> Premium </label> </div> </div> </div> <input type="hidden" value="{{{snoop "fields(name=overview_appCategory).value" data}}}" class="col-lg-6 col-sm-12 col-xs-12" name="overview_appCategory" id="overview_appCategory">
$(".appCategoryRadio").click(function(){ var output = []; $( ".appCategoryRadio" ).each(function( index ) { var categoryValue = $(this).data('value'); if( $(this).is(':checked')){ output.push(categoryValue); } }); $('#overview_appCategory').val(output); });
$(".appCategoryRadio").click(function(){ var output = []; $( ".appCategoryRadio" ).each(function( index ) { var categoryValue = $(this).data('value'); if( $(this).is(':checked')){ output.push(categoryValue); } }); $('#overview_appCategory').val(output); }); var appCategoryValue = $('#overview_appCategory').val().split(','); $( ".appCategoryRadio" ).each(function( index ) { var value = $(this).data('value'); if($.inArray(value, appCategoryValue) >= 0){ $(this).prop('checked', true); } });
<input type='text' value="{{{snoop "fields(name=overview_appCategory).value" data}}}" name="overview_appCategory" id="overview_appCategory"/>
Now, Let's see how to add customized fields to the REST APIs.
{ "customPropertyDefinitions": [ {"name":"overview_appCategory"} ] }
No comments:
Post a Comment