2014-08-25 01:02:34 +02:00
|
|
|
define(['app'], function (app) {
|
|
|
|
app.registerFactory('Playbook', ['$http', function ($http) {
|
|
|
|
var Playbook = function (id, cb) {
|
|
|
|
if (!id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.id = id;
|
|
|
|
|
|
|
|
this.get(cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
Playbook.prototype.save = function () {
|
2014-08-25 12:35:49 +02:00
|
|
|
return $http.put('/playbook/'+this.data._id, this.data);
|
2014-08-25 01:02:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Playbook.prototype.add = function () {
|
2014-08-25 12:35:49 +02:00
|
|
|
return $http.post('/playbooks', this.data);
|
2014-08-25 01:02:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Playbook.prototype.delete = function () {
|
2014-08-25 12:35:49 +02:00
|
|
|
return $http.delete('/playbook/'+this.data._id);
|
2014-08-25 01:02:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Playbook.prototype.get = function (cb) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
$http.get('/playbook/'+this.id)
|
|
|
|
.success(function (data, status) {
|
|
|
|
self.data = data;
|
|
|
|
cb();
|
|
|
|
})
|
|
|
|
.error(function (data, status) {
|
|
|
|
cb(data, status);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return Playbook;
|
|
|
|
}])
|
|
|
|
})
|