Skip to content

Commit

Permalink
Shorten to use Input instead of re-writing the code for it
Browse files Browse the repository at this point in the history
  • Loading branch information
GCheung55 committed Aug 23, 2012
1 parent 251b8e2 commit 5bc3462
Showing 1 changed file with 17 additions and 32 deletions.
49 changes: 17 additions & 32 deletions labs/architecture-examples/neuro/js/view/TodoListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
*/
events: {
'dblclick:relay(label)': 'onEdit',
// 'blur:relay(input.edit)': 'onUpdate',
// 'keyup:relay(input.edit)': 'onKeyup',
'click:relay(input.toggle)': 'onToggleStatus',
'click:relay(button.destroy)': 'destroy'
},
Expand Down Expand Up @@ -63,16 +61,6 @@
return this;
},

update: function(value){
if (value) {
this.element.removeClass('editing');

this.fireEvent('update', ['title', value]);
}

return this;
},

onUpdate: function(e, element){
var value = element.get('value').trim();

Expand All @@ -91,23 +79,6 @@
return this;
},

onKeyup: function(e, element){
var key = e.key,
canUpdate = key == 'enter' || key == 'esc';

// Revert to the old value
if (key == 'esc') {
element.set('value', this._previousTitle);
}

// Update the label
if (canUpdate) {
this.element.fireEvent('blur', [e, element]);
}

return this;
},

onToggleStatus: function(e, element){
var hasClass = this.element.hasClass('completed');
this.updateComplete(hasClass);
Expand All @@ -125,12 +96,12 @@
}).getElement('>');

this.setElement(element);
var _this = this;

var input = new View.Input({
element: element.getElement('input.edit'),
connector: {
'keyup:enter': 'update',
'keyup:reset': function(){_this.element.removeClass('editing');}
'keyup:enter': '_onEnter'
, 'keyup:reset': '_onReset'
}
}).connect(this);

Expand All @@ -142,6 +113,20 @@ var _this = this;

this.parent(model);

return this;
},

_onEnter: function(value){
if (value) {
this.fireEvent('update', ['title', value]);
}

return this;
},

_onReset: function(){
this.element.removeClass('editing');

return this;
}
});
Expand Down

0 comments on commit 5bc3462

Please sign in to comment.