diff --git a/client/desk/formmodal.js b/client/desk/formmodal.js
new file mode 100644
index 00000000..d951a46f
--- /dev/null
+++ b/client/desk/formmodal.js
@@ -0,0 +1,44 @@
+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);
+ }
+
+ makeForm() {
+ this.form = new (view.getFormClass(this.doctype))({
+ doctype: this.doctype,
+ parent: this.getBody(),
+ container: this,
+ actions: ['submit']
+ });
+
+ this.form.on('submit', () => {
+ this.hide();
+ });
+ }
+
+ addButton(label, className, action) {
+ if (className === 'primary') {
+ this.addPrimary(label, action);
+ } else {
+ this.addSecondary(label, action);
+ }
+ }
+
+ async showWith(doctype, name) {
+ await this.form.setDoc(doctype, name);
+ if (this.form.doc._notInserted) {
+ this.setTitle(frappe._('New {0}', doctype));
+ } else {
+ this.setTitle(`${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 5d609be3..194e32d3 100644
--- a/client/desk/formpage.js
+++ b/client/desk/formpage.js
@@ -8,14 +8,15 @@ module.exports = class FormPage extends Page {
super(`Edit ${meta.name}`);
this.meta = meta;
- this.form = new (view.get_form_class(doctype))({
+ this.form = new (view.getFormClass(doctype))({
doctype: doctype,
parent: this.body,
- page: this
+ container: this,
+ actions: ['submit', 'delete']
});
this.on('show', async (params) => {
- await this.show_doc(params.doctype, params.name);
+ await this.showDoc(params.doctype, params.name);
});
// if name is different after saving, change the route
@@ -32,10 +33,9 @@ module.exports = class FormPage extends Page {
});
}
- async show_doc(doctype, name) {
+ async showDoc(doctype, name) {
try {
- this.doc = await frappe.getDoc(doctype, name);
- this.form.use(this.doc);
+ await this.form.setDoc(doctype, name);
} catch (e) {
this.renderError(e.status_code, e.message);
}
diff --git a/client/desk/index.js b/client/desk/index.js
index eac90edf..fb1175bb 100644
--- a/client/desk/index.js
+++ b/client/desk/index.js
@@ -5,6 +5,7 @@ const Page = require('frappejs/client/view/page');
const FormPage = require('frappejs/client/desk/formpage');
const ListPage = require('frappejs/client/desk/listpage');
const Navbar = require('./navbar');
+const FormModal = require('frappejs/client/desk/formmodal');
module.exports = class Desk {
constructor() {
@@ -22,7 +23,8 @@ module.exports = class Desk {
this.pages = {
lists: {},
- forms: {}
+ forms: {},
+ formModals: {}
};
this.routeItems = {};
@@ -54,7 +56,6 @@ module.exports = class Desk {
let doc = await frappe.getNewDoc(params.doctype);
// unset the name, its local
await frappe.router.setRoute('edit', doc.doctype, doc.name);
- await doc.set('name', '');
});
frappe.router.on('change', () => {
@@ -79,6 +80,15 @@ module.exports = class Desk {
return this.pages.forms[doctype];
}
+ showFormModal(doctype, name) {
+ if (!this.pages.formModals[doctype]) {
+ this.pages.formModals[doctype] = new FormModal(doctype, name);
+ } else {
+ this.pages.formModals[doctype].showWith(doctype, name);
+ }
+ return this.pages.formModals[doctype];
+ }
+
setActive(item) {
let className = 'list-group-item-secondary';
let activeItem = this.sidebarList.querySelector('.' + className);
diff --git a/client/style/style.scss b/client/style/style.scss
index ee2a8799..1ffa285e 100644
--- a/client/style/style.scss
+++ b/client/style/style.scss
@@ -60,6 +60,10 @@ html {
.checkbox {
margin-right: $spacer-2;
}
+
+ a, a:hover, a:visited, a:active {
+ color: $gray-800;
+ }
}
.dropdown-menu-right {
diff --git a/client/ui/keyboard.js b/client/ui/keyboard.js
new file mode 100644
index 00000000..ca35fabc
--- /dev/null
+++ b/client/ui/keyboard.js
@@ -0,0 +1,40 @@
+module.exports = {
+ bindKey(element, key, handler) {
+ element.addEventListener('keydown', (e) => {
+ if (key === this.getKey(e)) {
+ handler(e);
+ }
+ })
+ },
+
+ getKey(e) {
+ var keycode = e.keyCode || e.which;
+ var key = this.keyMap[keycode] || String.fromCharCode(keycode);
+
+ if(e.ctrlKey || e.metaKey) {
+ // add ctrl+ the key
+ key = 'ctrl+' + key;
+ }
+ if(e.shiftKey) {
+ // add ctrl+ the key
+ key = 'shift+' + key;
+ }
+ return key.toLowerCase();
+ },
+
+ keyMap: {
+ 8: 'backspace',
+ 9: 'tab',
+ 13: 'enter',
+ 16: 'shift',
+ 17: 'ctrl',
+ 91: 'meta',
+ 18: 'alt',
+ 27: 'escape',
+ 37: 'left',
+ 39: 'right',
+ 38: 'up',
+ 40: 'down',
+ 32: 'space'
+ },
+}
\ No newline at end of file
diff --git a/client/ui/modal.js b/client/ui/modal.js
index 5d0737e7..55eef287 100644
--- a/client/ui/modal.js
+++ b/client/ui/modal.js
@@ -1,20 +1,27 @@
const $ = require('jquery');
const bootstrap = require('bootstrap');
+const Observable = require('frappejs/utils/observable');
-module.exports = class Modal {
+module.exports = class Modal extends Observable {
constructor({ title, body, primary, secondary }) {
+ super();
Object.assign(this, arguments[0]);
+ this.make();
+ this.show();
+ }
+
+ make() {
this.$modal = $(`
- ${body}
+ ${this.getBodyHTML()}
@@ -28,23 +35,33 @@ module.exports = class Modal {
if (this.secondary) {
this.addSecondary(this.secondary.label, this.secondary.action);
}
- this.show();
+
+ this.$modal.on('hidden.bs.modal', () => this.trigger('hide'));
+ this.$modal.on('shown.bs.modal', () => this.trigger('show'));
+ }
+
+ getBodyHTML() {
+ return this.body || '';
}
addPrimary(label, action) {
- this.$primary = $(`