123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- angular.module('app')
- .controller('PkGuidEditController', ['$scope', '$state', '$mdDialog', 'pkGuidBusiness', 'AppUtilsBusiness',
- function ($scope, $state, $mdDialog, pkGuidBusiness, AppUtilsBusiness) {
-
- $scope.pkguid = null;
- $scope.defaultPkguid = {
- id: null,
- someText: "Test.",
- someInt: 42
- };
-
- $scope.running = false;
-
- $scope.error = null;
-
- $scope.setTitle = function()
- {
- if ($scope.pkguid.id != null) {
- AppUtilsBusiness.setTitle(AppUtilsBusiness.tr('pkguid.edit.title', {text: $scope.pkguid.someText}));
- AppUtilsBusiness.setToolbarTitle(AppUtilsBusiness.tr('pkguid.edit.toolbarTitle', {text: $scope.pkguid.someText}));
- }
- };
-
- $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;
- $scope.setTitle();
- }, function (error) {
- $scope.running = false;
- $scope.error = error;
- });
- }
- };
-
-
- if ($state.params != null) {
- if ($state.params.pkguid != null) {
- $scope.pkguid = $state.params.pkguid;
- $scope.setTitle();
- }
- else if ($state.params.id != null) {
- $scope.running = true;
- pkGuidBusiness.getSingleById($state.params.id).then(function(data)
- {
- $scope.running = false;
- $scope.pkguid = data;
- $scope.setTitle();
- }, function (error) {
- $scope.running = false;
- $scope.error = error;
- $scope.pkguid = null;
- $scope.setTitle();
- });
- }
- else {
- $scope.pkguid = angular.copy($scope.defaultPkguid);
- $scope.setTitle();
- }
- }
- else {
- $scope.pkguid = angular.copy($scope.defaultPkguid);
- $scope.setTitle();
- }
-
- }]);
|