create_folder_ctrl.ts 1.0 KB

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