Add policy type and corrective action UI for edit policy

feature/appm-store/pbac
Saad Sahibjan 5 years ago
parent 1d2444f16f
commit fc916d4e4c

@ -1,7 +1,8 @@
{{#zone "content"}} {{#zone "content"}}
{{#if isAuthorized }} {{#if isAuthorized }}
<span id="logged-in-user" class="hidden" data-username="{{@user.username}}" data-domain="{{@user.domain}}" <span id="logged-in-user" class="hidden" data-username="{{@user.username}}" data-domain="{{@user.domain}}"
data-tenant-id="{{@user.tenantId}}" data-iscloud="{{isCloud}}" data-storeapps="{{storeApps}}"></span> data-tenant-id="{{@user.tenantId}}" data-iscloud="{{isCloud}}" data-storeapps="{{storeApps}}"
data-corrective-policies="{{correctivePolicies}}"></span>
<span id="policy-operations" class="hidden" data-template="{{policyOperations.template}}" <span id="policy-operations" class="hidden" data-template="{{policyOperations.template}}"
data-script="{{policyOperations.script}}" data-style="{{policyOperations.style}}"></span> data-script="{{policyOperations.script}}" data-style="{{policyOperations.style}}"></span>
<div class="row"> <div class="row">
@ -16,15 +17,22 @@
<br class="c-both"/> <br class="c-both"/>
</div> </div>
<div class="col-md-3 col-xs-3"> <div class="col-md-3 col-xs-3">
<div class="itm-wiz" data-step="policy-criteria"> <div class="itm-wiz itm-wiz" data-step="policy-type">
<div class="wiz-no">2</div> <div class="wiz-no">2</div>
<div class="wiz-lbl hidden-xs"><span>Edit policy type</span></div>
</div>
<br class="c-both"/>
</div>
<div class="col-md-3 col-xs-3">
<div class="itm-wiz" data-step="policy-criteria">
<div class="wiz-no">3</div>
<div class="wiz-lbl hidden-xs"><span>Edit assignment groups</span></div> <div class="wiz-lbl hidden-xs"><span>Edit assignment groups</span></div>
</div> </div>
<br class="c-both"/> <br class="c-both"/>
</div> </div>
<div class="col-md-3 col-xs-3"> <div class="col-md-3 col-xs-3">
<div class="itm-wiz" data-step="policy-naming"> <div class="itm-wiz" data-step="policy-naming">
<div class="wiz-no">3</div> <div class="wiz-no">4</div>
<div class="wiz-lbl hidden-xs"><span>Republish to devices</span></div> <div class="wiz-lbl hidden-xs"><span>Republish to devices</span></div>
</div> </div>
<br class="c-both"/> <br class="c-both"/>
@ -48,7 +56,7 @@
<hr> <hr>
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-12">
<h4 class="visible-xs">Step 3: Republish to devices</h4> <h4 class="visible-xs">Step 4: Republish to devices</h4>
<br> <br>
<div id="policy-naming-main-error-msg" class="alert alert-danger hidden" role="alert"> <div id="policy-naming-main-error-msg" class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span> <i class="icon fw fw-error"></i><span></span>
@ -107,7 +115,7 @@
<hr> <hr>
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-12">
<h4 class="visible-xs">Step 2: Edit assignment groups</h4> <h4 class="visible-xs">Step 3: Edit assignment groups</h4>
<br> <br>
<div id="policy-criteria-main-error-msg" class="alert alert-danger hidden" role="alert"> <div id="policy-criteria-main-error-msg" class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span> <i class="icon fw fw-error"></i><span></span>
@ -196,7 +204,7 @@
</div> </div>
<div class="wr-input-control wr-btn-grp"> <div class="wr-input-control wr-btn-grp">
<a href="#" class="wr-btn wizard-stepper" data-is-back-btn="true" <a href="#" class="wr-btn wizard-stepper" data-is-back-btn="true"
data-current="policy-criteria" data-next="policy-profile"> data-current="policy-criteria" data-next="policy-type">
Back Back
</a> </a>
<a href="#" class="wr-btn wizard-stepper" data-current="policy-criteria" <a href="#" class="wr-btn wizard-stepper" data-current="policy-criteria"
@ -209,6 +217,53 @@
</div> </div>
</div> </div>
<div class="col-centered wr-content policy-type hidden">
<div class="wr-form">
<h1 id="policy-type-page-wizard-title" class="page-sub-title">EDIT POLICY</h1>
<hr>
<div id="policy-type-wizard-steps" class="row wr-wizard"></div>
<hr>
<div class="row">
<div class="col-lg-12">
<h4 class="visible-xs"> Step 2: Select policy type</h4>
<br>
<div id="policy-type-main-error-msg" class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span>
</div>
<div>
<div class="wr-input-control">
<label class="wr-input-control radio light">
<input type="radio" id="policy-type-general" name="policy-type-radio-btn"
value="GENERAL"/>
<span class="helper">General Policy</span>
</label>
<label class="wr-input-control radio light">
<input type="radio" id="policy-type-corrective" name="policy-type-radio-btn"
value="CORRECTIVE"/>
<span class="helper">Corrective Policy</span>
</label>
</div>
</div>
<div class='policy-type-loading-corrective-actions'>
<br/>
<i class='fw fw-settings fw-spin fw-2x'></i>
Loading corrective actions . . .
<br/>
<br/>
</div>
<div id="select-general-policy-type"></div>
<div class="wr-input-control wr-btn-grp">
<a href="#" class="wr-btn wizard-stepper" data-is-back-btn="true"
data-current="policy-type" data-next="policy-profile">Back</a>
<a href="#" class="wr-btn wizard-stepper"
data-current="policy-type"
data-next="policy-criteria" data-validate="false">Continue</a>
</div>
</div>
</div>
</div>
</div>
<div class="col-centered wr-content policy-profile"> <div class="col-centered wr-content policy-profile">
<div class="wr-form"> <div class="wr-form">
<h1 id="policy-profile-page-wizard-title" class="page-sub-title">EDIT POLICY</h1> <h1 id="policy-profile-page-wizard-title" class="page-sub-title">EDIT POLICY</h1>
@ -238,7 +293,7 @@
</div> </div>
<div class="wr-input-control wr-btn-grp"> <div class="wr-input-control wr-btn-grp">
<a href="#" class="wr-btn wizard-stepper" data-current="policy-profile" <a href="#" class="wr-btn wizard-stepper" data-current="policy-profile"
data-next="policy-criteria" data-validate="true"> data-next="policy-type" data-validate="true">
Continue Continue
</a> </a>
</div> </div>

@ -84,5 +84,7 @@ function onRequest(context) {
var enrollmentApps = policyModule.getStoreAppsForPolicy(); var enrollmentApps = policyModule.getStoreAppsForPolicy();
context["storeApps"] = JSON.stringify(enrollmentApps["content"]); context["storeApps"] = JSON.stringify(enrollmentApps["content"]);
context["correctivePolicies"] = JSON.stringify(policyModule.getAllPoliciesByType("CORRECTIVE")["content"]);
return context; return context;
} }

@ -42,6 +42,7 @@ var currentlyEffected = {};
var validateInline = {}; var validateInline = {};
var clearInline = {}; var clearInline = {};
var hasPolicyProfileScript = false; var hasPolicyProfileScript = false;
var isCorrectiveActionProfileAdded = false;
var enableInlineError = function (inputField, errorMsg, errorSign) { var enableInlineError = function (inputField, errorMsg, errorSign) {
var fieldIdentifier = "#" + inputField; var fieldIdentifier = "#" + inputField;
@ -148,7 +149,6 @@ $("#policy-name-input").focus(function () {
skipStep["policy-platform"] = function (policyPayloadObj) { skipStep["policy-platform"] = function (policyPayloadObj) {
policy["name"] = policyPayloadObj["policyName"]; policy["name"] = policyPayloadObj["policyName"];
policy["platform"] = policyPayloadObj["profile"]["deviceType"]; policy["platform"] = policyPayloadObj["profile"]["deviceType"];
policy["policyType"] = policyPayloadObj["policyType"];
var userRoleInput = $("#user-roles-input"); var userRoleInput = $("#user-roles-input");
var ownershipInput = $("#ownership-input"); var ownershipInput = $("#ownership-input");
@ -161,6 +161,8 @@ skipStep["policy-platform"] = function (policyPayloadObj) {
currentlyEffected["roles"] = policyPayloadObj.roles; currentlyEffected["roles"] = policyPayloadObj.roles;
currentlyEffected["users"] = policyPayloadObj.users; currentlyEffected["users"] = policyPayloadObj.users;
currentlyEffected["groups"] = []; currentlyEffected["groups"] = [];
currentlyEffected["policyType"] = policyPayloadObj.policyType;
currentlyEffected["correctiveActions"] = policyPayloadObj.correctiveActions;
if (policyPayloadObj.deviceGroups) { if (policyPayloadObj.deviceGroups) {
var deviceGroups = policyPayloadObj.deviceGroups; var deviceGroups = policyPayloadObj.deviceGroups;
@ -278,6 +280,71 @@ stepForwardFrom["policy-profile"] = function () {
*/ */
policy["profile"] = generatePolicyProfile(); policy["profile"] = generatePolicyProfile();
} }
var policyType = currentlyEffected.policyType;
$("input[name=policy-type-radio-btn][value=" + policyType + "]").prop("checked", true);
// add policy correction action page
if (!isCorrectiveActionProfileAdded) {
var policyCorrectiveActionTemplateSrc =
"/public/cdmf.unit.policy.corrective-action/templates/policy-corrective-action.hbs";
var policyCorrectiveActionScriptSrc =
"/public/cdmf.unit.policy.corrective-action/js/policy-corrective-action.js";
var policyCorrectiveActionTemplateCacheKey = "policy-corrective-action";
$.template(policyCorrectiveActionTemplateCacheKey, context + policyCorrectiveActionTemplateSrc,
function (template) {
var content = template(
{
"deviceType": policy["platform"],
"correctivePolicies": $("#logged-in-user").data("corrective-policies")
}
);
$("#select-general-policy-type").html(content);
if ("GENERAL" === policyType && currentlyEffected.correctiveActions &&
currentlyEffected.correctiveActions.length > 0) {
currentlyEffected.correctiveActions.forEach(function (correctiveAction) {
if ("POLICY" === correctiveAction.actionType) {
$("#corrective-policy-input").val(correctiveAction.policyId);
// returned from for each since currently only supported corrective action type is
// POLICY.
return true;
}
});
}
});
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = context + policyCorrectiveActionScriptSrc;
document.head.prepend(script);
isCorrectiveActionProfileAdded = true;
}
$(".policy-type-loading-corrective-actions").addClass("hidden");
// updating next-page wizard title with selected platform
$("#policy-type-page-wizard-title").text("EDIT " + policy["platform"] + " POLICY - " + policy["name"]);
};
/**
* Forward action of policy type page.
*/
stepForwardFrom["policy-type"] = function () {
policy["type"] = $("input[name=policy-type-radio-btn]:checked").val();
var correctiveActionList = [];
if (policy.type === "GENERAL") {
var selectedCorrectivePolicyId = $("#corrective-policy-input").val();
if (selectedCorrectivePolicyId !== "none") {
var correctiveAction = {
"actionType": "POLICY",
"policyId": selectedCorrectivePolicyId
};
correctiveActionList.push(correctiveAction);
}
}
policy["correctiveActionList"] = correctiveActionList;
// updating next-page wizard title with selected platform // updating next-page wizard title with selected platform
$("#policy-criteria-page-wizard-title").text("EDIT " + policy["platform"] + " POLICY - " + policy["name"]); $("#policy-criteria-page-wizard-title").text("EDIT " + policy["platform"] + " POLICY - " + policy["name"]);
}; };
@ -489,9 +556,10 @@ var updatePolicy = function (policy, state) {
var payload = { var payload = {
"policyName": policy["policyName"], "policyName": policy["policyName"],
"description": policy["description"], "description": policy["description"],
"policyType": policy["policyType"],
"compliance": policy["selectedNonCompliantAction"], "compliance": policy["selectedNonCompliantAction"],
"ownershipType": null, "ownershipType": null,
"policyType": policy["type"],
"correctiveActions": policy["correctiveActionList"],
"profile": { "profile": {
"profileName": policy["policyName"], "profileName": policy["policyName"],
"deviceType": policy["platform"], "deviceType": policy["platform"],
@ -696,6 +764,16 @@ $(document).ready(function () {
$("#policy-profile-wizard-steps").html($(".wr-steps").html()); $("#policy-profile-wizard-steps").html($(".wr-steps").html());
isCorrectiveActionProfileAdded = false;
$('input[type=radio][name=policy-type-radio-btn]').change(function() {
if ($(this).val() === "CORRECTIVE") {
$("#select-general-policy-type").addClass("hidden");
} else {
$("#select-general-policy-type").removeClass("hidden");
}
});
$(".wizard-stepper").click(function () { $(".wizard-stepper").click(function () {
// button clicked here can be either a continue button or a back button. // button clicked here can be either a continue button or a back button.
var currentStep = $(this).data("current"); var currentStep = $(this).data("current");

Loading…
Cancel
Save