1
1
/**
2
2
* Data source.
3
- *
3
+ *
4
4
* Must implement methods.
5
5
*
6
6
* @param {Object } config
@@ -11,7 +11,9 @@ var DataSource = function (config, globalConfig) {
11
11
12
12
this . SOURCE_URL = config . MDX2JSONSource ||
13
13
location . host + ":" + location . port + "/" + ( location . pathname . split ( "/" ) || [ ] ) [ 1 ] ;
14
-
14
+ this . NAMESPACE = config [ "namespace" ] ;
15
+ this . USERNAME = config [ "username" ] ;
16
+ this . PASSWORD = config [ "password" ] ;
15
17
this . BASIC_MDX = config . basicMDX ;
16
18
17
19
this . GLOBAL_CONFIG = globalConfig ;
@@ -38,7 +40,6 @@ var DataSource = function (config, globalConfig) {
38
40
* @private
39
41
*/
40
42
DataSource . prototype . _post = function ( url , data , callback ) {
41
-
42
43
var xhr = new XMLHttpRequest ( ) ;
43
44
xhr . open ( "POST" , url ) ;
44
45
xhr . onreadystatechange = function ( ) {
@@ -54,12 +55,15 @@ DataSource.prototype._post = function (url, data, callback) {
54
55
}
55
56
} ) ( ) ) ;
56
57
} else if ( xhr . readyState === 4 && xhr . status !== 200 ) {
57
- callback ( { error : xhr . responseText
58
- || "Error while trying to retrieve data from server." } ) ;
58
+ callback ( {
59
+ error : xhr . responseText || "Error while trying to retrieve data from server."
60
+ } ) ;
59
61
}
60
62
} ;
63
+ if ( this . USERNAME && this . PASSWORD ) {
64
+ xhr . setRequestHeader ( "Authorization" , "Basic " + btoa ( this . USERNAME + ":" + this . PASSWORD ) ) ;
65
+ }
61
66
xhr . send ( JSON . stringify ( data ) ) ;
62
-
63
67
} ;
64
68
65
69
/**
@@ -217,7 +221,7 @@ DataSource.prototype.getCurrentData = function (callback) {
217
221
218
222
console . log ( "Requesting MDX: " + mdx ) ;
219
223
220
- _ . _post ( _ . SOURCE_URL + "/" + _ . ACTION , {
224
+ _ . _post ( _ . SOURCE_URL + "/" + _ . ACTION + ( _ . NAMESPACE ? "?Namespace=" + _ . NAMESPACE : "" ) , {
221
225
MDX : mdx
222
226
} , function ( data ) {
223
227
ready . data = data ;
@@ -227,7 +231,8 @@ DataSource.prototype.getCurrentData = function (callback) {
227
231
} ;
228
232
229
233
if ( this . DATA_SOURCE_PIVOT ) {
230
- this . _post ( this . SOURCE_URL + "/DataSource" , {
234
+ this . _post ( this . SOURCE_URL + "/DataSource"
235
+ + ( _ . NAMESPACE ? "?Namespace=" + _ . NAMESPACE : "" ) , {
231
236
DataSource : this . DATA_SOURCE_PIVOT
232
237
} , function ( data ) {
233
238
ready . pivotData = data ;
0 commit comments