diff --git a/src/auth.js b/src/auth.js index 31945a591b9ee1e8a79ddde8bfeec7b2619effbf..3a30596aa2691357e007827c677d0fbaf8fbc77c 100644 --- a/src/auth.js +++ b/src/auth.js @@ -187,9 +187,7 @@ export class ResourceHandler { post(item) { return new Promise((resolve, reject) => { getSession().then((api) => { - api.post(this.resource, { - data: item, - }).then((response) => { + api.post(this.resource, item).then((response) => { if (response.status >= 400) { resetSession(); reject(); diff --git a/src/userTool.js b/src/userTool.js index dd29c598d33c17b6d4f9c73433ba9b27357f3acb..41eeb50a94fdd2ceb1b66d796cb53a164f213ebb 100644 --- a/src/userTool.js +++ b/src/userTool.js @@ -72,9 +72,8 @@ class UserView extends ItemView { this.groupmemberships.handler.post({ user: this.data._id, group: group._id, - }).then((data) => { + }).then(() => { this.groupmemberships.refresh(); - }); }, }); diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 0000000000000000000000000000000000000000..0844554c3394f8eb10130d35cd701c4dcd8d49c3 --- /dev/null +++ b/src/utils.js @@ -0,0 +1,19 @@ +// as taken from underscore: +// Returns a function, that, as long as it continues to be invoked, will not +// be triggered. The function will be called after it stops being called for +// N milliseconds. If `immediate` is passed, trigger the function on the +// leading edge, instead of the trailing. +export function debounce(func, wait, immediate) { + let timeout; + return function outer(...args) { + const context = this; + function later() { + timeout = null; + if (!immediate) func.apply(context, args); + } + const callNow = immediate && !timeout; + clearTimeout(timeout); + timeout = setTimeout(later, wait); + if (callNow) func.apply(context, args); + }; +} diff --git a/src/views/elements.js b/src/views/elements.js index 90e37c3866b1615183686ef6b3e21b9d50618da3..83d8805a4cd42216b1c4beaf8bbf990d4d1bf764 100644 --- a/src/views/elements.js +++ b/src/views/elements.js @@ -43,11 +43,11 @@ export class selectGroup { } export class submitButton { - view(vnode) { - const args = vnode.attrs.args; - if (!vnode.attrs.active) { - args.disabled = 'disabled'; + view({ attrs: { args, active, text } }) { + const argsCopy = args; + if (!active) { + argsCopy.disabled = 'disabled'; } - return m('div.btn', args, vnode.attrs.text); + return m('div.btn', argsCopy, text); } } diff --git a/src/views/selectList.js b/src/views/selectList.js index b322a2c79baa798f5ad3cefe545ecef6c7e3e46f..2e7739e28263281aa63340907df50da71ba40b41 100644 --- a/src/views/selectList.js +++ b/src/views/selectList.js @@ -1,28 +1,8 @@ import { submitButton } from './elements'; +import { debounce } from '../utils'; const m = require('mithril'); -// as taken from underscore: -// Returns a function, that, as long as it continues to be invoked, will not -// be triggered. The function will be called after it stops being called for -// N milliseconds. If `immediate` is passed, trigger the function on the -// leading edge, instead of the trailing. -function debounce(func, wait, immediate) { - let timeout; - return function () { - const context = this; - const args = arguments; - const later = function () { - timeout = null; - if (!immediate) func.apply(context, args); - }; - const callNow = immediate && !timeout; - clearTimeout(timeout); - timeout = setTimeout(later, wait); - if (callNow) func.apply(context, args); - }; -} - export default class SelectList { constructor() { this.selected = null;