Permalink
Browse files

adding cards works

  • Loading branch information...
1 parent 9f806b7 commit 3d3c13880e0bd554cb03fa9785534cc55d4bfd2a @qoobaa committed Aug 12, 2011
Showing with 34 additions and 16 deletions.
  1. +9 −3 index.html
  2. +25 −13 lib/main.js
View
12 index.html
@@ -7,10 +7,16 @@
<h1>Ficha</h1>
<script type="text/x-handlebars">
- {{view Ficha.SideView valueBinding="Ficha.cardController.currentCard.front" placeholder="Front Side"}}
- {{view Ficha.SideView valueBinding="Ficha.cardController.currentCard.back" placeholder="Back Side"}}
+ <p>
+ {{view Ficha.SideView valueBinding="Ficha.cardController.currentCard.front" placeholder="Front side"}}
+ </p>
+ <p>
+ {{view Ficha.SideView valueBinding="Ficha.cardController.currentCard.back" placeholder="Back side"}}
+ </p>
- {{#view SC.Button target="Ficha.cardController" action="newCard"}}Create New Card{{/view}}
+ {{#collection contentBinding="Ficha.cardsController" tagName="ul"}}
+ {{content.front}} {{content.back}}
+ {{/collection}}
</script>
</body>
<script type="text/javascript" src="assets/bpm_libs.js"></script>
View
38 lib/main.js
@@ -3,37 +3,49 @@ spade.require("sproutcore");
Ficha = SC.Application.create();
Ficha.Card = SC.Object.extend({
- front: null,
- back: null,
+ front: "",
+ back: "",
- ready: function () {
+ isValid: function () {
return this.get("front") && this.get("back");
}.property("front", "back")
});
-Ficha.cardsController = SC.ArrayController.create();
+Ficha.cardsController = SC.ArrayController.create({
+ content: []
+});
Ficha.cardController = SC.Object.create({
currentCard: null,
+ init: function () {
+ this.newCard();
+ },
+
newCard: function () {
this.set("currentCard", Ficha.Card.create());
},
createCard: function () {
Ficha.cardsController.pushObject(this.get("currentCard"));
- this.set("currentCard", null); // alternatively, invoke this.newCard()
- }
-});
+ this.newCard();
+ },
-Ficha.SideView = SC.TextField.extend({
- insertNewline: function () {
- var currentCard = Ficha.cardController.currentCard;
+ sideViewInsertNewline: function (event) {
+ var currentCard = this.get("currentCard");
- if (currentCard.get("ready")) {
- Ficha.cardController.createCard();
+ if (currentCard.get("isValid")) {
+ this.createCard();
}
+
+ setTimeout(function () {
+ $(event.target).parents(".sc-view").find("input[type='text'][value='']:first").focus();
+ }, 0);
}
});
-
+Ficha.SideView = SC.TextField.extend({
+ insertNewline: function (event) {
+ Ficha.cardController.sideViewInsertNewline(event);
+ }
+});

0 comments on commit 3d3c138

Please sign in to comment.