refactor ajax, get rid of the module
This commit is contained in:
parent
521fc3112d
commit
6cbe6f140e
|
@ -43,7 +43,7 @@ GIT
|
|||
|
||||
GIT
|
||||
remote: git://github.com/travis-ci/travis-api.git
|
||||
revision: fa4c5db39b94234e9a3a87da0b4ccca466e034e2
|
||||
revision: 5d9c867142162b20d8471530f7447bd4af93c0e4
|
||||
specs:
|
||||
travis-api (0.0.1)
|
||||
backports (~> 2.5)
|
||||
|
@ -61,7 +61,7 @@ GIT
|
|||
|
||||
GIT
|
||||
remote: git://github.com/travis-ci/travis-core.git
|
||||
revision: 7c84635b5c180a716150c4300bff3ea8f381248c
|
||||
revision: adaa3d48f48a2a002827a2f15078323e53be1d10
|
||||
branch: sf-travis-api
|
||||
specs:
|
||||
travis-core (0.0.1)
|
||||
|
@ -159,7 +159,7 @@ GEM
|
|||
activesupport
|
||||
faraday (0.8.4)
|
||||
multipart-post (~> 1.1)
|
||||
foreman (0.60.0)
|
||||
foreman (0.60.2)
|
||||
thor (>= 0.13.6)
|
||||
fssm (0.2.9)
|
||||
guard (1.4.0)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'travis/model'
|
||||
|
||||
@Travis.Build = Travis.Model.extend Travis.DurationCalculations, Travis.Ajax,
|
||||
@Travis.Build = Travis.Model.extend Travis.DurationCalculations,
|
||||
eventType: DS.attr('string')
|
||||
repoId: DS.attr('number')
|
||||
commitId: DS.attr('number')
|
||||
|
@ -46,7 +46,7 @@ require 'travis/model'
|
|||
).property('config')
|
||||
|
||||
requeue: (->
|
||||
@post '/requests', build_id: @get('id')
|
||||
Travis.ajax.post '/requests', build_id: @get('id')
|
||||
)
|
||||
|
||||
@Travis.Build.reopenClass
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'travis/ajax'
|
||||
require 'travis/model'
|
||||
|
||||
@Travis.User = Travis.Model.extend Travis.Ajax,
|
||||
@Travis.User = Travis.Model.extend
|
||||
name: DS.attr('string')
|
||||
email: DS.attr('string')
|
||||
login: DS.attr('string')
|
||||
|
@ -27,7 +27,7 @@ require 'travis/model'
|
|||
permissions: (->
|
||||
unless @permissions
|
||||
@permissions = Ember.ArrayProxy.create(content: [])
|
||||
@ajax '/users/permissions', 'get', success: (data) => @permissions.set('content', data.permissions)
|
||||
Travis.ajax.get('/users/permissions', (data) => @permissions.set('content', data.permissions))
|
||||
@permissions
|
||||
).property()
|
||||
|
||||
|
@ -51,12 +51,12 @@ require 'travis/model'
|
|||
).property()
|
||||
|
||||
sync: ->
|
||||
@post('/users/sync')
|
||||
Travis.ajax.post('/users/sync')
|
||||
@setWithSession('isSyncing', true)
|
||||
@poll()
|
||||
|
||||
poll: ->
|
||||
@ajax '/users', 'get', success: (data) =>
|
||||
Travis.ajax.get '/users', (data) =>
|
||||
if data.user.is_syncing
|
||||
Ember.run.later(this, this.poll.bind(this), 3000)
|
||||
else
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'travis/ajax'
|
||||
require 'models'
|
||||
|
||||
@Travis.RestAdapter = DS.RESTAdapter.extend Travis.Ajax,
|
||||
@Travis.RestAdapter = DS.RESTAdapter.extend
|
||||
mappings:
|
||||
repositories: Travis.Repo
|
||||
repository: Travis.Repo
|
||||
|
@ -28,3 +28,6 @@ require 'models'
|
|||
job: 'jobs'
|
||||
worker: 'workers'
|
||||
profile: 'profile'
|
||||
|
||||
ajax: ->
|
||||
Travis.ajax.ajax.apply(this, arguments)
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
jQuery.support.cors = true
|
||||
|
||||
@Travis.Ajax = Ember.Mixin.create
|
||||
@Travis.ajax = Em.Object.create
|
||||
DEFAULT_OPTIONS:
|
||||
accepts:
|
||||
json: 'application/vnd.travis-ci.2+json'
|
||||
|
||||
get: (url, callback) ->
|
||||
@ajax(url, 'get', success: callback)
|
||||
|
||||
post: (url, data, callback) ->
|
||||
@ajax(url, 'post', data: data, success: callback)
|
||||
|
||||
|
@ -25,9 +28,16 @@ jQuery.support.cors = true
|
|||
if options.data && method != 'GET' && method != 'get'
|
||||
options.data = JSON.stringify(options.data)
|
||||
|
||||
$.ajax($.extend(options, @DEFAULT_OPTIONS))
|
||||
if options.success
|
||||
success = options.success
|
||||
options.success = (data) =>
|
||||
if Travis.app?.router && data.flash
|
||||
console.log(data.flash)
|
||||
Travis.app.router.flashController.pushObject(data.flash)
|
||||
delete data.flash
|
||||
success.call(this, data)
|
||||
|
||||
@Travis.ajax = Em.Object.create @Travis.Ajax,
|
||||
get: (url, callback) ->
|
||||
@ajax(url, 'get', success: callback)
|
||||
options.error = (data) =>
|
||||
Travis.app.router.flashController.pushObject(data.flash) if data.flash
|
||||
|
||||
$.ajax($.extend(options, Travis.ajax.DEFAULT_OPTIONS))
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
|||
dd0dc238
|
||||
f99eb613
|
Loading…
Reference in New Issue
Block a user