123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- /**
- * Created by robin on 11/2/15.
- */
-
- angular.module('luticate')
- .controller('UserSettingsController', ['$scope', 'luticateAuthSettingsUser', 'luticateAuthSettings', 'luticateAuthCache', 'luticateDialogErrorHelper', 'data',
- function($scope, luticateAuthSettingsUser, luticateAuthSettings, luticateAuthCache, luticateDialogErrorHelper, data) {
-
- $scope.user = data;
-
- $scope.userSettings = {};
- $scope.userEffectiveSettings = {};
- $scope.tmpSetting = {
- Value: "",
- Type: "string",
- Name: "",
- IsBlocked: false
- };
-
- $scope.loadSettings = function()
- {
- var promiseLoadSettings = {
- id: "promiseLoadSettings",
- loaderGroups: ["modal"]
- };
-
- luticateAuthSettingsUser.getAll({user_id: $scope.user.Id}, promiseLoadSettings)
- .then(function (user_settings) {
- $scope.userEffectiveSettings = luticateAuthCache.getEffectiveSettings();
- $scope.userSettings = {};
- for (var i = 0; i < user_settings.Data.length; ++i) {
- var s = user_settings.Data[i];
- $scope.userSettings[s.Name] = s;
- }
-
- var settings = Object.keys($scope.userEffectiveSettings);
- if ($scope.userEffectiveSettings[$scope.tmpSetting.Name] != null) {
- $scope.setTmpSetting($scope.tmpSetting.Name);
- }
- else if (settings.length > 0) {
- $scope.setTmpSetting(settings[0]);
- }
- });
- };
-
- $scope.setTmpSetting = function(setting_name)
- {
- var setting = $scope.userEffectiveSettings[setting_name];
- $scope.tmpSetting.Value = setting.Value;
- $scope.tmpSetting.Type = setting.Type;
- $scope.tmpSetting.Name = setting.Name;
- };
-
- $scope.editSetting = function(setting)
- {
- var promiseEditSettings = {
- id: "promiseEditSettings",
- loaderGroups: ["modal"]
- };
- luticateAuthSettingsUser.edit({
- user_id: $scope.user.Id,
- setting_name: setting.Name,
- setting: setting
- }, promiseEditSettings).then($scope.loadFullSettings, luticateDialogErrorHelper.errorDialog);
- };
-
- $scope.resetSetting = function(setting)
- {
- setting.Value = null;
- var promiseEditSettings = {
- id: "promiseEditSettings",
- loaderGroups: ["modal"]
- };
- luticateAuthSettingsUser.edit({
- user_id: $scope.user.Id,
- setting_name: setting.Name,
- setting: setting
- }, promiseEditSettings).then($scope.loadFullSettings, luticateDialogErrorHelper.errorDialog);
- };
-
- $scope.loadFullSettings = function()
- {
- var promiseLoadSettings = {
- id: "promiseLoadSettings",
- loaderGroups: ["modal"]
- };
- luticateAuthSettings.loadSettings(promiseLoadSettings)
- .then(function()
- {
- $scope.loadSettings();
- }, luticateDialogErrorHelper.errorDialog);
- };
-
- $scope.loadSettings();
-
- }]);
|