Permalink
Browse files

added fixtures storage

  • Loading branch information...
Jakub Kuźma
Jakub Kuźma committed Aug 17, 2011
1 parent 6ef36ed commit 83b12f0440b8ffac8687c6a0ffed34866d9b0456
Showing with 47 additions and 24 deletions.
  1. +2 −1 ficha.json
  2. +3 −3 index.html
  3. +42 −20 lib/main.js
View
@@ -16,6 +16,7 @@
},
"dependencies": {
"sproutcore": ">= 0-pre",
- "spade": ">= 0"
+ "spade": ">= 0",
+ "sproutcore-datastore": ">= 0-pre"
}
}
View
@@ -8,10 +8,10 @@ <h1>Ficha</h1>
<script id="card" type="text/x-handlebars">
<p>
- {{view Ficha.SideView valueBinding="Ficha.cardController.currentCard.front" placeholder="Front side"}}
+ {{view Ficha.SideView valueBinding="Ficha.newCardController.front" placeholder="Front side"}}
</p>
<p>
- {{view Ficha.SideView valueBinding="Ficha.cardController.currentCard.back" placeholder="Back side"}}
+ {{view Ficha.SideView valueBinding="Ficha.newCardController.back" placeholder="Back side"}}
</p>
</script>
@@ -25,5 +25,5 @@ <h1>Ficha</h1>
</script>
</body>
<script type="text/javascript" src="assets/bpm_libs.js"></script>
- <script>spade.require("ficha")</script>
+ <script>spade.require("ficha");</script>
</html>
View
@@ -1,14 +1,32 @@
spade.require("sproutcore");
+spade.require("sproutcore-datastore");
-Ficha = SC.Application.create();
+Ficha = SC.Application.create({
+ store: SC.Store.create().from("Ficha.FixturesDataSource")
+});
-Ficha.Card = SC.Object.extend({
- front: "",
- back: "",
+Ficha.store.commitRecordsAutomatically = true;
+
+Ficha.FixturesDataSource = SC.FixturesDataSource.extend({
+ // simulateRemoteResponse: true,
+ // latency: 250
+});
+
+Ficha.Card = SC.Record.extend({
+ primaryKey: "id",
+
+ front: SC.Record.attr(String),
+ back: SC.Record.attr(String)
+});
+
+Ficha.Card.FIXTURES = [
+ { id: "1", front: "a", back: "b" },
+ { id: "2", front: "c", back: "d" },
+ { id: "3", front: "e", back: "f" }
+];
+
+Ficha.categoriesController = SC.ArrayController.create({
- isValid: function () {
- return this.get("front") && this.get("back");
- }.property("front", "back")
});
Ficha.cardsController = SC.ArrayController.create({
@@ -19,23 +37,28 @@ Ficha.cardsController = SC.ArrayController.create({
}
});
-Ficha.cardController = SC.Object.create({
- currentCard: null,
+Ficha.newCardController = SC.Object.create({
+ isValid: function () {
+ return this.get("front") !== "" && this.get("back") !== "";
+ }.property("front", "back"),
init: function () {
- this.newCard();
+ this.reset();
},
- newCard: function () {
- this.set("currentCard", Ficha.Card.create());
+ reset: function () {
+ this.setProperties({ front: "", back: "" });
},
- createCard: function () {
- var currentCard = this.get("currentCard");
+ create: function () {
+ if (this.get("isValid")) {
+ var card = Ficha.store.createRecord(Ficha.Card, {
+ front: this.get("front"),
+ back: this.get("back")
+ });
- if (currentCard.get("isValid")) {
- Ficha.cardsController.pushObject(this.get("currentCard"));
- this.newCard();
+ Ficha.cardsController.pushObject(card);
+ this.reset();
}
}
});
@@ -50,9 +73,8 @@ Ficha.CardView = SC.View.extend({
templateName: "card",
sideViewInsertNewline: function () {
- SC.RunLoop.begin();
- Ficha.cardController.createCard();
- SC.RunLoop.end();
+ Ficha.newCardController.create();
+ SC.run.sync();
this.$("input[type='text'][value='']:first").focus();
}
});

0 comments on commit 83b12f0

Please sign in to comment.