1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-30 00:00:13 +01:00
VILLASweb/app/controllers/project/delete.js
Markus Grigull 480c90530d Add visualization create, edit and delete
All plots will be saved in the plot model (no subclasses).
2016-06-28 22:05:54 +02:00

44 lines
1.2 KiB
JavaScript

import Ember from 'ember';
export default Ember.Controller.extend({
sessionUser: Ember.inject.service('session-user'),
actions: {
cancelDelete() {
// go back to project view
let projectId = this.get('model.id');
this.transitionToRoute('/project/' + projectId);
},
confirmDelete() {
// get current user object
var userId = this.get('sessionUser.user.id');
var user = this.store.peekRecord('user', userId);
// get the project
var project = this.get('model');
let projectId = project.get('id');
// delete the project and remove from user projects
user.get('projects').removeObject(projectId);
user.save().then(function() {
// destroy all visualizations
var visualizations = project.get('visualizations');
visualizations.forEach(function(visualization) {
// destroy all plots
var plots = visualization.get('plots');
plots.forEach(function(plot) {
plot.destroyRecord();
});
visualization.destroyRecord();
});
project.destroyRecord();
// go back to project list
this.transitionToRoute('/projects');
});
}
}
});