From 30d4a5707a0e40c68bb9ae346a484a83dcd2dcee Mon Sep 17 00:00:00 2001 From: charitha Date: Tue, 17 Sep 2019 20:02:50 +0530 Subject: [PATCH] Fix platform config listing --- .../configuration.hbs | 7 ----- .../configuration.hbs | 9 ++++++ .../public/js/platform-configuration.js | 28 +++++++++++++------ 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.dynamic.platform.configuration/configuration.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.dynamic.platform.configuration/configuration.hbs index b4c64f7fd52..7c3f83eec5a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.dynamic.platform.configuration/configuration.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.dynamic.platform.configuration/configuration.hbs @@ -32,10 +32,3 @@ -{{#zone "bottomJs"}} - -{{/zone}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/configuration.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/configuration.hbs index 597b38ce182..8e4131fa19e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/configuration.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/configuration.hbs @@ -193,4 +193,13 @@ {{/zone}} {{#zone "bottomJs"}} {{js "js/platform-configuration.js"}} + {{/zone}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/public/js/platform-configuration.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/public/js/platform-configuration.js index d3a2152b06a..9e4176066b0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/public/js/platform-configuration.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/public/js/platform-configuration.js @@ -163,7 +163,7 @@ var loadDynamicDeviceTypeConfig = function (deviceType) { configAPI, function (data) { data = JSON.parse(data); - var fieldWrapper = "#" + deviceType + "-config-field-wrapper"; + var fieldWrapper = "#" + escapeSelector(deviceType + "-config-field-wrapper"); $(fieldWrapper).html(""); if (data.configuration) { var config; @@ -197,15 +197,18 @@ var loadDynamicDeviceTypeConfig = function (deviceType) { var onDynamicConfigSubmit = function (deviceType) { - var errorMsgWrapper = "#" + deviceType + "-config-error-msg"; - var errorMsg = "#" + deviceType + "-config-error-msg span"; + var errorMsgWrapper = "#" + escapeSelector(deviceType + "-config-error-msg"); + var errorMsg = "#" + escapeSelector(deviceType + "-config-error-msg span"); + var filedRaw = '.' + escapeSelector(deviceType + '-config-row'); + var filedName = "." + escapeSelector(deviceType + "-config-name"); + var filedValue = "." + escapeSelector(deviceType + "-config-value"); var addConfigFormData = {}; var configList = []; - $('.' + deviceType + '-config-row').each(function () { - var configName = $(this).find("." + deviceType + "-config-name").val(); - var configVal = $(this).find("." + deviceType + "-config-value").val(); + $(filedRaw).each(function () { + var configName = $(this).find(filedName).val(); + var configVal = $(this).find(filedValue).val(); if (configName && configName.trim() !== "" && configVal && configVal.trim() !== "") { var configurationEntry = {}; configurationEntry.name = configName.trim(); @@ -252,7 +255,8 @@ var onDynamicConfigSubmit = function (deviceType) { }; var onDynamicConfigAddNew = function (deviceType, name, value) { - $("#" + deviceType + "-config-field-wrapper").append( + var fieldWrapper = "#" + escapeSelector(deviceType + "-config-field-wrapper"); + $(fieldWrapper).append( '
' + '
' + @@ -272,5 +276,13 @@ var onDynamicConfigAddNew = function (deviceType, name, value) { }; var onDynamicConfigRemove = function (deviceType, rawId) { - $("#" + deviceType + "-config-row-" + rawId).remove() + var fieldWrapper = "#" + escapeSelector(deviceType + "-config-row-" + rawId); + $(fieldWrapper).remove() +}; + +var escapeSelector = function (text) { + return text.replace( + /([$%&()*+,./:;<=>?@\[\\\]^\{|}~])/g, + '\\$1' + ); }; \ No newline at end of file