1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00
Files
browser/src/popup/app/settings/folders/edit-folder.component.ts
2018-01-06 15:47:46 -05:00

80 lines
2.6 KiB
TypeScript

import * as angular from 'angular';
import { Folder } from '../../../../models/domain/folder';
import * as template from './edit-folder.component.html';
import { PlatformUtilsService } from '@bitwarden/jslib';
export class EditFolderController {
$transition$: any;
folderId: any;
savePromise: any = null;
i18n: any;
folder: Folder;
constructor($scope: any, $stateParams: any, private folderService: any, private toastr: any, private $state: any,
private SweetAlert: any, platformUtilsService: PlatformUtilsService, private $analytics: any,
private i18nService: any, $timeout: any) {
this.i18n = i18nService;
$timeout(() => {
platformUtilsService.initListSectionItemListeners(document, angular);
document.getElementById('name').focus();
}, 500);
$scope.folder = {};
}
$onInit() {
this.folderId = this.$transition$.params('to').folderId;
this.folderService.get(this.folderId).then((folder: any) => {
return folder.decrypt();
}).then((model: Folder) => {
this.folder = model;
});
}
save(model: any) {
if (!model.name) {
this.toastr.error(this.i18nService.nameRequired, this.i18nService.errorsOccurred);
return;
}
this.savePromise = this.folderService.encrypt(model).then((folderModel: any) => {
const folder = new Folder(folderModel, true);
return this.folderService.saveWithServer(folder);
}).then((folder: any) => {
this.$analytics.eventTrack('Edited Folder');
this.toastr.success(this.i18nService.editedFolder);
this.$state.go('^.list', { animation: 'out-slide-down' });
});
}
delete() {
this.SweetAlert.swal({
title: this.i18nService.deleteFolder,
text: this.i18nService.deleteFolderConfirmation,
showCancelButton: true,
confirmButtonText: this.i18nService.yes,
cancelButtonText: this.i18nService.no,
}, (confirmed: boolean) => {
if (confirmed) {
this.folderService.deleteWithServer(this.folderId).then(() => {
this.$analytics.eventTrack('Deleted Folder');
this.toastr.success(this.i18nService.deletedFolder);
this.$state.go('^.list', {
animation: 'out-slide-down',
});
});
}
});
}
}
export const EditFolderComponent = {
bindings: {
$transition$: '<',
},
controller: EditFolderController,
template: template,
};