/** * Created by robin on 11/4/15. */ angular.module('luticate') .controller('SettingEditController', ['$scope', 'luticateAuthSettings', 'data', 'luticateAuthCache', '$q', function($scope, luticateAuthSettings, data, luticateAuthCache, $q) { if (data != null) { $scope.setting = data; $scope.setting.IsNew = false; $scope.neededPermission = "LU_SETTING_EDIT"; } else { $scope.setting = { "Name": "", "Type": "string", "Value": "", "IsBlocked": false, "IsAdmin": false, "IsNew": true }; $scope.neededPermission = "LU_SETTING_ADD"; } $scope.types = [ "string", "int", "float", "bool", "object" ]; $scope.setType = function(type) { if ($scope.setting.Type == type) { return; } $scope.setting.Type = type; if (type == 'int' || type == 'float') { $scope.setting.Value = 0; } else if (type == 'string') { $scope.setting.Value = ""; } else if (type == 'bool') { $scope.setting.Value = true; } else if (type == 'object') { $scope.setting.Value = {}; } }; $scope.submitForm = function() { $scope.setting.Name = $scope.setting.Name.toUpperCase(); if (!$scope.setting.IsNew) { if (luticateAuthCache.hasEffectivePermission("LU_SETTING_EDIT")) { var promiseEditSetting = { id: "promiseEditSetting", loaderGroups: ["modal"] }; return luticateAuthSettings.edit({ setting_name: $scope.setting.Name, setting: $scope.setting }, promiseEditSetting); } else { var defer = $q.defer(); defer.resolve(); return defer.promise; } } else { var promiseAddSetting = { id: "promiseAddSetting", loaderGroups: ["modal"] }; return luticateAuthSettings.add($scope.setting, promiseAddSetting); } } }]);