Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
105 lines (97 loc) · 3.38 KB

File metadata and controls

105 lines (97 loc) · 3.38 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
var newPost = {
"Id": "",
"Title": "Unpublished",
"Author": "Admin",
"Content": "<p>Type here...</p>",
"DateCreated": moment().format("MM/DD/YYYY HH:MM"),
"Slug": "unpublished",
"Categories": "",
"Tags": "",
"Comments": "",
"IsPublished": true,
"CanUserDelete": true,
"CanUserEdit": true
}
function postVM(data) {
var self = this;
self.id = editVars.id;
self.title = ko.observable(data.Title);
self.author = ko.observable(data.Author);
self.content = ko.observable(data.Content);
self.dateCreated = ko.observable(data.DateCreated);
self.slug = ko.observable(data.slug);
self.isDeleted = ko.observable(data.IsDeleted);
self.categories = ko.observable(data.Categories);
self.tags = ko.observable(data.Tags);
self.comments = ko.observable(data.Comments);
self.isPublished = ko.observable(data.IsPublished);
self.canUserDelete = ko.observable(data.CanUserDelete);
self.canUserEdit = ko.observable(data.CanUserEdit);
self.save = function () {
self.content($('#editor').html());
$.ajax({
url: SiteVars.ApplicationRelativeWebRoot + "api/posts/" + editVars.id,
data: ko.toJSON(self),
type: "PUT",
contentType: "application/json",
beforeSend: onAjaxBeforeSend,
success: function (data) {
success('Data saved');
}
});
};
self.unpublish = function () {
self.content($('#editor').html());
self.isPublished('False');
$.ajax({
url: SiteVars.ApplicationRelativeWebRoot + "api/posts/" + editVars.id,
data: ko.toJSON(self),
type: "PUT",
contentType: "application/json",
beforeSend: onAjaxBeforeSend,
success: function (data) {
success('Post unpublished');
}
});
};
self.remove = function () {
self.content($('#editor').html());
$.ajax({
url: SiteVars.ApplicationRelativeWebRoot + "api/posts?id=" + editVars.id,
type: "DELETE",
contentType: "application/json",
beforeSend: onAjaxBeforeSend,
success: function (data) {
success('Post removed');
location.reload();
}
});
};
};
if (editVars.id) {
$.ajax({
url: SiteVars.ApplicationRelativeWebRoot + "api/posts/" + editVars.id,
type: "GET",
contentType: "application/json",
beforeSend: onAjaxBeforeSend,
success: function (data) {
ko.applyBindings(new postVM(data));
}
});
}
else {
ko.applyBindings(new postVM(newPost));
}
function success(msg) {
toastr.options.positionClass = 'toast-bottom-right';
toastr.success(msg, 'Success.');
}
function onAjaxBeforeSend(jqXHR, settings) {
// AJAX calls need to be made directly to the real physical location of the
// web service/page method. For this, SiteVars.ApplicationRelativeWebRoot is used.
// If an AJAX call is made to a virtual URL (for a blog instance), although
// the URL rewriter will rewrite these URLs, we end up with a "405 Method Not Allowed"
// error by the web service. Here we set a request header so the call to the server
// is done under the correct blog instance ID.
jqXHR.setRequestHeader('x-blog-instance', SiteVars.BlogInstanceId);
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.