From 289987db8ebaa22ba6042c750d6aca374e323c4c Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Wed, 7 Dec 2016 12:05:48 +0530 Subject: [PATCH 1/5] Throwing exception on getDevice when device is not found --- .../core/service/DeviceManagementProviderServiceImpl.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index aa6a9ba0803..fff5607ecfe 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -823,11 +823,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv DeviceManagementDAOFactory.openConnection(); device = deviceDAO.getDevice(deviceId, this.getTenantId()); if (device == null) { + String msg = "No device is found upon the type '" + deviceId.getType() + "' and id '" + + deviceId.getId() + "'"; if (log.isDebugEnabled()) { - log.debug("No device is found upon the type '" + deviceId.getType() + "' and id '" + - deviceId.getId() + "'"); + log.debug(msg); } - return null; + throw new DeviceManagementException(msg); } DeviceInfo info = deviceInfoDAO.getDeviceInformation(device.getId()); DeviceLocation location = deviceInfoDAO.getDeviceLocation(device.getId()); From 4e0730f50c8165b58e9e2361cabb5d1c784b09d2 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Wed, 7 Dec 2016 12:06:22 +0530 Subject: [PATCH 2/5] Fixing device identifier is null issue --- .../device/type/deployer/template/dao/DeviceTypePluginDAO.java | 1 + 1 file changed, 1 insertion(+) diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAO.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAO.java index ee4f6071b72..163ac647114 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAO.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAO.java @@ -67,6 +67,7 @@ public class DeviceTypePluginDAO { if (resultSet.next()) { device = new Device(); + device.setDeviceIdentifier(deviceId); if (log.isDebugEnabled()) { log.debug(deviceId + " data has been fetched from " + deviceDAODefinition.getDeviceTableName() + " database."); From da2fd787c48be37d7c0334a868ca8be8b7d73b6c Mon Sep 17 00:00:00 2001 From: Imesh Chandrasiri Date: Wed, 7 Dec 2016 12:50:23 +0530 Subject: [PATCH 3/5] Fix for datatable icon not showing issue --- .../public/css/custom-desktop.css | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-desktop.css b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-desktop.css index 211de751132..5ecc4e2118b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-desktop.css +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-desktop.css @@ -6526,4 +6526,41 @@ select > option:hover { } .table.list-table:not(.grid-view) tbody{ margin: 0px !important; -} \ No newline at end of file +} + +#user-grid td i { + padding-right: 5px; +} + + +/** + * + * Temporary responsive fix for table listing action button width issue + * Todo : Move responsive style to theme.less file + * +**/ +@media (max-width: 1199px) and (min-width: 992px){ + .table .fw-stack{ + font-size: 12px; + } +} + +@media (min-width: 1200px){ + table tbody tr { + width: 18% !important; + } + .table .fw-stack{ + font-size: 1.2vw; + } +} + +@media (min-width: 1500px){ + table tbody tr { + width: 14% !important; + } + .table .fw-stack{ + font-size: 0.8vw; + } +} + +/** End **/ From 641cc58bbf86f1f0a2deb642ee395917ec66f06b Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Wed, 7 Dec 2016 14:37:10 +0530 Subject: [PATCH 4/5] Fixing enrollment broken issue --- .../mgt/core/service/DeviceManagementProviderService.java | 6 ++++++ .../core/service/DeviceManagementProviderServiceImpl.java | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index 317f875b1cc..626203c304d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -220,6 +220,12 @@ public interface DeviceManagementProviderService { boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException; + /** + * Returns the device of specified id. + * @param deviceId device Id + * @return Device returns null when device is not avaialble. + * @throws DeviceManagementException + */ Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException; Device getDevice(DeviceIdentifier deviceId, Date since) throws DeviceManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index fff5607ecfe..d0b4f58a36b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -828,7 +828,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv if (log.isDebugEnabled()) { log.debug(msg); } - throw new DeviceManagementException(msg); + return null; } DeviceInfo info = deviceInfoDAO.getDeviceInformation(device.getId()); DeviceLocation location = deviceInfoDAO.getDeviceLocation(device.getId()); From 4b5c69d2d7b78a4601986a42318da0f331ce0e71 Mon Sep 17 00:00:00 2001 From: charitha Date: Wed, 7 Dec 2016 14:40:56 +0530 Subject: [PATCH 5/5] Update the way we are checking existence of policy operations. --- .../units/cdmf.unit.policy.create/create.hbs | 3 + .../units/cdmf.unit.policy.create/create.js | 19 +- .../public/js/policy-create.js | 63 +-- .../public/js/policy-create.js | 534 ------------------ .../units/cdmf.unit.policy.wizard/wizard.hbs | 244 -------- .../units/cdmf.unit.policy.wizard/wizard.js | 47 -- .../units/cdmf.unit.policy.wizard/wizard.json | 3 - 7 files changed, 46 insertions(+), 867 deletions(-) delete mode 100644 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 delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/wizard.hbs delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/wizard.js delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/wizard.json 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 09e414aa7bf..eb97eb86230 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 f467aa9222c..1b945e5e7c0 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 d7d7b99f149..f615fb49900 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 fd2bf3ff4f5..00000000000 --- 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( - "
" + - "
" + - "" + - "Loading Platform Features . . ." + - "
" + - "
" + - "
" - ); -}; - -stepForwardFrom["policy-criteria"] = function () { - $("input[type='radio'].select-users-radio").each(function () { - if ($(this).is(':radio')) { - if ($(this).is(":checked")) { - if ($(this).attr("id") == "users-radio-btn") { - policy["selectedUsers"] = $("#users-input").val(); - policy["selectedUserRoles"] = null; - } else if ($(this).attr("id") == "user-roles-radio-btn") { - policy["selectedUsers"] = null; - policy["selectedUserRoles"] = $("#user-roles-input").val(); - } - } - } - }); - policy["selectedNonCompliantAction"] = $("#action-input").find(":selected").data("action"); - policy["selectedOwnership"] = $("#ownership-input").val(); - //updating next-page wizard title with selected platform - $("#policy-naming-page-wizard-title").text("ADD " + policy["platform"] + " POLICY"); -}; - -/** - * Checks if provided input is valid against provided length range. - * - * @param input Alphanumeric or non-alphanumeric input - * @param minLength Minimum Required Length - * @param maxLength Maximum Required Length - * @returns {boolean} Returns true if input matches the provided minimum length and maximum length - */ -var inputIsValidAgainstLength = function (input, minLength, maxLength) { - var length = input.length; - return (length == minLength || (length > minLength && length < maxLength) || length == maxLength); -}; - -validateStep["policy-criteria"] = function () { - var validationStatus = {}; - var selectedAssignees; - var selectedField = "Role(s)"; - - $("input[type='radio'].select-users-radio").each(function () { - if ($(this).is(":checked")) { - if ($(this).attr("id") == "users-radio-btn") { - selectedAssignees = $("#users-input").val(); - selectedField = "User(s)"; - } else if ($(this).attr("id") == "user-roles-radio-btn") { - selectedAssignees = $("#user-roles-input").val(); - } - return false; - } - }); - - if (selectedAssignees) { - validationStatus["error"] = false; - } else { - validationStatus["error"] = true; - validationStatus["mainErrorMsg"] = selectedField + " is a required field. It cannot be empty"; - } - - var wizardIsToBeContinued; - if (validationStatus["error"]) { - wizardIsToBeContinued = false; - var mainErrorMsgWrapper = "#policy-criteria-main-error-msg"; - var mainErrorMsg = mainErrorMsgWrapper + " span"; - $(mainErrorMsg).text(validationStatus["mainErrorMsg"]); - $(mainErrorMsgWrapper).removeClass("hidden"); - } else { - wizardIsToBeContinued = true; - } - - return wizardIsToBeContinued; -}; - -validateStep["policy-naming"] = function () { - var validationStatus = {}; - - // taking values of inputs to be validated - var policyName = $("input#policy-name-input").val(); - // starting validation process and updating validationStatus - if (!policyName) { - validationStatus["error"] = true; - validationStatus["mainErrorMsg"] = "Policy name is empty. You cannot proceed."; - } else if (!inputIsValidAgainstLength(policyName, 1, 30)) { - validationStatus["error"] = true; - validationStatus["mainErrorMsg"] = - "Policy name exceeds maximum allowed length."; - } else { - validationStatus["error"] = false; - } - // ending validation process - - // start taking specific actions upon validation - var wizardIsToBeContinued; - if (validationStatus["error"]) { - wizardIsToBeContinued = false; - var mainErrorMsgWrapper = "#policy-naming-main-error-msg"; - var mainErrorMsg = mainErrorMsgWrapper + " span"; - $(mainErrorMsg).text(validationStatus["mainErrorMsg"]); - $(mainErrorMsgWrapper).removeClass("hidden"); - } else { - wizardIsToBeContinued = true; - } - - return wizardIsToBeContinued; -}; - -validateStep["policy-platform"] = function () { - return false; -}; - -validateStep["policy-naming-publish"] = function () { - var validationStatus = {}; - - // taking values of inputs to be validated - var policyName = $("input#policy-name-input").val(); - // starting validation process and updating validationStatus - if (!policyName) { - validationStatus["error"] = true; - validationStatus["mainErrorMsg"] = "Policy name is empty. You cannot proceed."; - } else if (!inputIsValidAgainstLength(policyName, 1, 30)) { - validationStatus["error"] = true; - validationStatus["mainErrorMsg"] = - "Policy name exceeds maximum allowed length."; - } else { - validationStatus["error"] = false; - } - // ending validation process - - // start taking specific actions upon validation - var wizardIsToBeContinued; - if (validationStatus["error"]) { - wizardIsToBeContinued = false; - var mainErrorMsgWrapper = "#policy-naming-main-error-msg"; - var mainErrorMsg = mainErrorMsgWrapper + " span"; - $(mainErrorMsg).text(validationStatus["mainErrorMsg"]); - $(mainErrorMsgWrapper).removeClass("hidden"); - } else { - wizardIsToBeContinued = true; - } - - return wizardIsToBeContinued; -}; - -stepForwardFrom["policy-naming-publish"] = function () { - policy["policyName"] = $("#policy-name-input").val(); - policy["description"] = $("#policy-description-input").val(); - //All data is collected. Policy can now be updated. - savePolicy(policy, true, "/api/device-mgt/v1.0/policies/"); -}; - -stepForwardFrom["policy-naming"] = function () { - policy["policyName"] = $("#policy-name-input").val(); - policy["description"] = $("#policy-description-input").val(); - //All data is collected. Policy can now be updated. - savePolicy(policy, false, "/api/device-mgt/v1.0/policies/"); -}; - -var savePolicy = function (policy, isActive, serviceURL) { - var profilePayloads = []; - // traverses key by key in policy["profile"] - var key; - for (key in policy["profile"]) { - if (policy["profile"].hasOwnProperty(key)) { - profilePayloads.push({ - "featureCode": key, - "deviceType": policy["platform"], - "content": policy["profile"][key] - }); - } - } - - $.each(profilePayloads, function (i, item) { - $.each(item.content, function (key, value) { - //cannot add a true check since it will catch value = false as well - if (value === null || value === undefined || value === "") { - item.content[key] = null; - } - }); - }); - - var payload = { - "policyName": policy["policyName"], - "description": policy["description"], - "compliance": policy["selectedNonCompliantAction"], - "ownershipType": policy["selectedOwnership"], - "active": isActive, - "profile": { - "profileName": policy["policyName"], - "deviceType": policy["platform"], - "profileFeaturesList": profilePayloads - } - }; - - if (policy["selectedUsers"]) { - payload["users"] = policy["selectedUsers"]; - } else if (policy["selectedUserRoles"]) { - payload["roles"] = policy["selectedUserRoles"]; - } else { - payload["users"] = []; - payload["roles"] = []; - } - - invokerUtil.post( - serviceURL, - payload, - function () { - $(".add-policy").addClass("hidden"); - $(".policy-naming").addClass("hidden"); - $(".policy-message").removeClass("hidden"); - }, - function (data) { - } - ); -}; - -function formatRepo(user) { - if (user.loading) { - return user.text; - } - if (!user.username) { - return; - } - var markup = '
' + - '
' + - '
' + - '
' + user.username + '
'; - if (user.firstname) { - markup += '
' + user.firstname + '
'; - } - if (user.emailAddress) { - markup += '
' + user.emailAddress + '
'; - } - markup += '
'; - return markup; -} - -function formatRepoSelection(user) { - return user.username || user.text; -} - -// End of functions related to grid-input-view - - -$(document).ready(function () { - $("#users-input").select2({ - multiple: true, - tags: false, - ajax: { - url: context + "/api/invoker/execute/", - method: "POST", - dataType: 'json', - delay: 250, - id: function (user) { - return user.username; - }, - data: function (params) { - var postData = {}; - postData.requestMethod = "GET"; - postData.requestURL = "/api/device-mgt/v1.0/users/search/usernames?filter=" + params.term; - postData.requestPayload = null; - return JSON.stringify(postData); - }, - processResults: function (data) { - var newData = []; - $.each(data, function (index, value) { - value.id = value.username; - newData.push(value); - }); - return { - results: newData - }; - }, - cache: true - }, - escapeMarkup: function (markup) { - return markup; - }, // let our custom formatter work - minimumInputLength: 1, - templateResult: formatRepo, // omitted for brevity, see the source of this page - templateSelection: formatRepoSelection // omitted for brevity, see the source of this page - }); - - $("#loading-content").remove(); - $(".policy-platform").removeClass("hidden"); - // Adding initial state of wizard-steps. - $("#policy-platform-wizard-steps").html($(".wr-steps").html()); - - $("select.select2[multiple=multiple]").select2({ - "tags": false - }); - - $("#users-select-field").hide(); - $("#user-roles-select-field").show(); - - $("input[type='radio'].select-users-radio").change(function () { - if ($("#users-radio-btn").is(":checked")) { - $("#user-roles-select-field").hide(); - $("#users-select-field").show(); - } - if ($("#user-roles-radio-btn").is(":checked")) { - $("#users-select-field").hide(); - $("#user-roles-select-field").show(); - } - }); - - // Support for special input type "ANY" on user(s) & user-role(s) selection - $("#user-roles-input").select2({ - "tags": false - }).on("select2:select", function (e) { - if (e.params.data.id == "ANY") { - $(this).val("ANY").trigger("change"); - } else { - $("option[value=ANY]", this).prop("selected", false).parent().trigger("change"); - } - }); - - //Policy wizard stepper - $(".wizard-stepper").click(function () { - // button clicked here can be either a continue button or a back button. - var currentStep = $(this).data("current"); - var validationIsRequired = $(this).data("validate"); - var wizardIsToBeContinued; - - if (validationIsRequired) { - wizardIsToBeContinued = validateStep[currentStep](); - } else { - wizardIsToBeContinued = true; - } - - if (wizardIsToBeContinued) { - // When moving back and forth, following code segment will - // remove if there are any visible error-messages. - var errorMsgWrappers = ".alert.alert-danger"; - $(errorMsgWrappers).each( - function () { - if (!$(this).hasClass("hidden")) { - $(this).addClass("hidden"); - } - } - ); - - var nextStep = $(this).data("next"); - var isBackBtn = $(this).data("is-back-btn"); - - // if current button is a continuation... - if (!isBackBtn) { - // initiate stepForwardFrom[*] functions to gather form data. - if (stepForwardFrom[currentStep]) { - stepForwardFrom[currentStep](this); - } - } else { - // initiate stepBackFrom[*] functions to rollback. - if (stepBackFrom[currentStep]) { - stepBackFrom[currentStep](); - } - } - - // following step occurs only at the last stage of the wizard. - if (!nextStep) { - window.location.href = $(this).data("direct"); - } - - // updating next wizard step as current. - $(".itm-wiz").each(function () { - var step = $(this).data("step"); - if (step == nextStep) { - $(this).addClass("itm-wiz-current"); - } else { - $(this).removeClass("itm-wiz-current"); - } - }); - - // adding next update of wizard-steps. - $("#" + nextStep + "-wizard-steps").html($(".wr-steps").html()); - - // hiding current section of the wizard and showing next section. - $("." + currentStep).addClass("hidden"); - $("." + nextStep).removeClass("hidden"); - } - }); -}); \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/wizard.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/wizard.hbs deleted file mode 100644 index 02f7bc76cf6..00000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/wizard.hbs +++ /dev/null @@ -1,244 +0,0 @@ - -
-
- - - - - - -
-
-

ADD POLICY

-
-
-
-
-
-

Step 2: Configure profile

-
- -
- {{unit "cdmf.unit.device.type.generic.policy-wizard"}} -
- -
-
-
-
- - -
-
-{{#zone "bottomJs"}} - {{js "js/policy-create.js"}} -{{/zone}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/wizard.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/wizard.js deleted file mode 100644 index c3cb1ea3b84..00000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/wizard.js +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * 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. - */ - -function onRequest(context) { - // var log = new Log("wizard.js"); - var constants = require("/app/modules/constants.js"); - var DTYPE_CONF_DEVICE_TYPE_KEY = "deviceType"; - var DTYPE_CONF_DEVICE_TYPE_LABEL_KEY = "label"; - - var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; - var utility = require('/app/modules/utility.js').utility; - var response = userModule.getRoles(); - var wizardPage = {}; - if (response["status"] == "success") { - wizardPage["roles"] = response["content"]; - } - var deviceType = context.uriParams.deviceType; - var typesListResponse = userModule.getPlatforms(); - if (typesListResponse["status"] == "success") { - wizardPage["type"] = {}; - for (var type in typesListResponse["content"]["deviceTypes"]) { - if (deviceType == typesListResponse["content"]["deviceTypes"][type]) { - wizardPage["type"]["name"] = deviceType; - wizardPage["type"]["label"] = deviceType; - } - } - } - var user = session.get(constants.USER_SESSION_KEY); - wizardPage.username = user.username; - wizardPage.permissions = userModule.getUIPermissions(); - return wizardPage; -} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/wizard.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/wizard.json deleted file mode 100644 index fd259012978..00000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/wizard.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "version" : "1.0.0" -} \ No newline at end of file