Fix angular style issues.

This commit is contained in:
Alexis Lahouze 2016-10-14 08:21:43 +02:00
parent 4aed242a48
commit f12c89a9ee
1 changed files with 76 additions and 75 deletions

View File

@ -25,99 +25,100 @@ angular.module('accountant.scheduler', [
'mgcrea.ngStrap'
])
.config(['$resourceProvider', function($resourceProvider) {
.config(function($resourceProvider) {
// Keep trailing slashes to avoid redirect by flask..
$resourceProvider.defaults.stripTrailingSlashes = false;
}])
})
.factory('ScheduledOperation', ['$resource', function($resource) {
.factory('ScheduledOperation', function($resource) {
return $resource(
'/api/scheduled_operation/:id', {
id: '@id'
}
);
}])
})
.controller('SchedulerController', [
'$scope', '$rootScope', '$routeParams', '$ngBootbox', 'Notification', 'ScheduledOperation',
function($scope, $rootScope, $routeParams, $ngBootbox, Notification, ScheduledOperation) {
// Operation store.
$scope.operations = [];
.controller('SchedulerController', function($rootScope, $routeParams, $ngBootbox, Notification, ScheduledOperation) {
var vm = this;
/*
* Add a new operation at the beginning of th array.
*/
$scope.add = function() {
var operation = new ScheduledOperation({
// eslint-disable-next-line camelcase
account_id: $routeParams.accountId
});
// Operation store.
vm.operations = [];
// Insert new operation at the beginning of the array.
$scope.operations.splice(0, 0, operation);
};
/*
* Add a new operation at the beginning of th array.
*/
vm.add = function() {
var operation = new ScheduledOperation({
// eslint-disable-next-line camelcase
account_id: $routeParams.accountId
});
/*
* Load operations.
*/
$scope.load = function() {
$scope.operations = ScheduledOperation.query({
// eslint-disable-next-line camelcase
account_id: $routeParams.accountId
});
};
// Insert new operation at the beginning of the array.
vm.operations.splice(0, 0, operation);
};
/*
* Save operation.
*/
$scope.save = function($data, $index) {
var operation;
/*
* Load operations.
*/
vm.load = function() {
vm.operations = ScheduledOperation.query({
// eslint-disable-next-line camelcase
account_id: $routeParams.accountId
});
};
if ($data.$save) {
operation = $data;
} else {
operation = $scope.operations[$index];
operation = angular.merge(operation, $data);
}
/*
* Save operation.
*/
vm.save = function($data, $index) {
var operation;
return operation.$save().then(function(data) {
Notification.success('Operation #' + data.id + ' saved.');
});
};
if ($data.$save) {
operation = $data;
} else {
operation = vm.operations[$index];
operation = angular.merge(operation, $data);
}
/*
* Cancel operation edition. Delete if new.
*/
$scope.cancelEdit = function(operation, rowform, $index) {
if (operation.id) {
rowform.$cancel();
} else {
$scope.operations.splice($index, 1);
}
};
return operation.$save().then(function(data) {
Notification.success('Operation #' + data.id + ' saved.');
});
};
/*
* Delete operation.
*/
$scope.delete = function(operation, $index) {
var id = operation.id;
/*
* Cancel operation edition. Delete if new.
*/
vm.cancelEdit = function(operation, rowform, $index) {
if (operation.id) {
rowform.$cancel();
} else {
vm.operations.splice($index, 1);
}
};
$ngBootbox.confirm(
'Voulez-vous supprimer l\'operation planifiée \\\'' + operation.label + '\\\' ?',
function(result) {
if (result) {
operation.$delete().then(function() {
Notification.success('Operation #' + id + ' deleted.');
/*
* Delete operation.
*/
vm.delete = function(operation, $index) {
var id = operation.id;
// Remove account from array.
$scope.operations.splice($index, 1);
});
}
$ngBootbox.confirm(
'Voulez-vous supprimer l\'operation planifiée \\\'' + operation.label + '\\\' ?',
function(result) {
if (result) {
operation.$delete().then(function() {
Notification.success('Operation #' + id + ' deleted.');
// Remove account from array.
vm.operations.splice($index, 1);
});
}
);
};
}
);
};
// Load operations on controller initialization.
$scope.load();
}
]);
// Load operations on controller initialization.
vm.load();
})
;