Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/marius-wieschollek/passwords-webextension.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
authorflo-mic <florianmichel@hotmail.de>2021-03-15 22:00:34 +0300
committerflo-mic <florianmichel@hotmail.de>2021-03-15 22:00:34 +0300
commita45e56d161d80165e422e06580e4aea28c09ba90 (patch)
tree7eaba72a458a7cbcc9228c26e8cd0b272b295e6e /src/js
parent1c806857b4edffafea26cfa0603dcf39495ee358 (diff)
add password view/edit feature with cutom fields
Diffstat (limited to 'src/js')
-rw-r--r--src/js/Controller/Password/Update.js63
-rw-r--r--src/js/Manager/ControllerManager.js7
2 files changed, 70 insertions, 0 deletions
diff --git a/src/js/Controller/Password/Update.js b/src/js/Controller/Password/Update.js
new file mode 100644
index 0000000..3d393dc
--- /dev/null
+++ b/src/js/Controller/Password/Update.js
@@ -0,0 +1,63 @@
+import AbstractController from '@js/Controller/AbstractController';
+import SearchIndex from '@js/Search/Index/SearchIndex';
+import ApiRepository from "@js/Repositories/ApiRepository";
+import ToastService from "@js/Services/ToastService";
+import ErrorManager from "@js/Manager/ErrorManager";
+import ServerManager from '@js/Manager/ServerManager';
+
+export default class Update extends AbstractController {
+
+ async execute(message, reply) {
+ let {data} = message.getPayload();
+ data.edited = new Date();
+
+ if(data.id === undefined) {
+ this._returnError();
+ return;
+ }
+
+ /** @type {EnhancedPassword} **/
+ let model = SearchIndex.getItem(data.id);
+ model.setProperties(data);
+
+ if(model !== null && !model.isTrashed()) {
+ await this._updatePassword(model, data.customFields === undefined ? false:true);
+ reply.setPayload({success: true, data: data});
+ } else {
+ reply.setPayload({success: false});
+ this._returnError()
+ }
+ }
+
+
+ /**
+ *
+ * @param {EnhancedPassword} password
+ * @private
+ */
+ async _updatePassword(password, reloadServer) {
+ let api = /** @type {PasswordsClient} **/ await ApiRepository.findById(password.getServer().getId());
+ let repository = /** @type {PasswordRepository} **/ api.getInstance('repository.password');
+ await repository.update(password);
+
+ if(reloadServer === true) {
+ ServerManager.reloadServer(password.getServer());
+ } else {
+ SearchIndex.removeItem(password);
+ SearchIndex.addItem(password, true);
+ }
+ ToastService.success('ToastPasswordUpdated')
+ .catch(ErrorManager.catch);
+ }
+
+ /**
+ *
+ * @private
+ */
+ _returnError() {
+ ToastService
+ .error('ToastPasswordUpdateFailed')
+ .catch(ErrorManager.catch);
+ }
+
+} \ No newline at end of file
diff --git a/src/js/Manager/ControllerManager.js b/src/js/Manager/ControllerManager.js
index 51e31fa..c8e0691 100644
--- a/src/js/Manager/ControllerManager.js
+++ b/src/js/Manager/ControllerManager.js
@@ -68,6 +68,13 @@ class ControllerManager {
}
);
MessageService.listen(
+ 'password.update',
+ async (message, reply) => {
+ let module = await import(/* webpackChunkName: "PasswordUpdate" */ '@js/Controller/Password/Update');
+ await this._executeController(module, message, reply);
+ }
+ );
+ MessageService.listen(
'folder.list',
async (message, reply) => {
let module = await import(/* webpackChunkName: "FolderList" */ '@js/Controller/Folder/List');