You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

settingedit.controller.js 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * Created by robin on 11/4/15.
  3. */
  4. angular.module('luticate')
  5. .controller('SettingEditController', ['$scope', 'luticateAuthSettings', 'data', 'luticateAuthCache', '$q',
  6. function($scope, luticateAuthSettings, data, luticateAuthCache, $q) {
  7. if (data != null) {
  8. $scope.setting = data;
  9. $scope.setting.IsNew = false;
  10. $scope.neededPermission = "LU_SETTING_EDIT";
  11. }
  12. else {
  13. $scope.setting = {
  14. "Name": "",
  15. "Type": "string",
  16. "Value": "",
  17. "IsBlocked": false,
  18. "IsAdmin": false,
  19. "IsNew": true
  20. };
  21. $scope.neededPermission = "LU_SETTING_ADD";
  22. }
  23. $scope.types = [
  24. "string",
  25. "int",
  26. "float",
  27. "bool",
  28. "object"
  29. ];
  30. $scope.setType = function(type)
  31. {
  32. if ($scope.setting.Type == type)
  33. {
  34. return;
  35. }
  36. $scope.setting.Type = type;
  37. if (type == 'int' || type == 'float')
  38. {
  39. $scope.setting.Value = 0;
  40. }
  41. else if (type == 'string')
  42. {
  43. $scope.setting.Value = "";
  44. }
  45. else if (type == 'bool')
  46. {
  47. $scope.setting.Value = true;
  48. }
  49. else if (type == 'object')
  50. {
  51. $scope.setting.Value = {};
  52. }
  53. };
  54. $scope.submitForm = function()
  55. {
  56. $scope.setting.Name = $scope.setting.Name.toUpperCase();
  57. if (!$scope.setting.IsNew) {
  58. if (luticateAuthCache.hasEffectivePermission("LU_SETTING_EDIT")) {
  59. var promiseEditSetting = {
  60. id: "promiseEditSetting",
  61. loaderGroups: ["modal"]
  62. };
  63. return luticateAuthSettings.edit({
  64. setting_name: $scope.setting.Name,
  65. setting: $scope.setting
  66. }, promiseEditSetting);
  67. }
  68. else {
  69. var defer = $q.defer();
  70. defer.resolve();
  71. return defer.promise;
  72. }
  73. }
  74. else {
  75. var promiseAddSetting = {
  76. id: "promiseAddSetting",
  77. loaderGroups: ["modal"]
  78. };
  79. return luticateAuthSettings.add($scope.setting, promiseAddSetting);
  80. }
  81. }
  82. }]);