Skip to content

Commit

Permalink
add cancel callback, clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mrflix committed Mar 6, 2013
1 parent 10d8293 commit a96ee32
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
36 changes: 18 additions & 18 deletions app/views/dialog_view.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var View = require('./view');
var clickCatcher = require('./click_catcher_view');

module.exports = View.extend({
template: require('./templates/dialog'),
Expand All @@ -16,35 +15,36 @@ module.exports = View.extend({
// set up the dialog captions
this.options.title = options.title || t('Confirm');
this.options.verb = options.verb || t('Ok');
this.options.cancel = options.cancel || t('Cancel');
this.options.cancelVerb = options.cancelVerb || t('Cancel');

// set up the callbacks
this.options.success = options.success || function(){};
this.options.cancel = options.cancel || function(){};

// set up the parent element
this.options.holder = options.holder || 'body';

// set up the success callback
var _this = this;
var _success = this.options.success || function(){};
this.success = function(event){
event.stopPropagation();
_success();
_this.cancel();
};

_.bindAll(this, 'handleKeys', 'success', 'cancel', 'stopPropagation', 'destroy');
_.bindAll(this, 'handleKeys', 'success', 'destroy');

this.render();
},

stopPropagation: function(event){
event.stopPropagation();
success: function(event){
if(event) event.stopPropagation();
this.options.success();
this.close();
},

cancel: function(event){
if(event) event.stopPropagation();
this.options.cancel();
this.close();
},

render: function(){
this.$el.html(this.template(this.options));
this.$el.appendTo(this.options.holder);
this.$el.on(this.inputDownEvent, this.stopPropagation);

this.clickCatcher = new clickCatcher({ callback: this.cancel, holder: $(this.options.holder) });
$(document).bind('keydown', this.handleKeys);

var _this = this;
Expand All @@ -59,12 +59,12 @@ module.exports = View.extend({
this.cancel();
break;
case 13: // Enter
this.success(event);
this.success();
break;
}
},

cancel: function(){
close: function(){
this.$el.one(this.transEndEventName, this.destroy).addClass('hidden');

if(this.clickCatcher)
Expand Down
2 changes: 1 addition & 1 deletion app/views/templates/dialog.eco
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<p class="text"><%= @text %></p>
<div class="buttons clearfix">
<button class="ok firstChoice"><%= @verb %></button>
<button class="cancel"><%= @cancel %></button>
<button class="cancel"><%= @cancelVerb %></button>
</div>
</div>

0 comments on commit a96ee32

Please sign in to comment.