normalize [%old ^] WorkActions to take item as first argument, cleaned up extraneous data- attributes

This commit is contained in:
Anton Dyudin 2015-08-21 13:42:41 -07:00
parent ad8ea27fe5
commit 307b02c34c
6 changed files with 70 additions and 77 deletions

View File

@ -49,7 +49,7 @@
==
++ id (ci (slat %uv) so)
++ ship (su fed:ag)
++ coma (of new/task old/(ot id/id dif/uppd ~) sort/(ar id) ~)
++ coma (of new/task old/(ot id/id version/ni dif/uppd ~) sort/(ar id) ~)
++ task
%- ot :~
audience/audi

View File

@ -21,12 +21,13 @@ module.exports =
Persistence.put "new":item
Dispatcher.handleViewAction {type:'newItem', index, item}
setItem: (id,version,key,val) ->
setItem: ({id,version},key,val) ->
set = {}
key = key.split('_').join '-'
set[key] = val
Persistence.put old:{id,version,dif:{set}}
addComment: (id,version,val) ->
addComment: ({id,version},val) ->
Persistence.put old:{id,version,dif:add:comment:val}
setFilter: (key,val) ->
@ -47,8 +48,8 @@ module.exports =
from:from
to:to
removeItem: (index,id) ->
Persistence.put old:{id,dif:set:done:true}
removeItem: ({id,version},index) ->
Persistence.put old:{id,version,dif:set:done:true}
Dispatcher.handleViewAction
type:'removeItem'
index:index
@ -60,7 +61,7 @@ module.exports =
item:item
listenList: (type)->
Persistence.subscribe type, (err,d)->
Persistence.subscribe type, (err,d)->
if d?
{sort,tasks} = d.data
Dispatcher.handleServerAction {type:"getData",sort,tasks}

View File

@ -54,7 +54,7 @@ module.exports = recl
return l isnt new Date(n)
l isnt n
validateField: ($t,id,key,val) ->
validateField: ($t,key,val) ->
valid = 1
if key is 'date_due'
valid = 0 if isNaN(val)
@ -73,26 +73,22 @@ module.exports = recl
onKeyUp: (e) ->
$t = $(e.target).closest '.field'
id = $t.closest('.item').attr 'data-id'
key = $t.attr 'data-key'
val = @getVal $t.find('.input'),key
if @compareVal @props.item[key],val,key
if not @validateField($t,id,key,val)
if not @validateField($t,key,val)
$t.addClass 'invalid'
return
$t.removeClass 'invalid'
if @to then clearTimeout @to
ver = @props.item.version
@to = setTimeout ->
WorkActions.setItem id,ver,key,val
@to = setTimeout =>
WorkActions.setItem @props.item,key,val
,1000
onFocus: (e) -> @props._focus e,@
_markDone: (e) ->
id = $(e.target).closest('.item').attr 'data-id'
WorkActions.setItem id,@props.item.version,'done',true
_markDone: (e) -> WorkActions.setItem @props.item,'done',true
_claim: (e) ->
@ -100,10 +96,9 @@ module.exports = recl
_submitComment: (e) ->
$t = $(e.target).closest('.item')
id = $t.attr 'data-id'
val = $t.find('.comment .input').text()
WorkActions.addComment id,@props.item.version,val
WorkActions.addComment @props.item,val
formatDate: (d) ->
return "" if d is null
@ -143,14 +138,9 @@ module.exports = recl
(div {
className:itemClass
draggable:true
'data-id':@props.item.id
'data-index':@props.index
@onDragStart,@onDragEnd
}, [
(div {
className:'owner ib'
'data-key':'owner'
},owner)
(div {className:'owner ib','data-key':'owner'},owner)
(@renderField 'audience', {}, @formatAudience) # no onKeyUp?
(div {className:'sort ib top'}, @props.item.sort)
(div {className:'done ib', onClick:@_markDone}, '')

View File

@ -31,8 +31,8 @@ module.exports = recl
_dragStart: (e,i) -> @dragged = i.dragged
_dragEnd: (e,i) ->
from = Number @dragged.attr('data-index')
to = Number @over.attr('data-index')
from = Number @dragged.closest('item-wrap').attr('data-index')
to = Number @over.closest('item-wrap').attr('data-index')
if from<to then to--
if @drop is 'after' then to++
WorkActions.swapItems to,from
@ -71,7 +71,7 @@ module.exports = recl
e.target.innerText.length is 0
if @state.selected isnt 0
@setState {selected:@state.selected-1,select:"end"}
WorkActions.removeItem @state.selected,@state.list[@state.selected].id
WorkActions.removeItem @state.list[@state.selected], @state.selected
e.preventDefault()
# up
when 38
@ -138,14 +138,14 @@ module.exports = recl
(div {
className:'items'
onDragOver:@_dragOver
}, [
_.map @state.list,(item,index) =>
rece(ItemComponent,{
item
index
@_focus
@_keyDown
@_dragStart
@_dragEnd})
])
}, _.map @state.list,(item,index) =>
div {className:'item-wrap','data-index':index},
rece(ItemComponent,{
item
@_focus
@_keyDown
@_dragStart
@_dragEnd
})
)
])

View File

@ -35,9 +35,11 @@ module.exports = {
item: item
});
},
setItem: function(id, version, key, val) {
var set;
setItem: function(arg, key, val) {
var id, set, version;
id = arg.id, version = arg.version;
set = {};
key = key.split('_').join('-');
set[key] = val;
return Persistence.put({
old: {
@ -49,7 +51,9 @@ module.exports = {
}
});
},
addComment: function(id, version, val) {
addComment: function(arg, val) {
var id, version;
id = arg.id, version = arg.version;
return Persistence.put({
old: {
id: id,
@ -83,10 +87,13 @@ module.exports = {
to: to
});
},
removeItem: function(index, id) {
removeItem: function(arg, index) {
var id, version;
id = arg.id, version = arg.version;
Persistence.put({
old: {
id: id,
version: version,
dif: {
set: {
done: true
@ -285,7 +292,7 @@ module.exports = recl({
}
return l !== n;
},
validateField: function($t, id, key, val) {
validateField: function($t, key, val) {
var i, valid;
valid = 1;
if (key === 'date_due') {
@ -313,13 +320,12 @@ module.exports = recl({
return valid;
},
onKeyUp: function(e) {
var $t, id, key, val, ver;
var $t, key, val;
$t = $(e.target).closest('.field');
id = $t.closest('.item').attr('data-id');
key = $t.attr('data-key');
val = this.getVal($t.find('.input'), key);
if (this.compareVal(this.props.item[key], val, key)) {
if (!this.validateField($t, id, key, val)) {
if (!this.validateField($t, key, val)) {
$t.addClass('invalid');
return;
}
@ -327,28 +333,26 @@ module.exports = recl({
if (this.to) {
clearTimeout(this.to);
}
ver = this.props.item.version;
return this.to = setTimeout(function() {
return WorkActions.setItem(id, ver, key, val);
}, 1000);
return this.to = setTimeout((function(_this) {
return function() {
return WorkActions.setItem(_this.props.item, key, val);
};
})(this), 1000);
}
},
onFocus: function(e) {
return this.props._focus(e, this);
},
_markDone: function(e) {
var id;
id = $(e.target).closest('.item').attr('data-id');
return WorkActions.setItem(id, this.props.item.version, 'done', true);
return WorkActions.setItem(this.props.item, 'done', true);
},
_claim: function(e) {},
_release: function(e) {},
_submitComment: function(e) {
var $t, id, val;
var $t, val;
$t = $(e.target).closest('.item');
id = $t.attr('data-id');
val = $t.find('.comment .input').text();
return WorkActions.addComment(id, this.props.item.version, val);
return WorkActions.addComment(this.props.item, val);
},
formatDate: function(d) {
if (d === null) {
@ -419,8 +423,6 @@ module.exports = recl({
return div({
className: itemClass,
draggable: true,
'data-id': this.props.item.id,
'data-index': this.props.index,
onDragStart: this.onDragStart,
onDragEnd: this.onDragEnd
}, [
@ -554,8 +556,8 @@ module.exports = recl({
},
_dragEnd: function(e, i) {
var from, to;
from = Number(this.dragged.attr('data-index'));
to = Number(this.over.attr('data-index'));
from = Number(this.dragged.closest('item-wrap').attr('data-index'));
to = Number(this.over.closest('item-wrap').attr('data-index'));
if (from < to) {
to--;
}
@ -612,7 +614,7 @@ module.exports = recl({
select: "end"
});
}
WorkActions.removeItem(this.state.selected, this.state.list[this.state.selected].id);
WorkActions.removeItem(this.state.list[this.state.selected], this.state.selected);
e.preventDefault();
}
break;
@ -698,20 +700,20 @@ module.exports = recl({
]), div({
className: 'items',
onDragOver: this._dragOver
}, [
_.map(this.state.list, (function(_this) {
return function(item, index) {
return rece(ItemComponent, {
item: item,
index: index,
_focus: _this._focus,
_keyDown: _this._keyDown,
_dragStart: _this._dragStart,
_dragEnd: _this._dragEnd
});
};
})(this))
])
}, _.map(this.state.list, (function(_this) {
return function(item, index) {
return div({
className: 'item-wrap',
'data-index': index
}, rece(ItemComponent, {
item: item,
_focus: _this._focus,
_keyDown: _this._keyDown,
_dragStart: _this._dragStart,
_dragEnd: _this._dragEnd
}));
};
})(this)))
]);
}
});
@ -1258,7 +1260,7 @@ _list = [
date_created: new Date('2015-8-18'),
date_modified: new Date('2015-8-18'),
date_due: new Date('2015-8-18'),
owner: "~zod",
owner: "zod",
audience: ["~doznec/urbit-meta", "~doznec/tlon"],
status: "working",
tags: ['food', 'office'],
@ -1292,7 +1294,7 @@ _list = [
date_created: new Date('2015-8-18'),
date_modified: new Date('2015-8-18'),
date_due: null,
owner: "~talsur-todres",
owner: "talsur-todres",
audience: ["~doznec/tlon"],
status: "working",
tags: ['home'],

View File

@ -9,7 +9,7 @@ _list = [
date_created:new Date('2015-8-18')
date_modified:new Date('2015-8-18')
date_due:new Date('2015-8-18')
owner:"~zod"
owner:"zod"
audience:["~doznec/urbit-meta","~doznec/tlon"]
status:"working"
tags:['food','office']
@ -43,7 +43,7 @@ _list = [
date_created:new Date('2015-8-18')
date_modified:new Date('2015-8-18')
date_due:null
owner:"~talsur-todres"
owner:"talsur-todres"
audience:["~doznec/tlon"]
status:"working"
tags:['home']