ZeroOmega/omega-web/src/coffee/omega_decoration.coffee

80 lines
2.3 KiB
CoffeeScript
Raw Normal View History

orderForType =
'FixedProfile': -2000
'PacProfile': -1000
2014-10-25 23:41:39 +08:00
'VirtualProfile': 1000
'SwitchProfile': 2000
'RuleListProfile': 3000
2014-09-20 23:49:04 +08:00
angular.module('omegaDecoration', []).value('profileIcons', {
'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'
'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) ->
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
).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 = []
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
scope.$watch(scope.profiles, ((profiles) ->
scope.currentProfiles = profiles
if scope.dispProfiles?
scope.dispProfiles = currentProfiles
updateView()
), true)
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()
scope.getName = (profile) ->
if profile
scope.dispName?({$profile: profile}) || profile?.name
)