+ // CRM-14353 - Warn of unsaved changes for all forms except those which have opted out
+ function cancelAction() {
+ var dirty = CRM.utils.initialValueChanged($('form:not([data-warn-changes=false])', widget));
+ widget
+ .attr('data-unsaved-changes', dirty ? 'true' : 'false')
+ .dialog('close');
+ if (dirty) {
+ var id = widget.attr('id') + '-unsaved-alert',
+ title = widget.dialog('option', 'title'),
+ alert = CRM.alert('<p>' + ts('%1 has not been saved.', {1: title}) + '</p><p><a href="#" id="' + id + '">' + ts('Restore') + '</a></p>', ts('Unsaved Changes'), 'alert unsaved-dialog', {expires: 60000});
+ $('#' + id).button({icons: {primary: 'ui-icon-arrowreturnthick-1-w'}}).click(function(e) {
+ widget.attr('data-unsaved-changes', 'false').dialog('open');
+ e.preventDefault();
+ });
+ }
+ }
+ if (widget.data('uiDialog')) {
+ // CRM-14353 - This is a bit harsh but we are removing jQuery UI's event handler from the close button and adding our own
+ widget.parent().find('.ui-dialog-titlebar-close').first().off().click(cancelAction);
+ }
+