Adding role creation UI

4.x.x
dilanua 8 years ago
parent 746a4d4372
commit 934c45cd95

@ -15,10 +15,10 @@
specific language governing permissions and limitations
under the License.
}}
<!-- content/body -->
<div class="row">
<div class="col-md-12">
<!-- content -->
<div id="role-create-form" class="container col-centered wr-content">
<div class="wr-form">
@ -32,15 +32,14 @@
<div class="wiz-no">1</div>
<div class="wiz-lbl hidden-xs"><span>Add a role</span></div>
</div>
<br class="c-both" />
</div>
<div class="col-md-6 col-xs-6">
<div class="itm-wiz" data-step="policy-profile">
<div class="wiz-no">2</div>
<div class="wiz-lbl hidden-xs"><span>Assign permissions</span></div>
</div>
<br class="c-both" />
</div>
<br class="c-both" />
</div>
<br /><br />
<hr />
@ -48,8 +47,8 @@
<i class="icon fw fw-error"></i><span></span>
</div>
<label class="wr-input-label">User Store Domain</label>
<div class="wr-input-control">
<!--suppress HtmlFormInputWithoutLabel -->
<select id="domain" class="form-control select">
<option>PRIMARY</option>
{{#each userStores}}
@ -57,6 +56,7 @@
{{/each}}
</select>
</div>
<label class="wr-input-label">
Role Name *
</label>
@ -66,20 +66,21 @@
</label>
<div id="roleNameField" class="form-group wr-input-control">
<input type="text" id="rolename" data-regex="{{roleNameJSRegEx}}"
data-errormsg="{{roleNameRegExViolationErrorMsg}}" class="form-control" />
<span class=" rolenameError hidden glyphicon glyphicon-remove form-control-feedback"></span>
<label class="error rolenameEmpty hidden" for="summary">Role name is required & Should be in
minimum 3 characters long and do not
include any whitespaces. </label>
<!--suppress HtmlFormInputWithoutLabel -->
<input type="text" id="roleName" data-regex="{{roleNameJSRegEx}}"
data-error-msg="{{roleNameRegExViolationErrorMsg}}" class="form-control" />
<span class="roleNameError hidden glyphicon glyphicon-remove form-control-feedback"></span>
<label class="error roleNameEmpty hidden" for="summary">
Role name is required, should be in minimum 3 characters long and not include any whitespaces.
</label>
</div>
<label class="wr-input-label">
User list
</label>
<div class="wr-input-control">
<select id="users" class="form-control select2" multiple="multiple">
</select>
<!--suppress HtmlFormInputWithoutLabel -->
<select id="users" class="form-control select2" multiple="multiple"></select>
</div>
</div>
</div>
@ -96,7 +97,8 @@
<button class="wr-btn" onclick="window.location.href='{{@app.context}}/roles'">
View Role List
</button>
<a href="{{@app.context}}/roles/add-role" class="cu-btn-inner">
<!--suppress HtmlUnknownTarget -->
<a href="{{@app.context}}/role/add" class="cu-btn-inner">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>

@ -25,14 +25,11 @@
function onRequest(context) {
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"];
var response = userModule.getRoles();
if (response["status"] == "success") {
context["roles"] = response["content"];
}
var userStores = userModule.getSecondaryUserStores();
context["userStores"] = userStores;
context["roleNameJSRegEx"] = deviceMgtProps.roleValidationConfig.rolenameJSRegEx;
context["roleNameHelpText"] = deviceMgtProps.roleValidationConfig.rolenameHelpMsg;
context["roleNameRegExViolationErrorMsg"] = deviceMgtProps.roleValidationConfig.rolenameRegExViolationErrorMsg;
context["userStores"] = userModule.getSecondaryUserStores();
context["roleNameJSRegEx"] = deviceMgtProps["roleValidationConfig"]["roleNameJSRegEx"];
context["roleNameHelpText"] = deviceMgtProps["roleValidationConfig"]["roleNameHelpMsg"];
context["roleNameRegExViolationErrorMsg"] = deviceMgtProps["roleValidationConfig"]["roleNameRegExViolationErrorMsg"];
return context;
}

@ -73,19 +73,19 @@ var disableInlineError = function (inputField, errorMsg, errorSign) {
*clear inline validation messages.
*/
clearInline["role-name"] = function () {
disableInlineError("roleNameField", "rolenameEmpty", "rolenameError");
disableInlineError("roleNameField", "roleNameEmpty", "roleNameError");
};
/**
* Validate if provided rolename is valid against RegEx configures.
* Validate if provided role-name is valid against RegEx configures.
*/
validateInline["role-name"] = function () {
var rolenameinput = $("input#rolename");
if (inputIsValid( rolenameinput.data("regex"), rolenameinput.val())) {
disableInlineError("roleNameField", "rolenameEmpty", "rolenameError");
var roleNameInput = $("input#roleName");
if (inputIsValid( roleNameInput.data("regex"), roleNameInput.val())) {
disableInlineError("roleNameField", "roleNameEmpty", "roleNameError");
} else {
enableInlineError("roleNameField", "rolenameEmpty", "rolenameError");
enableInlineError("roleNameField", "roleNameEmpty", "roleNameError");
}
};
@ -97,16 +97,16 @@ function formatRepo (user) {
return;
}
var markup = '<div class="clearfix">' +
'<div clas="col-sm-8">' +
'<div class="col-sm-8">' +
'<div class="clearfix">' +
'<div class="col-sm-3">' + user.username + '</div>';
if (user.firstname) {
markup += '<div class="col-sm-3"><i class="fa fa-code-fork"></i> ' + user.firstname + '</div>';
'<div class="col-sm-3">User : ' + user.username + '</div>';
if (user.name) {
markup += '<div class="col-sm-3"> ' + user.name + '</div>';
}
if (user.emailAddress) {
markup += '<div class="col-sm-2"><i class="fa fa-star"></i> ' + user.emailAddress + '</div></div>';
markup += '<div class="col-sm-3"> ' + user.emailAddress + '</div>';
}
markup += '</div></div>';
markup += '</div></div></div>';
return markup;
}
@ -129,17 +129,19 @@ $(document).ready(function () {
},
data: function (params) {
var postData = {};
postData.actionMethod = "GET";
postData.actionUrl = apiBasePath + "/users/search/usernames?filter=" + params.term;
postData.actionPayload = null;
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, page) {
processResults: function (data) {
var newData = [];
$.each(data, function (index, value) {
var user = {};
user.username = value.username;
user.id = value.username;
user.username = value.username;
user.name = value.firstname + " " + value.lastname;
user.emailAddress = value.emailAddress;
newData.push(user);
});
return {
@ -160,9 +162,9 @@ $(document).ready(function () {
* on Add Role page in WSO2 MDM Console.
*/
$("button#add-role-btn").click(function () {
var rolenameInput = $("input#rolename");
var roleName = rolenameInput.val();
var domain = $("#domain").val();
var roleNameInput = $("input#roleName");
var roleName = roleNameInput.val();
var users = $("#users").val();
var errorMsgWrapper = "#role-create-error-msg";
@ -170,8 +172,8 @@ $(document).ready(function () {
if (!roleName) {
$(errorMsg).text("Role name is a required field. It cannot be empty.");
$(errorMsgWrapper).removeClass("hidden");
} else if (!inputIsValid(rolenameInput.data("regex"), roleName)) {
$(errorMsg).text(rolenameInput.data("errormsg"));
} else if (!inputIsValid(roleNameInput.data("regex"), roleName)) {
$(errorMsg).text(roleNameInput.data("error-msg"));
$(errorMsgWrapper).removeClass("hidden");
} else if (!domain) {
$(errorMsg).text("Domain is a required field. It cannot be empty.");
@ -181,9 +183,7 @@ $(document).ready(function () {
$(errorMsgWrapper).removeClass("hidden");
} else {
var addRoleFormData = {};
addRoleFormData.roleName = roleName;
if (domain != "PRIMARY"){
addRoleFormData.roleName = domain + "/" + roleName;
}
@ -197,37 +197,31 @@ $(document).ready(function () {
invokerUtil.post(
addRoleAPI,
addRoleFormData,
function (data) {
data = JSON.parse(data);
if (data.errorMessage) {
$(errorMsg).text("Selected user store prompted an error : " + data.errorMessage);
$(errorMsgWrapper).removeClass("hidden");
} else {
function (data, textStatus, jqXHR) {
if (jqXHR.status == 201) {
// Clearing user input fields.
//$("input#rolename").val("");
//$("#domain").val("");
//// Refreshing with success message
//$("#role-create-form").addClass("hidden");
//$("#role-created-msg").removeClass("hidden");
window.location.href = appContext + '/role/edit-permission/' + roleName;
}
}, function (data) {
if (JSON.parse(data).errorMessage.indexOf("RoleExisting") > -1) {
$(errorMsg).text("Role name : " + roleName + " already exists. Pick another role name.");
} else {
$(errorMsg).text(JSON.parse(data.responseText).errorMessage);
$("input#roleName").val("");
$("#domain").val("PRIMARY");
$("#users").val("");
window.location.href = appContext + "/role/edit-permission/" + roleName;
}
},
function (jqXHR) {
if (jqXHR.status == 500) {
$(errorMsg).text("Either role already exists or unexpected error.");
$(errorMsgWrapper).removeClass("hidden");
}
}
);
}
});
$("#rolename").focus(function() {
var roleNameInputElement = "#roleName";
$(roleNameInputElement).focus(function() {
clearInline["role-name"]();
});
$("#rolename").blur(function() {
$(roleNameInputElement).blur(function() {
validateInline["role-name"]();
});
});
Loading…
Cancel
Save