Naming, comments.

This commit is contained in:
Alexis Lahouze 2015-08-21 00:25:10 +02:00
parent b5a483e8e5
commit ce3181537d
2 changed files with 30 additions and 20 deletions

View File

@ -16,7 +16,7 @@
*/
accountantApp
.factory("ScheduledOperations", ["$resource", function($resource) {
.factory("ScheduledOperation", ["$resource", function($resource) {
return $resource(
"/api/scheduled_operations/:id", {
id: "@id"
@ -26,31 +26,40 @@ accountantApp
.controller(
"SchedulerController", [
"$scope", "$rootScope", "$routeParams", "notificationService", "ScheduledOperations",
function($scope, $rootScope, $routeParams, notificationService, ScheduledOperations) {
// Operations store and selection
"$scope", "$rootScope", "$routeParams", "notificationService", "ScheduledOperation",
function($scope, $rootScope, $routeParams, notificationService, ScheduledOperation) {
// Operation store.
$scope.operations = [];
$scope.categories = [];
/*
* Add a new operation at the beginning of th array.
*/
$scope.add = function() {
var operation = new ScheduledOperation({
account_id: $routeParams.accountId
});
$scope.addOperation = function() {
operation = new ScheduledOperations({});
operation.account_id = $routeParams.accountId;
// Insert new operation at the beginning of the array.
$scope.operations.splice(0, 0, operation);
};
$scope.loadOperations = function(accountId) {
/*
* Load operations.
*/
$scope.load = function() {
// Clean up selected entry.
$scope.selectedOperation = null;
$scope.savedOperation = null;
$scope.operations = ScheduledOperations.query({
$scope.operations = ScheduledOperation.query({
account: $routeParams.accountId
});
};
// Save operation.
$scope.saveOperation = function($data, $index) {
/*
* Save operation.
*/
$scope.save = function($data, $index) {
var operation;
if($data.$save) {
@ -62,12 +71,13 @@ accountantApp
return operation.$save().then(function(data) {
notificationService.success("Operation #" + data.id + " saved.");
return data;
});
};
// Reload operation from server to cancel edition.
$scope.cancelEditOperation = function(operation, rowform, $index) {
/*
* Cancel operation edition. Delete if new.
*/
$scope.cancelEdit = function(operation, rowform, $index) {
if(!operation.id) {
$scope.operations.splice($index, 1);
} else {
@ -76,7 +86,7 @@ accountantApp
};
/*
* Delete a scheduled operation.
* Delete operation.
*/
$scope.delete = function(operation, $index) {
var id = operation.id;
@ -97,5 +107,5 @@ accountantApp
};
// Load operations on controller initialization.
$scope.loadOperations($routeParams.accountId);
$scope.load();
}]);

View File

@ -36,7 +36,7 @@
<tbody>
<tr>
<td colspan="8">
<button class="btn btn-success" ng-click="addOperation()">
<button class="btn btn-success" ng-click="add()">
Ajouter
</button>
</td>
@ -105,7 +105,7 @@
<td>
<form editable-form name="rowform"
onbeforesave="saveOperation($data, $index)"
onbeforesave="save($data, $index)"
shown="!operation.id">
<div class="btn-group btn-group-xs">
<!-- Save current operation -->
@ -124,7 +124,7 @@
<!-- Cancel edit. -->
<button type="button" class="btn btn-default"
ng-if="rowform.$visible"
ng-click="cancelEditOperation(operation, rowform, $index)"
ng-click="cancelEdit(operation, rowform, $index)"
title="Cancel">
<span class="fa fa-times"></span>
</button>