112 lines
3.7 KiB
JavaScript
Raw Normal View History

2014-03-29 17:10:52 -03:00
var BootstrapDialog = new Class({
2014-05-16 00:27:57 -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,
2014-04-19 16:25:28 -03:00
removeButton:false,
errorMessage: false,
onEventData:{}
2014-03-29 17:10:52 -03:00
},
2014-04-03 22:39:23 -03:00
initialize: function (title, options) {
this.setOptions(options);
this.options.onEventData.dialog = this;
this._native = $('<div class="modal fade" tabindex="-1"></div>').append('<div class="modal-dialog"></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);
}
var body = $('<div class="modal-body"></div>');
if(this.options.errorMessage){
var error = $('<div class="alert alert-danger"></div>');
error.hide();
body.append(error);
}
content.append(body);
2014-04-03 22:39:23 -03:00
var footer = this._buildFooter();
if (footer) {
content.append(footer);
}
2014-04-03 22:56:11 -03:00
this._native.find(".modal-dialog").append(content);
this._native.on('hidden.bs.modal', function() {
$(this).remove();
});
this._native.on('shown.bs.modal', this.onDialogShown);
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.unbind('click').on("click",this.options.onEventData, 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', this.options.onEventData, this.onRemoveClick);
2014-04-18 17:12:36 -03:00
}
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) {
2014-04-19 16:25:28 -03:00
header.append('<h2 class="modal-title">' + title + '</h2>');
2014-04-03 22:39:23 -03:00
}
return header;
},
2014-04-12 15:11:39 -03:00
onAcceptClick: function(event) {
throw "Unsupported operation";
2014-04-12 15:11:39 -03:00
},
2014-04-03 22:39:23 -03:00
onDialogShown: function() {},
2014-04-18 17:12:36 -03:00
onRemoveClick: function(event) {
throw "Unsupported operation";
2014-04-18 17:12:36 -03:00
},
2014-04-03 22:39:23 -03:00
show: function () {
this._native.modal();
},
setContent: function(content) {
var modalBody = this._native.find('.modal-body');
modalBody.append(content);
2014-04-03 22:39:23 -03:00
},
css: function(options){
2014-04-19 16:25:28 -03:00
this._native.find('.modal-dialog').css(options);
2014-04-18 17:54:24 -03:00
},
2014-04-03 22:39:23 -03:00
close: function() {
this._native.modal('hide');
2014-04-18 17:12:36 -03:00
},
alertError: function(message){
this._native.find('.alert-danger').text(message);
this._native.find('.alert-danger').show();
},
cleanError: function(){
this._native.find('.alert-danger').hide();
2014-03-29 17:10:52 -03:00
}
});