2019-10-26 14:46:04 +00:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2019-11-27 18:39:16 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|