Fix actions on views

Almost all actions on views were not properly handled, because they were still
methods directly on a view object rather than in `actions` property. This commit
fixes it.
This commit is contained in:
Piotr Sarnacki 2014-12-23 15:45:53 +01:00
parent f355bc58f3
commit 66be22af68
15 changed files with 108 additions and 100 deletions

View File

@ -30,6 +30,7 @@ Travis.FlashController = Ember.ArrayController.extend
@get('flashes').unshiftObject(msg) @get('flashes').unshiftObject(msg)
Ember.run.later(this, (-> @get('flashes.content').removeObject(msg)), 15000) Ember.run.later(this, (-> @get('flashes.content').removeObject(msg)), 15000)
actions:
close: (msg) -> close: (msg) ->
if msg instanceof Travis.Broadcast if msg instanceof Travis.Broadcast
msg.setSeen() msg.setSeen()

View File

@ -7,7 +7,7 @@
{{else}} {{else}}
<caption> <caption>
Allowed Failures Allowed Failures
<a title="What's this?" class="help open-popup" name="help-allowed_failures" {{action "popup" target="view"}}></a> <a title="What's this?" class="help open-popup" name="help-allowed_failures" {{action "popup" target=view}}></a>
</caption> </caption>
{{/if}} {{/if}}
<thead> <thead>
@ -44,7 +44,7 @@
{{#unless view.required}} {{#unless view.required}}
<div id="help-allowed_failures" class="popup"> <div id="help-allowed_failures" class="popup">
<a href="#" class="close" {{action "popupClose" target="view"}}></a> <a href="#" class="close" {{action "popupClose" target=view}}></a>
<h4></h4> <h4></h4>
<p> <p>
Allowed Failures are items in your build matrix that are allowed to Allowed Failures are items in your build matrix that are allowed to

View File

@ -1,5 +1,5 @@
<div id="log-container"> <div id="log-container">
<a href="#" id="tail" {{action "toggleTailing" target="view"}}> <a href="#" id="tail" {{action "toggleTailing" target=view}}>
<span class="status"></span> <span class="status"></span>
<label> <label>
@ -12,7 +12,7 @@
</a> </a>
<pre id="log" class="ansi"></pre> <pre id="log" class="ansi"></pre>
<a href='#' class="to-top" {{action "toTop" target="view"}}>To Top</a> <a href='#' class="to-top" {{action "toTop" target=view}}>To Top</a>
{{#if view.job.sponsor.name}} {{#if view.job.sponsor.name}}
<p class="sponsor"> <p class="sponsor">

View File

@ -1,6 +1,6 @@
{{#each flash in controller}} {{#each flash in controller}}
{{#view Travis.FlashItemView flashBinding="flash"}} {{#view Travis.FlashItemView flashBinding="flash"}}
<p>{{{flash.message}}}</p> <p>{{{flash.message}}}</p>
<a class="close" {{action "close" target="view"}}></a> <a class="close" {{action "close" target=view}}></a>
{{/view}} {{/view}}
{{/each}} {{/each}}

View File

@ -12,7 +12,7 @@
</div> </div>
<div id="right"> <div id="right">
<div id="slider" {{action "toggle" target="Travis.slider"}}> <div id="slider" {{action "toggle" target=Travis.slider}}>
<div class='icon'></div>&nbsp; <div class='icon'></div>&nbsp;
</div> </div>

View File

@ -8,7 +8,7 @@
</li> </li>
<li id="tab_search" {{bind-attr class="view.classSearch"}}> <li id="tab_search" {{bind-attr class="view.classSearch"}}>
<h5><a {{action "activate" "search"}}>Search</a></h5> <h5>Search</h5>
</li> </li>
<li id="tab_new" {{bind-attr class="view.classNew"}}> <li id="tab_new" {{bind-attr class="view.classNew"}}>

View File

@ -7,7 +7,7 @@
<h3>{{#link-to "repo" repo}}{{repo.slug}}{{/link-to}}</h3> <h3>{{#link-to "repo" repo}}{{repo.slug}}{{/link-to}}</h3>
<div class="github-icon"><a {{bind-attr href="controller.urlGithub"}}><img src="/images/icons/github.svg" width="21" height="21"/></a></div> <div class="github-icon"><a {{bind-attr href="controller.urlGithub"}}><img src="/images/icons/github.svg" width="21" height="21"/></a></div>
<div class="status-image"> <div class="status-image">
<a href="#" id="status-image-popup" name="status-images" class="open-popup" {{action "statusImages" target="view"}}> <a href="#" id="status-image-popup" name="status-images" class="open-popup" {{action "statusImages" target=view}}>
<img {{bind-attr src="view.statusImageUrl"}} title="Build Status Images"/> <img {{bind-attr src="view.statusImageUrl"}} title="Build Status Images"/>
</a> </a>
</div> </div>

View File

@ -2,13 +2,13 @@
<ul> <ul>
{{#if view.displayCancelBuild}} {{#if view.displayCancelBuild}}
<li class="icon cancel-build" title="Cancel Build"> <li class="icon cancel-build" title="Cancel Build">
<a href="#" {{action "cancelBuild" target="view"}} <a href="#" {{action "cancelBuild" target=view}}
{{bind-attr class="view.canCancelBuild::disabled"}}></a> {{bind-attr class="view.canCancelBuild::disabled"}}></a>
</li> </li>
{{/if}} {{/if}}
{{#if view.displayCancelJob}} {{#if view.displayCancelJob}}
<li class="icon cancel-job" title="Cancel Job"> <li class="icon cancel-job" title="Cancel Job">
<a href="#" {{action "cancelJob" target="view"}} <a href="#" {{action "cancelJob" target=view}}
{{bind-attr class="view.canCancelJob::disabled"}}></a> {{bind-attr class="view.canCancelJob::disabled"}}></a>
</li> </li>
{{/if}} {{/if}}
@ -17,7 +17,7 @@
{{#if view.requeueing}} {{#if view.requeueing}}
<span class="icon loading"></span> <span class="icon loading"></span>
{{else}} {{else}}
<a href="#" {{action "requeueBuild" target="view"}} <a href="#" {{action "requeueBuild" target=view}}
{{bind-attr class="view.canRequeueBuild::disabled"}}></a> {{bind-attr class="view.canRequeueBuild::disabled"}}></a>
{{/if}} {{/if}}
</li> </li>
@ -27,7 +27,7 @@
{{#if view.requeueing}} {{#if view.requeueing}}
<span class="icon loading"></span> <span class="icon loading"></span>
{{else}} {{else}}
<a href="#" {{action "requeueJob" target="view"}} <a href="#" {{action "requeueJob" target=view}}
{{bind-attr class="view.canRequeueJob::disabled"}}></a> {{bind-attr class="view.canRequeueJob::disabled"}}></a>
{{/if}} {{/if}}
</li> </li>
@ -42,7 +42,7 @@
{{#if view.displayCodeClimate}} {{#if view.displayCodeClimate}}
<li class="icon code-climate" title="Test Coverage with Code Climate"> <li class="icon code-climate" title="Test Coverage with Code Climate">
<a href="#" name="code-climate" <a href="#" name="code-climate"
{{action "codeClimatePopup" target="view"}} {{action "codeClimatePopup" target=view}}
{{bind-attr class=":open-popup"}}></a> {{bind-attr class=":open-popup"}}></a>
</li> </li>
{{/if}} {{/if}}

View File

@ -1,11 +1,11 @@
<div id="tools"> <div id="tools">
<a href="#" {{action "menu" target="view"}} class="menu-popup-button">Settings</a> <a href="#" {{action "menu" target=view}} class="menu-popup-button">Settings</a>
<ul class="menu"> <ul class="menu">
{{#if view.displayRegenerateKey}} {{#if view.displayRegenerateKey}}
<li> <li>
<a href="#" name="regenerate-key" <a href="#" name="regenerate-key"
{{action "regenerateKeyPopup" target="view"}} {{action "regenerateKeyPopup" target=view}}
{{bind-attr class=":open-popup view.canRegenerateKey::disabled"}}> {{bind-attr class=":open-popup view.canRegenerateKey::disabled"}}>
Regenerate Key Regenerate Key
</a> </a>
@ -29,7 +29,7 @@
</div> </div>
<div id="regenerate-key" class="popup"> <div id="regenerate-key" class="popup">
<a href="#" class="close" {{action "popupClose" target="view"}}></a> <a href="#" class="close" {{action "popupClose" target=view}}></a>
<p> <p>
Do you really want to regenerate ssl keys for this repository? Please note that Do you really want to regenerate ssl keys for this repository? Please note that
any data, which is encrypted, such as notification services credentials or secure any data, which is encrypted, such as notification services credentials or secure
@ -38,14 +38,14 @@
</p> </p>
<p> <p>
<a class="sync_now button" {{action "regenerateKey" target="view"}}>Yes, do it!</a> <a class="sync_now button" {{action "regenerateKey" target=view}}>Yes, do it!</a>
<span class="or">or</span> <span class="or">or</span>
<a href="#" class="cancel" {{action "popupClose" target="view"}}>Cancel</a> <a href="#" class="cancel" {{action "popupClose" target=view}}>Cancel</a>
</p> </p>
</div> </div>
<div id="regeneration-success" class="popup"> <div id="regeneration-success" class="popup">
<a href="#" class="close" {{action "popupClose" target="view"}}></a> <a href="#" class="close" {{action "popupClose" target=view}}></a>
<p> <p>
Key for this repository has been regenerated. If you used previous key Key for this repository has been regenerated. If you used previous key
for encryption, you will need encrypt your data again with the new key. for encryption, you will need encrypt your data again with the new key.
@ -58,7 +58,7 @@
<div id="code-climate" class="popup"> <div id="code-climate" class="popup">
<img src="/images/icons/code-climate-logo.svg" id="code-climate-logo"/> <img src="/images/icons/code-climate-logo.svg" id="code-climate-logo"/>
<a href="#" class="close" {{action "popupClose" target="view"}}></a> <a href="#" class="close" {{action "popupClose" target=view}}></a>
<p> <p>
<b>Want test coverage for your tests?</b> <b>Want test coverage for your tests?</b>
</p> </p>

View File

@ -1,4 +1,4 @@
<a href="#" class="close" {{action "close" target="view"}}></a> <a href="#" class="close" {{action "close" target=view}}></a>
<p> <p>
<label>Branch:</label> <label>Branch:</label>
{{#if view.branches.isLoaded}} {{#if view.branches.isLoaded}}

View File

@ -1,10 +1,10 @@
{{#view Travis.WorkersView}} {{#view Travis.WorkersView}}
<a id="toggle-workers" {{action "toggleWorkers" target="view"}}></a> <a id="toggle-workers" {{action "toggleWorkers" target=view}}></a>
<ul id="workers"> <ul id="workers">
{{#each group in controller.groups}} {{#each group in controller.groups}}
{{#view Travis.WorkersListView}} {{#view Travis.WorkersListView}}
<li class="group"> <li class="group">
<h5 {{action "toggle" target="view"}}> <h5 {{action "toggle" target=view}}>
{{group.firstObject.host}} {{group.firstObject.host}}
</h5> </h5>
<ul> <ul>

View File

@ -8,6 +8,10 @@ Em.View.reopen
@Travis.reopen @Travis.reopen
View: Em.View.extend View: Em.View.extend
actions:
popup: (name) -> @popup(name)
popupClose: -> @popupClose()
popup: (name) -> popup: (name) ->
@popupCloseAll() @popupCloseAll()
name = event?.target?.name || name name = event?.target?.name || name

View File

@ -12,5 +12,6 @@
@get('flash.type') || 'broadcast' @get('flash.type') || 'broadcast'
).property('flash.type') ).property('flash.type')
actions:
close: -> close: ->
@get('controller').close(@get('flash')) @get('controller').close(@get('flash'))

View File

@ -106,6 +106,7 @@ Travis.reopen
closeMenu: -> closeMenu: ->
$('.menu').removeClass('display') $('.menu').removeClass('display')
actions:
menu: -> menu: ->
@popupCloseAll() @popupCloseAll()
$('#tools .menu').toggleClass('display') $('#tools .menu').toggleClass('display')
@ -167,6 +168,15 @@ Travis.reopen
tabBinding: 'controller.tab' tabBinding: 'controller.tab'
currentUserBinding: 'controller.currentUser' currentUserBinding: 'controller.currentUser'
actions:
requeueBuild: ->
if @get('canRequeueBuild')
@requeue @get('build')
requeueJob: ->
if @get('canRequeueJob')
@requeue @get('job')
cancelBuild: -> cancelBuild: ->
if @get('canCancelBuild') if @get('canCancelBuild')
Travis.flash(notice: 'Build cancellation has been scheduled.') Travis.flash(notice: 'Build cancellation has been scheduled.')
@ -207,6 +217,11 @@ Travis.reopen
else else
Travis.flash(error: 'An error occured when canceling the job') Travis.flash(error: 'An error occured when canceling the job')
codeClimatePopup: ->
@popupCloseAll()
@popup('code-climate')
event.stopPropagation() if event?
hasPermission: (-> hasPermission: (->
if permissions = @get('currentUser.permissions') if permissions = @get('currentUser.permissions')
permissions.contains parseInt(@get('repo.id')) permissions.contains parseInt(@get('repo.id'))
@ -283,11 +298,6 @@ Travis.reopen
Travis.config.code_climate == "true" and @get('repo.githubLanguage') == 'Ruby' Travis.config.code_climate == "true" and @get('repo.githubLanguage') == 'Ruby'
).property('repo.githubLanguage') ).property('repo.githubLanguage')
codeClimatePopup: ->
@popupCloseAll()
@popup('code-climate')
event.stopPropagation() if event?
requeueFinished: -> requeueFinished: ->
@set('requeueing', false) @set('requeueing', false)
@ -296,12 +306,3 @@ Travis.reopen
@set('requeueing', true) @set('requeueing', true)
thing.requeue().then(this.requeueFinished.bind(this), this.requeueFinished.bind(this)) thing.requeue().then(this.requeueFinished.bind(this), this.requeueFinished.bind(this))
requeueBuild: ->
if @get('canRequeueBuild')
@requeue @get('build')
requeueJob: ->
if @get('canRequeueJob')
@requeue @get('job')

View File

@ -30,6 +30,7 @@ Travis.StatusImagesView = Em.View.extend
show: -> show: ->
@set('display', true) @set('display', true)
actions:
close: -> close: ->
@destroy() @destroy()