-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add filepicker for artist image uploads
There is still some UI cleanup to be done, and adding title and description for images
- Loading branch information
1 parent
38dcaa1
commit b5dc403
Showing
9 changed files
with
98 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Ember from 'ember'; | ||
|
||
export default Ember.ObjectController.extend({ | ||
|
||
showFilePicker: false, | ||
|
||
actions : { | ||
showPicker: function() { | ||
this.set('showFilePicker', true); | ||
}, | ||
hidePicker: function() { | ||
this.set('showFilePicker', false); | ||
}, | ||
fileSelected: function(data) { | ||
var self = this; | ||
data.forEach(function (upload){ | ||
let image = self.store.createRecord('image', { artist: self.get('model')}); | ||
image.set('path', upload.url); | ||
}); | ||
this.send('hidePicker'); | ||
}, | ||
onClose: function() { | ||
this.send('hidePicker'); | ||
}, | ||
onError: function(error) { | ||
this.send('hidePicker'); | ||
} | ||
} | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,62 @@ | ||
import Ember from 'ember'; | ||
|
||
export default Ember.Route.extend({ | ||
model() { | ||
return this.store.createRecord('image', { artist: this.modelFor('admin.artist')}); | ||
|
||
renderTemplate() { | ||
this.render({ outlet: 'newImage', into: 'admin/artist'}); | ||
}, | ||
actions: { | ||
queueImage(file) { | ||
let controller = this.controller; | ||
let image = controller.get('model'); | ||
image.set('file', file); | ||
file.read().then(function setPreviewUrl(url) { | ||
if (image.get('url') == null) { | ||
image.set('url', url); | ||
} | ||
}); | ||
}, | ||
saveArtistImage() { | ||
let controller = this.controller; | ||
let image = controller.get('model'); | ||
let artist = this.modelFor('admin.artist'); | ||
if (image && artist) { | ||
let accessToken = this.container.lookup('simple-auth-authorizer:oauth2-bearer').session.content.access_token; | ||
let file = image.file; | ||
let host = this.store.adapterFor('application').get('host'); | ||
let namespace = this.store.adapterFor('application').get('namespace'); | ||
let url = host + '/' + namespace + '/uploads/image'; | ||
// queueImage(file) { | ||
// let controller = this.controller; | ||
// let image = controller.get('model'); | ||
// image.set('file', file); | ||
// file.read().then(function setPreviewUrl(url) { | ||
// if (image.get('url') == null) { | ||
// image.set('url', url); | ||
// } | ||
// }); | ||
// }, | ||
// saveArtistImage() { | ||
// let controller = this.controller; | ||
// let image = controller.get('model'); | ||
// let artist = this.modelFor('admin.artist'); | ||
// if (image && artist) { | ||
// let accessToken = this.container.lookup('simple-auth-authorizer:oauth2-bearer').session.content.access_token; | ||
// let file = image.file; | ||
// let host = this.store.adapterFor('application').get('host'); | ||
// let namespace = this.store.adapterFor('application').get('namespace'); | ||
// let url = host + '/' + namespace + '/uploads/image'; | ||
|
||
file.upload(url, { | ||
data: { | ||
path: '/images/artists/' + artist.get('slug') | ||
// artist: artist.get('slug'), | ||
// title: image.get('title'), | ||
// description: image.get('description'), | ||
// order: image.get('order') | ||
}, | ||
headers: { Authorization: 'bearer ' + accessToken } | ||
}).then(function uploadSucceeded(response) { | ||
// console.log(response); | ||
image.set('path', response.body.path); | ||
image.save(); | ||
}).then( | ||
this.transitionTo('admin.artist') | ||
).catch(function uploadFailed(error) { | ||
console.error(error); | ||
image.rollback(); | ||
console.error('Could not upload image.'); | ||
}); | ||
return false; | ||
} | ||
}, | ||
cancelNewArtistImage() { | ||
let controller = this.controller; | ||
let image = controller.get('model'); | ||
if (image) { | ||
image.rollback(); | ||
} | ||
this.transitionTo('admin.artist'); | ||
} | ||
// file.upload(url, { | ||
// data: { | ||
// path: '/images/artists/' + artist.get('slug') | ||
// // artist: artist.get('slug'), | ||
// // title: image.get('title'), | ||
// // description: image.get('description'), | ||
// // order: image.get('order') | ||
// }, | ||
// headers: { Authorization: 'bearer ' + accessToken } | ||
// }).then(function uploadSucceeded(response) { | ||
// // console.log(response); | ||
// image.set('path', response.body.path); | ||
// image.save(); | ||
// }).then( | ||
// this.transitionTo('admin.artist') | ||
// ).catch(function uploadFailed(error) { | ||
// console.error(error); | ||
// image.rollback(); | ||
// console.error('Could not upload image.'); | ||
// }); | ||
// return false; | ||
// } | ||
// }, | ||
// cancelNewArtistImage() { | ||
// let controller = this.controller; | ||
// let image = controller.get('model'); | ||
// if (image) { | ||
// image.rollback(); | ||
// } | ||
// this.transitionTo('admin.artist'); | ||
// } | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters