2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 03:19:01 +00:00

minor fixes

This commit is contained in:
Rushabh Mehta 2018-03-07 16:07:58 +05:30
parent 5446c2cc2e
commit 4e9eaa0fff
10 changed files with 28 additions and 18 deletions

View File

@ -195,7 +195,8 @@ module.exports = class Database extends Observable {
}
triggerChange(doctype, name) {
this.trigger(`change:${doctype}`, {name:name}, 1000);
this.trigger(`change:${doctype}`, {name:name}, 500);
this.trigger(`change`, {doctype:name, name:name}, 500);
}
async insert(doctype, doc) {
@ -323,6 +324,10 @@ module.exports = class Database extends Observable {
// datetime
return value.toISOString();
}
} else if (field.fieldtype === 'Link' && !value) {
// empty value must be null to satisfy
// foreign key constraint
return null;
} else {
return value;
}

View File

@ -69,7 +69,7 @@ module.exports = class sqliteDatabase extends Database {
columns.push(def);
if (field.fieldtype==='Link' && field.target) {
indexes.push(`FOREIGN KEY (${field.fieldname}) REFERENCES ${field.target} ON UPDATE RESTRICT ON DELETE RESTRICT`);
indexes.push(`FOREIGN KEY (${field.fieldname}) REFERENCES ${field.target} ON UPDATE CASCADE ON DELETE RESTRICT`);
}
}

View File

@ -18,7 +18,7 @@ module.exports = class FormPage extends Page {
// if name is different after saving, change the route
this.form.on('save', async (params) => {
let route = frappe.router.get_route();
let route = frappe.router.getRoute();
if (this.form.doc.name && !(route && route[2] === this.form.doc.name)) {
await frappe.router.setRoute('edit', this.form.doc.doctype, this.form.doc.name);
frappe.ui.showAlert({message: 'Added', color: 'green'});

View File

@ -30,7 +30,9 @@ module.exports = class ListPage extends Page {
async show(params) {
super.show();
this.setTitle(name===this.list.doctype ? (this.list.meta.label || this.list.meta.name) : name);
frappe.desk.body.activePage.hide();
if (frappe.desk.body.activePage && frappe.router.getRoute()[0]==='list') {
frappe.desk.body.activePage.hide();
}
await this.list.refresh();
}
}

View File

@ -214,13 +214,13 @@ mark {
background-color: $gray-200 !important;
}
.data-table-col .edit-cell {
.data-table-cell .edit-cell {
padding: 0px !important;
input, textarea {
border-radius: none;
margin: none;
padding: $spacer-1;
padding: $spacer-2;
}
.awesomplete > ul {

View File

@ -4,7 +4,8 @@ const controls = require('frappejs/client/view/controls');
const Modal = require('frappejs/client/ui/modal');
module.exports = class ModelTable {
constructor({doctype, parent, layout='fixed', parentControl, getRowDoc, isDisabled}) {
constructor({doctype, parent, layout='fixed', parentControl, getRowDoc,
isDisabled, getTableData}) {
Object.assign(this, arguments[0]);
this.meta = frappe.getMeta(this.doctype);
this.make();

View File

@ -11,7 +11,8 @@ class TableControl extends BaseControl {
parentControl: this,
layout: this.layout || 'fixed',
getRowDoc: (rowIndex) => this.doc[this.fieldname][rowIndex],
isDisabled: () => this.isDisabled()
isDisabled: () => this.isDisabled(),
getTableData: () => this.getTableData()
});
this.setupToolbar();
}

View File

@ -180,7 +180,7 @@ module.exports = class BaseForm extends Observable {
this.container.setTitle(this.doc.name);
}
if (this.doc.submitted) {
this.container.addTitleBadge('✓', frappe._('Submitted'));
// this.container.addTitleBadge('✓', frappe._('Submitted'));
}
}

View File

@ -54,7 +54,7 @@ module.exports = class Router extends Observable {
listen() {
window.addEventListener('hashchange', (event) => {
let route = this.get_route_string();
let route = this.getRoute_string();
if (this.last_route !== route) {
this.show(route);
}
@ -62,8 +62,8 @@ module.exports = class Router extends Observable {
}
// split and get routes
get_route() {
let route = this.get_route_string();
getRoute() {
let route = this.getRoute_string();
if (route) {
return route.split('/');
} else {
@ -129,7 +129,7 @@ module.exports = class Router extends Observable {
}
}
get_route_string() {
getRoute_string() {
let route = window.location.hash;
if (route && route[0]==='#') {
route = route.substr(1);

View File

@ -9,6 +9,7 @@ module.exports = class BaseDocument extends Observable {
this.flags = {};
this.setup();
Object.assign(this, data);
frappe.db.on('change', (params) => this.fetchValues[`${params.doctype}:${params.name}`] = {});
}
setup() {
@ -216,7 +217,6 @@ module.exports = class BaseDocument extends Observable {
async commit() {
// re-run triggers
await naming.setName(this);
this.setStandardValues();
this.setKeywords();
this.setChildIdx();
@ -225,6 +225,7 @@ module.exports = class BaseDocument extends Observable {
}
async insert() {
await naming.setName(this);
await this.commit();
await this.trigger('beforeInsert');
@ -291,10 +292,10 @@ module.exports = class BaseDocument extends Observable {
async getFrom(doctype, name, fieldname) {
if (!name) return '';
let key = `${doctype}:${name}:${fieldname}`;
if (!this.fetchValues[key]) {
this.fetchValues[key] = await frappe.db.getValue(doctype, name, fieldname);
let _values = this.fetchValues[`${doctype}:${name}`] || (this.fetchValues[`${doctype}:${name}`] = {});
if (!_values[fieldname]) {
_values[fieldname] = await frappe.db.getValue(doctype, name, fieldname);
}
return this.fetchValues[key];
return _values[fieldname];
}
};