Skip to content

Instantly share code, notes, and snippets.

Created April 1, 2015 18:53
Show Gist options
  • Select an option

  • Save anonymous/5d1c788db2c4e780d880 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/5d1c788db2c4e780d880 to your computer and use it in GitHub Desktop.
onLoadData: function(){
this.errors = "";
SuperAgent
.get("http://127.0.0.1:8000/buildings/")
.set("Authorization", "")
.set("Accept", "application/json")
.end(function(err, res){
if(err)
{
this.errors = err;
this.updateError();
}
else
{
this.objects = res.body;
this.updateObjects();
}
}.bind(this));
},
onAddBuilding: function(item){
this.errors = "";
var updatedItem = -1;
SuperAgent
.post("http://127.0.0.1:8000/buildings/")
.send(item)
.set("Authorization", "")
.set("Accept", "application/json")
.end(function(err, res){
if (err) {
this.errors = err;
this.trigger(item);
}
else if(res.status !== 201)
{
this.errors = res.body;
this.trigger(item);
}
else
{
updatedItem = res.body;
if (!updatedItem.hasOwnProperty("id")) {
this.errors = res.body;
this.trigger(item);
}
this.objects.push(updatedItem);
this.trigger(updatedItem);
}
}.bind(this));
},
'use strict';
var Reflux = require('reflux');
var BuildingActions = Reflux.createActions([
"loadData",
"addBuilding",
"deleteBuilding",
"patchBuilding",
"addWatcher",
"deleteWatcher"
]);
module.exports = BuildingActions;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment