From b4fa3cd44d7b6827ca385f60e72d4f7798a3e02f Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 24 Feb 2013 17:47:51 +0100 Subject: added confirm dialogs --- module/web/static/js/views/abstract/modalView.js | 31 +++++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'module/web/static/js/views/abstract') diff --git a/module/web/static/js/views/abstract/modalView.js b/module/web/static/js/views/abstract/modalView.js index 56c060a42..e0542d552 100644 --- a/module/web/static/js/views/abstract/modalView.js +++ b/module/web/static/js/views/abstract/modalView.js @@ -3,6 +3,7 @@ define(['jquery', 'backbone', 'underscore', 'omniwindow'], function($, Backbone, return Backbone.View.extend({ events: { + 'click .btn-confirm': 'confirm', 'click .btn-close': 'hide', 'click .close': 'hide' }, @@ -10,12 +11,22 @@ define(['jquery', 'backbone', 'underscore', 'omniwindow'], function($, Backbone, template: null, dialog: null, - initialize: function() { + onHideDestroy: false, + confirmCallback: null, + + initialize: function(template, confirm) { + this.confirmCallback = confirm; var self = this; if (this.template === null) { - require(['text!tpl/default/modal.html'], function(template) { - self.template = template; - }); + if (template) { + this.template = template; + // When template was provided this is a temporary dialog + this.onHideDestroy = true; + } + else + require(['text!tpl/default/modal.html'], function(template) { + self.template = template; + }); } }, @@ -26,6 +37,8 @@ define(['jquery', 'backbone', 'underscore', 'omniwindow'], function($, Backbone, this.$el.css({opacity: 0, scale: 0.7}); $("body").append(this.el); + var self = this; + this.dialog = this.$el.omniWindow({ overlay: { selector: '#modal-overlay', @@ -34,6 +47,8 @@ define(['jquery', 'backbone', 'underscore', 'omniwindow'], function($, Backbone, hide: function(subjects, internalCallback) { subjects.overlay.transition({opacity: 'hide', delay: 100}, 300, function() { internalCallback(subjects); + if (self.onHideDestroy) + self.destroy(); }); }, show: function(subjects, internalCallback) { @@ -74,9 +89,17 @@ define(['jquery', 'backbone', 'underscore', 'omniwindow'], function($, Backbone, this.dialog.trigger('hide'); }, + confirm: function() { + if (this.confirmCallback) + this.confirmCallback.apply(); + + this.hide(); + }, + destroy: function() { this.$el.remove(); this.dialog = null; + this.remove(); } }); -- cgit v1.2.3