Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

usersettings.controller.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * Created by robin on 11/2/15.
  3. */
  4. angular.module('luticate')
  5. .controller('UserSettingsController', ['$scope', 'luticateAuthSettingsUser', 'luticateAuthSettings', 'luticateAuthCache', 'luticateDialogErrorHelper', 'data',
  6. function($scope, luticateAuthSettingsUser, luticateAuthSettings, luticateAuthCache, luticateDialogErrorHelper, data) {
  7. $scope.user = data;
  8. $scope.userSettings = {};
  9. $scope.userEffectiveSettings = {};
  10. $scope.tmpSetting = {
  11. Value: "",
  12. Type: "string",
  13. Name: "",
  14. IsBlocked: false
  15. };
  16. $scope.loadSettings = function()
  17. {
  18. var promiseLoadSettings = {
  19. id: "promiseLoadSettings",
  20. loaderGroups: ["modal"]
  21. };
  22. luticateAuthSettingsUser.getAll({user_id: $scope.user.Id}, promiseLoadSettings)
  23. .then(function (user_settings) {
  24. $scope.userEffectiveSettings = luticateAuthCache.getEffectiveSettings();
  25. $scope.userSettings = {};
  26. for (var i = 0; i < user_settings.Data.length; ++i) {
  27. var s = user_settings.Data[i];
  28. $scope.userSettings[s.Name] = s;
  29. }
  30. var settings = Object.keys($scope.userEffectiveSettings);
  31. if ($scope.userEffectiveSettings[$scope.tmpSetting.Name] != null) {
  32. $scope.setTmpSetting($scope.tmpSetting.Name);
  33. }
  34. else if (settings.length > 0) {
  35. $scope.setTmpSetting(settings[0]);
  36. }
  37. });
  38. };
  39. $scope.setTmpSetting = function(setting_name)
  40. {
  41. var setting = $scope.userEffectiveSettings[setting_name];
  42. $scope.tmpSetting.Value = setting.Value;
  43. $scope.tmpSetting.Type = setting.Type;
  44. $scope.tmpSetting.Name = setting.Name;
  45. };
  46. $scope.editSetting = function(setting)
  47. {
  48. var promiseEditSettings = {
  49. id: "promiseEditSettings",
  50. loaderGroups: ["modal"]
  51. };
  52. luticateAuthSettingsUser.edit({
  53. user_id: $scope.user.Id,
  54. setting_name: setting.Name,
  55. setting: setting
  56. }, promiseEditSettings).then($scope.loadFullSettings, luticateDialogErrorHelper.errorDialog);
  57. };
  58. $scope.resetSetting = function(setting)
  59. {
  60. setting.Value = null;
  61. var promiseEditSettings = {
  62. id: "promiseEditSettings",
  63. loaderGroups: ["modal"]
  64. };
  65. luticateAuthSettingsUser.edit({
  66. user_id: $scope.user.Id,
  67. setting_name: setting.Name,
  68. setting: setting
  69. }, promiseEditSettings).then($scope.loadFullSettings, luticateDialogErrorHelper.errorDialog);
  70. };
  71. $scope.loadFullSettings = function()
  72. {
  73. var promiseLoadSettings = {
  74. id: "promiseLoadSettings",
  75. loaderGroups: ["modal"]
  76. };
  77. luticateAuthSettings.loadSettings(promiseLoadSettings)
  78. .then(function()
  79. {
  80. $scope.loadSettings();
  81. }, luticateDialogErrorHelper.errorDialog);
  82. };
  83. $scope.loadSettings();
  84. }]);