From f062e04290b0c2a5ba4cac675101e69ade6e46c8 Mon Sep 17 00:00:00 2001 From: FelisCatus Date: Sat, 4 Oct 2014 17:17:50 +0800 Subject: [PATCH] Allow quick enable/disable attached rule lists. --- omega-i18n/en/messages.json | 3 +++ omega-i18n/zh/messages.json | 3 +++ omega-web/src/less/options.less | 9 +++++++ .../omega/controllers/switch_profile.coffee | 26 ++++++++++++++++--- omega-web/src/partials/profile_switch.jade | 13 +++++++--- 5 files changed, 48 insertions(+), 6 deletions(-) diff --git a/omega-i18n/en/messages.json b/omega-i18n/en/messages.json index 0a52ed1..64beea0 100644 --- a/omega-i18n/en/messages.json +++ b/omega-i18n/en/messages.json @@ -351,6 +351,9 @@ "options_switchAttachedProfileInConditionDetails": { "message": "(Any request matching the rule list below)" }, + "options_switchAttachedProfileInConditionDisabled": { + "message": "(Rule list rules are DISABLED)" + }, "options_switchDefaultProfile": { "message": "Default" }, diff --git a/omega-i18n/zh/messages.json b/omega-i18n/zh/messages.json index d537ff0..93b974c 100644 --- a/omega-i18n/zh/messages.json +++ b/omega-i18n/zh/messages.json @@ -351,6 +351,9 @@ "options_switchAttachedProfileInConditionDetails": { "message": "(按照规则列表匹配请求)" }, + "options_switchAttachedProfileInConditionDisabled": { + "message": "(规则列表已禁用!)" + }, "options_switchDefaultProfile": { "message": "默认情景模式" }, diff --git a/omega-web/src/less/options.less b/omega-web/src/less/options.less index af57085..33941a2 100644 --- a/omega-web/src/less/options.less +++ b/omega-web/src/less/options.less @@ -130,6 +130,15 @@ ul.list-style-none, li.list-style-none { display: none; // Prevent not loaded directive from showing. } +.disabled .btn { + background-color: #ddd !important; + border-color: #ccc !important; + cursor: not-allowed !important; + pointer-events: none !important; + opacity: .65 !important; + box-shadow: none !important; +} + /* body */ h1 { diff --git a/omega-web/src/omega/controllers/switch_profile.coffee b/omega-web/src/omega/controllers/switch_profile.coffee index d334347..e36084e 100644 --- a/omega-web/src/omega/controllers/switch_profile.coffee +++ b/omega-web/src/omega/controllers/switch_profile.coffee @@ -81,16 +81,35 @@ angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $modal, return profile $scope.omegaWatchAndChange 'options[attachedKey]', onAttachedChange, true + $scope.attachedOptions = {enabled: false} $scope.$watch 'profile.defaultProfileName', (name) -> - if not $scope.attached + $scope.attachedOptions.enabled = (name == $scope.attachedName) + if not $scope.attached or not $scope.attachedOptions.enabled $scope.defaultProfileName = name + $scope.$watch 'attachedOptions.enabled', (enabled, oldValue) -> + return if enabled == oldValue + if enabled + if $scope.profile.defaultProfileName != $scope.attachedName + $scope.profile.defaultProfileName = $scope.attachedName + else + if $scope.profile.defaultProfileName == $scope.attachedName + if $scope.attached + $scope.profile.defaultProfileName = $scope.attached.defaultProfileName + $scope.defaultProfileName = $scope.attached.defaultProfileName + else + $scope.profile.defaultProfileName = 'direct' + $scope.defaultProfileName = 'direct' + $scope.$watch 'attached.defaultProfileName', (name) -> - if name + if name and $scope.attachedOptions.enabled $scope.defaultProfileName = name $scope.$watch 'defaultProfileName', (name) -> - ($scope.attached || $scope.profile).defaultProfileName = name + if $scope.attached and $scope.attachedOptions.enabled + $scope.attached.defaultProfileName = name + else + $scope.profile.defaultProfileName = name $scope.attachNew = -> $scope.attached = OmegaPac.Profiles.create( @@ -101,6 +120,7 @@ angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $modal, ) OmegaPac.Profiles.updateRevision($scope.attached) $scope.options[$scope.attachedKey] = $scope.attached + $scope.attachedOptions.enabled = true $scope.profile.defaultProfileName = $scope.attachedName $scope.removeAttached = -> diff --git a/omega-web/src/partials/profile_switch.jade b/omega-web/src/partials/profile_switch.jade index 9913626..cebd7a6 100644 --- a/omega-web/src/partials/profile_switch.jade +++ b/omega-web/src/partials/profile_switch.jade @@ -46,12 +46,19 @@ div(ng-controller='SwitchProfileCtrl') tr td(style='border-right: none;') span.glyphicon(class='{{profileIcons["RuleListProfile"]}}') - td(style='border-left: none;') {{'options_switchAttachedProfileInCondition' | tr}} + td(style='border-left: none;') + span.checkbox + label + input(type='checkbox' ng-model='attachedOptions.enabled') + | {{'options_switchAttachedProfileInCondition' | tr}} td - span {{'options_switchAttachedProfileInConditionDetails' | tr}} + span(ng-show='!!attachedOptions.enabled') + | {{'options_switchAttachedProfileInConditionDetails' | tr}} + span(ng-show='!attachedOptions.enabled') + | {{'options_switchAttachedProfileInConditionDisabled' | tr}} td div.form-control(omega-profile-select='options | profiles:profile' ng-model='attached.matchProfileName' - disp-name='$profile.name | dispName') + disp-name='$profile.name | dispName' ng-class='{disabled: !attachedOptions.enabled}') td button.btn.btn-danger.btn-sm(title="{{'options_deleteAttached' | tr}}" ng-click='removeAttached()') span.glyphicon.glyphicon-trash