Browse Source

Add rule cloning function to switch profile. Fix #75.

FelisCatus 11 years ago
parent
commit
038b428619

+ 3 - 0
omega-i18n/en/messages.json

@@ -409,6 +409,9 @@
   "options_addCondition": {
     "message": "Add condition"
   },
+  "options_cloneRule": {
+    "message": "Clone"
+  },
   "options_switchAttachedProfileInCondition": {
     "message": "Rule list rules"
   },

+ 3 - 0
omega-i18n/zh_CN/messages.json

@@ -409,6 +409,9 @@
   "options_addCondition": {
     "message": "添加条件"
   },
+  "options_cloneRule": {
+    "message": "克隆"
+  },
   "options_switchAttachedProfileInCondition": {
     "message": "规则列表规则"
   },

+ 3 - 0
omega-i18n/zh_HK/messages.json

@@ -409,6 +409,9 @@
   "options_addCondition": {
     "message": "添加條件"
   },
+  "options_cloneRule": {
+    "message": "克隆"
+  },
   "options_switchAttachedProfileInCondition": {
     "message": "規則列表規則"
   },

+ 3 - 0
omega-i18n/zh_TW/messages.json

@@ -409,6 +409,9 @@
   "options_addCondition": {
     "message": "添加條件"
   },
+  "options_cloneRule": {
+    "message": "克隆"
+  },
   "options_switchAttachedProfileInCondition": {
     "message": "規則列表規則"
   },

+ 9 - 1
omega-web/src/omega/controllers/switch_profile.coffee

@@ -1,5 +1,5 @@
 angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $location,
-  $modal, profileIcons, getAttachedName, omegaTarget) ->
+  $modal, profileIcons, getAttachedName, omegaTarget, $timeout) ->
 
   $scope.showConditionHelp = ($location.search().help == 'condition')
 
@@ -127,6 +127,14 @@ angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $location,
     else
       removeForReal()
 
+  $scope.cloneRule = (index) ->
+    rule = angular.copy($scope.profile.rules[index])
+    $scope.profile.rules.splice(index + 1, 0, rule)
+    $timeout ->
+      input = angular.element(".switch-rule-row:nth-child(#{index + 2}) input")
+      input[0]?.focus()
+      input[0]?.select()
+
   $scope.resetRules = ->
     scope = $scope.$new('isolate')
     scope.ruleProfile = $scope.profileByName($scope.defaultProfileName)

+ 3 - 0
omega-web/src/partials/profile_switch.jade

@@ -58,6 +58,9 @@ div(ng-controller='SwitchProfileCtrl')
             td
               button.btn.btn-danger.btn-sm(title="{{'options_deleteRule' | tr}}" ng-click='removeRule($index)')
                 span.glyphicon.glyphicon-trash
+              = ' '
+              button.btn.btn-default.btn-sm(title="{{'options_cloneRule' | tr}}" ng-click='cloneRule($index)')
+                span.glyphicon.glyphicon-tags
         tbody
           tr
             td(style='border-right: none;')