improve upload functionality

This commit is contained in:
Sam
2017-05-10 14:43:05 -04:00
parent 27362c5a4b
commit 04b5516bf2
9 changed files with 58 additions and 16 deletions

View File

@ -1,11 +1,30 @@
import ModalFunctionality from 'discourse/mixins/modal-functionality';
import { ajax } from 'discourse/lib/ajax';
// import computed from 'ember-addons/ember-computed-decorators';
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
import { popupAjaxError } from 'discourse/lib/ajax-error';
export default Ember.Controller.extend(ModalFunctionality, {
adminCustomizeThemesShow: Ember.inject.controller(),
onShow() {
this.set('name', null);
this.set('fileSelected', false);
},
enabled: Em.computed.and('nameValid', 'fileSelected'),
disabled: Em.computed.not('enabled'),
@computed('name')
nameValid(name) {
return name && name.match(/^[a-zA-Z0-9-_]+$/)
},
@observes('name')
uploadChanged(){
let file = $('#file-input')[0];
this.set('fileSelected', file && file.files[0]);
},
actions: {
updateName() {
let name = this.get('name');
@ -13,6 +32,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
name = $('#file-input')[0].files[0].name;
this.set('name', name.split(".")[0]);
}
this.uploadChanged();
},
upload() {