forked from ServiceStack/ServiceStack.Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.htm
More file actions
234 lines (208 loc) · 9.8 KB
/
default.htm
File metadata and controls
234 lines (208 loc) · 9.8 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ServiceStack Movie Database</title>
<link rel="stylesheet" type="text/css" href="Content/Css/default.css" />
<script type="text/javascript" src="Scripts/jquery-1.8.1.min.js"></script>
<script type="text/javascript">
//Simple string formatting enhancement
if (!String.format) { String.prototype.format = function () { var args = arguments; return this.replace(/\{(\d+)\}/g, function (match, number) { return (typeof args[number] !== 'undefined') ? args[number] : match; }); }; }
$(function () {
$.ajaxSetup({ cache: false });
var restLog = function (method, url) {
if (method === "GET") {
url = '<a href="{0}" target="_blank">{0}</a>'.format(url);
}
$("#restlog").prepend("<div><b class='ib'>{0}</b><i>{1}</i></div>".format(method, url));
};
var allGenres = [];
var refreshExistingMovies = function () {
var moviesUrl = "movies", jqFilter = $("SELECT[name=genres]"), filterGenre = jqFilter.val();
if (filterGenre) {
moviesUrl += "/genres/" + filterGenre;
}
restLog("GET", moviesUrl);
$.getJSON(moviesUrl, function (r) {
var html = "";
for (var i = 0, count = r.Movies.length; i < count; i++) {
var movie = r.Movies[i];
html += "<dd id='{0}'><label class='ib'>{1}</label><span class='ib lnk-update'>update</span><span class='ib lnk-delete'>delete</span></dd>".format(movie.Id, movie.Title);
$.each(movie.Genres, function (i, genre) {
if ($.inArray(genre, allGenres) == -1) {
allGenres.push(genre);
}
});
var genreHtml = '<option class="first" value="">[ All Genres ]</option>';
$.each(allGenres, function (i, genre) {
var selected = filterGenre === genre ? ' selected="selected"' : '';
genreHtml += '<option value="{0}"{1}>{0}</option>'.format(genre, selected);
});
jqFilter.html(genreHtml);
}
$("#existing-movies").html(html);
$("#existing-movies .lnk-delete").on('click', function () {
var request = { type: 'delete', url: "movies/" + $(this).parent().attr('id') };
restLog("DELETE", request.url);
request.success = refreshExistingMovies;
$.ajax(request);
});
$("#existing-movies .lnk-update").on('click', function () {
var movieId = $(this).parent().attr('id');
restLog("GET", "movies/" + movieId);
$.getJSON("movies/" + movieId, function (r) {
showDetailsForm(r.Movie);
});
});
});
};
$("SELECT[name=genres]").change(function () {
refreshExistingMovies();
});
$("#btnReset").click(function () {
restLog("POST", "reset-movies");
$.post("reset-movies", function (r) {
refreshExistingMovies();
});
});
var showDetailsForm = function (updateMovie) {
var isUpdate = !!updateMovie;
var newMovie = {
Id: 0,
ImdbId: "tt0110912",
Title: "Pulp Fiction",
Rating: 8.9,
Director: "Quentin Tarantino",
ReleaseDate: new Date(1994, 10, 24),
TagLine: "Girls like me don't make invitations like this to just anyone!",
Genres: ["Crime", "Drama", "Thriller"]
};
var movie = updateMovie || newMovie;
$("FORM INPUT[type=submit]").val(isUpdate ? "Update movie" : "Add new movie");
var action = "movies";
$("FORM").attr('action', isUpdate ? action + "/" + movie.Id : action);
$("FORM").attr('method', isUpdate ? 'PUT' : 'POST');
var title = isUpdate ? "Update " + movie.Title : "Add a new movie";
$("FORM H2").html(title);
for (var name in movie) {
$("INPUT[name=" + name + "]").val(movie[name]);
}
var date = typeof movie['ReleaseDate'] == 'string'
? new Date(parseFloat(/Date\(([^)]+)\)/.exec(movie['ReleaseDate'])[1]))
: movie['ReleaseDate'];
$("INPUT[name=ReleaseDate]").val(date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate());
$("FORM").fadeIn('fast');
};
$("#btnAdd").click(function () {
showDetailsForm();
});
$("FORM").submit(function (e) {
e.preventDefault();
var data = {}, form = $(this);
$("FORM INPUT[type=text]").each(function () {
data[this.name] = this.value;
});
$.ajax({
url: form.attr("action"),
type: form.attr('method'),
data: data,
dataType: "json",
success: function () {
restLog(form.attr('method'), form.attr('action'));
form.hide();
refreshExistingMovies();
}
});
});
$("#csvformat B").click(function () {
restLog("GET", "movies?format=csv");
location.href = "movies?format=csv";
});
refreshExistingMovies();
});
</script>
</head>
<body>
<a href="http://www.servicestack.net" style="display: block; position: absolute;
top: 5px; left: 10px;">
<img src="http://servicestack.net/icon-home.jpg" alt="ServiceStack Home" /></a>
<div id="header-links">
<a href="../ServiceStack.Hello/">Hello World</a> <a href="../Backbone.Todos/">Todos</a>
<a href="../RedisStackOverflow/">Redis StackOverflow</a> <a href="../RestFiles/">REST
Files</a> <a href="../ServiceStack.MovieRest/">REST Movies</a> <a href="../ServiceStack.Northwind/">
Northwind Database</a> <a href="../ServiceStack.Examples.Clients/">Ajax Client</a>
<a href="../ServiceStack.Examples.Clients/Soap12.aspx">Soap 1.2</a>
</div>
<a class="lnk-src" href="https://github.com/ServiceStack/ServiceStack">
<img src="Content/Images/btn-github.png" width="186" height="84" /></a>
<h1>
<a href="default.htm">Nothing but REST!</a></h1>
<div id="summary">
Clean mark-up, No config & No code-gen - Complete Ajax CRUD app in <a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/ServiceStack.MovieRest/default.htm">
1 page of jQuery</a> and <a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/ServiceStack.MovieRest/MovieService.cs">
1 page of C# server code</a>.
</div>
<button id="btnReset">
Reset Movie Database</button>
<h4>
HTTP REST LOG</h4>
<code id="restlog"></code>
<div id="existing">
<select name="genres">
</select>
<h2>
Existing Movies</h2>
<dl id="existing-movies">
</dl>
<button id="btnAdd">
Add >></button>
</div>
<form action="movies" method="post">
<h2>
</h2>
<input type="hidden" name="Id" />
<dl>
<dt>Imdb Id</dt>
<dd>
<input type="text" name="ImdbId" /></dd>
<dt>Title</dt>
<dd>
<input type="text" name="Title" /></dd>
<dt>Rating</dt>
<dd>
<input type="text" name="Rating" /></dd>
<dt>Director</dt>
<dd>
<input type="text" name="Director" /></dd>
<dt>Release Date</dt>
<dd>
<input type="text" name="ReleaseDate" /></dd>
<dt>Tag Line</dt>
<dd>
<input type="text" name="TagLine" /></dd>
<dt>Genres</dt>
<dd>
<input type="text" name="Genres" /></dd>
</dl>
<input type="submit" />
</form>
<div id="csvformat">
<b>Download movies</b> in the new <a href="https://github.com/ServiceStack/ServiceStack/wiki/ServiceStack-CSV-Format">
CSV Format</a> or <strong><a href="movies">View movies</a></strong> in the new
<a href="https://github.com/ServiceStack/ServiceStack/wiki/HTML5ReportFormat">HTML5
Format</a>
</div>
<a id="btn-download" href="https://github.com/ServiceStack/ServiceStack.Examples/downloads">
<img src="http://www.servicestack.net/btn-download.gif" alt="Download ServiceStack.Examples.zip">
</a>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-7722718-7']);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>