Commit bfbf8087 authored by 神楽坂玲奈's avatar 神楽坂玲奈

history fix

parent 75205994
...@@ -81,15 +81,13 @@ class Deck extends Spine.Controller ...@@ -81,15 +81,13 @@ class Deck extends Spine.Controller
count = decoded >> 27 & 0x3 count = decoded >> 27 & 0x3
{card_id: card_id, side: side, count: count} {card_id: card_id, side: side, count: count}
@refresh card_usages @refresh card_usages
refresh: (card_usages, modify_url=true)-> refresh: (card_usages)->
cards_need_load = (card_usage.card_id for card_usage in card_usages when !Card.exists(card_usage.card_id)) cards_need_load = (card_usage.card_id for card_usage in card_usages when !Card.exists(card_usage.card_id))
if cards_need_load.length if cards_need_load.length
Card.query {_id: { $in: cards_need_load}}, => Card.query {_id: { $in: cards_need_load}}, =>
CardUsage.refresh card_usages, clear: true CardUsage.refresh card_usages, clear: true
history.pushState(CardUsage.toJSON(), @deck_name, @location()) if modify_url else
else CardUsage.refresh card_usages, clear: true
CardUsage.refresh card_usages, clear: true
history.pushState(CardUsage.toJSON(), @deck_name, @location()) if modify_url
render: => render: =>
@main = [] @main = []
...@@ -137,6 +135,7 @@ class Deck extends Spine.Controller ...@@ -137,6 +135,7 @@ class Deck extends Spine.Controller
last_item = {card_id: card_id, side: side, count: 1} last_item = {card_id: card_id, side: side, count: 1}
card_usages.push last_item card_usages.push last_item
@refresh card_usages @refresh card_usages
@set_history()
).disableSelection(); ).disableSelection();
if $('.operate_area').hasClass('text') if $('.operate_area').hasClass('text')
@el.jscroll({W: "12px", Btn: @el.jscroll({W: "12px", Btn:
...@@ -145,7 +144,8 @@ class Deck extends Spine.Controller ...@@ -145,7 +144,8 @@ class Deck extends Spine.Controller
"/decks/?name=#{@deck_name}&cards=#{@encode()}" "/decks/?name=#{@deck_name}&cards=#{@encode()}"
url: -> url: ->
"http://my-card.in" + @location() "http://my-card.in" + @location()
set_history: ->
history.pushState(CardUsage.toJSON(), @deck_name, @location())
tab_control: -> tab_control: ->
$(".bottom_area div").click -> $(".bottom_area div").click ->
...@@ -173,7 +173,7 @@ class Deck extends Spine.Controller ...@@ -173,7 +173,7 @@ class Deck extends Spine.Controller
if count < 3 #TODO: lflist if count < 3 #TODO: lflist
card_usage.count++ card_usage.count++
card_usage.save() card_usage.save()
history.pushState(CardUsage.toJSON(), @deck_name, @location()) @set_history()
minus: (e)-> minus: (e)->
e.preventDefault() e.preventDefault()
card_usage = $(e.target).tmplItem().data card_usage = $(e.target).tmplItem().data
...@@ -182,7 +182,7 @@ class Deck extends Spine.Controller ...@@ -182,7 +182,7 @@ class Deck extends Spine.Controller
card_usage.save() card_usage.save()
else else
card_usage.destroy() card_usage.destroy()
history.pushState(CardUsage.toJSON(), @deck_name, @location()) @set_history()
$(document).ready -> $(document).ready ->
$('#name').html $.url().param('name') $('#name').html $.url().param('name')
...@@ -237,6 +237,7 @@ $(document).ready -> ...@@ -237,6 +237,7 @@ $(document).ready ->
result.push {card_id: last_id, side: side, count: count} if last_id result.push {card_id: last_id, side: side, count: count} if last_id
$('#deck_load').attr 'disabled', false $('#deck_load').attr 'disabled', false
deck.refresh result deck.refresh result
deck.set_history()
reader.readAsText(file) reader.readAsText(file)
$.i18n.properties $.i18n.properties
......
...@@ -201,12 +201,9 @@ ...@@ -201,12 +201,9 @@
return this.refresh(card_usages); return this.refresh(card_usages);
}; };
Deck.prototype.refresh = function(card_usages, modify_url) { Deck.prototype.refresh = function(card_usages) {
var card_usage, cards_need_load, var card_usage, cards_need_load,
_this = this; _this = this;
if (modify_url == null) {
modify_url = true;
}
cards_need_load = (function() { cards_need_load = (function() {
var _i, _len, _results; var _i, _len, _results;
_results = []; _results = [];
...@@ -224,20 +221,14 @@ ...@@ -224,20 +221,14 @@
$in: cards_need_load $in: cards_need_load
} }
}, function() { }, function() {
CardUsage.refresh(card_usages, { return CardUsage.refresh(card_usages, {
clear: true clear: true
}); });
if (modify_url) {
return history.pushState(CardUsage.toJSON(), _this.deck_name, _this.location());
}
}); });
} else { } else {
CardUsage.refresh(card_usages, { return CardUsage.refresh(card_usages, {
clear: true clear: true
}); });
if (modify_url) {
return history.pushState(CardUsage.toJSON(), this.deck_name, this.location());
}
} }
}; };
...@@ -383,7 +374,8 @@ ...@@ -383,7 +374,8 @@
} }
} }
card_usages.push(last_item); card_usages.push(last_item);
return _this.refresh(card_usages); _this.refresh(card_usages);
return _this.set_history();
} }
}).disableSelection(); }).disableSelection();
if ($('.operate_area').hasClass('text')) { if ($('.operate_area').hasClass('text')) {
...@@ -404,6 +396,10 @@ ...@@ -404,6 +396,10 @@
return "http://my-card.in" + this.location(); return "http://my-card.in" + this.location();
}; };
Deck.prototype.set_history = function() {
return history.pushState(CardUsage.toJSON(), this.deck_name, this.location());
};
Deck.prototype.tab_control = function() { Deck.prototype.tab_control = function() {
$(".bottom_area div").click(function() { $(".bottom_area div").click(function() {
var $dangqian; var $dangqian;
...@@ -446,7 +442,7 @@ ...@@ -446,7 +442,7 @@
card_usage.count++; card_usage.count++;
card_usage.save(); card_usage.save();
} }
return history.pushState(CardUsage.toJSON(), this.deck_name, this.location()); return this.set_history();
}; };
Deck.prototype.minus = function(e) { Deck.prototype.minus = function(e) {
...@@ -459,7 +455,7 @@ ...@@ -459,7 +455,7 @@
} else { } else {
card_usage.destroy(); card_usage.destroy();
} }
return history.pushState(CardUsage.toJSON(), this.deck_name, this.location()); return this.set_history();
}; };
return Deck; return Deck;
...@@ -551,7 +547,8 @@ ...@@ -551,7 +547,8 @@
}); });
} }
$('#deck_load').attr('disabled', false); $('#deck_load').attr('disabled', false);
return deck.refresh(result); deck.refresh(result);
return deck.set_history();
}; };
return reader.readAsText(file); return reader.readAsText(file);
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment