2
0
mirror of https://github.com/frappe/books.git synced 2024-12-26 20:30:25 +00:00
books/src/utils.js
2019-11-28 00:09:16 +05:30

59 lines
1.3 KiB
JavaScript

import { _ } from 'frappejs';
import { remote } from 'electron';
export function createNewDatabase() {
return new Promise(resolve => {
remote.dialog.showSaveDialog(
remote.getCurrentWindow(),
{
title: _('Select folder'),
defaultPath: 'frappe-accounting.db'
},
filePath => {
if (filePath) {
if (!filePath.endsWith('.db')) {
filePath = filePath + '.db';
}
resolve(filePath);
}
}
);
});
}
export function loadExistingDatabase() {
return new Promise(resolve => {
remote.dialog.showOpenDialog(
remote.getCurrentWindow(),
{
title: _('Select file'),
properties: ['openFile'],
filters: [{ name: 'SQLite DB File', extensions: ['db'] }]
},
files => {
if (files && files[0]) {
resolve(files[0]);
}
}
);
});
}
export function showMessageDialog({ message, description, buttons }) {
let buttonLabels = buttons.map(a => a.label);
remote.dialog.showMessageBox(
remote.getCurrentWindow(),
{
message,
detail: description,
buttons: buttonLabels
},
response => {
let button = buttons[response];
if (button && button.action) {
button.action();
}
}
);
}