Add labels to settings forms
This commit is contained in:
parent
8bc8463045
commit
907c363707
|
@ -3,51 +3,6 @@ require 'ext/ember/bound_helper'
|
||||||
safe = (string) ->
|
safe = (string) ->
|
||||||
new Handlebars.SafeString(string)
|
new Handlebars.SafeString(string)
|
||||||
|
|
||||||
Travis.Tab = Ember.Object.extend
|
|
||||||
url: (->
|
|
||||||
id = @get('id')
|
|
||||||
if id == 'env_vars' || id == 'ssh_key'
|
|
||||||
id
|
|
||||||
else
|
|
||||||
"repo.settings.#{id}"
|
|
||||||
).property('id')
|
|
||||||
|
|
||||||
Travis.TabsView = Ember.View.extend
|
|
||||||
tabBinding: 'controller.tab'
|
|
||||||
tabsBinding: 'controller.tabs'
|
|
||||||
|
|
||||||
# TODO: remove hardcoded link
|
|
||||||
layout: Ember.Handlebars.compile(
|
|
||||||
'<ul class="tabs">' +
|
|
||||||
' {{#each tab in _tabs}}' +
|
|
||||||
' <li {{bindAttr class="tab.visible:active"}}>' +
|
|
||||||
' <h5>{{#link-to tab.url}}{{tab.name}}{{/link-to}}</h5>' +
|
|
||||||
' </li>' +
|
|
||||||
' {{/each}}' +
|
|
||||||
'</ul>' +
|
|
||||||
'{{yield}}')
|
|
||||||
|
|
||||||
Ember.Handlebars.registerHelper('travis-tabs', (options) ->
|
|
||||||
template = options.fn
|
|
||||||
delete options.fn
|
|
||||||
|
|
||||||
view = Travis.TabsView.create(
|
|
||||||
controller: this
|
|
||||||
template: template
|
|
||||||
)
|
|
||||||
|
|
||||||
Ember.Handlebars.helpers.view.call(this, view, options)
|
|
||||||
)
|
|
||||||
|
|
||||||
Travis.FormSettingsView = Ember.View.extend Ember.TargetActionSupport,
|
|
||||||
target: Ember.computed.alias('controller')
|
|
||||||
actionContext: Ember.computed.alias('context'),
|
|
||||||
action: 'submit'
|
|
||||||
tagName: 'form'
|
|
||||||
submit: (event) ->
|
|
||||||
event.preventDefault()
|
|
||||||
@triggerAction()
|
|
||||||
|
|
||||||
Ember.LinkView.reopen
|
Ember.LinkView.reopen
|
||||||
init: ->
|
init: ->
|
||||||
@_super()
|
@_super()
|
||||||
|
@ -64,6 +19,63 @@ FormFieldRowView = Ember.View.extend
|
||||||
classNameBindings: ['invalid']
|
classNameBindings: ['invalid']
|
||||||
classNames: 'field'
|
classNames: 'field'
|
||||||
|
|
||||||
|
LabelView = Ember.View.extend(
|
||||||
|
tagName: 'label'
|
||||||
|
|
||||||
|
attributeBindings: ['for', 'accesskey', 'form']
|
||||||
|
)
|
||||||
|
|
||||||
|
Ember.Handlebars.registerHelper('label', (options) ->
|
||||||
|
view = LabelView
|
||||||
|
|
||||||
|
name = options.hash.for
|
||||||
|
if name
|
||||||
|
labels = @get('_labels')
|
||||||
|
unless labels
|
||||||
|
labels = Ember.Object.create()
|
||||||
|
@set('_labels', labels)
|
||||||
|
|
||||||
|
# for now I support only label + input in their own context
|
||||||
|
id = labels.get(name)
|
||||||
|
unless id
|
||||||
|
id = "#{name}-#{Math.round(Math.random() * 1000000)}"
|
||||||
|
labels.set(name, id)
|
||||||
|
|
||||||
|
options.hash.for = id
|
||||||
|
options.hashTypes.for = 'STRING'
|
||||||
|
options.hashContexts.for = this
|
||||||
|
|
||||||
|
Ember.Handlebars.helpers.view.call(this, view, options)
|
||||||
|
)
|
||||||
|
|
||||||
|
originalInputHelper = Ember.Handlebars.helpers.input
|
||||||
|
|
||||||
|
Ember.Handlebars.registerHelper('input', (options) ->
|
||||||
|
# for now I can match label only with the property name
|
||||||
|
# passed here matches the label
|
||||||
|
name = (options.hash.value || options.hash.checked)
|
||||||
|
id = options.hash.id
|
||||||
|
|
||||||
|
# generate id only if it's not given
|
||||||
|
if name && !id
|
||||||
|
labels = @get('_labels')
|
||||||
|
unless labels
|
||||||
|
labels = Ember.Object.create()
|
||||||
|
@set('_labels', labels)
|
||||||
|
|
||||||
|
# for now I support only label + input in their own context
|
||||||
|
id = labels.get(name)
|
||||||
|
unless id
|
||||||
|
id = "#{name}-#{Math.round(Math.random() * 1000000)}"
|
||||||
|
labels.set(name, id)
|
||||||
|
|
||||||
|
options.hash.id = id
|
||||||
|
options.hashTypes.id = 'STRING'
|
||||||
|
options.hashContexts.id = this
|
||||||
|
|
||||||
|
originalInputHelper.call(this, options)
|
||||||
|
)
|
||||||
|
|
||||||
Ember.Handlebars.registerHelper('travis-field', (name, options) ->
|
Ember.Handlebars.registerHelper('travis-field', (name, options) ->
|
||||||
errors = @get('errors').for(name)
|
errors = @get('errors').for(name)
|
||||||
template = options.fn
|
template = options.fn
|
||||||
|
@ -77,6 +89,7 @@ Ember.Handlebars.registerHelper('travis-field', (name, options) ->
|
||||||
|
|
||||||
Ember.Handlebars.helpers.view.call(this, view, options)
|
Ember.Handlebars.helpers.view.call(this, view, options)
|
||||||
)
|
)
|
||||||
|
|
||||||
Travis.ErrorsView = Ember.View.extend
|
Travis.ErrorsView = Ember.View.extend
|
||||||
tagName: 'span'
|
tagName: 'span'
|
||||||
template: Ember.Handlebars.compile("{{#each view.errors}}{{message}}{{/each}}")
|
template: Ember.Handlebars.compile("{{#each view.errors}}{{message}}{{/each}}")
|
||||||
|
@ -96,23 +109,6 @@ Ember.Handlebars.helper('travis-errors', (name, options) ->
|
||||||
Ember.Handlebars.helpers.view.call(this, view, options)
|
Ember.Handlebars.helpers.view.call(this, view, options)
|
||||||
)
|
)
|
||||||
|
|
||||||
Ember.Handlebars.registerHelper('settings-form', (path, options) ->
|
|
||||||
if arguments.length == 1
|
|
||||||
options = path
|
|
||||||
path = 'settings'
|
|
||||||
|
|
||||||
view = Travis.FormSettingsView.create(
|
|
||||||
template: options.fn
|
|
||||||
controller: this
|
|
||||||
settingsPath: path
|
|
||||||
classNames: ['settings-form']
|
|
||||||
)
|
|
||||||
|
|
||||||
delete options.fn
|
|
||||||
|
|
||||||
Ember.Handlebars.helpers.view.call(this, view, options)
|
|
||||||
)
|
|
||||||
|
|
||||||
Handlebars.registerHelper 'tipsy', (text, tip) ->
|
Handlebars.registerHelper 'tipsy', (text, tip) ->
|
||||||
safe '<span class="tool-tip" original-title="' + tip + '">' + text + '</span>'
|
safe '<span class="tool-tip" original-title="' + tip + '">' + text + '</span>'
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
<form class="env-var" {{action "save" on="submit"}}>
|
<form class="env-var" {{action "save" on="submit"}}>
|
||||||
{{#travis-field "name"}}
|
{{#travis-field "name"}}
|
||||||
<label>Name:</label>
|
{{#label for="name"}}Name:{{/label}}
|
||||||
{{input value=name class="env-name"}} {{travis-errors "name"}}
|
{{input value=name class="env-name"}} {{travis-errors "name"}}
|
||||||
{{/travis-field}}
|
{{/travis-field}}
|
||||||
{{#if showValueField}}
|
{{#if showValueField}}
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Value:</label>
|
{{#label for="value"}}Value:{{/label}}
|
||||||
{{input value=value class="env-value"}}
|
{{input value=value class="env-value"}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Public:</label>
|
{{#label for="public"}}Public:{{/label}}
|
||||||
{{input type="checkbox" checked=public}}
|
{{input type="checkbox" checked=public}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<ul class="navigation">
|
<ul class="navigation">
|
||||||
<li>{{#link-to "settings.index"}}General settings{{/link-to}}</li>
|
<li>{{#link-to "settings.index"}}General{{/link-to}}</li>
|
||||||
<li>{{#link-to "env_vars"}}Environment variables{{/link-to}}</li>
|
<li>{{#link-to "env_vars"}}Environment variables{{/link-to}}</li>
|
||||||
{{#if Travis.config.ssh_key_enabled}}
|
{{#if Travis.config.ssh_key_enabled}}
|
||||||
<li>{{#link-to "ssh_key"}}Ssh key{{/link-to}}</li>
|
<li>{{#link-to "ssh_key"}}Ssh key{{/link-to}}</li>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{{#settings-form}}
|
<form class='settings-form'>
|
||||||
<p class="settings-row">
|
<p class="settings-row">
|
||||||
Build only if .travis.yml is present
|
Build only if .travis.yml is present
|
||||||
{{travis-switch action="save" active=settings.builds_only_with_travis_yml}}
|
{{travis-switch action="save" active=settings.builds_only_with_travis_yml}}
|
||||||
|
@ -22,4 +22,4 @@
|
||||||
Concurrent builds
|
Concurrent builds
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
{{/settings-form}}
|
</form>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user