Created
November 19, 2012 19:14
-
-
Save Leksat/4112980 to your computer and use it in GitHub Desktop.
Task creation before switching to web components.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Task(this.timeTracker, [this.name = '', this.seconds = 0]) { | |
// copy task from template | |
taskDiv = document.query('#task-template').clone(true); | |
taskDiv.attributes.remove('id'); | |
// init inputs | |
nameInput = taskDiv.query('.name'); | |
timeInput = taskDiv.query('.time'); | |
nameInput.value = name; | |
timeInput.value = formatTimeString(seconds); | |
// attach to dom | |
timeTracker.tasksDiv.elements.add(taskDiv); | |
// attach event handlers | |
nameInput.on.keyUp.add((Event event) { | |
name = (event.srcElement as InputElement).value; | |
}); | |
timeInput.on.keyUp.add((Event event) { | |
InputElement timeInput = event.srcElement; | |
var s = parseTimeString(timeInput.value); | |
if (s != -1) { | |
seconds = s; | |
timeInput.classes.remove('error'); | |
} else { | |
timeInput.classes.add('error'); | |
} | |
}); | |
taskDiv.query('.start').on.click.add((event) => this.start()); | |
taskDiv.query('.stop').on.click.add((event) => this.stop()); | |
taskDiv.query('.delete').on.click.add((Event event) { | |
if (window.confirm('Do you really want to remove this task?')) { | |
this.remove(); | |
timeTracker.tasks.removeRange(timeTracker.tasks.indexOf(this), 1); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment