Skip to content

Commit 7efeb98

Browse files
committed
Changed address to azure
1 parent 36d6a49 commit 7efeb98

File tree

4 files changed

+143
-116
lines changed

4 files changed

+143
-116
lines changed

wwwroot/editor.js

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
11
function getParams() {
2-
var url = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
3-
var result = {};
4-
url.forEach(function(item) {
5-
var param = item.split("=");
6-
result[param[0]] = param[1];
7-
});
8-
return result;
2+
var url = window.location.href
3+
.slice(window.location.href.indexOf("?") + 1)
4+
.split("&");
5+
var result = {};
6+
url.forEach(function(item) {
7+
var param = item.split("=");
8+
result[param[0]] = param[1];
9+
});
10+
return result;
911
}
10-
11-
Survey.dxSurveyService.serviceUrl = "http://localhost:5000/api/Service";
12+
13+
Survey.dxSurveyService.serviceUrl =
14+
"https://surveyjs-aspnet-mvc.azurewebsites.net/api/Service";
1215
var accessKey = "";
1316
var editor = new SurveyEditor.SurveyEditor("editor");
1417
var surveyId = getParams()["id"];
1518
editor.loadSurvey(surveyId);
16-
editor.saveSurveyFunc = function (saveNo, callback) {
17-
var xhr = new XMLHttpRequest();
18-
xhr.open('POST', Survey.dxSurveyService.serviceUrl + '/changeJson?accessKey=' + accessKey);
19-
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
20-
xhr.onload = function () {
21-
var result = xhr.response ? JSON.parse(xhr.response) : null;
22-
if(xhr.status === 200) {
23-
callback(saveNo, true)
24-
}
25-
};
26-
xhr.send(JSON.stringify({ Id: surveyId, Json: editor.text, Text: editor.text }));
19+
editor.saveSurveyFunc = function(saveNo, callback) {
20+
var xhr = new XMLHttpRequest();
21+
xhr.open(
22+
"POST",
23+
Survey.dxSurveyService.serviceUrl + "/changeJson?accessKey=" + accessKey
24+
);
25+
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
26+
xhr.onload = function() {
27+
var result = xhr.response ? JSON.parse(xhr.response) : null;
28+
if (xhr.status === 200) {
29+
callback(saveNo, true);
30+
}
31+
};
32+
xhr.send(
33+
JSON.stringify({ Id: surveyId, Json: editor.text, Text: editor.text })
34+
);
2735
};
2836
editor.isAutoSave = true;
2937
editor.showState = true;

wwwroot/index.js

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,56 @@
11
function SurveyManager(baseUrl, accessKey) {
2-
var self = this;
3-
self.availableSurveys = ko.observableArray();
2+
var self = this;
3+
self.availableSurveys = ko.observableArray();
44

5-
self.loadSurveys = function () {
6-
var xhr = new XMLHttpRequest();
7-
xhr.open('GET', baseUrl + '/getActive?accessKey=' + accessKey);
8-
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
9-
xhr.onload = function () {
10-
var result = xhr.response ? JSON.parse(xhr.response) : {};
11-
self.availableSurveys(Object.keys(result).map(function(key) {
12-
return {
13-
id: key,
14-
survey: result[key]
15-
}
16-
}));
17-
};
18-
xhr.send();
19-
}
5+
self.loadSurveys = function() {
6+
var xhr = new XMLHttpRequest();
7+
xhr.open("GET", baseUrl + "/getActive?accessKey=" + accessKey);
8+
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
9+
xhr.onload = function() {
10+
var result = xhr.response ? JSON.parse(xhr.response) : {};
11+
self.availableSurveys(
12+
Object.keys(result).map(function(key) {
13+
return {
14+
id: key,
15+
survey: result[key]
16+
};
17+
})
18+
);
19+
};
20+
xhr.send();
21+
};
2022

21-
self.createSurvey = function(name, onCreate) {
22-
var xhr = new XMLHttpRequest();
23-
xhr.open('GET', baseUrl + '/create?accessKey=' + accessKey + "&name=" + name);
24-
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
25-
xhr.onload = function () {
26-
var result = xhr.response ? JSON.parse(xhr.response) : null
27-
!!onCreate && onCreate(xhr.status == 200, result, xhr.response);
28-
};
29-
xhr.send();
30-
}
31-
32-
self.deleteSurvey = function(id, onDelete) {
33-
var xhr = new XMLHttpRequest();
34-
xhr.open('GET', baseUrl + '/delete?accessKey=' + accessKey + "&id=" + id);
35-
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
36-
xhr.onload = function () {
37-
var result = xhr.response ? JSON.parse(xhr.response) : null
38-
!!onDelete && onDelete(xhr.status == 200, result, xhr.response);
39-
};
40-
xhr.send();
41-
}
42-
43-
self.loadSurveys();
23+
self.createSurvey = function(name, onCreate) {
24+
var xhr = new XMLHttpRequest();
25+
xhr.open(
26+
"GET",
27+
baseUrl + "/create?accessKey=" + accessKey + "&name=" + name
28+
);
29+
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
30+
xhr.onload = function() {
31+
var result = xhr.response ? JSON.parse(xhr.response) : null;
32+
!!onCreate && onCreate(xhr.status == 200, result, xhr.response);
33+
};
34+
xhr.send();
35+
};
36+
37+
self.deleteSurvey = function(id, onDelete) {
38+
var xhr = new XMLHttpRequest();
39+
xhr.open("GET", baseUrl + "/delete?accessKey=" + accessKey + "&id=" + id);
40+
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
41+
xhr.onload = function() {
42+
var result = xhr.response ? JSON.parse(xhr.response) : null;
43+
!!onDelete && onDelete(xhr.status == 200, result, xhr.response);
44+
};
45+
xhr.send();
46+
};
47+
48+
self.loadSurveys();
4449
}
4550

46-
ko.applyBindings(new SurveyManager("http://localhost:5000/api/Service"), document.getElementById("surveys-list"));
51+
ko.applyBindings(
52+
new SurveyManager(
53+
"https://surveyjs-aspnet-mvc.azurewebsites.net/api/Service"
54+
),
55+
document.getElementById("surveys-list")
56+
);

wwwroot/results.js

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
11
function getParams() {
2-
var url = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
3-
var result = {};
4-
url.forEach(function(item) {
5-
var param = item.split("=");
6-
result[param[0]] = param[1];
7-
});
8-
return result;
2+
var url = window.location.href
3+
.slice(window.location.href.indexOf("?") + 1)
4+
.split("&");
5+
var result = {};
6+
url.forEach(function(item) {
7+
var param = item.split("=");
8+
result[param[0]] = param[1];
9+
});
10+
return result;
911
}
10-
12+
1113
function SurveyManager(baseUrl, accessKey) {
12-
var self = this;
13-
self.surveyId = getParams()["id"];
14-
self.results = ko.observableArray();
14+
var self = this;
15+
self.surveyId = getParams()["id"];
16+
self.results = ko.observableArray();
1517

16-
self.loadResults = function () {
17-
var xhr = new XMLHttpRequest();
18-
xhr.open('GET', baseUrl + '/results?postId=' + self.surveyId);
19-
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
20-
xhr.onload = function () {
21-
var result = xhr.response ? JSON.parse(xhr.response) : {};
22-
self.results(result);
23-
};
24-
xhr.send();
25-
}
18+
self.loadResults = function() {
19+
var xhr = new XMLHttpRequest();
20+
xhr.open("GET", baseUrl + "/results?postId=" + self.surveyId);
21+
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
22+
xhr.onload = function() {
23+
var result = xhr.response ? JSON.parse(xhr.response) : {};
24+
self.results(result);
25+
};
26+
xhr.send();
27+
};
2628

27-
self.loadResults();
29+
self.loadResults();
2830
}
2931

30-
ko.applyBindings(new SurveyManager("http://localhost:5000/api/Service"), document.getElementById("results"));
32+
ko.applyBindings(
33+
new SurveyManager(
34+
"https://surveyjs-aspnet-mvc.azurewebsites.net/api/Service"
35+
),
36+
document.getElementById("results")
37+
);

wwwroot/survey.js

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
11
function getParams() {
2-
var url = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
3-
var result = {};
4-
url.forEach(function(item) {
5-
var param = item.split("=");
6-
result[param[0]] = param[1];
7-
});
8-
return result;
2+
var url = window.location.href
3+
.slice(window.location.href.indexOf("?") + 1)
4+
.split("&");
5+
var result = {};
6+
url.forEach(function(item) {
7+
var param = item.split("=");
8+
result[param[0]] = param[1];
9+
});
10+
return result;
911
}
10-
12+
1113
function init() {
14+
Survey.dxSurveyService.serviceUrl =
15+
"https://surveyjs-aspnet-mvc.azurewebsites.net/api/Service";
16+
Survey.defaultBootstrapCss.navigationButton = "btn btn-primary";
17+
Survey.Survey.cssType = "bootstrap";
1218

13-
Survey.dxSurveyService.serviceUrl = "http://localhost:5000/api/Service";
14-
Survey.defaultBootstrapCss.navigationButton = "btn btn-primary";
15-
Survey.Survey.cssType = "bootstrap";
19+
var url = new URL(document.URL);
20+
var surveyId = getParams()["id"];
21+
var model = new Survey.Model({ surveyId: surveyId, surveyPostId: surveyId });
22+
window.survey = model;
23+
model.render("surveyElement");
1624

17-
var url = new URL(document.URL);
18-
var surveyId = getParams()["id"];
19-
var model = new Survey.Model({ surveyId: surveyId, surveyPostId: surveyId });
20-
window.survey = model;
21-
model.render("surveyElement");
22-
23-
// // Load survey by id from url
24-
// var xhr = new XMLHttpRequest();
25-
// xhr.open('GET', "http://localhost:8000" + '/survey?surveyId=' + surveyId);
26-
// xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
27-
// xhr.onload = function () {
28-
// var result = JSON.parse(xhr.response);
29-
// if(!!result) {
30-
// var surveyModel = new Survey.Model(result);
31-
// window.survey = surveyModel;
32-
// ko.cleanNode(document.getElementById("surveyElement"));
33-
// document.getElementById("surveyElement").innerText = "";
34-
// surveyModel.render("surveyElement");
35-
// }
36-
// };
37-
// xhr.send();
25+
// // Load survey by id from url
26+
// var xhr = new XMLHttpRequest();
27+
// xhr.open('GET', "https://surveyjs-aspnet-mvc.azurewebsites.net" + '/survey?surveyId=' + surveyId);
28+
// xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
29+
// xhr.onload = function () {
30+
// var result = JSON.parse(xhr.response);
31+
// if(!!result) {
32+
// var surveyModel = new Survey.Model(result);
33+
// window.survey = surveyModel;
34+
// ko.cleanNode(document.getElementById("surveyElement"));
35+
// document.getElementById("surveyElement").innerText = "";
36+
// surveyModel.render("surveyElement");
37+
// }
38+
// };
39+
// xhr.send();
3840
}
3941

4042
init();

0 commit comments

Comments
 (0)