2019-07-27 23:08:22 +02:00
|
|
|
import {ajax} from 'discourse/lib/ajax';
|
|
|
|
|
|
|
|
export default Ember.Controller.extend({
|
|
|
|
init() {
|
|
|
|
|
|
|
|
this._super();
|
|
|
|
this.set('selected', new Set());
|
|
|
|
this.set('filePath', []);
|
2019-07-29 10:00:56 +02:00
|
|
|
|
2019-07-27 23:08:22 +02:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
|
|
|
|
checkChanged(event) {
|
|
|
|
|
2019-07-29 10:00:56 +02:00
|
|
|
let selected = this.get('selected');
|
2019-07-27 23:08:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
if (event.target.checked) {
|
|
|
|
|
|
|
|
|
|
|
|
selected.add(event.target.id)
|
|
|
|
|
|
|
|
} else if (!event.target.checked) {
|
|
|
|
selected.delete(event.target.id)
|
|
|
|
}
|
2019-07-29 10:00:56 +02:00
|
|
|
console.log(selected);
|
2019-07-27 23:08:22 +02:00
|
|
|
this.set('selected', selected)
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
export() {
|
2019-07-29 10:00:56 +02:00
|
|
|
let wizards = this.get('selected');
|
|
|
|
let url = Discourse.BaseUrl;
|
|
|
|
let route = '/admin/wizards/transfer/export';
|
|
|
|
url += route + '?';
|
2019-07-27 23:08:22 +02:00
|
|
|
|
|
|
|
wizards.forEach((wizard) => {
|
|
|
|
let step = 'wizards[]=' + wizard;
|
2019-07-29 10:00:56 +02:00
|
|
|
step += '&';
|
2019-07-27 23:08:22 +02:00
|
|
|
url += step
|
2019-07-29 10:00:56 +02:00
|
|
|
});
|
2019-07-27 23:08:22 +02:00
|
|
|
|
|
|
|
location.href = url;
|
|
|
|
|
|
|
|
console.log(url)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
setFilePath(event) {
|
2019-07-29 10:00:56 +02:00
|
|
|
console.log(event.target.files[0]);
|
|
|
|
|
|
|
|
// 512 kb is the max file size
|
|
|
|
let maxFileSize = 512 * 1024;
|
|
|
|
|
|
|
|
if (maxFileSize < event.target.files[0].size) {
|
|
|
|
this.set('fileError', 'The file size is too big')
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.set('filePath', event.target.files[0])
|
2019-07-27 23:08:22 +02:00
|
|
|
|
2019-07-29 10:00:56 +02:00
|
|
|
}
|
2019-07-27 23:08:22 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
,
|
|
|
|
import() {
|
2019-07-29 10:00:56 +02:00
|
|
|
|
|
|
|
let $formData = new FormData();
|
|
|
|
$formData.append('file', this.get('filePath'));
|
|
|
|
console.log($formData);
|
|
|
|
|
|
|
|
ajax('/admin/wizards/transfer/import', {
|
|
|
|
type: 'POST',
|
|
|
|
data: $formData,
|
|
|
|
processData: false,
|
|
|
|
contentType: false,
|
|
|
|
|
|
|
|
}).then(result => {
|
|
|
|
if (result.error) {
|
|
|
|
alert(result.error)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
alert(result.success)
|
|
|
|
}
|
|
|
|
})
|
2019-07-27 23:08:22 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|