delegate hook click events
This commit is contained in:
parent
d84cc0520f
commit
3fb489f6fc
|
@ -44,9 +44,12 @@ module.exports = function(env) {
|
|||
this.vm.mode = store.mode.set(mode);
|
||||
}.bind(this);
|
||||
|
||||
this.clickHook = function(hook) {
|
||||
this.clickHook = function(id) {
|
||||
if (this.vm.stepping) return;
|
||||
if (hook.action === 'cancel' || variant.confirm(data.variant)) socket.send(hook.action, hook.id);
|
||||
var hook = hookRepo.find(this, id);
|
||||
if (!hook || hook.disabled) return;
|
||||
console.log(hook);
|
||||
// if (hook.action === 'cancel' || variant.confirm(hook.variant)) this.socket.send(hook.action, hook.id);
|
||||
}.bind(this);
|
||||
|
||||
this.router = env.routes;
|
||||
|
|
|
@ -28,5 +28,10 @@ module.exports = {
|
|||
},
|
||||
stepSlice: function(ctrl) {
|
||||
return ctrl.data.hooks.slice(0, 14);
|
||||
},
|
||||
find: function(ctrl, id) {
|
||||
return ctrl.data.hooks.filter(function(h) {
|
||||
return h.id === id;
|
||||
})[0];
|
||||
}
|
||||
};
|
||||
|
|
|
@ -16,12 +16,11 @@ function renderHook(ctrl, hook) {
|
|||
key: hook.id,
|
||||
title: (hook.action === 'join') ? ctrl.trans('joinTheGame') + ' - ' + hook.perf.name : ctrl.trans('cancel'),
|
||||
'data-id': hook.id,
|
||||
class: 'hook ' + hook.action + (hook.disabled ? ' disabled' : ''),
|
||||
onclick: util.partial(ctrl.clickHook, hook)
|
||||
class: 'hook ' + hook.action + (hook.disabled ? ' disabled' : '')
|
||||
}, tds([
|
||||
m('span', {
|
||||
class: 'is is2 color-icon ' + (hook.color || 'random')
|
||||
}), (hook.rating ? m('a', {
|
||||
}), (hook.rating ? m('a.ulink', {
|
||||
href: '/@/' + hook.username
|
||||
}, hook.username) : 'Anonymous'),
|
||||
hook.rating ? hook.rating : '',
|
||||
|
@ -55,7 +54,18 @@ module.exports = function(ctrl) {
|
|||
m('th', ctrl.trans('mode'))
|
||||
])
|
||||
),
|
||||
m('tbody' + (ctrl.vm.stepping ? '.stepping' : ''), [
|
||||
m('tbody', {
|
||||
class: ctrl.vm.stepping ? 'stepping' : '',
|
||||
onclick: function(e) {
|
||||
var el = e.target;
|
||||
if (el.classList.contains('ulink')) return;
|
||||
do {
|
||||
el = el.parentNode;
|
||||
if (el.nodeName === 'TR') return ctrl.clickHook(el.getAttribute('data-id'));
|
||||
}
|
||||
while (el.nodeName !== 'TABLE');
|
||||
}
|
||||
}, [
|
||||
standards,
|
||||
variants.length ? m('tr.variants',
|
||||
m('td[colspan=5]', '- ' + ctrl.trans('variant') + ' -')
|
||||
|
|
Loading…
Reference in a new issue