2014-10-01 14:37:10 +08:00
|
|
|
orderForType =
|
|
|
|
'FixedProfile': -2000
|
|
|
|
'PacProfile': -1000
|
2014-10-25 23:41:39 +08:00
|
|
|
'VirtualProfile': 1000
|
2014-10-01 14:37:10 +08:00
|
|
|
'SwitchProfile': 2000
|
|
|
|
'RuleListProfile': 3000
|
|
|
|
|
2014-09-20 23:49:04 +08:00
|
|
|
angular.module('omegaDecoration', []).value('profileIcons', {
|
2014-10-01 14:37:10 +08:00
|
|
|
'DirectProfile': 'glyphicon-transfer'
|
|
|
|
'SystemProfile': 'glyphicon-off'
|
|
|
|
'AutoDetectProfile': 'glyphicon-file'
|
|
|
|
'FixedProfile': 'glyphicon-globe'
|
|
|
|
'PacProfile': 'glyphicon-file'
|
2014-10-25 23:41:39 +08:00
|
|
|
'VirtualProfile': 'glyphicon-question-sign'
|
2014-10-01 14:37:10 +08:00
|
|
|
'RuleListProfile': 'glyphicon-list'
|
|
|
|
'SwitchProfile': 'glyphicon-retweet'
|
|
|
|
}).constant('profileOrder', (a, b) ->
|
|
|
|
diff = (orderForType[a.profileType] | 0) - (orderForType[b.profileType] | 0)
|
|
|
|
return diff if diff != 0
|
|
|
|
if a.name == b.name
|
|
|
|
0
|
|
|
|
else if a.name < b.name
|
|
|
|
-1
|
|
|
|
else
|
|
|
|
1
|
2014-10-25 23:41:39 +08:00
|
|
|
).directive('omegaProfileIcon', (profileIcons) ->
|
2014-10-01 17:36:29 +08:00
|
|
|
restrict: 'A'
|
2014-10-25 23:41:39 +08:00
|
|
|
templateUrl: 'partials/omega_profile_icon.html'
|
|
|
|
scope:
|
|
|
|
'profile': '=?omegaProfileIcon'
|
|
|
|
'icon': '=?icon'
|
|
|
|
'color': '=?color'
|
|
|
|
link: (scope, element, attrs, ngModel) ->
|
|
|
|
scope.profileIcons = profileIcons
|
2014-10-01 17:36:29 +08:00
|
|
|
).directive('omegaProfileSelect', ($timeout, profileIcons) ->
|
|
|
|
restrict: 'A'
|
|
|
|
templateUrl: 'partials/omega_profile_select.html'
|
|
|
|
require: '?ngModel'
|
|
|
|
scope:
|
|
|
|
'profiles': '&omegaProfileSelect'
|
|
|
|
'defaultText': '@?defaultText'
|
|
|
|
'dispName': '&?dispName'
|
|
|
|
link: (scope, element, attrs, ngModel) ->
|
|
|
|
scope.profileIcons = profileIcons
|
|
|
|
scope.currentProfiles = []
|
2014-10-18 22:48:58 +08:00
|
|
|
scope.dispProfiles = undefined
|
|
|
|
updateView = ->
|
|
|
|
scope.profileIcon = ''
|
|
|
|
for profile in scope.currentProfiles
|
|
|
|
if profile.name == scope.profileName
|
|
|
|
scope.selectedProfile = profile
|
|
|
|
scope.profileIcon = profileIcons[profile.profileType]
|
|
|
|
break
|
2014-10-01 17:36:29 +08:00
|
|
|
scope.$watch(scope.profiles, ((profiles) ->
|
|
|
|
scope.currentProfiles = profiles
|
2014-10-18 22:48:58 +08:00
|
|
|
if scope.dispProfiles?
|
|
|
|
scope.dispProfiles = currentProfiles
|
|
|
|
updateView()
|
2014-10-01 17:36:29 +08:00
|
|
|
), true)
|
2014-10-18 22:48:58 +08:00
|
|
|
|
|
|
|
scope.toggled = (open) ->
|
|
|
|
if open and not scope.dispProfiles?
|
|
|
|
scope.dispProfiles = scope.currentProfiles
|
|
|
|
scope.toggled = undefined
|
|
|
|
|
|
|
|
if ngModel
|
|
|
|
ngModel.$render = ->
|
|
|
|
scope.profileName = ngModel.$viewValue
|
|
|
|
updateView()
|
|
|
|
|
|
|
|
scope.setProfileName = (name) ->
|
|
|
|
if ngModel
|
|
|
|
ngModel.$setViewValue(name)
|
|
|
|
ngModel.$render()
|
|
|
|
|
2014-10-01 17:36:29 +08:00
|
|
|
scope.getName = (profile) ->
|
2014-10-20 20:52:23 +08:00
|
|
|
if profile
|
|
|
|
scope.dispName?({$profile: profile}) || profile?.name
|
2014-10-01 14:37:10 +08:00
|
|
|
)
|