*/
function on_load_init_blocks(showBlocks, hideBlocks, elementType) {
if (elementType == null) {
- var elementType = 'block';
+ elementType = 'block';
}
+ var myElement, i;
+
/* This loop is used to display the blocks whose IDs are present within the showBlocks array */
- for (var i = 0; i < showBlocks.length; i++) {
- var myElement = document.getElementById(showBlocks[i]);
+ for (i = 0; i < showBlocks.length; i++) {
+ myElement = document.getElementById(showBlocks[i]);
/* getElementById returns null if element id doesn't exist in the document */
if (myElement != null) {
myElement.style.display = elementType;
}
/* This loop is used to hide the blocks whose IDs are present within the hideBlocks array */
- for (var i = 0; i < hideBlocks.length; i++) {
- var myElement = document.getElementById(hideBlocks[i]);
+ for (i = 0; i < hideBlocks.length; i++) {
+ myElement = document.getElementById(hideBlocks[i]);
/* getElementById returns null if element id doesn't exist in the document */
if (myElement != null) {
myElement.style.display = 'none';
* @param invert Boolean - if true, we HIDE target on value match; if false, we SHOW target on value match
*/
function showHideByValue(trigger_field_id, trigger_value, target_element_id, target_element_type, field_type, invert) {
+ var target, j;
if (field_type == 'select') {
var trigger = trigger_value.split("|");
var selectedOptionValue = cj('#' + trigger_field_id).val();
- var target = target_element_id.split("|");
- for (var j = 0; j < target.length; j++) {
+ target = target_element_id.split("|");
+ for (j = 0; j < target.length; j++) {
if (invert) {
cj('#' + target[j]).show();
}
}
else {
if (field_type == 'radio') {
- var target = target_element_id.split("|");
- for (var j = 0; j < target.length; j++) {
+ target = target_element_id.split("|");
+ for (j = 0; j < target.length; j++) {
if (cj('[name="' + trigger_field_id + '"]:first').is(':checked')) {
if (invert) {
cj('#' + target[j]).hide();
if (endMsg) {
$msg.removeClass('status-start').addClass('status-' + status).find('.crm-status-box-msg').html(endMsg);
window.setTimeout(function() {
- $msg.fadeOut('slow', function() {$msg.remove()});
+ $msg.fadeOut('slow', function() {
+ $msg.remove();
+ });
}, 2000);
} else {
$msg.remove();
var ele = $(this);
setTimeout(function () {
ele.one('change', function () {
- msg && msg.close && msg.close();
+ if (msg && msg.close) msg.close();
ele.removeClass('error');
label.removeClass('crm-error');
});
if (typeof(response.crmMessages) == 'object') {
$.each(response.crmMessages, function(n, msg) {
CRM.alert(msg.text, msg.title, msg.type, msg.options);
- })
+ });
}
if (response.backtrace) {
CRM.console('log', response.backtrace);
var tplURL;
CRM.url = function (path, query, mode) {
if (typeof path === 'object') {
- return tplURL = path;
+ tplURL = path;
+ return path;
}
if (!tplURL) {
CRM.console('error', 'Error: CRM.url called before initialization');
},
_onFailure: function(data, status) {
var msg, title = ts('Network Error');
- this.options.block && this.element.unblock();
+ if (this.options.block) this.element.unblock();
this.element.trigger('crmAjaxFail', data);
switch (status) {
case 'Forbidden':
_handleOrderLinks: function() {
var that = this;
$('a.crm-weight-arrow', that.element).click(function(e) {
- that.options.block && that.element.block();
+ if (that.options.block) that.element.block();
$.getJSON(that._formatUrl(this.href)).done(function() {
that.refresh();
});
refresh: function() {
var that = this;
var url = this._formatUrl(this.options.url);
- this.options.crmForm && $('form', this.element).ajaxFormUnbind();
+ if (this.options.crmForm) $('form', this.element).ajaxFormUnbind();
if (this._originalContent === null) {
this._originalContent = this.element.contents().detach();
}
- this.options.block && this.element.block();
+ if (this.options.block) this.element.block();
$.getJSON(url, function(data) {
- that.options.block && that.element.unblock();
+ if (that.options.block) that.element.unblock();
if (!$.isPlainObject(data)) {
that._onFailure(data);
return;
that.element.html(data.content);
that._handleOrderLinks();
that.element.trigger('crmLoad', data);
- that.options.crmForm && that.element.trigger('crmFormLoad', data);
+ if (that.options.crmForm) that.element.trigger('crmFormLoad', data);
}).fail(function(data, msg, status) {
that._onFailure(data, status);
});
}
});
}
- this.options.crmForm && $('form', this.element).ajaxFormUnbind();
+ if (this.options.crmForm) $('form', this.element).ajaxFormUnbind();
},
_destroy: function() {
this.element.removeClass('crm-ajax-container').trigger('crmUnload');
height: '75%'
};
}
- options && $.extend(true, settings, options);
+ if (options) $.extend(true, settings, options);
settings.url = url;
// Create new dialog
if (settings.dialog) {
}
};
// Move options that belong to crmForm. Others will be passed through to crmSnippet
- options && $.each(options, function(key, value) {
+ if (options) $.each(options, function(key, value) {
if (typeof(settings.crmForm[key]) !== 'undefined') {
settings.crmForm[key] = value;
}
}
}
- widget.data('uiDialog') && widget.on('dialogbeforeclose', function(e) {
+ if (widget.data('uiDialog')) widget.on('dialogbeforeclose', function(e) {
// CRM-14353 - Warn unsaved changes if user clicks close button or presses "esc"
if (e.originalEvent) {
cancelAction();
widget.on('crmFormLoad.crmForm', function(event, data) {
var $el = $(this).attr('data-unsaved-changes', 'false'),
settings = $el.crmSnippet('option', 'crmForm');
- settings.cancelButton && $(settings.cancelButton, this).click(function(e) {
+ if (settings.cancelButton) $(settings.cancelButton, this).click(function(e) {
e.preventDefault();
var returnVal = settings.onCancel.call($el, e);
if (returnVal !== false) {
}
}
else {
- $el.crmSnippet('option', 'block') && $el.unblock();
+ if ($el.crmSnippet('option', 'block')) $el.unblock();
response.url = data.url;
$el.html(response.content).trigger('crmLoad', response).trigger('crmFormLoad', response);
if (response.status === 'form_error') {
beforeSerialize: function(form, options) {
if (window.CKEDITOR && window.CKEDITOR.instances) {
$.each(CKEDITOR.instances, function() {
- this.updateElement && this.updateElement();
+ if (this.updateElement) this.updateElement();
});
}
if (window.tinyMCE && tinyMCE.editors) {
},
beforeSubmit: function(submission) {
$.each(formErrors, function() {
- this && this.close && this.close();
+ if (this && this.close) this.close();
});
- $el.crmSnippet('option', 'block') && $el.block();
+ if ($el.crmSnippet('option', 'block')) $el.block();
$el.trigger('crmFormSubmit', submission);
}
}, settings.ajaxForm));
if ($table.length && $.fn.DataTable.fnIsDataTable($table[0]) && $table.dataTable().fnSettings().sAjaxSource) {
// Refresh ALL datatables - needed for contact relationship tab
$.each($.fn.dataTable.fnTables(), function() {
- $(this).dataTable().fnSettings().sAjaxSource && $(this).unblock().dataTable().fnDraw();
+ if ($(this).dataTable().fnSettings().sAjaxSource) $(this).unblock().dataTable().fnDraw();
});
}
// Otherwise refresh the nearest crmSnippet