mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt
This commit is contained in:
commit
86fdc85d13
@ -99,7 +99,7 @@ public class CommandOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
|
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
commandOperation = new CommandOperation();
|
commandOperation = new CommandOperation();
|
||||||
commandOperation.setEnabled(rs.getInt("ENABLED") != 0);
|
commandOperation.setEnabled(rs.getBoolean("ENABLED"));
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("SQL Error occurred while retrieving the command operation " +
|
throw new OperationManagementDAOException("SQL Error occurred while retrieving the command operation " +
|
||||||
|
|||||||
@ -22,7 +22,7 @@ var log = new Log("api/data-tables-invoker-api.jag");
|
|||||||
var uri = request.getRequestURI();
|
var uri = request.getRequestURI();
|
||||||
var uriMatcher = new URIMatcher(String(uri));
|
var uriMatcher = new URIMatcher(String(uri));
|
||||||
|
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
var devicemgtProps = require("/app/conf/devicemgt-props.js").config();
|
||||||
var serviceInvokers = require("/app/modules/backend-service-invoker.js")["backendServiceInvoker"];
|
var serviceInvokers = require("/app/modules/backend-service-invoker.js")["backendServiceInvoker"];
|
||||||
|
|
||||||
if (uriMatcher.match("/{context}/api/data-tables/invoker")) {
|
if (uriMatcher.match("/{context}/api/data-tables/invoker")) {
|
||||||
|
|||||||
@ -1,43 +1,47 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
*
|
*
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||||
* KIND, either express or implied. See the License for the
|
* either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This backendServiceInvoker contains the wrappers for back end jaggary calls.
|
* This backendServiceInvoker contains the wrappers for back end jaggery calls.
|
||||||
*/
|
*/
|
||||||
var backendServiceInvoker = function () {
|
var backendServiceInvoker = function () {
|
||||||
var log = new Log("/app/modules/backend-service-invoker.js");
|
var log = new Log("/app/modules/backend-service-invoker.js");
|
||||||
|
|
||||||
var publicXMLHTTPInvokers = {};
|
var publicXMLHTTPInvokers = {};
|
||||||
|
var publicHTTPClientInvokers = {};
|
||||||
|
|
||||||
var privateMethods = {};
|
var privateMethods = {};
|
||||||
var publicWSInvokers = {};
|
var publicWSInvokers = {};
|
||||||
var publicHTTPClientInvokers = {};
|
|
||||||
var IS_OAUTH_ENABLED = true;
|
|
||||||
var TOKEN_EXPIRED = "Access token expired";
|
var TOKEN_EXPIRED = "Access token expired";
|
||||||
var TOKEN_INVALID = "Invalid input. Access token validation failed";
|
var TOKEN_INVALID = "Invalid input. Access token validation failed";
|
||||||
|
|
||||||
|
var devicemgtProps = require("/app/conf/devicemgt-props.js").config();
|
||||||
var constants = require("/app/modules/constants.js");
|
var constants = require("/app/modules/constants.js");
|
||||||
var tokenUtil = require("/app/modules/api-wrapper-util.js").apiWrapperUtil;
|
var userModule = require("/app/modules/user.js")["userModule"];
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
var tokenUtil = require("/app/modules/api-wrapper-util.js")["apiWrapperUtil"];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This methoad reads the token pair from the session and return the access token.
|
* This method reads the token pair from the session and return the access token.
|
||||||
* If the token pair s not set in the session this will send a redirect to the login page.
|
* If the token pair s not set in the session this will send a redirect to the login page.
|
||||||
*/
|
*/
|
||||||
privateMethods.getAccessToken = function () {
|
privateMethods.getAccessToken = function () {
|
||||||
var tokenPair = session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER);
|
var tokenPair = session.get(constants["ACCESS_TOKEN_PAIR_IDENTIFIER"]);
|
||||||
if (tokenPair) {
|
if (tokenPair) {
|
||||||
return tokenPair.accessToken;
|
return tokenPair.accessToken;
|
||||||
} else {
|
} else {
|
||||||
@ -46,152 +50,119 @@ var backendServiceInvoker = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method add Oauth authentication header to outgoing XMLHTTP Requests if Oauth authentication is enabled.
|
* ---------------------------------------------------------------------------
|
||||||
* @param method HTTP request type.
|
* Start of XML-HTTP-REQUEST based Interceptor implementations
|
||||||
* @param url target url.
|
* ---------------------------------------------------------------------------
|
||||||
* @param payload payload/data which need to be send.
|
*/
|
||||||
* @param successCallback a function to be called if the respond if successful.
|
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
/**
|
||||||
|
* This method add Oauth authentication header to outgoing XML-HTTP Requests if Oauth authentication is enabled.
|
||||||
|
* @param httpMethod HTTP request type.
|
||||||
|
* @param requestPayload payload/data if exists which is needed to be send.
|
||||||
|
* @param endpoint Backend REST API url.
|
||||||
|
* @param responseCallback a function to be called with response retrieved.
|
||||||
* @param count a counter which hold the number of recursive execution
|
* @param count a counter which hold the number of recursive execution
|
||||||
*/
|
*/
|
||||||
privateMethods.execute = function (method, url, successCallback, errorCallback, payload, count, contentType, acceptType) {
|
privateMethods.execute = function (httpMethod, requestPayload, endpoint, responseCallback, count) {
|
||||||
var xmlHttpRequest = new XMLHttpRequest();
|
var xmlHttpRequest = new XMLHttpRequest();
|
||||||
xmlHttpRequest.open(method, url);
|
|
||||||
if(!contentType){
|
xmlHttpRequest.open(httpMethod, endpoint);
|
||||||
contentType = constants.APPLICATION_JSON;
|
xmlHttpRequest.setRequestHeader(constants["CONTENT_TYPE_IDENTIFIER"], constants["APPLICATION_JSON"]);
|
||||||
}
|
xmlHttpRequest.setRequestHeader(constants["ACCEPT_IDENTIFIER"], constants["APPLICATION_JSON"]);
|
||||||
if(!acceptType){
|
|
||||||
acceptType = constants.APPLICATION_JSON;
|
if (devicemgtProps["isOAuthEnabled"]) {
|
||||||
}
|
|
||||||
xmlHttpRequest.setRequestHeader(constants.CONTENT_TYPE_IDENTIFIER, contentType);
|
|
||||||
xmlHttpRequest.setRequestHeader(constants.ACCEPT_IDENTIFIER, acceptType);
|
|
||||||
xmlHttpRequest.setRequestHeader(constants.REFERER, String(privateMethods.getClientDomain()));
|
|
||||||
if (IS_OAUTH_ENABLED) {
|
|
||||||
var accessToken = privateMethods.getAccessToken();
|
var accessToken = privateMethods.getAccessToken();
|
||||||
if (!accessToken) {
|
if (!accessToken) {
|
||||||
response.sendRedirect(devicemgtProps["httpsURL"] + "/devicemgt/login");
|
userModule.logout(function () {
|
||||||
|
response.sendRedirect(devicemgtProps["appContext"] + "login");
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
xmlHttpRequest.setRequestHeader(constants.AUTHORIZATION_HEADER, constants.BEARER_PREFIX + accessToken);
|
xmlHttpRequest.
|
||||||
|
setRequestHeader(constants["AUTHORIZATION_HEADER"], constants["BEARER_PREFIX"] + accessToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (payload) {
|
|
||||||
xmlHttpRequest.send(payload);
|
if (requestPayload) {
|
||||||
|
xmlHttpRequest.send(requestPayload);
|
||||||
} else {
|
} else {
|
||||||
xmlHttpRequest.send();
|
xmlHttpRequest.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((xmlHttpRequest.status >= 200 && xmlHttpRequest.status < 300) || xmlHttpRequest.status == 302) {
|
log.debug("Service Invoker-URL: " + endpoint);
|
||||||
if (xmlHttpRequest.responseText != null) {
|
log.debug("Service Invoker-Method: " + httpMethod);
|
||||||
return successCallback(parse(xmlHttpRequest.responseText));
|
|
||||||
} else {
|
log.info("Request : " + httpMethod + " " + endpoint);
|
||||||
return successCallback({"status": xmlHttpRequest.status, "messageFromServer": "Operation Completed"});
|
log.info("Request payload if any : " + stringify(requestPayload));
|
||||||
}
|
log.info("Response status : " + xmlHttpRequest.status);
|
||||||
} else if (xmlHttpRequest.status == 401 && (xmlHttpRequest.responseText == TOKEN_EXPIRED ||
|
log.info("Response payload if any : " + xmlHttpRequest.responseText);
|
||||||
xmlHttpRequest.responseText == TOKEN_INVALID ) && count < 5) {
|
//log.info("Response headers : " + xmlHttpRequest.getAllResponseHeaders());
|
||||||
|
|
||||||
|
if (xmlHttpRequest.status == 401 && (xmlHttpRequest.responseText == TOKEN_EXPIRED ||
|
||||||
|
xmlHttpRequest.responseText == TOKEN_INVALID ) && count < 5) {
|
||||||
tokenUtil.refreshToken();
|
tokenUtil.refreshToken();
|
||||||
return privateMethods.execute(method, url, successCallback, errorCallback, payload, (count + 1));
|
return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, ++count);
|
||||||
} else if (xmlHttpRequest.status == 500) {
|
|
||||||
return errorCallback(xmlHttpRequest);
|
|
||||||
} else {
|
} else {
|
||||||
return errorCallback(xmlHttpRequest);
|
return responseCallback(xmlHttpRequest);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method add Oauth authentication header to outgoing XMLHTTP Requests if Oauth authentication is enabled.
|
* This method add Oauth authentication header to outgoing XML-HTTP Requests if Oauth authentication is enabled.
|
||||||
* @param method HTTP request type.
|
* @param httpMethod HTTP request type.
|
||||||
* @param url target url.
|
* @param requestPayload payload/data if exists which is needed to be send.
|
||||||
* @param payload payload/data which need to be send.
|
* @param endpoint Backend REST API url.
|
||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param responseCallback a function to be called with response retrieved.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
|
||||||
*/
|
*/
|
||||||
privateMethods.initiateXMLHTTPRequest = function (method, url, successCallback, errorCallback, payload, contentType, acceptType) {
|
privateMethods.initiateXMLHTTPRequest = function (httpMethod, requestPayload, endpoint, responseCallback) {
|
||||||
if (privateMethods.getAccessToken()) {
|
return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, 0);
|
||||||
return privateMethods.execute(method, url, successCallback, errorCallback, payload, 0, contentType, acceptType);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method add Oauth authentication header to outgoing HTTPClient Requests if Oauth authentication is enabled.
|
* This method invokes return initiateXMLHttpRequest for get calls
|
||||||
* @param method HTTP request type.
|
* @param endpoint Backend REST API url.
|
||||||
* @param url target url.
|
* @param responseCallback a function to be called with response retrieved.
|
||||||
* @param payload payload/data which need to be send.
|
|
||||||
* @param successCallback a function to be called if the respond if successful.
|
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
|
||||||
*/
|
*/
|
||||||
privateMethods.initiateHTTPClientRequest = function (method, url, successCallback, errorCallback, payload, contentType, acceptType) {
|
publicXMLHTTPInvokers.get = function (endpoint, responseCallback) {
|
||||||
var HttpClient = Packages.org.apache.commons.httpclient.HttpClient;
|
var requestPayload = null;
|
||||||
var httpMethodObject;
|
return privateMethods.initiateXMLHTTPRequest(constants["HTTP_GET"], requestPayload, endpoint, responseCallback);
|
||||||
switch (method) {
|
|
||||||
case constants.HTTP_POST:
|
|
||||||
var PostMethod = Packages.org.apache.commons.httpclient.methods.PostMethod;
|
|
||||||
httpMethodObject = new PostMethod(url);
|
|
||||||
break;
|
|
||||||
case constants.HTTP_PUT:
|
|
||||||
var PutMethod = Packages.org.apache.commons.httpclient.methods.PutMethod;
|
|
||||||
httpMethodObject = new PutMethod(url);
|
|
||||||
break;
|
|
||||||
case constants.HTTP_GET:
|
|
||||||
var GetMethod = Packages.org.apache.commons.httpclient.methods.GetMethod;
|
|
||||||
httpMethodObject = new GetMethod(url);
|
|
||||||
break;
|
|
||||||
case constants.HTTP_DELETE:
|
|
||||||
var DeleteMethod = Packages.org.apache.commons.httpclient.methods.DeleteMethod;
|
|
||||||
httpMethodObject = new DeleteMethod(url);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("Invalid HTTP request type: " + method);
|
|
||||||
}
|
|
||||||
var Header = Packages.org.apache.commons.httpclient.Header;
|
|
||||||
var header = new Header();
|
|
||||||
header.setName(constants.CONTENT_TYPE_IDENTIFIER);
|
|
||||||
header.setValue(contentType);
|
|
||||||
httpMethodObject.addRequestHeader(header);
|
|
||||||
header = new Header();
|
|
||||||
header.setName(constants.ACCEPT_IDENTIFIER);
|
|
||||||
header.setValue(acceptType);
|
|
||||||
httpMethodObject.addRequestHeader(header);
|
|
||||||
header = new Header();
|
|
||||||
header.setName(constants.REFERER);
|
|
||||||
header.setValue(String(privateMethods.getClientDomain()));
|
|
||||||
httpMethodObject.addRequestHeader(header);
|
|
||||||
if (IS_OAUTH_ENABLED) {
|
|
||||||
var accessToken = privateMethods.getAccessToken();
|
|
||||||
if (accessToken) {
|
|
||||||
header = new Header();
|
|
||||||
header.setName(constants.AUTHORIZATION_HEADER);
|
|
||||||
header.setValue(constants.BEARER_PREFIX + accessToken);
|
|
||||||
httpMethodObject.addRequestHeader(header);
|
|
||||||
} else {
|
|
||||||
response.sendRedirect(devicemgtProps["httpsURL"] + "/devicemgt/login");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (payload) {
|
|
||||||
var stringRequestEntity = new StringRequestEntity(stringify(payload));
|
|
||||||
httpMethodObject.setRequestEntity(stringRequestEntity);
|
|
||||||
}
|
|
||||||
var client = new HttpClient();
|
|
||||||
try {
|
|
||||||
client.executeMethod(httpMethodObject);
|
|
||||||
var status = httpMethodObject.getStatusCode();
|
|
||||||
if (status == 200) {
|
|
||||||
var responseContentDispositionHeader = httpMethodObject.getResponseHeader(constants.CONTENT_DISPOSITION_IDENTIFIER);
|
|
||||||
if (responseContentDispositionHeader) {
|
|
||||||
return successCallback(httpMethodObject.getResponseBodyAsStream(), httpMethodObject.getResponseHeaders());
|
|
||||||
} else {
|
|
||||||
return successCallback(httpMethodObject.getResponseBody());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return errorCallback(httpMethodObject.getResponseBody());
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
return errorCallback(response);
|
|
||||||
} finally {
|
|
||||||
httpMethodObject.releaseConnection();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method invokes return initiateXMLHttpRequest for post calls
|
||||||
|
* @param endpoint Backend REST API url.
|
||||||
|
* @param requestPayload payload/data if exists which is needed to be send.
|
||||||
|
* @param responseCallback a function to be called with response retrieved.
|
||||||
|
*/
|
||||||
|
publicXMLHTTPInvokers.post = function (endpoint, requestPayload, responseCallback) {
|
||||||
|
return privateMethods.initiateXMLHTTPRequest(constants["HTTP_POST"], requestPayload, endpoint, responseCallback);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method invokes return initiateXMLHttpRequest for put calls
|
||||||
|
* @param endpoint Backend REST API url.
|
||||||
|
* @param requestPayload payload/data if exists which is needed to be send.
|
||||||
|
* @param responseCallback a function to be called with response retrieved.
|
||||||
|
*/
|
||||||
|
publicXMLHTTPInvokers.put = function (endpoint, requestPayload, responseCallback) {
|
||||||
|
return privateMethods.initiateXMLHTTPRequest(constants["HTTP_PUT"], requestPayload, endpoint, responseCallback);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method invokes return initiateXMLHttpRequest for delete calls
|
||||||
|
* @param endpoint Backend REST API url.
|
||||||
|
* @param responseCallback a function to be called with response retrieved.
|
||||||
|
*/
|
||||||
|
publicXMLHTTPInvokers.delete = function (endpoint, responseCallback) {
|
||||||
|
var requestPayload = null;
|
||||||
|
return privateMethods.initiateXMLHTTPRequest(constants["HTTP_DELETE"], requestPayload, endpoint, responseCallback);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ---------------------------------------------------------------------------
|
||||||
|
* Start of WS-REQUEST based Interceptor implementations
|
||||||
|
* ---------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method add Oauth authentication header to outgoing WS Requests if Oauth authentication is enabled.
|
* This method add Oauth authentication header to outgoing WS Requests if Oauth authentication is enabled.
|
||||||
* @param action
|
* @param action
|
||||||
@ -202,32 +173,26 @@ var backendServiceInvoker = function () {
|
|||||||
* @param soapVersion soapVersion which need to used.
|
* @param soapVersion soapVersion which need to used.
|
||||||
*/
|
*/
|
||||||
privateMethods.initiateWSRequest = function (action, endpoint, successCallback, errorCallback, soapVersion, payload) {
|
privateMethods.initiateWSRequest = function (action, endpoint, successCallback, errorCallback, soapVersion, payload) {
|
||||||
var ws = require('ws');
|
var ws = require("ws");
|
||||||
var wsRequest = new ws.WSRequest();
|
var wsRequest = new ws.WSRequest();
|
||||||
var options = [];
|
var options = [];
|
||||||
if (IS_OAUTH_ENABLED) {
|
if (devicemgtProps["isOAuthEnabled"]) {
|
||||||
var accessToken = privateMethods.getAccessToken();
|
var accessToken = privateMethods.getAccessToken();
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
var authenticationHeaderName = String(constants.AUTHORIZATION_HEADER);
|
var authenticationHeaderName = String(constants["AUTHORIZATION_HEADER"]);
|
||||||
var authenticationHeaderValue = String(constants.BEARER_PREFIX + accessToken);
|
var authenticationHeaderValue = String(constants["BEARER_PREFIX"] + accessToken);
|
||||||
var headers = [];
|
var headers = [];
|
||||||
var oAuthAuthenticationData = {};
|
var oAuthAuthenticationData = {};
|
||||||
oAuthAuthenticationData.name = authenticationHeaderName;
|
oAuthAuthenticationData.name = authenticationHeaderName;
|
||||||
oAuthAuthenticationData.value = authenticationHeaderValue;
|
oAuthAuthenticationData.value = authenticationHeaderValue;
|
||||||
headers.push(oAuthAuthenticationData);
|
headers.push(oAuthAuthenticationData);
|
||||||
|
|
||||||
var referrerData = {};
|
|
||||||
referrerData.name = constants.REFERER;
|
|
||||||
referrerData.value = String(privateMethods.getClientDomain());
|
|
||||||
headers.push(referrerData);
|
|
||||||
|
|
||||||
options.HTTPHeaders = headers;
|
options.HTTPHeaders = headers;
|
||||||
} else {
|
} else {
|
||||||
response.sendRedirect(devicemgtProps["httpsURL"] + "/devicemgt/login");
|
response.sendRedirect(devicemgtProps["appContext"] + "login");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
options.useSOAP = soapVersion;
|
options.useSOAP = soapVersion;
|
||||||
options.useWSA = constants.WEB_SERVICE_ADDRESSING_VERSION;
|
options.useWSA = constants["WEB_SERVICE_ADDRESSING_VERSION"];
|
||||||
options.action = action;
|
options.action = action;
|
||||||
var wsResponse;
|
var wsResponse;
|
||||||
try {
|
try {
|
||||||
@ -244,60 +209,94 @@ var backendServiceInvoker = function () {
|
|||||||
return successCallback(wsResponse);
|
return successCallback(wsResponse);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* This method invokes return initiateXMLHttpRequest for get calls
|
|
||||||
* @param url target url.
|
|
||||||
* @param successCallback a function to be called if the respond if successful.
|
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
|
||||||
*/
|
|
||||||
publicXMLHTTPInvokers.get = function (url, successCallback, errorCallback, contentType, acceptType) {
|
|
||||||
return privateMethods.initiateXMLHTTPRequest(constants.HTTP_GET, url, successCallback, errorCallback, contentType, acceptType);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method invokes return initiateXMLHttpRequest for post calls
|
|
||||||
* @param url target url.
|
|
||||||
* @param payload payload/data which need to be send.
|
|
||||||
* @param successCallback a function to be called if the respond if successful.
|
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
|
||||||
*/
|
|
||||||
publicXMLHTTPInvokers.post = function (url, payload, successCallback, errorCallback, contentType, acceptType) {
|
|
||||||
return privateMethods.initiateXMLHTTPRequest(constants.HTTP_POST, url, successCallback, errorCallback, payload, contentType, acceptType);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method invokes return initiateXMLHttpRequest for put calls
|
|
||||||
* @param url target url.
|
|
||||||
* @param payload payload/data which need to be send.
|
|
||||||
* @param successCallback a function to be called if the respond if successful.
|
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
|
||||||
*/
|
|
||||||
publicXMLHTTPInvokers.put = function (url, payload, successCallback, errorCallback, contentType, acceptType) {
|
|
||||||
return privateMethods.initiateXMLHTTPRequest(constants.HTTP_PUT, url, successCallback, errorCallback, payload, contentType, acceptType);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method invokes return initiateXMLHttpRequest for delete calls
|
|
||||||
* @param url target url.
|
|
||||||
* @param successCallback a function to be called if the respond if successful.
|
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
|
||||||
*/
|
|
||||||
publicXMLHTTPInvokers.delete = function (url, successCallback, errorCallback, contentType, acceptType) {
|
|
||||||
return privateMethods.initiateXMLHTTPRequest(constants.HTTP_DELETE, url, successCallback, errorCallback, contentType, acceptType);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method invokes return initiateWSRequest for soap calls
|
* This method invokes return initiateWSRequest for soap calls
|
||||||
|
* @param action describes particular soap action.
|
||||||
|
* @param requestPayload SOAP request payload which is needed to be send.
|
||||||
* @param endpoint service end point to be triggered.
|
* @param endpoint service end point to be triggered.
|
||||||
* @param payload soap payload which need to be send.
|
|
||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
* @param soapVersion soapVersion which need to used.
|
* @param soapVersion soapVersion which need to used.
|
||||||
*/
|
*/
|
||||||
publicWSInvokers.soapRequest = function (action, endpoint, payload, successCallback, errorCallback, soapVersion) {
|
publicWSInvokers.soapRequest = function (action, requestPayload, endpoint, successCallback, errorCallback, soapVersion) {
|
||||||
return privateMethods.initiateWSRequest(action, endpoint, successCallback, errorCallback, soapVersion, payload);
|
return privateMethods.initiateWSRequest(action, endpoint, successCallback, errorCallback, soapVersion, requestPayload);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ---------------------------------------------------------------------------
|
||||||
|
* Start of HTTP-CLIENT-REQUEST based Interceptor implementations
|
||||||
|
* ---------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method add Oauth authentication header to outgoing HTTPClient Requests if Oauth authentication is enabled.
|
||||||
|
* @param method HTTP request type.
|
||||||
|
* @param url target url.
|
||||||
|
* @param payload payload/data which need to be send.
|
||||||
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
|
*/
|
||||||
|
privateMethods.initiateHTTPClientRequest = function (method, url, successCallback, errorCallback, payload) {
|
||||||
|
var HttpClient = Packages.org.apache.commons.httpclient.HttpClient;
|
||||||
|
var httpMethodObject;
|
||||||
|
switch (method) {
|
||||||
|
case constants["HTTP_GET"]:
|
||||||
|
var GetMethod = Packages.org.apache.commons.httpclient.methods.GetMethod;
|
||||||
|
httpMethodObject = new GetMethod(url);
|
||||||
|
break;
|
||||||
|
case constants["HTTP_POST"]:
|
||||||
|
var PostMethod = Packages.org.apache.commons.httpclient.methods.PostMethod;
|
||||||
|
httpMethodObject = new PostMethod(url);
|
||||||
|
break;
|
||||||
|
case constants["HTTP_PUT"]:
|
||||||
|
var PutMethod = Packages.org.apache.commons.httpclient.methods.PutMethod;
|
||||||
|
httpMethodObject = new PutMethod(url);
|
||||||
|
break;
|
||||||
|
case constants["HTTP_DELETE"]:
|
||||||
|
var DeleteMethod = Packages.org.apache.commons.httpclient.methods.DeleteMethod;
|
||||||
|
httpMethodObject = new DeleteMethod(url);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Invalid HTTP request method: " + method);
|
||||||
|
}
|
||||||
|
var Header = Packages.org.apache.commons.httpclient.Header;
|
||||||
|
var header = new Header();
|
||||||
|
header.setName(constants["CONTENT_TYPE_IDENTIFIER"]);
|
||||||
|
header.setValue(constants["APPLICATION_JSON"]);
|
||||||
|
httpMethodObject.addRequestHeader(header);
|
||||||
|
header = new Header();
|
||||||
|
header.setName(constants["ACCEPT_IDENTIFIER"]);
|
||||||
|
header.setValue(constants["APPLICATION_JSON"]);
|
||||||
|
httpMethodObject.addRequestHeader(header);
|
||||||
|
|
||||||
|
if (devicemgtProps["isOAuthEnabled"]) {
|
||||||
|
var accessToken = privateMethods.getAccessToken();
|
||||||
|
if (accessToken) {
|
||||||
|
header = new Header();
|
||||||
|
header.setName(constants["AUTHORIZATION_HEADER"]);
|
||||||
|
header.setValue(constants["BEARER_PREFIX"] + accessToken);
|
||||||
|
httpMethodObject.addRequestHeader(header);
|
||||||
|
} else {
|
||||||
|
response.sendRedirect(devicemgtProps["appContext"] + "login");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var stringRequestEntity = new StringRequestEntity(stringify(payload));
|
||||||
|
httpMethodObject.setRequestEntity(stringRequestEntity);
|
||||||
|
var client = new HttpClient();
|
||||||
|
try {
|
||||||
|
client.executeMethod(httpMethodObject);
|
||||||
|
var status = httpMethodObject.getStatusCode();
|
||||||
|
if (status == 200) {
|
||||||
|
return successCallback(httpMethodObject.getResponseBody());
|
||||||
|
} else {
|
||||||
|
return errorCallback(httpMethodObject.getResponseBody());
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return errorCallback(response);
|
||||||
|
} finally {
|
||||||
|
method.releaseConnection();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method invokes return initiateHTTPClientRequest for get calls
|
* This method invokes return initiateHTTPClientRequest for get calls
|
||||||
@ -305,8 +304,10 @@ var backendServiceInvoker = function () {
|
|||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
*/
|
*/
|
||||||
publicHTTPClientInvokers.get = function (url, successCallback, errorCallback, contentType, acceptType) {
|
publicHTTPClientInvokers.get = function (url, successCallback, errorCallback) {
|
||||||
return privateMethods.initiateHTTPClientRequest(constants.HTTP_GET, url, successCallback, errorCallback, null, contentType, acceptType);
|
var requestPayload = null;
|
||||||
|
return privateMethods.
|
||||||
|
initiateHTTPClientRequest(constants["HTTP_GET"], url, successCallback, errorCallback, requestPayload);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -316,9 +317,9 @@ var backendServiceInvoker = function () {
|
|||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
*/
|
*/
|
||||||
publicHTTPClientInvokers.post = function (url, payload, successCallback, errorCallback, contentType, acceptType) {
|
publicHTTPClientInvokers.post = function (url, payload, successCallback, errorCallback) {
|
||||||
return privateMethods.
|
return privateMethods.
|
||||||
initiateHTTPClientRequest(constants.HTTP_POST, url, successCallback, errorCallback, payload, contentType, acceptType);
|
initiateHTTPClientRequest(constants["HTTP_POST"], url, successCallback, errorCallback, payload);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -328,8 +329,9 @@ var backendServiceInvoker = function () {
|
|||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
*/
|
*/
|
||||||
publicHTTPClientInvokers.put = function (url, payload, successCallback, errorCallback, contentType, acceptType) {
|
publicHTTPClientInvokers.put = function (url, payload, successCallback, errorCallback) {
|
||||||
return privateMethods.initiateHTTPClientRequest(constants.HTTP_PUT, url, successCallback, errorCallback, payload, contentType, acceptType);
|
return privateMethods.
|
||||||
|
initiateHTTPClientRequest(constants["HTTP_PUT"], url, successCallback, errorCallback, payload);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -338,23 +340,16 @@ var backendServiceInvoker = function () {
|
|||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
*/
|
*/
|
||||||
publicHTTPClientInvokers.delete = function (url, successCallback, errorCallback, contentType, acceptType) {
|
publicHTTPClientInvokers.delete = function (url, successCallback, errorCallback) {
|
||||||
return privateMethods.initiateHTTPClientRequest(constants.HTTP_DELETE, url, successCallback, errorCallback, contentType, acceptType);
|
var requestPayload = null;
|
||||||
|
return privateMethods.
|
||||||
|
initiateHTTPClientRequest(constants["HTTP_DELETE"], url, successCallback, errorCallback, requestPayload);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
var publicMethods = {};
|
||||||
* This method fetch the current logged user from the session and returns
|
publicMethods.XMLHttp = publicXMLHTTPInvokers;
|
||||||
* the tenant domain name of the user
|
publicMethods.WS = publicWSInvokers;
|
||||||
* @returns {tenantDomain}
|
publicMethods.HttpClient = publicHTTPClientInvokers;
|
||||||
*/
|
|
||||||
privateMethods.getClientDomain = function () {
|
|
||||||
var user = session.get(constants.USER_SESSION_KEY);
|
|
||||||
return user.domain;
|
|
||||||
}
|
|
||||||
|
|
||||||
var publicInvokers = {};
|
return publicMethods;
|
||||||
publicInvokers.XMLHttp = publicXMLHTTPInvokers;
|
}();
|
||||||
publicInvokers.WS = publicWSInvokers;
|
|
||||||
publicInvokers.HttpClient = publicHTTPClientInvokers;
|
|
||||||
return publicInvokers;
|
|
||||||
}();
|
|
||||||
|
|||||||
@ -25,11 +25,12 @@ var util = function () {
|
|||||||
var carbon = require('carbon');
|
var carbon = require('carbon');
|
||||||
var constants = require("/app/modules/constants.js");
|
var constants = require("/app/modules/constants.js");
|
||||||
var adminUser = devicemgtProps["adminUser"];
|
var adminUser = devicemgtProps["adminUser"];
|
||||||
|
var clientName = devicemgtProps["clientName"];
|
||||||
|
|
||||||
module.getDyanmicCredentials = function (owner) {
|
module.getDyanmicCredentials = function (owner) {
|
||||||
var payload = {
|
var payload = {
|
||||||
"callbackUrl": devicemgtProps.callBackUrl,
|
"callbackUrl": devicemgtProps.callBackUrl,
|
||||||
"clientName": "devicemgt",
|
"clientName": clientName,
|
||||||
"tokenScope": "admin",
|
"tokenScope": "admin",
|
||||||
"owner": adminUser,
|
"owner": adminUser,
|
||||||
"applicationType": "webapp",
|
"applicationType": "webapp",
|
||||||
@ -79,7 +80,7 @@ var util = function () {
|
|||||||
*/
|
*/
|
||||||
module.getTokenWithPasswordGrantType = function (username, password, encodedClientKeys, scope) {
|
module.getTokenWithPasswordGrantType = function (username, password, encodedClientKeys, scope) {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
var tokenEndpoint = devicemgtProps.idPServer + "/token";
|
var tokenEndpoint = devicemgtProps.idPServer;
|
||||||
xhr.open("POST", tokenEndpoint, false);
|
xhr.open("POST", tokenEndpoint, false);
|
||||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + encodedClientKeys);
|
xhr.setRequestHeader("Authorization", "Basic " + encodedClientKeys);
|
||||||
@ -119,7 +120,7 @@ var util = function () {
|
|||||||
encodedExtractedAssertion = this.encode(extractedAssertion);
|
encodedExtractedAssertion = this.encode(extractedAssertion);
|
||||||
|
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
var tokenEndpoint = devicemgtProps.idPServer + "/token";
|
var tokenEndpoint = devicemgtProps.idPServer;
|
||||||
xhr.open("POST", tokenEndpoint, false);
|
xhr.open("POST", tokenEndpoint, false);
|
||||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + clientKeys);
|
xhr.setRequestHeader("Authorization", "Basic " + clientKeys);
|
||||||
@ -140,7 +141,7 @@ var util = function () {
|
|||||||
|
|
||||||
module.refreshToken = function (tokenPair, clientData, scope) {
|
module.refreshToken = function (tokenPair, clientData, scope) {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
var tokenEndpoint = devicemgtProps.idPServer + "/token";
|
var tokenEndpoint = devicemgtProps.idPServer;
|
||||||
xhr.open("POST", tokenEndpoint, false);
|
xhr.open("POST", tokenEndpoint, false);
|
||||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + clientData);
|
xhr.setRequestHeader("Authorization", "Basic " + clientData);
|
||||||
|
|||||||
@ -1,21 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
*
|
*
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||||
* KIND, either express or implied. See the License for the
|
* either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
var deviceMgtAPIsBasePath = "/api/device-mgt/v1.0";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if provided input is valid against RegEx input.
|
* Checks if provided input is valid against RegEx input.
|
||||||
*
|
*
|
||||||
@ -35,10 +37,10 @@ function inputIsValid(regExp, inputString) {
|
|||||||
$(function () {
|
$(function () {
|
||||||
var sortableElem = '.wr-sortable';
|
var sortableElem = '.wr-sortable';
|
||||||
$(sortableElem).sortable({
|
$(sortableElem).sortable({
|
||||||
beforeStop: function () {
|
beforeStop: function () {
|
||||||
var sortedIDs = $(this).sortable('toArray');
|
$(this).sortable('toArray');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$(sortableElem).disableSelection();
|
$(sortableElem).disableSelection();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -46,11 +48,9 @@ var modalPopup = ".wr-modalpopup";
|
|||||||
var modalPopupContainer = modalPopup + " .modalpopup-container";
|
var modalPopupContainer = modalPopup + " .modalpopup-container";
|
||||||
var modalPopupContent = modalPopup + " .modalpopup-content";
|
var modalPopupContent = modalPopup + " .modalpopup-content";
|
||||||
var body = "body";
|
var body = "body";
|
||||||
var isInit = true;
|
//var isInit = true;
|
||||||
$(".icon .text").res_text(0.2);
|
$(".icon .text").res_text(0.2);
|
||||||
|
|
||||||
var resetPasswordServiceURL = "/devicemgt_admin/users/reset-password";
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* set popup maximum height function.
|
* set popup maximum height function.
|
||||||
*/
|
*/
|
||||||
@ -80,11 +80,9 @@ function hidePopup() {
|
|||||||
*/
|
*/
|
||||||
function getSelectedUsernames() {
|
function getSelectedUsernames() {
|
||||||
var usernameList = [];
|
var usernameList = [];
|
||||||
var userList = $("#user-grid").find('> tbody > tr');
|
var userList = $("#user-grid").find('tr.DTTT_selected');
|
||||||
userList.each(function () {
|
userList.each(function () {
|
||||||
if ($(this).hasClass('DTTT_selected')) {
|
usernameList.push($(this).data('username'));
|
||||||
usernameList.push($(this).attr('data-username'));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return usernameList;
|
return usernameList;
|
||||||
}
|
}
|
||||||
@ -96,7 +94,7 @@ function getSelectedUsernames() {
|
|||||||
*/
|
*/
|
||||||
$("a.invite-user-link").click(function () {
|
$("a.invite-user-link").click(function () {
|
||||||
var usernameList = getSelectedUsernames();
|
var usernameList = getSelectedUsernames();
|
||||||
var inviteUserAPI = "/devicemgt_admin/users/email-invitation";
|
var inviteUserAPI = deviceMgtAPIsBasePath + "/users/send-invitation";
|
||||||
|
|
||||||
if (usernameList.length == 0) {
|
if (usernameList.length == 0) {
|
||||||
$(modalPopupContent).html($("#errorUsers").html());
|
$(modalPopupContent).html($("#errorUsers").html());
|
||||||
@ -108,20 +106,25 @@ $("a.invite-user-link").click(function () {
|
|||||||
|
|
||||||
$("a#invite-user-yes-link").click(function () {
|
$("a#invite-user-yes-link").click(function () {
|
||||||
invokerUtil.post(
|
invokerUtil.post(
|
||||||
inviteUserAPI,
|
inviteUserAPI,
|
||||||
usernameList,
|
usernameList,
|
||||||
function () {
|
// The success callback
|
||||||
|
function (data, textStatus, jqXHR) {
|
||||||
|
if (jqXHR.status == 200) {
|
||||||
$(modalPopupContent).html($('#invite-user-success-content').html());
|
$(modalPopupContent).html($('#invite-user-success-content').html());
|
||||||
$("a#invite-user-success-link").click(function () {
|
$("a#invite-user-success-link").click(function () {
|
||||||
hidePopup();
|
hidePopup();
|
||||||
});
|
});
|
||||||
},
|
|
||||||
function () {
|
|
||||||
$(modalPopupContent).html($('#invite-user-error-content').html());
|
|
||||||
$("a#invite-user-error-link").click(function () {
|
|
||||||
hidePopup();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
// The error callback
|
||||||
|
function (jqXHR) {
|
||||||
|
console.log("error in invite-user API, status code: " + jqXHR.status);
|
||||||
|
$(modalPopupContent).html($('#invite-user-error-content').html());
|
||||||
|
$("a#invite-user-error-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
});
|
||||||
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -137,16 +140,17 @@ $("a.invite-user-link").click(function () {
|
|||||||
*/
|
*/
|
||||||
function removeUser(uname, uid) {
|
function removeUser(uname, uid) {
|
||||||
var username = uname;
|
var username = uname;
|
||||||
var userid = uid;
|
var userId = uid;
|
||||||
var removeUserAPI = "/devicemgt_admin/users?username=" + username;
|
var removeUserAPI = deviceMgtAPIsBasePath + "/users/" + username;
|
||||||
$(modalPopupContent).html($('#remove-user-modal-content').html());
|
$(modalPopupContent).html($('#remove-user-modal-content').html());
|
||||||
showPopup();
|
showPopup();
|
||||||
|
|
||||||
$("a#remove-user-yes-link").click(function () {
|
$("a#remove-user-yes-link").click(function () {
|
||||||
invokerUtil.delete(
|
invokerUtil.delete(
|
||||||
removeUserAPI,
|
removeUserAPI,
|
||||||
function () {
|
function (data, textStatus, jqXHR) {
|
||||||
$("#" + userid).remove();
|
if (jqXHR.status == 200) {
|
||||||
|
$("#" + userId).remove();
|
||||||
// get new user-list-count
|
// get new user-list-count
|
||||||
var newUserListCount = $(".user-list > span").length;
|
var newUserListCount = $(".user-list > span").length;
|
||||||
// update user-listing-status-msg with new user-count
|
// update user-listing-status-msg with new user-count
|
||||||
@ -156,13 +160,16 @@ function removeUser(uname, uid) {
|
|||||||
$("a#remove-user-success-link").click(function () {
|
$("a#remove-user-success-link").click(function () {
|
||||||
hidePopup();
|
hidePopup();
|
||||||
});
|
});
|
||||||
},
|
|
||||||
function () {
|
|
||||||
$(modalPopupContent).html($('#remove-user-error-content').html());
|
|
||||||
$("a#remove-user-error-link").click(function () {
|
|
||||||
hidePopup();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
// The error callback
|
||||||
|
function (jqXHR) {
|
||||||
|
console.log("error in remove-user API, status code: " + jqXHR.status);
|
||||||
|
$(modalPopupContent).html($('#remove-user-error-content').html());
|
||||||
|
$("a#remove-user-error-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
});
|
||||||
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -202,29 +209,30 @@ function resetPassword(uname) {
|
|||||||
$(errorMsgWrapper).removeClass("hidden");
|
$(errorMsgWrapper).removeClass("hidden");
|
||||||
} else {
|
} else {
|
||||||
var resetPasswordFormData = {};
|
var resetPasswordFormData = {};
|
||||||
resetPasswordFormData.username = user;
|
//resetPasswordFormData.username = user;
|
||||||
resetPasswordFormData.newPassword = window.btoa(unescape(encodeURIComponent(confirmedPassword)));
|
resetPasswordFormData.newPassword = unescape(confirmedPassword);
|
||||||
|
|
||||||
|
var resetPasswordServiceURL = deviceMgtAPIsBasePath + "/admin/users/"+ user +"/credentials";
|
||||||
|
|
||||||
invokerUtil.post(
|
invokerUtil.post(
|
||||||
resetPasswordServiceURL,
|
resetPasswordServiceURL,
|
||||||
resetPasswordFormData,
|
resetPasswordFormData,
|
||||||
function (data) { // The success callback
|
// The success callback
|
||||||
data = JSON.parse(data);
|
function (data, textStatus, jqXHR) {
|
||||||
if (data.statusCode == 201) {
|
if (jqXHR.status == 200) {
|
||||||
$(modalPopupContent).html($('#reset-password-success-content').html());
|
$(modalPopupContent).html($('#reset-password-success-content').html());
|
||||||
$("a#reset-password-success-link").click(function () {
|
$("a#reset-password-success-link").click(function () {
|
||||||
hidePopup();
|
hidePopup();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}, function (data) { // The error callback
|
|
||||||
if (data.statusCode == 400) {
|
|
||||||
$(errorMsg).text("Old password does not match with the provided value.");
|
|
||||||
$(errorMsgWrapper).removeClass("hidden");
|
|
||||||
} else {
|
|
||||||
$(errorMsg).text("An unexpected error occurred. Please try again later.");
|
|
||||||
$(errorMsgWrapper).removeClass("hidden");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
// The error callback
|
||||||
|
function (jqXHR) {
|
||||||
|
console.log("error in reset-password API, status code: " + jqXHR.status);
|
||||||
|
var payload = JSON.parse(jqXHR.responseText);
|
||||||
|
$(errorMsg).text(payload.message);
|
||||||
|
$(errorMsgWrapper).removeClass("hidden");
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -250,7 +258,7 @@ $("#search-btn").click(function () {
|
|||||||
* when a user clicks on the list item
|
* when a user clicks on the list item
|
||||||
* initial mode and with out select mode.
|
* initial mode and with out select mode.
|
||||||
*/
|
*/
|
||||||
function InitiateViewOption() {
|
function initiateViewOption() {
|
||||||
if ($("#can-view").val()) {
|
if ($("#can-view").val()) {
|
||||||
$(location).attr('href', $(this).data("url"));
|
$(location).attr('href', $(this).data("url"));
|
||||||
} else {
|
} else {
|
||||||
@ -259,74 +267,112 @@ function InitiateViewOption() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadUsers(searchParam) {
|
function loadUsers() {
|
||||||
$("#loading-content").show();
|
var loadingContentIcon = "#loading-content";
|
||||||
var userListing = $("#user-listing");
|
$(loadingContentIcon).show();
|
||||||
var userListingSrc = userListing.attr("src");
|
|
||||||
$.template("user-listing", userListingSrc, function (template) {
|
var dataFilter = function (data) {
|
||||||
var serviceURL = "/devicemgt_admin/users";
|
data = JSON.parse(data);
|
||||||
if (searchParam) {
|
|
||||||
serviceURL = serviceURL + "/view-users?username=" + searchParam;
|
var objects = [];
|
||||||
}
|
|
||||||
var successCallback = function (data) {
|
$(data.users).each(function (index) {
|
||||||
if (!data) {
|
objects.push({
|
||||||
$('#ast-container').addClass('hidden');
|
username: data.users[index].username,
|
||||||
$('#user-listing-status-msg').text('No users are available to be displayed.');
|
firstname: data.users[index].firstname ? data.users[index].firstname: '' ,
|
||||||
return;
|
lastname: data.users[index].lastname ? data.users[index].lastname : '',
|
||||||
}
|
emailAddress : data.users[index].emailAddress ? data.users[index].emailAddress: '',
|
||||||
var canRemove = $("#can-remove").val();
|
DT_RowId : "role-" + data.users[index].username})
|
||||||
var canEdit = $("#can-edit").val();
|
});
|
||||||
var canResetPassword = $("#can-reset-password").val();
|
|
||||||
data = JSON.parse(data);
|
var json = {
|
||||||
data = data.responseContent;
|
"recordsTotal": data.count,
|
||||||
var viewModel = {};
|
"recordsFiltered": data.count,
|
||||||
viewModel.users = data;
|
"data": objects
|
||||||
for (var i = 0; i < viewModel.users.length; i++) {
|
|
||||||
viewModel.users[i].userid = viewModel.users[i].username.replace(/[^\w\s]/gi, '');
|
|
||||||
if (canRemove) {
|
|
||||||
viewModel.users[i].canRemove = true;
|
|
||||||
}
|
|
||||||
if (canEdit) {
|
|
||||||
viewModel.users[i].canEdit = true;
|
|
||||||
}
|
|
||||||
if (canResetPassword) {
|
|
||||||
viewModel.users[i].canResetPassword = true;
|
|
||||||
}
|
|
||||||
viewModel.users[i].adminUser = $("#user-table").data("user");
|
|
||||||
}
|
|
||||||
if (data.length > 0) {
|
|
||||||
$('#ast-container').removeClass('hidden');
|
|
||||||
$('#user-listing-status-msg').text("");
|
|
||||||
var content = template(viewModel);
|
|
||||||
$("#ast-container").html(content);
|
|
||||||
} else {
|
|
||||||
$('#ast-container').addClass('hidden');
|
|
||||||
$('#user-listing-status-msg').text('No users are available to be displayed.');
|
|
||||||
}
|
|
||||||
$("#loading-content").hide();
|
|
||||||
if (isInit) {
|
|
||||||
$('#user-grid').datatables_extended();
|
|
||||||
isInit = false;
|
|
||||||
}
|
|
||||||
$(".icon .text").res_text(0.2);
|
|
||||||
};
|
};
|
||||||
invokerUtil.get(serviceURL,
|
|
||||||
successCallback,
|
return JSON.stringify(json);
|
||||||
function (message) {
|
};
|
||||||
$('#ast-container').addClass('hidden');
|
|
||||||
$('#user-listing-status-msg').text('Invalid search query. Try again with a valid search query');
|
var fnCreatedRow = function(nRow, aData, iDataIndex) {
|
||||||
}
|
console.log(JSON.stringify(aData));
|
||||||
);
|
$(nRow).attr('data-type', 'selectable');
|
||||||
});
|
$(nRow).attr('data-username', aData["username"]);
|
||||||
|
};
|
||||||
|
|
||||||
|
var columns = [
|
||||||
|
{
|
||||||
|
class: "remove-padding icon-only content-fill",
|
||||||
|
data: null,
|
||||||
|
defaultContent:
|
||||||
|
'<div class="thumbnail icon">' +
|
||||||
|
'<i class="square-element text fw fw-user" style="font-size: 30px;"></i>' +
|
||||||
|
'</div>'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
class: "fade-edge",
|
||||||
|
data: null,
|
||||||
|
render: function (data, type, row, meta) {
|
||||||
|
return '<h4>' + data.firstname + ' ' + data.lastname + '</h4>';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
class: "fade-edge remove-padding-top",
|
||||||
|
data: null,
|
||||||
|
render: function (data, type, row, meta) {
|
||||||
|
return '<i class="fw-user"></i> ' + data.username;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
class: "fade-edge remove-padding-top",
|
||||||
|
data: null,
|
||||||
|
render: function (data, type, row, meta) {
|
||||||
|
return '<a href="mailto:' + data.emailAddress + ' " class="wr-list-email"><i class="fw-mail"></i> ' +
|
||||||
|
data.emailAddress + ' </a>';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
class: "text-right content-fill text-left-on-grid-view no-wrap",
|
||||||
|
data: null,
|
||||||
|
render: function (data, type, row, meta) {
|
||||||
|
return '<a href="/emm/users/edit-user?username=' + data.username + '" data-username="' + data.username +
|
||||||
|
'" data-click-event="edit-form" class="btn padding-reduce-on-grid-view edit-user-link"> ' +
|
||||||
|
'<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i>' +
|
||||||
|
'<i class="fw fw-edit fw-stack-1x"></i>' +
|
||||||
|
' </span> <span class="hidden-xs hidden-on-grid-view">Edit</span> </a>' +
|
||||||
|
|
||||||
|
'<a href="#" data-username="' + data.username + '" data-user-id=' + data.username +
|
||||||
|
' data-click-event="remove-form" onclick="javascript:removeUser(\'' + data.username + '\', \'' +
|
||||||
|
data.username + '\')" class="btn padding-reduce-on-grid-view remove-user-link">' +
|
||||||
|
'<span class="fw-stack"> <i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-delete fw-stack-1x">' +
|
||||||
|
'</i> </span> <span class="hidden-xs hidden-on-grid-view">Remove</span> </a>' +
|
||||||
|
|
||||||
|
'<a href="#" data-username="' + data.username + '" data-user-id="' + data.username +
|
||||||
|
'" data-click-event="edit-form" onclick="javascript:resetPassword(\'' + data.username +
|
||||||
|
'\')" class="btn padding-reduce-on-grid-view remove-user-link"> <span class="fw-stack">' +
|
||||||
|
'<i class="fw fw-ring fw-stack-2x">' +
|
||||||
|
'</i> <i class="fw fw-key fw-stack-1x"></i> <span class="fw-stack fw-move-right fw-move-bottom"> ' +
|
||||||
|
'<i class="fw fw-circle fw-stack-2x fw-stroke fw-inverse"><' +
|
||||||
|
'/i> <i class="fw fw-circle fw-stack-2x"></i> <i class="fw fw-refresh fw-stack-1x fw-inverse">' +
|
||||||
|
'</i> </span> </span> <span class="hidden-xs hidden-on-grid-view">Reset</span> </a>'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
$('#user-grid').datatables_extended_serverside_paging(null, '/api/device-mgt/v1.0/users', dataFilter, columns, fnCreatedRow, null);
|
||||||
|
|
||||||
|
$("#loading-content").hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
loadUsers();
|
loadUsers();
|
||||||
|
|
||||||
$(".viewEnabledIcon").click(function () {
|
$(".viewEnabledIcon").click(function () {
|
||||||
InitiateViewOption();
|
initiateViewOption();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!$("#can-invite").val()) {
|
if (!$("#can-invite").val()) {
|
||||||
$("#invite-user-button").remove();
|
$("#invite-user-button").remove();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -52,6 +52,11 @@
|
|||||||
<span class="fw-stack">
|
<span class="fw-stack">
|
||||||
<i class="fw fw-ring fw-stack-2x"></i>
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
<i class="fw fw-key fw-stack-1x"></i>
|
<i class="fw fw-key fw-stack-1x"></i>
|
||||||
|
<span class="fw-stack fw-move-right fw-move-bottom">
|
||||||
|
<i class="fw fw-circle fw-stack-2x fw-stroke fw-inverse"></i>
|
||||||
|
<i class="fw fw-circle fw-stack-2x"></i>
|
||||||
|
<i class="fw fw-refresh fw-stack-1x fw-inverse"></i>
|
||||||
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<span class="hidden-xs hidden-on-grid-view">Reset</span>
|
<span class="hidden-xs hidden-on-grid-view">Reset</span>
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@ -298,15 +298,13 @@
|
|||||||
Enter new password
|
Enter new password
|
||||||
<br><br>
|
<br><br>
|
||||||
<div>
|
<div>
|
||||||
<input type="password" class="form-control modal-input operationDataKeys" id="new-password"
|
<input type="password" class="form-control modal-input operationDataKeys" id="new-password" data-key="message"/>
|
||||||
data-key="message"/>
|
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
Retype new password
|
Retype new password
|
||||||
<br><br>
|
<br><br>
|
||||||
<div>
|
<div>
|
||||||
<input type="password" class="form-control modal-input operationDataKeys"
|
<input type="password" class="form-control modal-input operationDataKeys" id="confirmed-password" data-key="message"/>
|
||||||
id="confirmed-password" data-key="message"/>
|
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
</h4>
|
</h4>
|
||||||
@ -338,6 +336,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{/zone}}
|
{{/zone}}
|
||||||
{{#zone "common-navigation"}}
|
{{#zone "common-navigation"}}
|
||||||
<!--Later add the navigation menu from here-->
|
<!--Later add the navigation menu from here-->
|
||||||
|
|||||||
@ -26,13 +26,13 @@ function onRequest(context) {
|
|||||||
return options.fn(this);
|
return options.fn(this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var page = {};
|
var page = {};
|
||||||
var userModule = require("/app/modules/user.js")["userModule"];
|
var userModule = require("/app/modules/user.js")["userModule"];
|
||||||
var deviceMgtProps = require("/app/conf/devicemgt-props.js").config();
|
var deviceMgtProps = require("/app/conf/devicemgt-props.js").config();
|
||||||
|
|
||||||
|
page["adminUser"] = deviceMgtProps["adminUser"];
|
||||||
page["permissions"] = userModule.getUIPermissions();
|
page["permissions"] = userModule.getUIPermissions();
|
||||||
if (userModule.isAuthorized("/permission/admin/device-mgt/users/delete")) {
|
|
||||||
page["removePermitted"] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userModule.isAuthorized("/permission/admin/device-mgt/users/remove")) {
|
if (userModule.isAuthorized("/permission/admin/device-mgt/users/remove")) {
|
||||||
page["removePermitted"] = true;
|
page["removePermitted"] = true;
|
||||||
@ -51,6 +51,5 @@ function onRequest(context) {
|
|||||||
page["resetPasswordPermitted"] = true;
|
page["resetPasswordPermitted"] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
page["adminUser"] = deviceMgtProps.adminUser;
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
@ -19,9 +19,10 @@
|
|||||||
{{~css "css/dataTables.bootstrap.css"}}
|
{{~css "css/dataTables.bootstrap.css"}}
|
||||||
{{~css "css/dataTables.responsive.css"}}
|
{{~css "css/dataTables.responsive.css"}}
|
||||||
{{/zone}}
|
{{/zone}}
|
||||||
{{~#zone "bottomJs"}}
|
{{#zone "bottomJs"}}
|
||||||
{{~js "js/jquery.dataTables.min.js"}}
|
{{~js "js/jquery.dataTables.min.js"}}
|
||||||
{{~js "js/dataTables.bootstrap.js"}}
|
{{~js "js/dataTables.bootstrap.js"}}
|
||||||
{{~js "js/dataTables.responsive.min.js"}}
|
{{~js "js/dataTables.responsive.min.js"}}
|
||||||
{{~js "js/dataTables.extended.js"}}
|
{{~js "js/dataTables.extended.js"}}
|
||||||
|
{{~js "js/dataTables.extended.serversidepaging.js"}}
|
||||||
{{/zone}}
|
{{/zone}}
|
||||||
|
|||||||
@ -0,0 +1,281 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* =========================================================
|
||||||
|
* data-tables extended function (Server-side Pagination)
|
||||||
|
* =========================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @namespace $
|
||||||
|
* The $ is just a function.
|
||||||
|
* It is actually an alias for the function called jQuery.
|
||||||
|
* For ex: $(this) means jQuery(this) and S.fn.x means jQuery.fn.x
|
||||||
|
*/
|
||||||
|
|
||||||
|
$.fn.datatables_extended_serverside_paging = function (settings , url, dataFilter,
|
||||||
|
columns, fnCreatedRow, fnDrawCallback) {
|
||||||
|
var elem = $(this);
|
||||||
|
|
||||||
|
// EMM related function
|
||||||
|
if (initiateViewOption) {
|
||||||
|
$(".viewEnabledIcon").bind("click", initiateViewOption);
|
||||||
|
}
|
||||||
|
//--- End of EMM related codes
|
||||||
|
|
||||||
|
$(elem).DataTable(
|
||||||
|
$.extend({},{
|
||||||
|
serverSide: true,
|
||||||
|
bSortCellsTop: true,
|
||||||
|
ajax : {
|
||||||
|
url: "/emm/api/data-tables/invoker",
|
||||||
|
data : function (params) {
|
||||||
|
var filter = "";
|
||||||
|
var i;
|
||||||
|
for (i = 0; i < params.columns.length; i++) {
|
||||||
|
// console.log(i);
|
||||||
|
filter += "&" + params.columns[i].data + "=" + params.columns[i].search.value;
|
||||||
|
}
|
||||||
|
// console.log(filter);
|
||||||
|
params.offset = params.start;
|
||||||
|
params.limit = params.length;
|
||||||
|
params.filter = filter;
|
||||||
|
params.url = url;
|
||||||
|
},
|
||||||
|
dataFilter: dataFilter
|
||||||
|
},
|
||||||
|
columns: columns,
|
||||||
|
responsive: false,
|
||||||
|
autoWidth: false,
|
||||||
|
dom:'<"dataTablesTop"' +
|
||||||
|
'f' +
|
||||||
|
'<"dataTables_toolbar">' +
|
||||||
|
'>' +
|
||||||
|
'rt' +
|
||||||
|
'<"dataTablesBottom"' +
|
||||||
|
'lip' +
|
||||||
|
'>',
|
||||||
|
language: {
|
||||||
|
searchPlaceholder: 'Search by Role name',
|
||||||
|
search: ''
|
||||||
|
},
|
||||||
|
fnCreatedRow: fnCreatedRow,
|
||||||
|
"fnDrawCallback": fnDrawCallback,
|
||||||
|
initComplete: function () {
|
||||||
|
this.api().columns().every(function () {
|
||||||
|
|
||||||
|
var column = this;
|
||||||
|
var filterColumn = $('.filter-row th', elem);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create & add select/text filters to each column
|
||||||
|
*/
|
||||||
|
if (filterColumn.eq(column.index()).hasClass('select-filter')) {
|
||||||
|
var select = $('<select class="form-control"><option value="">All</option></select>')
|
||||||
|
.appendTo(filterColumn.eq(column.index()).empty())
|
||||||
|
.on('change', function () {
|
||||||
|
var val = $.fn.dataTable.util.escapeRegex(
|
||||||
|
$(this).val()
|
||||||
|
);
|
||||||
|
|
||||||
|
column
|
||||||
|
//.search(val ? '^' + val + '$' : '', true, false)
|
||||||
|
.search(val ? val : '', true, false)
|
||||||
|
.draw();
|
||||||
|
|
||||||
|
if (filterColumn.eq(column.index()).hasClass('data-platform')) {
|
||||||
|
if (val == null || val == undefined || val == "") {
|
||||||
|
$("#operation-bar").hide();
|
||||||
|
$("#operation-guide").show();
|
||||||
|
} else {
|
||||||
|
$("#operation-guide").hide();
|
||||||
|
$("#operation-bar").show();
|
||||||
|
loadOperationBar(val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$(column).each(function () {
|
||||||
|
if ($(column.nodes()).attr('data-search')) {
|
||||||
|
var titles = [];
|
||||||
|
column.nodes().unique().sort().each(function (d, j) {
|
||||||
|
var title = $(d).attr('data-display');
|
||||||
|
if ($.inArray(title, titles) < 0) {
|
||||||
|
titles.push(title);
|
||||||
|
if (title !== undefined) {
|
||||||
|
select.append('<option value="' + title + '">' + title + '</option>')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
column.data().unique().sort().each(function (d, j) {
|
||||||
|
select.append('<option value="' + d + '">' + d + '</option>')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (filterColumn.eq(column.index()).hasClass('text-filter')) {
|
||||||
|
var title = filterColumn.eq(column.index()).attr('data-for');
|
||||||
|
$(filterColumn.eq(column.index()).empty()).html('<input type="text" class="form-control" placeholder="Search ' + title + '" />');
|
||||||
|
|
||||||
|
filterColumn.eq(column.index()).find('input').on('keyup change', function () {
|
||||||
|
column.search($(this).val()).draw();
|
||||||
|
if ($('.dataTables_empty').length > 0) {
|
||||||
|
$('.bulk-action-row').addClass("hidden");
|
||||||
|
} else {
|
||||||
|
$('.bulk-action-row').removeClass("hidden");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* search input default styles override
|
||||||
|
*/
|
||||||
|
var search_input = $(this).closest('.dataTables_wrapper').find('div[id$=_filter] input');
|
||||||
|
search_input.before('<i class="fw fw-search search-icon"></i>').removeClass('input-sm');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create sorting dropdown menu for list table advance operations
|
||||||
|
*/
|
||||||
|
var dropdownmenu = $('<ul class="dropdown-menu arrow arrow-top-right dark sort-list add-margin-top-2x"><li class="dropdown-header">Sort by</li></ul>');
|
||||||
|
$('.sort-row th', elem).each(function () {
|
||||||
|
if (!$(this).hasClass('no-sort')) {
|
||||||
|
dropdownmenu.append('<li><a href="#' + $(this).html() + '" data-column="' + $(this).index() + '">' + $(this).html() + '</a></li>');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* append advance operations to list table toolbar
|
||||||
|
*/
|
||||||
|
$('.dataTable.list-table').closest('.dataTables_wrapper').find('.dataTablesTop .dataTables_toolbar').html('' +
|
||||||
|
'<ul class="nav nav-pills navbar-right remove-margin" role="tablist">' +
|
||||||
|
'<li><button data-click-event="toggle-selectable" class="btn btn-default btn-primary select-enable-btn">Select</li>' +
|
||||||
|
'<li><button data-click-event="toggle-selected" id="dt-select-all" class="btn btn-default btn-primary disabled">Select All</li>' +
|
||||||
|
'<li><button data-click-event="toggle-list-view" data-view="grid" class="btn btn-default"><i class="fw fw-grid"></i></button></li>' +
|
||||||
|
'<li><button data-click-event="toggle-list-view" data-view="list" class="btn btn-default"><i class="fw fw-list"></i></button></li>' +
|
||||||
|
'<li><button class="btn btn-default" data-toggle="dropdown"><i class="fw fw-sort"></i></button>' + dropdownmenu[0].outerHTML + '</li>' +
|
||||||
|
'</ul>'
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sorting dropdown menu select function
|
||||||
|
*/
|
||||||
|
$('.dataTables_wrapper .sort-list li a').click(function () {
|
||||||
|
$(this).closest('li').siblings('li').find('a').removeClass('sorting_asc').removeClass('sorting_desc');
|
||||||
|
|
||||||
|
var thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable();
|
||||||
|
|
||||||
|
if (!($(this).hasClass('sorting_asc')) && !($(this).hasClass('sorting_desc'))) {
|
||||||
|
$(this).addClass('sorting_asc');
|
||||||
|
thisTable.fnSort([[$(this).attr('data-column'), 'asc']]);
|
||||||
|
}
|
||||||
|
else if ($(this).hasClass('sorting_asc')) {
|
||||||
|
$(this).switchClass('sorting_asc', 'sorting_desc');
|
||||||
|
thisTable.fnSort([[$(this).attr('data-column'), 'desc']]);
|
||||||
|
}
|
||||||
|
else if ($(this).hasClass('sorting_desc')) {
|
||||||
|
$(this).switchClass('sorting_desc', 'sorting_asc');
|
||||||
|
thisTable.fnSort([[$(this).attr('data-column'), 'asc']]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var rowSelectedClass = 'DTTT_selected selected';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable/Disable selection on rows
|
||||||
|
*/
|
||||||
|
$('.dataTables_wrapper [data-click-event=toggle-selectable]').click(function () {
|
||||||
|
var button = this,
|
||||||
|
thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable();
|
||||||
|
if ($(button).html() == 'Select') {
|
||||||
|
thisTable.addClass("table-selectable");
|
||||||
|
$(button).addClass("active").html('Cancel');
|
||||||
|
$(button).parent().next().children("button").removeClass("disabled");
|
||||||
|
// EMM related code
|
||||||
|
$(".viewEnabledIcon").unbind("click");
|
||||||
|
//--- End of EMM related codes
|
||||||
|
} else if ($(button).html() == 'Cancel') {
|
||||||
|
thisTable.removeClass("table-selectable");
|
||||||
|
$(button).addClass("active").html('Select');
|
||||||
|
$(button).parent().next().children().addClass("disabled");
|
||||||
|
// EMM related function
|
||||||
|
$(".viewEnabledIcon").bind("click", initiateViewOption);
|
||||||
|
//--- End of EMM related codes
|
||||||
|
}
|
||||||
|
});
|
||||||
|
/**
|
||||||
|
* select/deselect all rows function
|
||||||
|
*/
|
||||||
|
$('.dataTables_wrapper [data-click-event=toggle-selected]').click(function () {
|
||||||
|
var button = this,
|
||||||
|
thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable();
|
||||||
|
if (!$(button).hasClass('disabled')) {
|
||||||
|
if ($(button).html() == 'Select All') {
|
||||||
|
thisTable.api().rows().every(function () {
|
||||||
|
$(this.node()).addClass(rowSelectedClass);
|
||||||
|
$(button).html('Deselect All');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if ($(button).html() == 'Deselect All') {
|
||||||
|
thisTable.api().rows().every(function () {
|
||||||
|
$(this.node()).removeClass(rowSelectedClass);
|
||||||
|
$(button).html('Select All');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* on row click select/deselect row function
|
||||||
|
*/
|
||||||
|
$('body').on('click', '[data-type=selectable]', function () {
|
||||||
|
var rowSelectedClass = 'DTTT_selected selected';
|
||||||
|
$(this).toggleClass(rowSelectedClass);
|
||||||
|
var button = this,
|
||||||
|
thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable();
|
||||||
|
|
||||||
|
thisTable.api().rows().every(function () {
|
||||||
|
if (!$(this.node()).hasClass(rowSelectedClass)) {
|
||||||
|
$(button).closest('.dataTables_wrapper').find('[data-click-event=toggle-selected]').html('Select All');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list table list/grid view toggle function
|
||||||
|
*/
|
||||||
|
var toggleButton = $('[data-click-event=toggle-list-view]');
|
||||||
|
toggleButton.click(function () {
|
||||||
|
if ($(this).attr('data-view') == 'grid') {
|
||||||
|
$(this).closest('.dataTables_wrapper').find('.dataTable').addClass('grid-view');
|
||||||
|
//$(this).closest('li').hide();
|
||||||
|
//$(this).closest('li').siblings().show();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$(this).closest('.dataTables_wrapper').find('.dataTable').removeClass('grid-view');
|
||||||
|
//$(this).closest('li').hide();
|
||||||
|
//$(this).closest('li').siblings().show();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},settings)
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
@ -1,72 +1,70 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
*
|
*
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||||
* KIND, either express or implied. See the License for the
|
* either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var invokerUtil = function () {
|
var invokerUtil = function () {
|
||||||
|
|
||||||
var module = {};
|
var publicMethods = {};
|
||||||
|
var privateMethods = {};
|
||||||
|
|
||||||
var END_POINT = window.location.origin+"/devicemgt/api/invoker/execute/";
|
privateMethods.execute = function (requestMethod, requestURL, requestPayload, successCallback, errorCallback) {
|
||||||
|
var restAPIRequestDetails = {};
|
||||||
|
restAPIRequestDetails["requestMethod"] = requestMethod;
|
||||||
|
restAPIRequestDetails["requestURL"] = requestURL;
|
||||||
|
restAPIRequestDetails["requestPayload"] = JSON.stringify(requestPayload);
|
||||||
|
|
||||||
module.get = function (url, successCallback, errorCallback, contentType, acceptType) {
|
var request = {
|
||||||
var payload = null;
|
url: context + "/api/invoker/execute/",
|
||||||
execute("GET", url, payload, successCallback, errorCallback, contentType, acceptType);
|
|
||||||
};
|
|
||||||
module.post = function (url, payload, successCallback, errorCallback, contentType, acceptType) {
|
|
||||||
execute("POST", url, payload, successCallback, errorCallback, contentType, acceptType);
|
|
||||||
};
|
|
||||||
module.put = function (url, payload, successCallback, errorCallback, contentType, acceptType) {
|
|
||||||
execute("PUT", url, payload, successCallback, errorCallback, contentType, acceptType);
|
|
||||||
};
|
|
||||||
module.delete = function (url, successCallback, errorCallback, contentType, acceptType) {
|
|
||||||
var payload = null;
|
|
||||||
execute("DELETE", url, payload, successCallback, errorCallback, contentType, acceptType);
|
|
||||||
};
|
|
||||||
function execute (methoad, url, payload, successCallback, errorCallback, contentType, acceptType) {
|
|
||||||
if(contentType == undefined){
|
|
||||||
contentType = "application/json";
|
|
||||||
}
|
|
||||||
if(acceptType == undefined){
|
|
||||||
acceptType = "application/json";
|
|
||||||
}
|
|
||||||
var data = {
|
|
||||||
url: END_POINT,
|
|
||||||
type: "POST",
|
type: "POST",
|
||||||
contentType: contentType,
|
contentType: "application/json",
|
||||||
accept: acceptType,
|
data: JSON.stringify(restAPIRequestDetails),
|
||||||
success: successCallback
|
accept: "application/json",
|
||||||
};
|
success: successCallback,
|
||||||
var paramValue = {};
|
error: function (jqXHR) {
|
||||||
paramValue.actionMethod = methoad;
|
if (jqXHR.status == 401) {
|
||||||
paramValue.actionUrl = url;
|
console.log("Unauthorized access attempt!");
|
||||||
paramValue.actionPayload = payload;
|
$(modalPopupContent).html($("#error-msg").html());
|
||||||
if(contentType == "application/json"){
|
showPopup();
|
||||||
paramValue.actionPayload = JSON.stringify(payload);
|
} else {
|
||||||
}
|
errorCallback(jqXHR);
|
||||||
data.data = JSON.stringify(paramValue);
|
}
|
||||||
$.ajax(data).fail(function (jqXHR) {
|
|
||||||
if (jqXHR.status == "401") {
|
|
||||||
console.log("Unauthorized access attempt!");
|
|
||||||
$(modalPopupContent).html($('#error-msg').html());
|
|
||||||
showPopup();
|
|
||||||
} else {
|
|
||||||
errorCallback(jqXHR);
|
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
$.ajax(request);
|
||||||
};
|
};
|
||||||
return module;
|
|
||||||
|
publicMethods.get = function (requestURL, successCallback, errorCallback) {
|
||||||
|
var requestPayload = null;
|
||||||
|
privateMethods.execute("GET", requestURL, requestPayload, successCallback, errorCallback);
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.post = function (requestURL, requestPayload, successCallback, errorCallback) {
|
||||||
|
privateMethods.execute("POST", requestURL, requestPayload, successCallback, errorCallback);
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.put = function (requestURL, requestPayload, successCallback, errorCallback) {
|
||||||
|
privateMethods.execute("PUT", requestURL, requestPayload, successCallback, errorCallback);
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.delete = function (requestURL, successCallback, errorCallback) {
|
||||||
|
var requestPayload = null;
|
||||||
|
privateMethods.execute("DELETE", requestURL, requestPayload, successCallback, errorCallback);
|
||||||
|
};
|
||||||
|
|
||||||
|
return publicMethods;
|
||||||
}();
|
}();
|
||||||
|
|||||||
@ -15,10 +15,7 @@
|
|||||||
specific language governing permissions and limitations
|
specific language governing permissions and limitations
|
||||||
under the License.
|
under the License.
|
||||||
}}
|
}}
|
||||||
{{#zone "bottomJs"}}
|
{{#zone "content"}}
|
||||||
{{js "js/js.cookie.js"}}
|
|
||||||
{{js "js/invoker-lib.js"}}
|
|
||||||
|
|
||||||
<div id="error-msg" class="hide">
|
<div id="error-msg" class="hide">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -34,4 +31,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{/zone}}
|
{{/zone}}
|
||||||
|
{{#zone "bottomJs"}}
|
||||||
|
<script type="text/javascript">
|
||||||
|
var context = "{{@app.context}}"
|
||||||
|
</script>
|
||||||
|
{{js "js/js.cookie.js"}}
|
||||||
|
{{js "js/invoker-lib.js"}}
|
||||||
|
{{/zone}}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"displayName": "Carbon Device Management App",
|
"displayName": "Carbon Device Management App",
|
||||||
"logLevel": "warn",
|
"logLevel": "info",
|
||||||
"initScripts": ["/app/modules/init.js"],
|
"initScripts": ["/app/modules/init.js"],
|
||||||
"urlMappings": [
|
"urlMappings": [
|
||||||
{
|
{
|
||||||
@ -50,6 +50,10 @@
|
|||||||
{
|
{
|
||||||
"url": "/*",
|
"url": "/*",
|
||||||
"path": "/lib/pages.jag"
|
"path": "/lib/pages.jag"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "/api/data-tables/invoker",
|
||||||
|
"path": "/api/data-tables-invoker-api.jag"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user