-
Notifications
You must be signed in to change notification settings - Fork 2k
/
confirm-action.min.js
2 lines (2 loc) · 1.53 KB
/
confirm-action.min.js
1
2
this.ckan.module('confirm-action',function(jQuery,_){return{options:{i18n:{heading:_('Please Confirm Action'),content:_('Are you sure you want to perform this action?'),confirm:_('Confirm'),cancel:_('Cancel')},template:['<div class="modal">','<div class="modal-header">','<button type="button" class="close" data-dismiss="modal">×</button>','<h3></h3>','</div>','<div class="modal-body"></div>','<div class="modal-footer">','<button class="btn btn-cancel"></button>','<button class="btn btn-primary"></button>','</div>','</div>'].join('\n')},initialize:function(){jQuery.proxyAll(this,/_on/);this.el.on('click',this._onClick);},confirm:function(){this.sandbox.body.append(this.createModal());this.modal.modal('show');this.modal.css({'margin-top':this.modal.height()*-0.5,'top':'50%'});},performAction:function(){var form=jQuery('<form/>',{action:this.el.attr('href'),method:'POST'});form.appendTo('body').submit();},createModal:function(){if(!this.modal){var element=this.modal=jQuery(this.options.template);element.on('click','.btn-primary',this._onConfirmSuccess);element.on('click','.btn-cancel',this._onConfirmCancel);element.modal({show:false});element.find('h3').text(this.i18n('heading'));element.find('.modal-body').text(this.i18n('content'));element.find('.btn-primary').text(this.i18n('confirm'));element.find('.btn-cancel').text(this.i18n('cancel'));}
return this.modal;},_onClick:function(event){event.preventDefault();this.confirm();},_onConfirmSuccess:function(event){this.performAction();},_onConfirmCancel:function(event){this.modal.modal('hide');}};});