2017-12-20 12:33:33 +01:00
|
|
|
import appEvents from 'app/core/app_events';
|
2018-02-07 15:32:30 +01:00
|
|
|
import locationUtil from 'app/core/utils/location_util';
|
2017-12-07 19:32:38 +01:00
|
|
|
|
2019-01-23 20:21:07 +01:00
|
|
|
export default class CreateFolderCtrl {
|
2017-12-20 12:33:33 +01:00
|
|
|
title = '';
|
2017-12-07 19:32:38 +01:00
|
|
|
navModel: any;
|
|
|
|
|
titleTouched = false;
|
2017-12-19 13:39:10 +01:00
|
|
|
hasValidationError: boolean;
|
|
|
|
|
validationError: any;
|
2017-12-07 19:32:38 +01:00
|
|
|
|
2018-08-31 16:40:43 +02:00
|
|
|
/** @ngInject */
|
2017-12-21 08:39:31 +01:00
|
|
|
constructor(private backendSrv, private $location, private validationSrv, navModelSrv) {
|
2017-12-19 13:39:10 +01:00
|
|
|
this.navModel = navModelSrv.getNav('dashboards', 'manage-dashboards', 0);
|
2017-12-07 19:32:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create() {
|
2017-12-19 13:39:10 +01:00
|
|
|
if (this.hasValidationError) {
|
2017-12-07 19:32:38 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-01 22:32:26 +01:00
|
|
|
return this.backendSrv.createFolder({ title: this.title }).then(result => {
|
2017-12-19 13:39:10 +01:00
|
|
|
appEvents.emit('alert-success', ['Folder Created', 'OK']);
|
2018-02-12 15:11:58 +01:00
|
|
|
this.$location.url(locationUtil.stripBaseFromUrl(result.url));
|
2017-12-07 19:32:38 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
titleChanged() {
|
|
|
|
|
this.titleTouched = true;
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
this.validationSrv
|
2018-02-03 10:03:01 +01:00
|
|
|
.validateNewFolderName(this.title)
|
2017-12-19 13:39:10 +01:00
|
|
|
.then(() => {
|
|
|
|
|
this.hasValidationError = false;
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
this.hasValidationError = true;
|
|
|
|
|
this.validationError = err.message;
|
|
|
|
|
});
|
2017-12-07 19:32:38 +01:00
|
|
|
}
|
|
|
|
|
}
|