1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- angular.module('app')
- .controller('PkGuidEditController', ['$scope', '$state', '$mdDialog', 'pkGuidBusiness',
- function ($scope, $state, $mdDialog, pkGuidBusiness) {
-
- $scope.pkguid = null;
- $scope.defaultPkguid = {
- id: null,
- someText: "Test.",
- someInt: 42
- };
-
- $scope.running = false;
-
- $scope.error = null;
-
- if ($state.params != null) {
- if ($state.params.pkguid != null) {
- $scope.pkguid = $state.params.pkguid;
- }
- else if ($state.params.id != null) {
- $scope.running = true;
- pkGuidBusiness.getSingleById($state.params.id).then(function(data)
- {
- $scope.running = false;
- $scope.pkguid = data;
- }, function (error) {
- $scope.running = false;
- $scope.error = error;
- });
- }
- else {
- $scope.pkguid = angular.copy($scope.defaultPkguid);
- }
- }
- else {
- $scope.pkguid = angular.copy($scope.defaultPkguid);
- }
-
- $scope.submit = function () {
- $scope.error = null;
- $scope.running = true;
- if ($scope.pkguid.id == null) {
- pkGuidBusiness.addDbo($scope.pkguid).then(function (data) {
- $scope.running = false;
- $state.go('pkguid_edit', {pkguid: data, id: data.id});
- }, function (error) {
- $scope.running = false;
- $scope.error = error;
- });
- }
- else {
- pkGuidBusiness.editSingleByIdDbo($scope.pkguid.id, $scope.pkguid).then(function (data) {
- $scope.running = false;
- $scope.pkguid = data;
- }, function (error) {
- $scope.running = false;
- $scope.error = error;
- });
- }
- };
-
- }]);
|