92 lines
2.9 KiB
JavaScript
Raw Normal View History

2014-03-29 17:10:52 -03:00
var BootstrapDialog = new Class({
2014-04-03 22:39:23 -03:00
Implements: Options,
2014-03-29 17:10:52 -03:00
2014-04-03 22:39:23 -03:00
options: {
cancelButton: false,
closeButton: false,
2014-04-18 17:12:36 -03:00
acceptButton: true,
removeButton:false
2014-03-29 17:10:52 -03:00
},
2014-04-03 22:39:23 -03:00
initialize: function (title, options) {
this.setOptions(options);
2014-04-18 17:12:36 -03:00
this._native = $('<div class="modal fade"></div>').append('<div class="modal-dialog" style="margin:150px auto"></div>');
2014-04-03 22:39:23 -03:00
var content = $('<div class="modal-content"></div>');
var header = this._buildHeader(title);
if (header) {
content.append(header);
}
content.append('<div class="modal-body"></div>');
var footer = this._buildFooter();
if (footer) {
content.append(footer);
}
2014-03-29 17:10:52 -03:00
2014-04-03 22:56:11 -03:00
this._native.find(".modal-dialog").append(content);
2014-03-29 17:10:52 -03:00
},
2014-04-03 22:39:23 -03:00
_buildFooter: function() {
var footer = null;
2014-04-18 17:12:36 -03:00
if (this.options.acceptButton || this.options.removeButton || this.options.cancelButton) {
footer = $('<div class="modal-footer" style="paddingTop:5;textAlign:center">');
2014-04-03 22:39:23 -03:00
}
2014-04-18 17:12:36 -03:00
if (this.options.acceptButton) {
2014-04-12 15:11:39 -03:00
this.acceptButton = $('<button type="button" class="btn btn-primary" id="acceptBtn" data-dismiss="modal">'+ $msg('ACCEPT') + '</button>');
footer.append(this.acceptButton);
this.acceptButton.on('click', this.onAcceptClick)
2014-04-03 22:39:23 -03:00
}
2014-04-18 17:12:36 -03:00
if (this.options.removeButton) {
this.removeButton = $('<button type="button" class="btn btn-secondary" id="removeBtn" data-dismiss="modal">'+ $msg('REMOVE') +'</button>');
footer.append(this.removeButton);
this.removeButton.on('click', {data:'hola'}, this.onRemoveClick);
this.removeButton.hide();
}
2014-04-03 22:39:23 -03:00
if (this.options.cancelButton) {
2014-04-10 19:33:48 -03:00
footer.append('<button type="button" class="btn btn-secondary" data-dismiss="modal">'+ $msg('CANCEL') +'</button>');
2014-04-03 22:39:23 -03:00
}
return footer;
},
_buildHeader: function(title) {
var header = null;
if (this.options.closeButton || title) {
header = $('<div class="modal-header"></div>');
}
if (this.options.closeButton) {
header.append(
'<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>'
);
}
if (title) {
header.append('<h3 class="modal-title">' + title + '</h3>');
}
return header;
},
2014-04-12 15:11:39 -03:00
onAcceptClick: function(event) {
//this method should be abstract
},
2014-04-03 22:39:23 -03:00
2014-04-18 17:12:36 -03:00
onRemoveClick: function(event) {
//this method should be abstract
},
2014-04-03 22:39:23 -03:00
show: function () {
this._native.modal();
},
setContent: function(content) {
// faltaria remover body previo
this._native.find('.modal-body').append(content);
},
close: function() {
this._native.modal('hide');
2014-04-18 17:12:36 -03:00
},
showRemoveButton: function(){
this.removeButton.show();
2014-03-29 17:10:52 -03:00
}
});