Fix condition types and add help link in popup. Fix #39.

This commit is contained in:
FelisCatus 2014-10-10 12:33:02 +08:00
parent feb2389fd8
commit 817528ef21
8 changed files with 53 additions and 20 deletions

View File

@ -27,11 +27,11 @@ angular.module('omegaTarget', []).factory 'omegaTarget', ($q) ->
isChromeUrl = (url) -> url.substr(0, 6) == 'chrome'
optionsChangeCallback = []
prefix = 'omega.local.'
urlParser = document.createElement('a')
omegaTarget =
options: null
state: (name, value) ->
prefix = 'omega.local.'
if arguments.length == 1
getValue = (key) -> try JSON.parse(localStorage[prefix + key])
if Array.isArray(name)
@ -41,6 +41,13 @@ angular.module('omegaTarget', []).factory 'omegaTarget', ($q) ->
else
localStorage[prefix + name] = JSON.stringify(value)
return $q.when(value)
lastUrl: (url) ->
name = 'web.last_url'
if url
omegaTarget.state(name, url)
url
else
try JSON.parse(localStorage[prefix + name])
addOptionsChangeCallback: (callback) ->
optionsChangeCallback.push(callback)
refresh: (args) ->
@ -62,14 +69,23 @@ angular.module('omegaTarget', []).factory 'omegaTarget', ($q) ->
results
).then omegaTarget.refresh
getMessage: chrome.i18n.getMessage.bind(chrome.i18n)
openOptions: ->
openOptions: (hash) ->
d = $q['defer']()
options_url = chrome.extension.getURL('options.html')
chrome.tabs.query url: options_url, (tabs) ->
if tabs.length > 0
chrome.tabs.update(tabs[0].id, {active: true})
url = if hash
urlParser.href = tabs[0]?.url || options_url
urlParser.hash = hash
urlParser.href
else
chrome.tabs.create({url: options_url})
options_url
if tabs.length > 0
props = {active: true}
if hash
props.url = url
chrome.tabs.update(tabs[0].id, props)
else
chrome.tabs.create({url: url})
d.resolve()
return d.promise
applyProfile: (name) ->

View File

@ -29,9 +29,12 @@ module.controller 'PopupCtrl', ($scope, $window, $q, omegaTarget,
'glyphicon-ok'
else
profileIcons[profile.profileType]
$scope.openOptions = ->
omegaTarget.openOptions().then ->
$scope.openOptions = (hash) ->
omegaTarget.openOptions(hash).then ->
$window.close()
$scope.openConditionHelp = ->
pname = encodeURIComponent($scope.currentProfileName)
$scope.openOptions("#/profile/#{pname}?help=condition")
$scope.applyProfile = (profile) ->
omegaTarget.applyProfile(profile.name).then ->
refresh()

View File

@ -6,6 +6,10 @@
/* popup */
.clear-padding {
padding: 0 !important;
}
body {
margin: 0;
padding: 0;

View File

@ -24,6 +24,11 @@ angular.module('omega').config ($stateProvider, $urlRouterProvider,
$animateProvider.classNameFilter(/angular-animate/)
$urlRouterProvider.otherwise '/ui'
$urlRouterProvider.otherwise ($injector, $location) ->
if $location.path() == '' or $location.path() == '/'
$injector.get('omegaTarget').lastUrl()
else
'/ui'
$stateProvider
.state('ui',

View File

@ -184,7 +184,7 @@ angular.module('omega').controller 'MasterCtrl', ($scope, $rootScope, $window,
event.preventDefault()
$rootScope.$on '$stateChangeSuccess', ->
omegaTarget.state('web.last_url', $location.url())
omegaTarget.lastUrl($location.url())
$window.onbeforeunload = ->
if $rootScope.optionsDirty
@ -218,6 +218,3 @@ angular.module('omega').controller 'MasterCtrl', ($scope, $rootScope, $window,
"options_downloadInterval_" + (if interval < 0 then "never" else interval)
omegaTarget.refresh()
omegaTarget.state('web.last_url').then (lastUrl) ->
$location.url(lastUrl) if lastUrl?

View File

@ -1,5 +1,7 @@
angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $modal,
profileIcons, getAttachedName) ->
angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $location,
$modal, profileIcons, getAttachedName) ->
$scope.showConditionHelp = ($location.search().help == 'condition')
$scope.basicConditionTypes = [
{

View File

@ -25,7 +25,7 @@ div(ng-controller='SwitchProfileCtrl')
| {{'options_conditionType' | tr}}
= ' '
button.btn.btn-link.btn-sm.clear-padding(title='{{"options_showConditionTypeHelp" | tr}}'
ng-click='showConditionHelp = !showConditionHelp' ng-init='showConditionHelp = false')
ng-click='showConditionHelp = !showConditionHelp')
span.glyphicon.glyphicon-question-sign
th {{'options_conditionDetails' | tr}}
th {{'options_resultProfile' | tr}}

View File

@ -99,13 +99,19 @@ html(lang='en' ng-app='omegaPopup' ng-controller='PopupCtrl' ng-csp)
= ' '
| {{currentProfileName | dispName}}
div.form-group
label {{'options_conditionType' | tr}}
label
| {{'options_conditionType' | tr}}
= ' '
button.btn.btn-link.btn-sm.clear-padding(type='button' ng-click='openConditionHelp()')
| {{"options_showConditionTypeHelp" | tr}}
= ' '
span.glyphicon.glyphicon-new-window
select.form-control(ng-model='rule.condition.conditionType')
option(value='HostWildcardCondition') {{'condition_hostWildcard' | tr}}
option(value='HostRegexCondition') {{'condition_hostRegex' | tr}}
option(value='UrlWildcardCondition') {{'condition_urlWildcard' | tr}}
option(value='UrlRegexCondition') {{'condition_urlRegex' | tr}}
option(value='KeywordCondition') {{'condition_keyword' | tr}}
option(value='HostWildcardCondition') {{'condition_HostWildcardCondition' | tr}}
option(value='HostRegexCondition') {{'condition_HostRegexCondition' | tr}}
option(value='UrlWildcardCondition') {{'condition_UrlWildcardCondition' | tr}}
option(value='UrlRegexCondition') {{'condition_UrlRegexCondition' | tr}}
option(value='KeywordCondition') {{'condition_KeywordCondition' | tr}}
div.form-group
label {{'options_conditionDetails' | tr}}
input.form-control.condition-details(type='text' required ng-model='rule.condition.pattern')