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

View File

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