Skip to content

Commit

Permalink
added copy new to old btn
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensayshi committed Jun 7, 2012
1 parent 588c829 commit 222097c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
7 changes: 7 additions & 0 deletions js/View/ItemView.js
Expand Up @@ -120,6 +120,13 @@ var ItemView = Backbone.View.extend({
}, this);
},

replaceItem: function(newItem) {
this.model = newItem;

this.model.on('change', this.modelToView, this);
this.modelToView();
},

renderItem: function() {
this.model.on('change', this.modelToView, this);

Expand Down
30 changes: 26 additions & 4 deletions js/View/SimulationView.js
Expand Up @@ -248,11 +248,31 @@ var SimulationView = Backbone.View.extend({

var $currentItem = $('<div class="current-item span6" />'),
$newItem = $('<div class="new-item span6" />'),
$copy = $('<button />')
.addClass('btn btn-info')
.append($('<i />').addClass('icon-arrow-left icon-white'))
.append($('<span />').html(' copy new to current'))
.on('click', _.bind(function(e) {
curItem.destroy();
curItem = newItem.clone();

this.model.gearbag.add(curItem);
curItem.save();

curItemView.replaceItem(curItem);

this.doItemCompare(itemslot);
}, this)),
$tabpane = $('<div class="tab-pane" />')
.attr('id', tid)
.data('itemslot', itemslot)
.append($currentItem)
.append($newItem),
.append($('<div class="row-fluid" />')
.append($currentItem)
.append($newItem)
)
.append($('<div class="row-fluid" />')
.append($('<div class="span12 well" style="text-align: center;" />').append($copy))
),
$tabA = $('<a />')
.on('click', _.bind(function(e) {
this.doItemCompare(itemslot);
Expand All @@ -268,8 +288,10 @@ var SimulationView = Backbone.View.extend({
var curItem = this.model.getItemForSlot(itemslot, this.model.gearbag);
var newItem = this.model.getItemForSlot(itemslot, this.model.new_gearbag);

(new ItemView({'el': $currentItem, 'model': curItem, 'title': 'Current Item'})).render();
(new ItemView({'el': $newItem, 'model': newItem, 'title': 'New Item'})).render();
var curItemView = new ItemView({'el': $currentItem, 'model': curItem, 'title': 'Current Item'});
var newItemView = new ItemView({'el': $newItem, 'model': newItem, 'title': 'New Item'});
curItemView.render();
newItemView.render();

curItem.on('change', function() { this.doItemCompare(itemslot); }, this);
newItem.on('change', function() { this.doItemCompare(itemslot); }, this);
Expand Down

0 comments on commit 222097c

Please sign in to comment.