Remove unused helpers

This commit is contained in:
Piotr Sarnacki 2014-07-28 10:45:40 +02:00
parent 7c922ddebb
commit 73e852b23a

View File

@ -89,57 +89,6 @@ Ember.Handlebars.registerHelper('travis-tabs', (options) ->
Ember.Handlebars.helpers.view.call(this, view, options)
)
Travis.SettingsMultiplierView = Ember.CollectionView.extend()
createObjects = (path, offset) ->
segments = path.split('.')
if segments.length > offset
for i in [1..(segments.length - offset)]
path = segments.slice(0, i).join('.')
if Ember.isNone(Ember.get(this, path))
Ember.set(this, path, {})
return segments
Ember.Handlebars.registerHelper('settings-multiplier', (path, options) ->
template = options.fn
delete options.fn
parentsPath = getSettingsPath(options.data.view)
if parentsPath && parentsPath != ''
path = parentsPath + '.' + path
createObjects.call(this, path, 1)
if Ember.isNone(@get(path))
collection = [{}]
@set(path, collection)
itemViewClass = Ember.View.extend(
template: template,
controller: this,
tagName: 'li',
multiplier: true
)
view = Travis.SettingsMultiplierView.create(
contentBinding: 'controller.' + path
controller: this
tagName: 'ul'
itemViewClass: itemViewClass
fields: []
settingsPath: path
)
view.addObserver('content.length', ->
if @get('content.length') == 0
@get('content').pushObject({})
)
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'),
@ -176,130 +125,6 @@ Ember.Handlebars.registerHelper('settings-form', (path, options) ->
Ember.Handlebars.helpers.view.call(this, view, options)
)
Ember.Handlebars.helper('settings-select', (options) ->
view = options.data.view
optionValues = options.hash.options
delete options.hash.options
originalPath = options.hash.value
parentsPath = getSettingsPath(view)
#TODO: such checks should also check parents, not only current context view
if !view.get('multiplier') && parentsPath && parentsPath != ''
originalPath = parentsPath + '.' + originalPath
fullPath = originalPath
if view.get('multiplier')
fullPath = 'view.content.' + fullPath
createObjects.call(this, fullPath, 1)
# TODO: setting a value here does not work and we still need
# a valueBinding in the view, I'm not sure why
options.hash.value = fullPath
selectView = Ember.Select.create(
content: [''].pushObjects(optionValues.split(','))
controller: this
valueBinding: 'controller.' + fullPath
)
Ember.Handlebars.helpers.view.call(this, selectView, options)
)
Ember.Handlebars.helper('settings-remove-link', (options) ->
view = Ember.View.extend(
tagName: 'a'
attributeBindings: ['href', 'style']
href: '#'
style: (->
# TODO: do not assume that we're direct child
if @get('parentView.parentView.content.length') == 1
'display: none'
).property('parentView.parentView.content.length')
template: Ember.Handlebars.compile('remove')
controller: this
click: (event) ->
event.preventDefault()
if content = @get('parentView.content')
@get('parentView.parentView.content').removeObject(content)
).create()
Ember.Handlebars.helpers.view.call(this, view, options)
)
Ember.Handlebars.registerHelper('settings-add-link', (path, options) ->
parentsPath = getSettingsPath(options.data.view)
if parentsPath && parentsPath != ''
path = parentsPath + '.' + path
view = Ember.View.create(
tagName: 'a'
attributeBindings: ['href']
href: '#'
template: options.fn
controller: this
click: (event) ->
event.preventDefault()
if collection = @get('controller.' + path)
collection.pushObject({})
)
Ember.Handlebars.helpers.view.call(this, view, options)
)
getSettingsPath = (view) ->
settingsPaths = []
if settingsPath = view.get('settingsPath')
settingsPaths.pushObject settingsPath
parent = view
while parent = parent.get('parentView')
if settingsPath = parent.get('settingsPath')
settingsPaths.pushObject settingsPath
return settingsPaths.reverse().join('.')
Ember.Handlebars.helper('settings-input', (options) ->
view = options.data.view
if options.hash.type == 'checkbox'
originalPath = options.hash.checked
else
originalPath = options.hash.value
parentsPath = getSettingsPath(view)
#TODO: such checks should also check parents, not only current context view
if !view.get('multiplier') && parentsPath && parentsPath != ''
originalPath = parentsPath + '.' + originalPath
fullPath = originalPath
if view.get('multiplier')
fullPath = 'view.content.' + fullPath
if options.hash.type != 'password'
createObjects.call(this, fullPath, 1)
else
createObjects.call(view, fullPath, 2)
content = view.get('content')
fullPath += ".value"
if Ember.isNone(Ember.get(content, originalPath))
Ember.set(content, originalPath, {})
Ember.set(content, originalPath + ".type", 'password')
if options.hash.type == 'checkbox'
options.hash.checked = fullPath
else
options.hash.value = fullPath
Ember.Handlebars.helpers.input.call(this, options)
)
Handlebars.registerHelper 'tipsy', (text, tip) ->
safe '<span class="tool-tip" original-title="' + tip + '">' + text + '</span>'