create_folder_ctrl.ts 965 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import appEvents from 'app/core/app_events';
  2. export class CreateFolderCtrl {
  3. title = '';
  4. navModel: any;
  5. titleTouched = false;
  6. hasValidationError: boolean;
  7. validationError: any;
  8. /** @ngInject **/
  9. constructor(private backendSrv, private $location, private validationSrv, navModelSrv) {
  10. this.navModel = navModelSrv.getNav('dashboards', 'manage-dashboards', 0);
  11. }
  12. create() {
  13. if (this.hasValidationError) {
  14. return;
  15. }
  16. return this.backendSrv.createFolder({ title: this.title }).then(result => {
  17. appEvents.emit('alert-success', ['Folder Created', 'OK']);
  18. this.$location.url(result.url);
  19. });
  20. }
  21. titleChanged() {
  22. this.titleTouched = true;
  23. this.validationSrv
  24. .validateNewDashboardOrFolderName(this.title)
  25. .then(() => {
  26. this.hasValidationError = false;
  27. })
  28. .catch(err => {
  29. this.hasValidationError = true;
  30. this.validationError = err.message;
  31. });
  32. }
  33. }