Files
flood/source/scripts/actions/TorrentActions.js
2015-04-08 19:13:41 -04:00

41 lines
987 B
JavaScript

var AppDispatcher = require('../dispatcher/AppDispatcher');
var TorrentConstants = require('../constants/TorrentConstants');
var performAction = function(action, hash, success, error) {
$.ajax({
url: '/torrents/' + hash + '/' + action,
dataType: 'json',
success: function(data) {
success(data);
}.bind(this),
error: function(xhr, status, err) {
console.error(torrentsData, status, err.toString());
}.bind(this)
});
};
var TorrentActions = {
stop: function(hash) {
performAction('stop', hash, function(data) {
AppDispatcher.dispatch({
actionType: TorrentConstants.TORRENT_STOP
});
});
},
start: function(hash) {
performAction('start', hash, function(data) {
AppDispatcher.dispatch({
actionType: TorrentConstants.TORRENT_START
});
});
}
}
module.exports = TorrentActions;