55 lines
1.8 KiB
JavaScript
55 lines
1.8 KiB
JavaScript
import Ember from 'ember';
|
|
import BaseEditRoute from '../base-edit';
|
|
|
|
export default BaseEditRoute.extend({
|
|
afterModel(model) {
|
|
const me = this;
|
|
me._super(...arguments);
|
|
// model.images = [{}];
|
|
this.set('breadcrumbs',
|
|
[{route: 'customer-application.list', params: 1, text: 'Customer Application'},
|
|
{text: 'Edit Customer Application[' + model.name + ']'}]);
|
|
},
|
|
|
|
actions: {
|
|
addImage() {
|
|
const me = this;
|
|
me.get('controller.model.images').pushObject({});
|
|
},
|
|
removeImage(image) {
|
|
const me = this;
|
|
me.get('dialog').confirm('Are you sure to remove image?', () => {
|
|
me.get('store').ajaxPost('application/remove-image', image, () => {
|
|
me.get('message').alert('Image removed');
|
|
me.get('controller.model.images').removeObject(image);
|
|
});
|
|
});
|
|
},
|
|
moveUp(image) {
|
|
let me = this;
|
|
let images = me.get('controller.model.images');
|
|
if (images && images.length > 1) {
|
|
let index = images.indexOf(image);
|
|
images.removeObject(image);
|
|
images.insertAt(index - 1, image);
|
|
--image.sort;
|
|
me.updateImage(image);
|
|
}
|
|
},
|
|
moveDown(image) {
|
|
let me = this;
|
|
let images = me.get('controller.model.images');
|
|
if (images && images.length > 1) {
|
|
let index = images.indexOf(image);
|
|
images.removeObject(image);
|
|
images.insertAt(index + 1, image);
|
|
++image.sort;
|
|
me.updateImage(image);
|
|
}
|
|
}
|
|
},
|
|
updateImage(image) {
|
|
this.get('ajax').doPost('application/update-image', image, false);
|
|
}
|
|
});
|