Download this file

tester.js    164 lines (145 with data), 5.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* Copyright (c) 2013/2014, Intel Performance Learning Solutions Ltd, Intel Corporation.
*
* Licensed 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 (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.
*
**/
/**
* Contains functions to to support API Tester webpage functions
*
* Created by : Sridhar Voorakkara (vsridhar420@gmail.com)
*/
var waitWin;
var authenticate = function() {
clearApiMessage();
var form = document.forms["auth"];
var url = "api/user/"+ form["userid"].value +"/authorize";
//validation
if (form["userid"].value.length ==0) {
alert("'userid' is a required field");
return;
}
if (form["password"].value.length ==0) {
alert("'password' is a required field");
return;
}
var qs = "password="+ form.password.value;
//display waiting image
displayApiWait();
//Do ajax post
xmlhttpPost(url, qs, handleApiResponse);
};
var createproject = function() {
clearApiMessage();
var form = document.forms["proj_create"];
var url = "api/project/create";
//validation
if (form["projectname"].value.length ==0) {
alert("'projectname' is a required field");
return;
}
var qs = "projectname="+ form.projectname.value;
if (form.projectdescr.value.length > 0)
qs = qs + "&projectdescr="+ form.projectdescr.value;
if (form.riskdocument.value.length > 0)
qs = qs + "&riskdocument="+ form.riskdocument.value;
if (form.ontologyUri.value.length > 0)
qs = qs + "&ontologyUri="+ form.ontologyUri.value;
//display waiting image
displayApiWait();
//Do ajax post
xmlhttpPost(url, qs, handleApiResponse, form.authenticationKey.value);
};
var updateproject = function() {
clearApiMessage();
var form = document.forms["proj_update"];
//validation
if (form["projectid"].value.length ==0) {
alert("'projectid' is a required field");
return;
}
if (form.riskdocument.value.length == 0 && form.ontologyUri.value.length == 0) {
alert("'riskdocument' or 'ontologyUri' values should be provided");
return
}
var url = "api/project/"+ form.projectid.value +"/update";
var qs = "dummy=0";
if (form.riskdocument.value.length > 0)
qs = qs + "&riskdocument="+ form.riskdocument.value;
if (form.ontologyUri.value.length > 0)
qs = qs + "&ontologyUri="+ form.ontologyUri.value;
//display waiting image
displayApiWait();
//Do ajax post
xmlhttpPost(url, qs, handleApiResponse, form.authenticationKey.value);
};
var getriskalternatives = function() {
clearApiMessage();
var form = document.forms["risk_alternatives_get"];
var projectId = form.projectid.value;
var url = "api/project/"+projectId+"/riskalternatives";
var qs = "";
displayApiWait();
xmlhttpPost(url, qs, handleApiResponse, form.authenticationKey.value);
};
var getstatus = function() {
clearApiMessage();
var form = document.forms["status_get"];
var projectId = form.projectid.value;
var url = "api/project/"+projectId+"/status";
var qs = "";
displayApiWait();
xmlhttpPost(url, qs, handleApiResponse, form.authenticationKey.value);
};
var sendrecommendation = function() {
clearApiMessage();
var form = document.forms["recommendation_set"];
var projectId = form.projectid.value;
var url = "api/project/"+projectId+"/recommendation";
var qs = "preserve="+form.preserve.value+"&ontologyuri="+form.ontologyuri.value;
displayApiWait();
xmlhttpPost(url, qs, handleApiResponse, form.authenticationKey.value);
};
var handleApiResponse = function (err, result) {
clearApiMessage();
displayApiMessage(err ? JSON.stringify(err) : result);
};
//remove a user feedback message
var clearApiMessage = function () {
document.getElementById("feedback").innerHTML = "";
};
//show a user feedback message
var displayApiMessage = function (msg) {
//document.getElementById("feedback").innerHTML = "<textarea>" + msg + "</textarea>";
var height = screen.height/2;
var width = screen.width/2;
var top = height/2;
var left = width/2;
var settings = "width="+width+",height="+height+"scrollbars=yes,top="+top+",left="+left;
if (waitWin)
waitWin.close();
msg = "API Response:<br><textarea style='width:100%;height:90%'>" + msg + "</textarea>";
var respWin = window.open("", "", settings, "center");
respWin.document.write(msg);
};
//show a wait graphic to the user
var displayApiWait = function () {
var height = screen.height/2;
var width = screen.width/2;
var top = height/2;
var left = width/2;
var settings = "width="+width+",height="+height+"scrollbars=yes,top="+top+",left="+left;
waitWin = window.open("", "respWin", settings, "center");
waitWin.document.write("<img src='resources/images/ajaxloader.gif'>");
//document.getElementById("feedback").innerHTML = "<img src='resources/images/ajaxloader.gif'>";
};