Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

JS portion to submit score implemented.

  • Loading branch information...
commit 3009a220f47c88ecf884e765aab90865884279be 1 parent e14b38c
@exhuma authored
View
9 js/app.js
@@ -52,14 +52,17 @@ lost_tracker.app.attachEvents = function(stationId) {
});
goog.events.listen(submit_buttons[0], goog.events.EventType.CLICK, function(evt) {
var formData = goog.dom.forms.getFormDataMap(evt.target.form);
+ var formString = goog.dom.forms.getFormDataString(evt.target.form);
goog.net.XhrIo.send(
- '/group/' + formData.get('group_id')[0] + '/' + stationId,
+ '/form_score',
function(evt){
var xhr = evt.target;
var data = xhr.getResponseJson();
window['console']['log'](data);
- }, 'POST',
- 'score=' + formData.get('score')[0]);
+ }, 'POST', formString, {
+ 'Accept': 'application/json',
+ 'X-Requested-With': 'XMLHttpRequest'
+ });
evt.preventDefault();
});
});
View
3  lost_tracker/main.py
@@ -147,6 +147,9 @@ def form_score():
if group_id:
set_form_score(group_id, form_id, score)
+ if request.is_xhr:
+ return jsonify(status='ok')
+
return redirect(url_for("init_form_score"))
if __name__ == '__main__':
View
4 lost_tracker/static/js/lost_tracker.js
@@ -330,5 +330,5 @@ goog.net.XhrIo.prototype.getResponseJson=function(a){if(this.xhr_){var b=this.xh
goog.net.XhrIo.prototype.getResponse=function(){try{if(!this.xhr_)return null;if("response"in this.xhr_)return this.xhr_.response;switch(this.responseType_){case goog.net.XhrIo.ResponseType.DEFAULT:case goog.net.XhrIo.ResponseType.TEXT:return this.xhr_.responseText;case goog.net.XhrIo.ResponseType.ARRAY_BUFFER:if("mozResponseArrayBuffer"in this.xhr_)return this.xhr_.mozResponseArrayBuffer}this.logger_.severe("Response type "+this.responseType_+" is not supported on this browser");return null}catch(a){return this.logger_.fine("Can not get response: "+
a.message),null}};goog.net.XhrIo.prototype.getResponseHeader=function(a){return this.xhr_&&this.isComplete()?this.xhr_.getResponseHeader(a):void 0};goog.net.XhrIo.prototype.getAllResponseHeaders=function(){return this.xhr_&&this.isComplete()?this.xhr_.getAllResponseHeaders():""};goog.net.XhrIo.prototype.getLastErrorCode=function(){return this.lastErrorCode_};goog.net.XhrIo.prototype.getLastError=function(){return goog.isString(this.lastError_)?this.lastError_:String(this.lastError_)};
goog.net.XhrIo.prototype.formatMsg_=function(a){return a+" ["+this.lastMethod_+" "+this.lastUri_+" "+this.getStatus()+"]"};goog.debug.entryPointRegistry.register(function(a){goog.net.XhrIo.prototype.onReadyStateChangeEntryPoint_=a(goog.net.XhrIo.prototype.onReadyStateChangeEntryPoint_)});var lost_tracker={app:function(){}};lost_tracker.app.advanceState=function(a,b,c){var d=a.parentNode.parentNode;goog.dom.classlist.removeAll(d,["state_0","state_1","state_2"]);goog.net.XhrIo.send("/advance/"+b+"/"+c,function(a){a=a.target.getResponseJson();if(goog.isDefAndNotNull(a.new_state)){var b=goog.dom.getElement("icon_"+a.station_id+"_"+a.group_id);goog.isDefAndNotNull(b)&&(b.src="/static/icons/"+a.new_state+".png");goog.dom.classlist.add(d,"state_"+a.new_state)}})};
-lost_tracker.app.attachEvents=function(a){goog.array.forEach(goog.dom.getElementsByTagNameAndClass("div","group"),function(b){b=goog.dom.getElementsByTagNameAndClass("form",null,b);b=goog.array.filter(b[0],function(a){return"submit"==a.type});goog.events.listen(b[0],goog.events.EventType.CLICK,function(b){var d=goog.dom.forms.getFormDataMap(b.target.form);goog.net.XhrIo.send("/group/"+d.get("group_id")[0]+"/"+a,function(a){a=a.target.getResponseJson();window.console.log(a)},"POST","score="+d.get("score")[0]);
-b.preventDefault()})})};goog.exportSymbol("lost_tracker.app.attachEvents",lost_tracker.app.attachEvents);goog.exportSymbol("lost_tracker.app.advanceState",lost_tracker.app.advanceState);
+lost_tracker.app.attachEvents=function(){goog.array.forEach(goog.dom.getElementsByTagNameAndClass("div","group"),function(a){a=goog.dom.getElementsByTagNameAndClass("form",null,a);a=goog.array.filter(a[0],function(a){return"submit"==a.type});goog.events.listen(a[0],goog.events.EventType.CLICK,function(a){goog.dom.forms.getFormDataMap(a.target.form);var c=goog.dom.forms.getFormDataString(a.target.form);goog.net.XhrIo.send("/form_score",function(a){a=a.target.getResponseJson();window.console.log(a)},
+"POST",c,{Accept:"application/json","X-Requested-With":"XMLHttpRequest"});a.preventDefault()})})};goog.exportSymbol("lost_tracker.app.attachEvents",lost_tracker.app.attachEvents);goog.exportSymbol("lost_tracker.app.advanceState",lost_tracker.app.advanceState);
View
3  lost_tracker/templates/station.html
@@ -22,10 +22,11 @@
</div>
<div>
<form action="{{url_for('index')}}" method="POST">
+ <p style="display: none;"><input type="hidden" name="form_id"
+ value="{{station.id}}" /></p>
<p style="display: none;"><input type="hidden" name="group_id"
value="{{row.group.id}}" /></p>
<input type="number" name="score" />
- <input type="number" name="forobou" />
<input type="submit" value="OK" />
</form>
</div>
Please sign in to comment.
Something went wrong with that request. Please try again.