-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·240 lines (200 loc) · 8.15 KB
/
index.html
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
235
236
237
238
239
240
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Mi Chancla</title>
<script type="text/javascript" charset="utf8" src="phonegap.js"></script>
<script type="text/javascript" charset="utf8" src="js/app.js"></script>
<link rel="stylesheet" href="css/jquery.mobile-1.1.0.min.css" />
<link rel="stylesheet" href="css/style.css" />
<script src="js/jquery.min.js"></script>
<script src="js/jquery.mobile-1.1.0.min.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
var upload_id;
function sendImage(src) {
// Set the image source [library || camera]
src = (src == 'library') ? Camera.PictureSourceType.PHOTOLIBRARY : Camera.PictureSourceType.CAMERA;
// Aquire the image -> Phonegap API
navigator.camera.getPicture(success, fail, {quality: 50, sourceType: src, destinationType: 0});
// Successfully aquired image data -> base64 encoded string of the image file
function success(imageData) {
var params = {image: imageData};
$('#image').attr('src', 'data:image/jpeg;base64,' + params['image']);
$.mobile.changePage( $("#chancla_details"), { transition: "slideup"} );
// send the data
//$.post(url, params, function(data) {
var file = {
file: params['image'],
//filename: "my_cool_image.jpg"
};
var jqxhr = $.ajax({
url: "http://michancla.es/rest/file.json",
type: 'POST',
dataType: 'json',
//data: JSON.stringify(obj),
data: file,
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('No internet connection? Check your settings');
console.log(JSON.stringify(XMLHttpRequest));
console.log(JSON.stringify(textStatus));
console.log(JSON.stringify(errorThrown));
},
success: function (data) {
upload_id = data.fid;
$('#butSave').removeClass('ui-hidden');
//alert("fid from server: " + upload_id)
//console.log(JSON.stringify(data));
}
});
// Display the selected image on send complete
//});
}
function fail(message) { alert(message); }
}
function saveNode() {
//alert("You have been logged out.");
//$.mobile.loading( 'show', { text: "uploading photo" });
//$.mobile.loading( 'show' );
//$.mobile.changePage( $("#chancla_details"), { transition: "slideup"} );
try {
var nodeInfo = "node[type]=chancla&node[title]=" + removeTags($("#description").val()) + "&node[language]=''&node[field_foto][und][0][fid]=" + upload_id;
var jqxhr = $.ajax({
url: "http://michancla.es/rest/node.json",
type: 'POST',
dataType: 'json',
//data: JSON.stringify(obj),
data: nodeInfo,
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('No internet connection? Check your settings' + errorThrown + ' ' + textStatus );
console.log(JSON.stringify(XMLHttpRequest));
console.log(JSON.stringify(textStatus));
console.log(JSON.stringify(errorThrown));
},
success: function (data) {
$.mobile.changePage( $("#pagConfirm") );
}
});
//console.log(JSON.stringify(data));
}
catch (error) { alert("We encountered an error - " + error); }
}
var tagBody = '(?:[^"\'>]|"[^"]*"|\'[^\']*\')*';
var tagOrComment = new RegExp(
'<(?:'
// Comment body.
+ '!--(?:(?:-*[^->])*--+|-?)'
// Special "raw text" elements whose content should be elided.
+ '|script\\b' + tagBody + '>[\\s\\S]*?</script\\s*'
+ '|style\\b' + tagBody + '>[\\s\\S]*?</style\\s*'
// Regular name
+ '|/?[a-z]'
+ tagBody
+ ')>',
'gi');
function removeTags(html) {
var oldHtml;
do {
oldHtml = html;
html = html.replace(tagOrComment, '');
} while (html !== oldHtml);
return html.replace(/</g, '<');
}
$('.send-image').click(function () { sendImage($(this).val()); });
$('#butSave').click(function () { saveNode(); });
});
</script>
</head>
<body>
<div data-role="page" id="page1">
<div data-theme="a" data-role="header">
<h3>
Mi Chancla
</h3>
</div>
<div data-role="content">
<div>
<p>
<strong>
We love chanclas!
<br />
<br />
</strong>
</p>
</div>
<div>
<p>
Upload a photo of your chanclas, or a friends, or any chancla you see around.
<br />
</p>
</div>
<input type="button" class="send-image" value="camera" />
<input type="button" class="send-image" value="library" />
</div>
</div>
<div data-role="page" id="chancla_details">
<div data-theme="a" data-role="header">
<h3>
Review submition
</h3>
</div>
<div data-role="content">
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<label for="description">
Description
</label>
<input id="description" placeholder="Description..." value="" type="text" />
</fieldset>
</div>
<div>
<img src="" id="image" alt="image" style="width: 100%;" />
</div>
<div data-role="fieldcontain">
<label for="category">
Category
</label>
<select name="category" id="category">
<option value="casual">
Casual
</option>
<option value="fun">
Fun
</option>
<option value="style">
Style
</option>
<option value="other">
Other
</option>
</select>
</div>
<button type="button" id="butSave" class="ui-hidden" data-theme="e" >Save</button>
</div>
</div>
<div data-role="page" id="pagConfirm">
<div data-theme="a" data-role="header">
<h3>
Success
</h3>
</div>
<div data-role="content">
<div>
<p>
<strong>
You uploaded your chanclas!
<br />
<br />
</strong>
</p>
</div>
<div>
<a data-role="button" href="#page1">
Send another photo
</a>
</div>
</div>
</div>
</body>
</html>