From e881aa6da4dce3d4ad733253a799a7be7e5a8da2 Mon Sep 17 00:00:00 2001 From: dilanua Date: Fri, 2 Sep 2016 18:55:00 +0530 Subject: [PATCH] Fixing Role Editing UI --- .../app/modules/business-controllers/user.js | 4 ++- .../app/pages/cdmf.page.role.edit/edit.hbs | 1 + .../app/units/cdmf.unit.role.edit/edit.hbs | 11 +++----- .../app/units/cdmf.unit.role.edit/edit.js | 28 ++++++++++++------- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js index 0590605891..dde8854bbb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js @@ -308,7 +308,9 @@ var userModule = function () { var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/roles/" + encodeURIComponent(roleName); var response = privateMethods.callBackend(url, constants["HTTP_GET"]); - response.content = parse(response.content); + if (response.status == "success") { + response.content = parse(response.content); + } return response; } catch (e) { throw e; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.edit/edit.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.edit/edit.hbs index cdf32d9884..d1c488dbef 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.edit/edit.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.edit/edit.hbs @@ -26,6 +26,7 @@
  • + Roles diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.hbs index 249e35a6e3..281f5ea350 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.hbs @@ -31,11 +31,8 @@
    - +
    diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js index cf54af034e..ac21d0b696 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js @@ -18,30 +18,38 @@ /** * Returns the dynamic state to be populated by add-user page. - * + * * @param context Object that gets updated with the dynamic state of this page to be presented * @returns {*} A context object that returns the dynamic state of this page to be presented */ function onRequest(context) { var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"]; + var uri = request.getRequestURI(); var uriMatcher = new URIMatcher(String(uri)); - var isMatched = uriMatcher.match("/{context}/role/edit/{rolename}"); + var isMatched = uriMatcher.match("/{context}/role/edit/{roleName}"); if (isMatched) { var matchedElements = uriMatcher.elements(); - var roleName = matchedElements.rolename; + var roleName = matchedElements["roleName"]; var response = userModule.getRole(roleName); if (response["status"] == "success") { context["role"] = response["content"]; } - var userStores = userModule.getSecondaryUserStores(); - context["userStores"] = userStores; + var userStore; + if (roleName.indexOf("/") > -1) { + userStore = roleName.substring(0, roleName.indexOf("/")); + } else { + userStore = "PRIMARY"; + } + context["userStore"] = userStore; + context["roleNameJSRegEx"] = deviceMgtProps["roleValidationConfig"]["roleNameJSRegEx"]; + context["roleNameHelpText"] = deviceMgtProps["roleValidationConfig"]["roleNameHelpMsg"]; + context["roleNameRegExViolationErrorMsg"] = deviceMgtProps["roleValidationConfig"]["roleNameRegExViolationErrorMsg"]; + return context; + } else { + //TODO: handle error scenario + return context; } - //TODO: error scenario - context["roleNameJSRegEx"] = deviceMgtProps.roleValidationConfig.rolenameJSRegEx; - context["roleNameHelpText"] = deviceMgtProps.roleValidationConfig.rolenameHelpMsg; - context["roleNameRegExViolationErrorMsg"] = deviceMgtProps.roleValidationConfig.rolenameRegExViolationErrorMsg; - return context; } \ No newline at end of file