2014-02-08 01:40:16 +00:00
|
|
|
var app = angular.module('gophish', ['ngTable', 'ngResource']);
|
|
|
|
|
|
|
|
app.factory('CampaignService', function($resource) {
|
2014-02-08 21:16:36 +00:00
|
|
|
return $resource('/api/campaigns/:id?api_key=' + API_KEY, {
|
|
|
|
id: "@id"
|
|
|
|
}, {
|
|
|
|
update: {
|
|
|
|
method: 'PUT'
|
|
|
|
}
|
|
|
|
});
|
2014-02-08 01:40:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
app.factory('GroupService', function($resource) {
|
2014-02-10 01:34:47 +00:00
|
|
|
return $resource('/api/groups/:id?api_key=' + API_KEY, {}, {
|
2014-02-08 21:16:36 +00:00
|
|
|
update: {
|
|
|
|
method: 'PUT'
|
|
|
|
}
|
|
|
|
});
|
2014-02-08 01:40:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
app.controller('CampaignCtrl', function($scope, CampaignService) {
|
2014-02-08 21:16:36 +00:00
|
|
|
CampaignService.query(function(campaigns) {
|
2014-02-08 01:40:16 +00:00
|
|
|
$scope.campaigns = campaigns
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2014-02-10 07:15:36 +00:00
|
|
|
app.controller('GroupCtrl', function($scope, GroupService, ngTableParams) {
|
|
|
|
|
|
|
|
|
|
|
|
$scope.tableParams = new ngTableParams({
|
|
|
|
page: 1, // show first page
|
|
|
|
count: 10, // count per page
|
|
|
|
sorting: {
|
|
|
|
name: 'asc' // initial sorting
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
total: 0, // length of data
|
|
|
|
getData: function($defer, params) {
|
|
|
|
GroupService.query(function(groups) {
|
|
|
|
$scope.groups = groups
|
|
|
|
params.total(groups.length)
|
|
|
|
$defer.resolve(groups.slice((params.page() - 1) * params.count(), params.page() * params.count()));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
2014-02-08 01:40:16 +00:00
|
|
|
|
|
|
|
$scope.editGroup = function(group) {
|
|
|
|
if (group === 'new') {
|
|
|
|
$scope.newGroup = true;
|
|
|
|
$scope.group = {
|
|
|
|
name: '',
|
2014-02-08 21:16:36 +00:00
|
|
|
targets: [],
|
2014-02-08 01:40:16 +00:00
|
|
|
id: 0
|
|
|
|
};
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$scope.newGroup = false;
|
|
|
|
$scope.group = group;
|
|
|
|
}
|
|
|
|
};
|
2014-02-08 21:16:36 +00:00
|
|
|
|
|
|
|
$scope.addTarget = function() {
|
|
|
|
if ($scope.newTarget.email != "") {
|
|
|
|
$scope.group.targets.push({
|
|
|
|
email: $scope.newTarget.email
|
|
|
|
});
|
|
|
|
$scope.newTarget.email = ""
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$scope.removeTarget = function(target) {
|
|
|
|
$scope.group.targets.splice($scope.group.targets.indexOf(target), 1);
|
|
|
|
};
|
2014-02-10 01:34:47 +00:00
|
|
|
$scope.saveGroup = function(group) {
|
|
|
|
var newGroup = new GroupService($scope.group);
|
|
|
|
if ($scope.newGroup) {
|
|
|
|
newGroup.$save(function() {
|
|
|
|
$scope.groups.push(newGroup);
|
|
|
|
});
|
2014-02-10 07:15:36 +00:00
|
|
|
} else {
|
2014-02-10 01:34:47 +00:00
|
|
|
newGroup.$update()
|
|
|
|
}
|
|
|
|
}
|
2014-02-08 01:40:16 +00:00
|
|
|
})
|