From cb446ba49fb26c1528a46031d9e71ea6f75333a1 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 15 Feb 2018 22:09:50 +0530 Subject: [PATCH] minor fixes --- client/desk/formmodal.js | 24 +++++++++++++++--------- client/desk/formpage.js | 3 +++ client/desk/index.js | 11 +++++------ client/style/style.scss | 2 -- client/ui/modal.js | 5 ++++- client/view/controls/link.js | 4 +--- client/view/controls/table.js | 1 + 7 files changed, 29 insertions(+), 21 deletions(-) diff --git a/client/desk/formmodal.js b/client/desk/formmodal.js index 126262d5..c98f2ed5 100644 --- a/client/desk/formmodal.js +++ b/client/desk/formmodal.js @@ -1,13 +1,23 @@ const Modal = require('frappejs/client/ui/modal'); const view = require('frappejs/client/view'); -const frappe = require('frappejs'); module.exports = class FormModal extends Modal { constructor(doctype, name) { super({title: doctype}); this.doctype = doctype; - this.makeForm(); - this.showWith(doctype, name); + } + + async showWith(doctype, name) { + this.show(); + await this.setDoc(doctype, name); + } + + async setDoc(doctype, name) { + if (!this.form) { + this.makeForm(); + } + await this.form.setDoc(doctype, name); + this.modal.querySelector('input').focus(); } makeForm() { @@ -18,7 +28,8 @@ module.exports = class FormModal extends Modal { actions: ['submit'] }); - this.form.on('submit', () => { + this.form.on('submit', async () => { + await this.trigger('submit'); this.hide(); }); } @@ -31,9 +42,4 @@ module.exports = class FormModal extends Modal { } } - async showWith(doctype, name) { - await this.form.setDoc(doctype, name); - this.show(); - this.$modal.find('input:first').focus(); - } } \ No newline at end of file diff --git a/client/desk/formpage.js b/client/desk/formpage.js index 7c0be46f..0d0fff59 100644 --- a/client/desk/formpage.js +++ b/client/desk/formpage.js @@ -17,6 +17,9 @@ module.exports = class FormPage extends Page { this.on('show', async (params) => { await this.showDoc(params.doctype, params.name); + if (frappe.desk.center && !frappe.desk.center.activePage) { + frappe.desk.showListPage(doctype); + } }); // if name is different after saving, change the route diff --git a/client/desk/index.js b/client/desk/index.js index 9c42c803..3bc17800 100644 --- a/client/desk/index.js +++ b/client/desk/index.js @@ -69,8 +69,7 @@ module.exports = class Desk { }) frappe.router.add('list/:doctype', async (params) => { - let page = this.getListPage(params.doctype); - await page.show(params); + await this.showListPage(params.doctype); }); frappe.router.add('edit/:doctype/:name', async (params) => { @@ -92,10 +91,11 @@ module.exports = class Desk { } - getListPage(doctype) { + async showListPage(doctype) { if (!this.pages.lists[doctype]) { this.pages.lists[doctype] = new ListPage(doctype); } + await this.pages.lists[doctype].show(doctype); return this.pages.lists[doctype]; } @@ -108,10 +108,9 @@ module.exports = class Desk { showFormModal(doctype, name) { if (!this.pages.formModals[doctype]) { - this.pages.formModals[doctype] = new FormModal(doctype, name); - } else { - this.pages.formModals[doctype].showWith(doctype, name); + this.pages.formModals[doctype] = new FormModal(doctype); } + this.pages.formModals[doctype].showWith(doctype, name); return this.pages.formModals[doctype]; } diff --git a/client/style/style.scss b/client/style/style.scss index 7e9a652e..c71ac402 100644 --- a/client/style/style.scss +++ b/client/style/style.scss @@ -36,7 +36,6 @@ html { } .page { - max-width: $page-width; padding-bottom: $spacer-4; .page-head { @@ -62,7 +61,6 @@ html { .form-body { padding: $spacer-3; - max-width: $page-width; .form-control.font-weight-bold { background-color: lightyellow; diff --git a/client/ui/modal.js b/client/ui/modal.js index 55eef287..e3209d36 100644 --- a/client/ui/modal.js +++ b/client/ui/modal.js @@ -28,6 +28,7 @@ module.exports = class Modal extends Observable { `).appendTo(document.body); + this.modal = this.$modal.get(0); if (this.primary) { this.addPrimary(this.primary.label, this.primary.action); @@ -37,7 +38,9 @@ module.exports = class Modal extends Observable { } this.$modal.on('hidden.bs.modal', () => this.trigger('hide')); - this.$modal.on('shown.bs.modal', () => this.trigger('show')); + this.$modal.on('shown.bs.modal', () => { + this.trigger('show'); + }); } getBodyHTML() { diff --git a/client/view/controls/link.js b/client/view/controls/link.js index 91d90117..3d2d49d0 100644 --- a/client/view/controls/link.js +++ b/client/view/controls/link.js @@ -25,8 +25,6 @@ class LinkControl extends BaseControl { list.push({ label:frappe._('+ New {0}', this.target), value: '__newItem', - action: () => { - } }); this.awesomplete.list = list; @@ -38,7 +36,7 @@ class LinkControl extends BaseControl { e.preventDefault(); const newDoc = await frappe.getNewDoc(this.target); const formModal = frappe.desk.showFormModal(this.target, newDoc.name); - formModal.form.once('submit', async () => { + formModal.once('submit', async () => { await this.updateDocValue(formModal.form.doc.name); }) } diff --git a/client/view/controls/table.js b/client/view/controls/table.js index f64da459..a972d8dd 100644 --- a/client/view/controls/table.js +++ b/client/view/controls/table.js @@ -55,6 +55,7 @@ class TableControl extends BaseControl { setInputValue(value) { this.datatable.refresh(this.getTableData(value)); + this.datatable.setDimensions(); } getTableData(value) {