}
}
+var submitcount = 0;
/**
- * Function to change button text and disable one it is clicked
+ * Old submit-once function. Will be removed soon.
* @deprecated
- * @param obj object - the button clicked
- * @param formID string - the id of the form being submitted
- * @param string procText - button text after user clicks it
- * @return bool
*/
-var submitcount = 0;
-/* Changes button label on submit, and disables button after submit for newer browsers.
- Puts up alert for older browsers. */
function submitOnce(obj, formId, procText) {
// if named button clicked, change text
if (obj.value != null) {
});
};
+ // Submit-once
+ var submitted = [],
+ submitButton;
+ function submitOnceForm(e) {
+ if (e.isDefaultPrevented()) {
+ return;
+ }
+ if (_.contains(submitted, e.target)) {
+ return false;
+ }
+ submitted.push(e.target);
+ // Spin submit button icon
+ if (submitButton && $(submitButton, e.target).length) {
+ // Dialog button
+ if ($(e.target).closest('.ui-dialog .crm-ajax-container')) {
+ var identifier = $(submitButton).attr('name') || $(submitButton).attr('href');
+ if (identifier) {
+ submitButton = $(e.target).closest('.ui-dialog').find('button[data-identifier="' + identifier + '"]')[0] || submitButton;
+ }
+ }
+ var $icon = $(submitButton).siblings('.crm-i').add('.crm-i, .ui-icon', submitButton);
+ $icon.data('origClass', $icon.attr('class')).removeClass().addClass('crm-i crm-submit-icon fa-spinner fa-pulse');
+ }
+ }
+
+ // If form fails validation, restore button icon and reset the submitted array
+ function submitFormInvalid(form) {
+ submitted = [];
+ $('.crm-i.crm-submit-icon').each(function() {
+ if ($(this).data('origClass')) {
+ $(this).removeClass().addClass($(this).data('origClass'));
+ }
+ });
+ }
+
// Initialize widgets
$(document)
.on('crmLoad', function(e) {
CRM.wysiwyg.create(this);
}
});
+ // Submit once handlers
+ $('form[data-submit-once]', e.target)
+ .submit(submitOnceForm)
+ .on('invalid-form', submitFormInvalid);
+ $('form[data-submit-once] input[type=submit]', e.target).click(function(e) {
+ submitButton = e.target;
+ });
})
.on('dialogopen', function(e) {
var $el = $(e.target);
return (yiq >= 128) ? 'black' : 'white';
};
+ // based on https://github.com/janl/mustache.js/blob/master/mustache.js
+ // If you feel the need to use this function, consider whether assembling HTML
+ // via DOM might be a cleaner approach rather than using string concatenation.
+ CRM.utils.escapeHtml = function(string) {
+ var entityMap = {
+ '&': '&',
+ '<': '<',
+ '>': '>',
+ '"': '"',
+ "'": ''',
+ '/': '/',
+ '`': '`',
+ '=': '='
+ };
+ return String(string).replace(/[&<>"'`=\/]/g, function fromEntityMap (s) {
+ return entityMap[s];
+ });
+ }
+
// CVE-2015-9251 - Prevent auto-execution of scripts when no explicit dataType was provided
$.ajaxPrefilter(function(s) {
if (s.crossDomain) {