Skip to content

Instantly share code, notes, and snippets.

@marshall007
Created January 31, 2012 15:22
Show Gist options
  • Select an option

  • Save marshall007/1711042 to your computer and use it in GitHub Desktop.

Select an option

Save marshall007/1711042 to your computer and use it in GitHub Desktop.
ProductPicker Error Dialogue
ProductPicker.Error = function (opts) {
// private data
var self = {};
var defaults = {
target: $('#ppAlert'),
severity: $('#ppAlertSeverity'),
message: $('#ppAlertMessage'),
error: {
header: 'Alert',
message: 'An error has occured.',
buttons: ['close', 'help'],
blink: true,
callbackFn: function () { console.log('default'); }
},
bindings: {
'#ppAlert': {
'click div.wrap': 'blink'
},
'#ppAlertButtons': {
'click a.ok': 'close',
'click a.close': 'close',
'click a.help': 'getHelp'
}
}
};
self.opts = $.extend(true, defaults, opts || {});
// private methods
self.alert = function () {
self.opts.severity.text(self.opts.error.header);
self.opts.message.text(self.opts.error.message);
if ($.inArray('ok', self.opts.error.buttons))
$('#ppAlertButtons a.ok').show();
if ($.inArray('close', self.opts.error.buttons))
$('#ppAlertButtons a.close').show();
if ($.inArray('help', self.opts.error.buttons))
$('#ppAlertButtons a.help').show();
if (self.opts.error.blink)
self.blink();
self.opts.target.show();
};
self.blink = function () {
var i = 0;
var intervalid = setInterval(function () {
self.opts.target.toggleClass('blink');
if (i++ > 3) {
clearInterval(intervalid);
self.opts.target.removeClass('blink');
}
}, 100);
};
self.close = function (e) {
var button = false;
if (e) {
e.preventDefault();
e.stopPropagation();
if ($(this).hasClass('ok')) {
button = true;
}
}
$(self.opts.target).hide();
$(self.opts.severity).html('Alert');
$(self.opts.message).html('');
$('#ppAlertButtons a').hide();
self.opts.error.callbackFn(button);
};
// public interface to be exposed
return {
init: function () {
ProductPicker.Util.bindTooltips(self.opts.target);
ProductPicker.Util.bindEvents(self, self.opts.bindings);
},
show: self.alert,
close: self.close
};
};
ProductPicker.Error({
error: {
header: 'Warning',
message: 'You are about to remove all ' + itemGUIDs.length + ' products from the cart. Are you sure you want to continue?',
buttons: ['ok', 'close'],
blink: false,
callbackFn: function (result) {
if (result) {
console.log('ANYTHING BUT THE DEFAULT!!!');
}
}
}
}).show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment