mirror of
https://github.com/zero-peak/ZeroOmega.git
synced 2025-02-02 02:58:13 -05:00
Use custom directive instead of bootstrap-select for performance. Fix #46.
This commit is contained in:
parent
0be33856e2
commit
3badc664be
@ -37,7 +37,6 @@
|
|||||||
"FileSaver": "*",
|
"FileSaver": "*",
|
||||||
"angular-ui-utils": "bower-validate",
|
"angular-ui-utils": "bower-validate",
|
||||||
"angular-ladda": "~0.1.6",
|
"angular-ladda": "~0.1.6",
|
||||||
"bootstrap-select": "~1.6.2",
|
|
||||||
"angular-sanitize": "~1.2.26"
|
"angular-sanitize": "~1.2.26"
|
||||||
},
|
},
|
||||||
"exportsOverride": {
|
"exportsOverride": {
|
||||||
|
@ -36,24 +36,38 @@ angular.module('omegaDecoration', []).value('profileIcons', {
|
|||||||
'defaultText': '@?defaultText'
|
'defaultText': '@?defaultText'
|
||||||
'dispName': '&?dispName'
|
'dispName': '&?dispName'
|
||||||
link: (scope, element, attrs, ngModel) ->
|
link: (scope, element, attrs, ngModel) ->
|
||||||
scope.classes = [].slice.call(element[0].classList)
|
|
||||||
element.attr('class', '')
|
|
||||||
selectpicker = element.find('.selectpicker')
|
|
||||||
if ngModel
|
|
||||||
ngModel.$render = ->
|
|
||||||
selectpicker.selectpicker('val', ngModel.$viewValue)
|
|
||||||
return
|
|
||||||
selectpicker.selectpicker().change (e) ->
|
|
||||||
ngModel.$setViewValue($(e.target).val())
|
|
||||||
scope.profileIcons = profileIcons
|
scope.profileIcons = profileIcons
|
||||||
scope.currentProfiles = []
|
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.$watch(scope.profiles, ((profiles) ->
|
||||||
scope.currentProfiles = profiles
|
scope.currentProfiles = profiles
|
||||||
|
if scope.dispProfiles?
|
||||||
|
scope.dispProfiles = currentProfiles
|
||||||
|
updateView()
|
||||||
), true)
|
), true)
|
||||||
scope.onItemsUpdated = ->
|
|
||||||
selectpicker.selectpicker('refresh')
|
scope.toggled = (open) ->
|
||||||
ngModel?.$render()
|
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) ->
|
scope.getName = (profile) ->
|
||||||
scope.dispName?({$profile: profile}) || profile.name
|
scope.dispName?({$profile: profile}) || profile?.name
|
||||||
)
|
)
|
||||||
|
@ -28,8 +28,6 @@ $script.ready ['angular-loader'], ->
|
|||||||
'lib/angular-ui-utils/validate.min.js'
|
'lib/angular-ui-utils/validate.min.js'
|
||||||
'lib/jsondiffpatch/bundle.min.js'
|
'lib/jsondiffpatch/bundle.min.js'
|
||||||
'lib/angular-spectrum-colorpicker/angular-spectrum-colorpicker.min.js'
|
'lib/angular-spectrum-colorpicker/angular-spectrum-colorpicker.min.js'
|
||||||
'lib/bootstrap/js/dropdown.js'
|
|
||||||
'lib/bootstrap-select/bootstrap-select.js'
|
|
||||||
], 'omega-deps')
|
], 'omega-deps')
|
||||||
$script.ready ['jquery'], ->
|
$script.ready ['jquery'], ->
|
||||||
$script 'lib/jquery-ui-1.10.4.custom.min.js', 'jquery-ui'
|
$script 'lib/jquery-ui-1.10.4.custom.min.js', 'jquery-ui'
|
||||||
|
@ -115,23 +115,32 @@ ul.list-style-none, li.list-style-none {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* bootstrap-select */
|
/* omega-profile-select */
|
||||||
|
|
||||||
.dropdown-menu>.selected>a {
|
.omega-profile-select {
|
||||||
&, &:hover, &:focus {
|
width: 100%;
|
||||||
color: #FFF;
|
|
||||||
text-decoration: none;
|
.btn {
|
||||||
outline: 0;
|
width: 100%;
|
||||||
background-color: #428BCA;
|
display: block;
|
||||||
|
text-align: left;
|
||||||
|
text-align: initial;
|
||||||
|
position: relative;
|
||||||
|
padding-right: 25px;
|
||||||
|
|
||||||
|
.caret {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
right: 12px;
|
||||||
|
margin-top: -2px;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
.bootstrap-select.btn-group {
|
.dropdown-menu {
|
||||||
margin-bottom: 0 !important;
|
width: 100%;
|
||||||
}
|
cursor: pointer;
|
||||||
|
}
|
||||||
.form-control[omega-profile-select] {
|
|
||||||
display: none; // Prevent not loaded directive from showing.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.disabled .btn {
|
.disabled .btn {
|
||||||
|
@ -1,5 +1,18 @@
|
|||||||
select.selectpicker(ng-class='classes')
|
.btn-group.omega-profile-select(dropdown on-toggle="toggled(open)")
|
||||||
option(ng-if='!!defaultText' value='' data-icon='glyphicon-time') {{defaultText}}
|
button.btn.btn-default.dropdown-toggle(type='button' aria-expanded='false'
|
||||||
option(ng-repeat='profile in currentProfiles' value='{{profile.name}}' omega-repeat-done='onItemsUpdated()'
|
role='listbox' aria-haspopup='true')
|
||||||
data-content='<span class="glyphicon {{profileIcons[profile.profileType]}}" style="color: {{profile.color}}"></span> {{getName(profile)}}')
|
span.glyphicon(class='{{profileIcon || "glyphicon-time"}}' ng-style='{color: selectedProfile.color}')
|
||||||
| {{getName(profile)}}
|
= ' '
|
||||||
|
span(ng-show='!!profileName') {{getName(selectedProfile)}}
|
||||||
|
span(ng-show='!profileName') {{defaultText}}
|
||||||
|
= ' '
|
||||||
|
span.caret
|
||||||
|
ul.dropdown-menu(role='listbox')
|
||||||
|
li(role='option' ng-if='!!defaultText' ng-class='{active: profileName == ""}')
|
||||||
|
a(ng-click='setProfileName("")')
|
||||||
|
span.glyphicon.glyphicon-time
|
||||||
|
= ' {{defaultText}}'
|
||||||
|
li(role='option' ng-repeat='profile in dispProfiles' ng-class='{active: profileName == profile.name}')
|
||||||
|
a(ng-click='setProfileName(profile.name)')
|
||||||
|
span.glyphicon(class='{{profileIcons[profile.profileType]}}' ng-style='{color: profile.color}')
|
||||||
|
= ' {{getName(profile)}}'
|
||||||
|
@ -51,7 +51,7 @@ div(ng-controller='SwitchProfileCtrl')
|
|||||||
input.form-control(ng-model='rule.condition.pattern' ng-switch-default required
|
input.form-control(ng-model='rule.condition.pattern' ng-switch-default required
|
||||||
ui-validate='{pattern: "validateCondition(rule.condition, $value)"}')
|
ui-validate='{pattern: "validateCondition(rule.condition, $value)"}')
|
||||||
td
|
td
|
||||||
div.form-control(omega-profile-select='options | profiles:profile' ng-model='rule.profileName'
|
div(omega-profile-select='options | profiles:profile' ng-model='rule.profileName'
|
||||||
disp-name='$profile.name | dispName' ng-class='{disabled: rule.condition.conditionType == "NeverCondition"}')
|
disp-name='$profile.name | dispName' ng-class='{disabled: rule.condition.conditionType == "NeverCondition"}')
|
||||||
td
|
td
|
||||||
button.btn.btn-danger.btn-sm(title="{{'options_deleteRule' | tr}}" ng-click='removeRule($index)')
|
button.btn.btn-danger.btn-sm(title="{{'options_deleteRule' | tr}}" ng-click='removeRule($index)')
|
||||||
@ -79,7 +79,7 @@ div(ng-controller='SwitchProfileCtrl')
|
|||||||
span(ng-show='!attachedOptions.enabled')
|
span(ng-show='!attachedOptions.enabled')
|
||||||
| {{'options_switchAttachedProfileInConditionDisabled' | tr}}
|
| {{'options_switchAttachedProfileInConditionDisabled' | tr}}
|
||||||
td
|
td
|
||||||
div.form-control(omega-profile-select='options | profiles:profile' ng-model='attached.matchProfileName'
|
div(omega-profile-select='options | profiles:profile' ng-model='attached.matchProfileName'
|
||||||
disp-name='$profile.name | dispName' ng-class='{disabled: !attachedOptions.enabled}')
|
disp-name='$profile.name | dispName' ng-class='{disabled: !attachedOptions.enabled}')
|
||||||
td
|
td
|
||||||
button.btn.btn-danger.btn-sm(title="{{'options_deleteAttached' | tr}}" ng-click='removeAttached()')
|
button.btn.btn-danger.btn-sm(title="{{'options_deleteAttached' | tr}}" ng-click='removeAttached()')
|
||||||
@ -89,7 +89,7 @@ div(ng-controller='SwitchProfileCtrl')
|
|||||||
td
|
td
|
||||||
td(colspan='2') {{'options_switchDefaultProfile' | tr}}
|
td(colspan='2') {{'options_switchDefaultProfile' | tr}}
|
||||||
td
|
td
|
||||||
div.form-control(omega-profile-select='options | profiles:profile' ng-model='defaultProfileName'
|
div(omega-profile-select='options | profiles:profile' ng-model='defaultProfileName'
|
||||||
disp-name='$profile.name | dispName')
|
disp-name='$profile.name | dispName')
|
||||||
td
|
td
|
||||||
button.btn.btn-info.btn-sm(title="{{'options_resetRules_help' | tr}}" ng-click='resetRules()')
|
button.btn.btn-info.btn-sm(title="{{'options_resetRules_help' | tr}}" ng-click='resetRules()')
|
||||||
|
Loading…
Reference in New Issue
Block a user