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