Semaphore/public/js/factories/playbook.js

52 lines
1.0 KiB
JavaScript
Raw Normal View History

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);
})
}
Playbook.prototype.getHostGroups = function (cb) {
$http.get('/playbook/'+this.data._id+'/hosts')
.success(function (data, status) {
self.hosts = data;
cb();
})
.error(function (data, status) {
cb(data, status);
})
}
2014-08-25 01:02:34 +02:00
return Playbook;
}])
})