Refactoring policy view and edit units

Refactored the units policy.view and policy.edit to be consistant with policy.create unit. Related to IOTS-296
revert-70aa11f8
Madawa Soysa 8 years ago
parent bb7286c2d5
commit a28458cf13

@ -2,6 +2,8 @@
{{#if isAuthorized }}
<span id="logged-in-user" class="hidden" data-username="{{user.username}}" data-domain="{{user.domain}}"
data-tenant-id="{{user.tenantId}}"></span>
<span id="policy-operations" class="hidden" data-template="{{policyOperations.template}}"
data-script="{{policyOperations.script}}" data-style="{{policyOperations.style}}"></span>
<div class="row">
<div class="col-md-12">

@ -17,8 +17,8 @@
*/
function onRequest(context) {
var log = new Log("policy-view-edit-unit backend js");
var deviceType = request.getParameter("deviceType");
var utility = require("/app/modules/utility.js").utility;
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"];
@ -31,12 +31,30 @@ function onRequest(context) {
if (usersResult.status == "success") {
context.users = usersResult.content;
}
context["groups"] = groupModule.getGroups();
var user = userModule.getCarbonUser();
context["user"] = {username: user.username, domain: user.domain, tenantId: user.tenantId};
context["policyOperations"] = {};
var policyEditSrc = "/app/units/" + utility.getTenantedDeviceUnitName(deviceType, "policy-edit");
if (new File(policyEditSrc).isExists()) {
var policyOperationsTemplateSrc = policyEditSrc + "/public/templates/" + deviceType + "-policy-edit.hbs";
if (new File(policyOperationsTemplateSrc).isExists()) {
context["policyOperations"].template = "/public/cdmf.unit.device.type." + deviceType +
".policy-edit/templates/" + deviceType + "-policy-edit.hbs";
}
var policyOperationsScriptSrc = policyEditSrc + "/public/js/" + deviceType + "-policy-edit.js";
if (new File(policyOperationsScriptSrc).isExists()) {
context["policyOperations"].script = "/public/cdmf.unit.device.type." + deviceType + ".policy-edit/js/" +
deviceType + "-policy-edit.js";
}
var policyOperationsStylesSrc = policyEditSrc + "/public/css/" + deviceType + "-policy-edit.css";
if (new File(policyOperationsStylesSrc).isExists()) {
context["policyOperations"].style = "/public/cdmf.unit.device.type." + deviceType + ".policy-edit/css/" +
deviceType + "-policy-edit.css";
}
}
context.isAuthorized = userModule.isAuthorized("/permission/admin/device-mgt/policies/manage");
context.isAuthorizedViewUsers = userModule.isAuthorized("/permission/admin/device-mgt/roles/view");
context.isAuthorizedViewRoles = userModule.isAuthorized("/permission/admin/device-mgt/users/view");

@ -179,52 +179,47 @@ skipStep["policy-platform"] = function (policyPayloadObj) {
$("#policy-profile-page-wizard-title").text("EDIT " + policy["platform"] + " POLICY - " + policy["name"]);
var deviceType = policy["platform"];
var policyOperationsTemplateSrc = context + '/public/cdmf.unit.device.type.' + deviceType +
'.policy-edit/templates/' + deviceType + '-policy-edit.hbs';
var policyOperationsScriptSrc = context + '/public/cdmf.unit.device.type.' + deviceType +
'.policy-edit/js/' + deviceType + '-policy-edit.js';
var policyOperationsStylesSrc = context + '/public/cdmf.unit.device.type.' + deviceType +
'.policy-edit/css/' + deviceType + '-policy-edit.css';
var policyOperationsTemplateCacheKey = deviceType + '-policy-operations';
$.isResourceExists(policyOperationsTemplateSrc, function (status) {
if (status) {
$.template(policyOperationsTemplateCacheKey, policyOperationsTemplateSrc, function (template) {
var content = template();
$("#device-type-policy-operations").html(content).removeClass("hidden");
$(".policy-platform").addClass("hidden");
$.isResourceExists(policyOperationsScriptSrc, function (status) {
if (status) {
hasPolicyProfileScript = true;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = policyOperationsScriptSrc;
$(".wr-advance-operations").prepend(script);
/*
This method should be implemented in the relevant plugin side and should include the logic to
populate the policy profile in the plugin specific UI.
*/
polulateProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]);
}
});
});
$.isResourceExists(policyOperationsStylesSrc, function (status) {
if (status) {
var style = document.createElement('link');
style.type = 'text/css';
style.rel = 'stylesheet';
style.href = policyOperationsStylesSrc;
$(".wr-advance-operations").prepend(style);
}
});
var policyOperations = $("#policy-operations");
var policyEditTemplateSrc = $(policyOperations).data("template");
var policyEditScriptSrc = $(policyOperations).data("script");
var policyEditStylesSrc = $(policyOperations).data("style");
var policyEditTemplateCacheKey = deviceType + '-policy-edit';
if (policyEditTemplateSrc) {
if (policyEditScriptSrc) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = context + policyEditScriptSrc;
$(".wr-advance-operations").prepend(script);
hasPolicyProfileScript = true;
} else {
$("#generic-policy-operations").removeClass("hidden");
hasPolicyProfileScript = false;
}
$(".wr-advance-operations-init").addClass("hidden");
});
$.template(policyEditTemplateCacheKey, context + policyEditTemplateSrc, function (template) {
var content = template();
$("#device-type-policy-operations").html(content).removeClass("hidden");
$(".policy-platform").addClass("hidden");
if (hasPolicyProfileScript) {
/*
This method should be implemented in the relevant plugin side and should include the logic to
populate the policy profile in the plugin specific UI.
*/
polulateProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]);
}
});
} else {
$("#generic-policy-operations").removeClass("hidden");
}
if (policyEditStylesSrc) {
var style = document.createElement('link');
style.type = 'text/css';
style.rel = 'stylesheet';
style.href = context + policyEditStylesSrc;
$(".wr-advance-operations").prepend(style);
}
$(".wr-advance-operations-init").addClass("hidden");
if(!hasPolicyProfileScript) {
if (!hasPolicyProfileScript) {
populateGenericProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]);
}
};

@ -67,52 +67,47 @@ var displayPolicy = function (policyPayloadObj) {
}
var deviceType = policy["platform"];
var policyOperationsTemplateSrc = context + '/public/cdmf.unit.device.type.' + deviceType +
'.policy-view/templates/' + deviceType + '-policy-view.hbs';
var policyOperationsScriptSrc = context + '/public/cdmf.unit.device.type.' + deviceType +
'.policy-view/js/' + deviceType + '-policy-view.js';
var policyOperationsStylesSrc = context + '/public/cdmf.unit.device.type.' + deviceType +
'.policy-view/css/' + deviceType + '-policy-view.css';
var policyOperationsTemplateCacheKey = deviceType + '-policy-operations';
var policyOperations = $("#policy-operations");
var policyViewTemplateSrc = $(policyOperations).data("template");
var policyViewScriptSrc = $(policyOperations).data("script");
var policyViewStylesSrc = $(policyOperations).data("style");
var policyViewTemplateCacheKey = deviceType + '-policy-view';
$.isResourceExists(policyOperationsTemplateSrc, function (status) {
if (status) {
$.template(policyOperationsTemplateCacheKey, policyOperationsTemplateSrc, function (template) {
var content = template();
$("#device-type-policy-operations").html(content).removeClass("hidden");
$(".policy-platform").addClass("hidden");
$.isResourceExists(policyOperationsScriptSrc, function (status) {
if (status) {
hasPolicyProfileScript = true;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = policyOperationsScriptSrc;
$(".wr-advance-operations").prepend(script);
/*
This method should be implemented in the relevant plugin side and should include the logic to
populate the policy profile in the plugin specific UI.
*/
polulateProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]);
}
});
});
$.isResourceExists(policyOperationsStylesSrc, function (status) {
if (status) {
var style = document.createElement('link');
style.type = 'text/css';
style.rel = 'stylesheet';
style.href = policyOperationsStylesSrc;
$(".wr-advance-operations").prepend(style);
}
});
if (policyViewTemplateSrc) {
if (policyViewScriptSrc) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = context + policyViewScriptSrc;
$(".wr-advance-operations").prepend(script);
hasPolicyProfileScript = true;
} else {
$("#generic-policy-operations").removeClass("hidden");
hasPolicyProfileScript = false;
}
$(".wr-advance-operations-init").addClass("hidden");
});
$.template(policyViewTemplateCacheKey, context + policyViewTemplateSrc, function (template) {
var content = template();
$("#device-type-policy-operations").html(content).removeClass("hidden");
$(".policy-platform").addClass("hidden");
if (hasPolicyProfileScript) {
/*
This method should be implemented in the relevant plugin side and should include the logic to
populate the policy profile in the plugin specific UI.
*/
polulateProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]);
}
});
} else {
$("#generic-policy-operations").removeClass("hidden");
}
if (policyViewStylesSrc) {
var style = document.createElement('link');
style.type = 'text/css';
style.rel = 'stylesheet';
style.href = context + policyViewStylesSrc;
$(".wr-advance-operations").prepend(style);
}
$(".wr-advance-operations-init").addClass("hidden");
if(!hasPolicyProfileScript) {
if (!hasPolicyProfileScript) {
populateGenericProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]);
}
};

@ -8,7 +8,8 @@
</div>
</div>
{{/defineZone}}
<span id="policy-operations" class="hidden" data-template="{{template}}" data-script="{{script}}"
data-style="{{style}}"></span>
<!-- #page-content-wrapper -->
<div class="page-content-wrapper">
<div class="row no-gutter add-padding-5x add-margin-top-5x" style="border: 1px solid #e4e4e4;">

@ -17,10 +17,27 @@
*/
function onRequest(context) {
// var log = new Log("policy-view-edit-unit backend js");
// var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
// context.roles = userModule.getRoles();
context.isAuthorized = userModule.isAuthorized("/permission/admin/device-mgt/policies/view");
return context;
var utility = require("/app/modules/utility.js").utility;
var page = {};
var deviceType = request.getParameter("deviceType");
var policyViewSrc = "/app/units/" + utility.getTenantedDeviceUnitName(deviceType, "policy-view");
if (new File(policyViewSrc).isExists()) {
var policyOperationsTemplateSrc = policyViewSrc + "/public/templates/" + deviceType + "-policy-view.hbs";
if (new File(policyOperationsTemplateSrc).isExists()) {
page.template = "/public/cdmf.unit.device.type." + deviceType + ".policy-view/templates/" + deviceType +
"-policy-view.hbs";
}
var policyOperationsScriptSrc = policyViewSrc + "/public/js/" + deviceType + "-policy-view.js";
if (new File(policyOperationsScriptSrc).isExists()) {
page.script = "/public/cdmf.unit.device.type." + deviceType + ".policy-view/js/" + deviceType +
"-policy-view.js";
}
var policyOperationsStylesSrc = policyViewSrc + "/public/css/" + deviceType + "-policy-view.css";
if (new File(policyOperationsStylesSrc).isExists()) {
page.style = "/public/cdmf.unit.device.type." + deviceType + ".policy-view/css/" + deviceType +
"-policy-view.css";
}
}
page.isAuthorized = userModule.isAuthorized("/permission/admin/device-mgt/policies/view");
return page;
}
Loading…
Cancel
Save