diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.hbs
index 64f90e27498..44a501021d4 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.hbs
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.hbs
@@ -2,6 +2,8 @@
{{#if isAuthorized }}
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.js
index cdaf4ae8b47..4f7f10346ea 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.js
@@ -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");
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/public/js/policy-edit.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/public/js/policy-edit.js
index 9b711ffc224..309f7ea6404 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/public/js/policy-edit.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/public/js/policy-edit.js
@@ -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"]);
}
};
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.view/public/js/view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.view/public/js/view.js
index 552aba52c31..c308acb65a2 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.view/public/js/view.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.view/public/js/view.js
@@ -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"]);
}
};
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.view/view.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.view/view.hbs
index 2b0af7b23de..ca5b9d39690 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.view/view.hbs
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.view/view.hbs
@@ -8,7 +8,8 @@
{{/defineZone}}
-
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.view/view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.view/view.js
index e8247821b69..af53c46116e 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.view/view.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.view/view.js
@@ -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;
}
\ No newline at end of file