diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs
index 09e414aa7b..eb97eb8623 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs
@@ -299,6 +299,9 @@
data-current="policy-platform"
data-next="policy-profile"
data-platform="{{name}}"
+ data-template="{{template}}"
+ data-script="{{script}}"
+ data-style="{{style}}"
data-validate="false">
{{label}}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.js
index f467aa9222..1b945e5e7c 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.js
@@ -43,10 +43,25 @@ function onRequest(context) {
if (configs && configs[DTYPE_CONF_DEVICE_TYPE_KEY][DTYPE_CONF_DEVICE_TYPE_LABEL_KEY]) {
deviceTypeLabel = configs[DTYPE_CONF_DEVICE_TYPE_KEY][DTYPE_CONF_DEVICE_TYPE_LABEL_KEY];
}
- var policyWizard = new File("/app/units/" + utility.getTenantedDeviceUnitName(deviceType, "policy-wizard"));
- if(policyWizard.isExists()){
+ var policyWizardSrc = "/app/units/" + utility.getTenantedDeviceUnitName(deviceType, "policy-wizard");
+ if (new File(policyWizardSrc).isExists()) {
content["icon"] = utility.getDeviceThumb(deviceType);
content["label"] = deviceTypeLabel;
+ var policyOperationsTemplateSrc = policyWizardSrc + "/public/templates/" + deviceType + "-policy-operations.hbs";
+ if (new File(policyOperationsTemplateSrc).isExists()) {
+ content["template"] = "/public/cdmf.unit.device.type." + deviceType +
+ ".policy-wizard/templates/" + deviceType + "-policy-operations.hbs";
+ }
+ var policyOperationsScriptSrc = policyWizardSrc + "/public/js/" + deviceType + "-policy-operations.js";
+ if (new File(policyOperationsScriptSrc).isExists()) {
+ content["script"] = "/public/cdmf.unit.device.type." + deviceType +
+ ".policy-wizard/js/" + deviceType + "-policy-operations.js";;
+ }
+ var policyOperationsStylesSrc = policyWizardSrc + "/public/css/" + deviceType + "-policy-operations.css";
+ if (new File(policyOperationsStylesSrc).isExists()) {
+ content["style"] = "/public/cdmf.unit.device.type." + deviceType +
+ ".policy-wizard/css/" + deviceType + "-policy-operations.css";;
+ }
types["types"].push(content);
}
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/public/js/policy-create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/public/js/policy-create.js
index d7d7b99f14..f615fb4990 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/public/js/policy-create.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/public/js/policy-create.js
@@ -139,45 +139,34 @@ stepForwardFrom["policy-platform"] = function (actionButton) {
$("#policy-profile-page-wizard-title").text("ADD " + policy["platform"] + " POLICY");
var deviceType = policy["platform"];
- var policyOperationsTemplateSrc = context + '/public/cdmf.unit.device.type.' + deviceType +
- '.policy-wizard/templates/' + deviceType + '-policy-operations.hbs';
- var policyOperationsScriptSrc = context + '/public/cdmf.unit.device.type.' + deviceType +
- '.policy-wizard/js/' + deviceType + '-policy-operations.js';
- var policyOperationsStylesSrc = context + '/public/cdmf.unit.device.type.' + deviceType +
- '.policy-wizard/css/' + deviceType + '-policy-operations.css';
+ var policyOperationsTemplateSrc = $(actionButton).data("template");
+ var policyOperationsScriptSrc = $(actionButton).data("script");
+ var policyOperationsStylesSrc = $(actionButton).data("style");
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) {
- var script = document.createElement('script');
- script.type = 'text/javascript';
- script.src = policyOperationsScriptSrc;
- $(".wr-advance-operations").prepend(script);
- }
- });
-
- $.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);
- }
- });
- } else {
- $("#generic-policy-operations").removeClass("hidden");
- }
- $(".wr-advance-operations-init").addClass("hidden");
- });
+ if (policyOperationsTemplateSrc) {
+ $.template(policyOperationsTemplateCacheKey, context + policyOperationsTemplateSrc, function (template) {
+ var content = template();
+ $("#device-type-policy-operations").html(content).removeClass("hidden");
+ $(".policy-platform").addClass("hidden");
+ });
+ } else {
+ $("#generic-policy-operations").removeClass("hidden");
+ }
+ if (policyOperationsScriptSrc) {
+ var script = document.createElement('script');
+ script.type = 'text/javascript';
+ script.src = context + policyOperationsScriptSrc;
+ $(".wr-advance-operations").prepend(script);
+ }
+ if (policyOperationsStylesSrc) {
+ var style = document.createElement('link');
+ style.type = 'text/css';
+ style.rel = 'stylesheet';
+ style.href = context + policyOperationsStylesSrc;
+ $(".wr-advance-operations").prepend(style);
+ }
+ $(".wr-advance-operations-init").addClass("hidden");
};
/**
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/public/js/policy-create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/public/js/policy-create.js
deleted file mode 100644
index fd2bf3ff4f..0000000000
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/public/js/policy-create.js
+++ /dev/null
@@ -1,534 +0,0 @@
-/*
- *
- * WSO2 Inc. licenses this file to you under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
- * either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-var validateStep = {};
-var stepForwardFrom = {};
-var stepBackFrom = {};
-var policy = {};
-var configuredOperations = [];
-var validateInline = {};
-var clearInline = {};
-
-var enableInlineError = function (inputField, errorMsg, errorSign) {
- var fieldIdentifier = "#" + inputField;
- var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
- var errorSignIdentifier = "#" + inputField + " ." + errorSign;
-
- if (inputField) {
- $(fieldIdentifier).addClass(" has-error has-feedback");
- }
-
- if (errorMsg) {
- $(errorMsgIdentifier).removeClass(" hidden");
- }
-
- if (errorSign) {
- $(errorSignIdentifier).removeClass(" hidden");
- }
-};
-
-var disableInlineError = function (inputField, errorMsg, errorSign) {
- var fieldIdentifier = "#" + inputField;
- var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
- var errorSignIdentifier = "#" + inputField + " ." + errorSign;
-
- if (inputField) {
- $(fieldIdentifier).removeClass(" has-error has-feedback");
- }
-
- if (errorMsg) {
- $(errorMsgIdentifier).addClass(" hidden");
- }
-
- if (errorSign) {
- $(errorSignIdentifier).addClass(" hidden");
- }
-};
-
-/**
- *clear inline validation messages.
- */
-clearInline["policy-name"] = function () {
- disableInlineError("policyNameField", "nameEmpty", "nameError");
-};
-
-
-/**
- * Validate if provided policy name is valid against RegEx configures.
- */
-validateInline["policy-name"] = function () {
- var policyName = $("input#policy-name-input").val();
- if (policyName && inputIsValidAgainstLength(policyName, 1, 30)) {
- disableInlineError("policyNameField", "nameEmpty", "nameError");
- } else {
- enableInlineError("policyNameField", "nameEmpty", "nameError");
- }
-};
-
-$("#policy-name-input").focus(function(){
- clearInline["policy-name"]();
-}).blur(function(){
- validateInline["policy-name"]();
-});
-
-stepForwardFrom["policy-platform"] = function (actionButton) {
- policy["platform"] = $(actionButton).data("platform");
- policy["platformId"] = $(actionButton).data("platform-type");
- // updating next-page wizard title with selected platform
- $("#policy-profile-page-wizard-title").text("ADD " + policy["platform"] + " POLICY");
-
- var deviceType = policy["platform"];
- var policyOperationsTemplateSrc = context + '/public/cdmf.unit.device.type.' + deviceType +
- '.policy-wizard/templates/' + deviceType + '-policy-operations.hbs';
- var policyOperationsScriptSrc = context + '/public/cdmf.unit.device.type.' + deviceType +
- '.policy-wizard/js/' + deviceType + '-policy-operations.js';
- var policyOperationsStylesSrc = context + '/public/cdmf.unit.device.type.' + deviceType +
- '.policy-wizard/css/' + deviceType + '-policy-operations.css';
- var policyOperationsTemplateCacheKey = deviceType + '-policy-operations';
-
- $.isResourceExists(policyOperationsTemplateSrc, function (status) {
- if (status) {
- $.template(policyOperationsTemplateCacheKey, policyOperationsTemplateSrc, function (template) {
- var content = template();
- $(".wr-advance-operations").html(content);
- $(".policy-platform").addClass("hidden");
- });
- }
- });
-
- $.isResourceExists(policyOperationsScriptSrc, function (status) {
- if (status) {
- var script = document.createElement('script');
- script.type = 'text/javascript';
- script.src = policyOperationsScriptSrc;
- $(".wr-advance-operations").prepend(script);
- }
- });
-
- $.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);
- }
- });
-};
-
-stepForwardFrom["policy-profile"] = function () {
- policy["profile"] = operationModule.generateProfile(policy["platform"], configuredOperations);
- // updating next-page wizard title with selected platform
- $("#policy-criteria-page-wizard-title").text("ADD " + policy["platform"] + " POLICY");
-};
-
-stepBackFrom["policy-profile"] = function () {
- // reinitialize configuredOperations
- configuredOperations = [];
- // clearing already-loaded platform specific hidden-operations html content from the relevant div
- // so that, the wrong content would not be shown at the first glance, in case
- // the user selects a different platform
- $(".wr-advance-operations").html(
- "