2014-02-08 01:40:16 +00:00
|
|
|
var app = angular.module('gophish', ['ngTable', 'ngResource']);
|
|
|
|
|
|
|
|
app.factory('CampaignService', function($resource) {
|
2014-02-11 23:32:29 +00:00
|
|
|
return $resource('/api/campaigns/:id?api_key=' + API_KEY, {id: "@id"}, {
|
2014-02-08 21:16:36 +00:00
|
|
|
update: {
|
|
|
|
method: 'PUT'
|
|
|
|
}
|
|
|
|
});
|
2014-02-08 01:40:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
app.factory('GroupService', function($resource) {
|
2014-02-11 23:32:29 +00:00
|
|
|
return $resource('/api/groups/:id?api_key=' + API_KEY, {id: "@id"}, {
|
2014-02-08 21:16:36 +00:00
|
|
|
update: {
|
|
|
|
method: 'PUT'
|
|
|
|
}
|
|
|
|
});
|
2014-02-08 01:40:16 +00:00
|
|
|
});
|
|
|
|
|
2014-02-10 15:44:15 +00:00
|
|
|
app.controller('CampaignCtrl', function($scope, CampaignService, 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) {
|
|
|
|
CampaignService.query(function(campaigns) {
|
|
|
|
$scope.campaigns = campaigns
|
|
|
|
params.total(campaigns.length)
|
|
|
|
$defer.resolve(campaigns.slice((params.page() - 1) * params.count(), params.page() * params.count()));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
2014-02-08 01:40:16 +00:00
|
|
|
});
|
|
|
|
|
2014-02-10 07:15:36 +00:00
|
|
|
app.controller('GroupCtrl', function($scope, GroupService, ngTableParams) {
|
2014-02-10 15:44:15 +00:00
|
|
|
$scope.mainTableParams = new ngTableParams({
|
2014-02-10 07:15:36 +00:00
|
|
|
page: 1, // show first page
|
|
|
|
count: 10, // count per page
|
|
|
|
sorting: {
|
2014-02-10 15:44:15 +00:00
|
|
|
name: 'asc' // initial sorting
|
2014-02-10 07:15:36 +00:00
|
|
|
}
|
|
|
|
}, {
|
|
|
|
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
|
|
|
|
2014-02-10 15:44:15 +00:00
|
|
|
$scope.editGroupTableParams = 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) {
|
|
|
|
params.total($scope.group.targets.length)
|
|
|
|
$defer.resolve($scope.group.targets.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
|
|
|
};
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$scope.newGroup = false;
|
|
|
|
$scope.group = group;
|
2014-02-10 15:44:15 +00:00
|
|
|
$scope.editGroupTableParams.reload()
|
2014-02-08 01:40:16 +00:00
|
|
|
}
|
|
|
|
};
|
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 = ""
|
2014-02-10 15:44:15 +00:00
|
|
|
$scope.editGroupTableParams.reload()
|
2014-02-08 21:16:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
$scope.removeTarget = function(target) {
|
|
|
|
$scope.group.targets.splice($scope.group.targets.indexOf(target), 1);
|
2014-02-10 15:44:15 +00:00
|
|
|
$scope.editGroupTableParams.reload()
|
2014-02-08 21:16:36 +00:00
|
|
|
};
|
2014-02-10 01:34:47 +00:00
|
|
|
$scope.saveGroup = function(group) {
|
|
|
|
var newGroup = new GroupService($scope.group);
|
|
|
|
if ($scope.newGroup) {
|
2014-02-12 16:43:54 +00:00
|
|
|
newGroup.$save({},function() {
|
2014-02-10 01:34:47 +00:00
|
|
|
$scope.groups.push(newGroup);
|
2014-02-10 19:02:44 +00:00
|
|
|
$scope.mainTableParams.reload()
|
2014-02-10 01:34:47 +00:00
|
|
|
});
|
2014-02-10 07:15:36 +00:00
|
|
|
} else {
|
2014-02-11 23:32:29 +00:00
|
|
|
console.log(newGroup.id)
|
|
|
|
newGroup.$update({id : newGroup.id})
|
2014-02-10 01:34:47 +00:00
|
|
|
}
|
2014-02-10 19:02:44 +00:00
|
|
|
$scope.group = {
|
|
|
|
name: '',
|
|
|
|
targets: [],
|
|
|
|
};
|
|
|
|
$scope.editGroupTableParams.reload()
|
2014-02-10 01:34:47 +00:00
|
|
|
}
|
2014-02-08 01:40:16 +00:00
|
|
|
})
|