function console_log() {
// attempt to send a message to the console
try {
for(var i =0; i < arguments.length; i++) {
console.log(arguments[i]);
}
} catch(e) {} // fail gracefully if it does not exist
}
function form_branding_delete(plan, rsid, formid) {
if (!plan && !rsid ) {
alert(strFormUpgrade);
} else {
form_part_delete("branding",formid);
}
}
function jump(url) {
ac_loader_show();
window.location = url;
}
/*
CLONER FUNCTIONS
*/
function clone_1st_element(node, elem, clearInputs) {
return ac_dom_clone_node(node, elem, 0, clearInputs);
}
function clone_1st_div(node) {
return clone_1st_element(node, 'div', true);
}
function clone_1st_tr(node) {
return clone_1st_element(node, 'tr', false);
}
function clear_inputs(node) {
$J('input', node).each(function(i) {
var o = $J(this);
var t = o.attr('type');
if (t == 'text' || t == 'file') o.val('');
});
}
function clear_selects(node) {
$J('select', node).each(function(i) {
this.selectedIndex = -1;
});
}
function clear_areas(node) {
$J('textarea', node).html('');
}
function remove_element(node) {
var me = $J(node);
var dad = me.parent();
if ( $J("> div", dad).length > 1 ) {
me.remove();
} else {
clear_inputs(node);
clear_selects(node);
clear_areas(node);
}
}
/*
CLONER END
*/
function preview_template(id, isBasic) {
if ( !isBasic ) {
var preview_url = plink + '/template/' + id + '/preview_dual';
} else {
var preview_url = plink + '/admin/preview_dual.php?t=' + id;
}
window.open(preview_url ,'preview','height=812,width=1250,menubar=no,location=no,resizable=yes,scrollbars=no,status=yes');
}
function toggleEditor(id, action, settings) {
if ( action == ac_editor_is(id + 'Editor') ) return false;
ac_editor_toggle(id + 'Editor', settings);
$J('#' + id + 'EditorLinkOn').toggleClass("currenttab", action).toggleClass("othertab", !action);
$J('#' + id + 'EditorLinkOff').toggleClass("currenttab", !action).toggleClass("othertab", action);
$J('#' + id + 'EditorLinkDefault').toggle( action != ( ac_js_admin.htmleditor == 1 ) );
return false;
}
function setDefaultEditor(id) {
var isEditor = ac_editor_is(id + 'Editor');
if ( isEditor == ( ac_js_admin.htmleditor == 1 ) ) return false;
// send save command
// save new admin limit remotelly
ac.get("user.user_update_value", ['htmleditor', ( isEditor ? 1 : 0 )]);
$J('#' + id + 'EditorLinkDefault').toggle();
ac_js_admin.htmleditor = ( isEditor ? 1 : 0 );
return false;
}
function form_editor_personalization_push(nodes, id) {
for (var i = 0; i < nodes.length; i++)
$J('#' + id).append(nodes[i]);
}
function form_editor_insert(field, value) {
// only today tag should be reset
if ( value.match( /^%TODAY[+-]\d+%$/ ) ) {
value = '%TODAY*%';
}
if ( value == '%TODAY*%' ) {
var entered = prompt(strEnterRange, '+1');
if ( !entered || !entered.match( /^[-+]?\d+$/ ) ) {
alert(strEnterRangeInvalid);
return '';
}
if ( !entered.match(/^[-+].*$/) ) {
entered = '+' + entered;
}
value = '%TODAY' + entered + '%';
}
ac_form_insert_cursor(field, value);
}
function form_editor_defaults(prfx, format, sets) {
$J('#' + prfx + 'textField').val('');
$J('#' + prfx + 'formatField').val(format);
ac_form_value_set($J('#' + prfx + 'Editor').get(0), '');
// show appropriate editor
ac_editor_mime_switch(prfx, $J('#' + prfx + 'formatField').val());
}
function form_editor_update(prfx, ary, suffix) {
if ( typeof suffix != 'string' ) suffix = 'PersTags';
if(ary.format) $J('#' + prfx + 'formatField').val(ary.format);
$J('#' + prfx + 'textField').val(ary.text);
ac_form_value_set($J('#' + prfx + 'Editor').get(0), ary.html);
// show appropriate editor
ac_editor_mime_switch(prfx, $J('#' + prfx + 'formatField').val());
}
function export_link_build(context, ary) {
var link = 'export.php?action=' + context;
for ( var i in ary ) {
link += '&' + i + '=' + ary[i];
}
if ( typeof(ourflag) == 'undefined' || prompt('Go to this export URL?', link) )
window.location.href = link;
}
var listfilters = {};
function list_filter(rnd) {
var post = ac_form_post($J("#" + "listfilter" + rnd).get(0));
listfilters[rnd] = post.listid;
ac.post("contact.subscriber_filter_post", {}, function(ary) {
list_filters_update(ary.filterid, post.listid, true);
});
}
function list_filters_update(filterid, listid, doContextFilters) {
for ( var rnd in listfilters ) {
if ( $J('#' + 'listFilterManager' + rnd).val(listid) ) {
$J('#' + 'listFilterManager' + rnd).val(listid);
listfilters[rnd] = listid;
}
}
if ( doContextFilters ) {
// try to change the list filter on this context page
if ( $J('#' + 'JSListManager').get(0) ) $J('#' + 'JSListManager').val(listid);
// try to run assign filterid based on context
/* try {
var v = eval(ac_action + "_list_filter = " + filterid + ";");
} catch (e) {
// do nothing, none found
}
*/ // try to run assign listid based on context
try {
var v = eval(ac_action + "_listfilter = " + listid + ";");
} catch (e) {
// do nothing, none found
}
// try to run a search function based on context
var func = null;
try {
var func = eval(ac_action + "_list_search");
} catch (e) {
// do nothing, none found
}
if ( typeof func == "function" ) {
func();
}
}
}
function parents_list_select(all, firstIsAll) {
if ( all ) {
ac_form_select_multiple_all($J('#parentsList').get(0), firstIsAll);
} else {
ac_form_select_multiple_none($J('#parentsList').get(0));
}
// campaign_new - only stuff
if ( $J('#step2next').get(0) ) {
// stop the scene until the call returns
$J('#step2next').prop('disabled', true);
$J('.lists-segment-container').hide();
}
return false;
}
function parents_box_select(all, firstIsAll) {
if (all) {
$J(".parentsList").attr("checked", true);
} else {
$J(".parentsList").attr("checked", false);
}
// campaign_new - only stuff
if ( $J('#step2next').get(0) ) {
campaign_step2_checknext();
// stop the scene until the call returns
$J('#step2next').prop("disabled", true);
$J('.lists-segment-container').hide();
}
return false;
}
/*
ACTIVE RSS
*/
function form_editor_activerss_open(type, insertObj) {
if ( !insertObj ) insertObj = '';
// set type
$J('#activerss4').val(type);
$J('#activerss2').val(insertObj);
// set data
$J('#activerssurl').val('http://');
$J('#activerssloop').val('10');
$J('#activerssall').attr("checked", true);
$J('#activersspreviewbox').modal("hide");
// open modal
$J('#message_activerss').modal("show");
}
function form_editor_activerss_insert() {
// build the code
var code = form_editor_activerss_build();
if ( code == '' ) return;
// push it into needed editor
ac_editor_insert($J('#activerss2').attr("value"), ( $J('#activerss4').attr("value") == 'html' ? nl2br(code) : code ));
// close the modal
$J('#message_activerss').modal("hide");
}
function form_editor_activerss_preview() {
// build the code
var code = form_editor_activerss_build();
if ( code == '' ) return;
if ( $J('#activerss4').attr("value") == 'html' ) code = nl2br(code);
// push it into preview box
$J('#activersspreview').val(code);
$J('#activersspreviewbox').toggle();
}
function form_editor_activerss_build() {
// what type of code to build
var type = $J('#activerss4').val();
// what url to fetch
var url = $J('#activerssurl').val();
if ( !ac_str_is_url(url) ) {
alert(strURLNotURL);
$J('#activerssurl').focus();
return '';
}
// how many to show
if ( !ac_ui_numbersonly($J('#activerssloop').get(0)) ) {
$J('#activerssloop').val(0);
}
var loop = $J('#activerssloop').val();
// what to show
var show = ( $J('#activerssnew').prop("checked") ? 'NEW' : 'ALL' ); // ALL/NEW
// what are line breaks
var nl = ( type == 'html' ? '
\n' : '\n' );
var code =
'%RSS-FEED|URL:' + url + '|SHOW:' + show + '%\n\n' + // start feed section
'%RSS:CHANNEL:TITLE%\n\n' + // print out title
'%RSS-LOOP|LIMIT:' + loop + '%\n\n' + // start item section
'%RSS:ITEM:DATE%\n' + // within a section
'%RSS:ITEM:TITLE%\n' +
'%RSS:ITEM:SUMMARY%\n' +
'%RSS:ITEM:LINK%\n\n' +
'%RSS-LOOP%\n\n' +
'%RSS-FEED%\n' // end section
;
return code;
}
function ac_editor_activerss_click() {
form_editor_activerss_open('html');
}
function form_editor_activerss_loop_changed() {
window.setTimeout(
function() {
ac_ui_numbersonly($J('#activerssloop').get(0), true);
},
100
);
}
/*
PERSONALIZATION TAGS
*/
// global
function perstag_openmodal(target) {
$J('#smtoggle').hide();
$J('#apps li').removeClass('inactive');
$J('#surveymonkey_tag').removeClass('active');
$J('#tabs li a:first').click();
if ($J('.cke_inner').is(':visible')) {
$J('.cke_inner').hide();
}
$J("#personalize")
.data("target", target)
.modal("show");
};
function perstag_insert(target, perstag) {
if ( perstag == '' ) {
return;
}
var use_designer = typeof designer != 'undefined' && typeof designer.inlineCommand != 'undefined';
var use_ace = typeof ace_editor != 'undefined' && typeof ace_editor.insert != 'undefined';
var textonly = typeof tinyMCE == 'undefined' && typeof CKEDITOR == 'undefined' && !use_designer;
var code = perstag_build(perstag, textonly);
// clear any setTimeouts running. (one is used for SurveyMonkey integration)
ac.stop("campaign_service_get");
if (use_designer) {
if (ac.browser.isIE()) {
//"insertHTML" command is not supported by IE (grrr). So we have to do something different here.
var sel = document.getSelection();
range = sel.getRangeAt(0);
range.deleteContents();
var el = document.createElement("div");
el.innerHTML = code;
el.style.display = "inline";
range.insertNode(el);
// Place cursor at end of pasted content
//element.focus();
//range.selectNodeContents(lastNode);
range.collapse(false);
sel.removeAllRanges();
sel.addRange(range);
} else {
designer.inlineCommand('insertHTML', code);
}
} else if (use_ace && $J("#tmpsource").is(":visible")) {
ace_editor.insert(code);
} else {
if ( !textonly ) code = nl2br(code);
ac_editor_insert(target, code);
}
$J("#personalize").modal("hide");
};
function perstag_build(val, textonly) {
var text = '';
// only today tag should be reset
if ( val.match( /^%TODAY[+-]\d+%$/ ) ) {
val = '%TODAY*%';
}
if ( val.match( /^SERVICE-SURVEYMONKEY/ ) ) {
var split_value = val.split("||"); // IE: survey_url_id + "||" + survey.title
var link_href = "%SERVICE-SURVEYMONKEY-" + split_value[1] + "%";
text = strSurveyText + ": " + split_value[2];
entered = prompt(strEnterText, text) || ''; // Coerce null to blank string if user cancels
if ( entered.trim() === '' ) {
entered = text;
}
if ( textonly ) {
val = entered + ' (' + strSurveyText2 + ': ' + split_value[2] + ' -- ' + link_href + ')';
} else {
val = '' + entered + '';
}
return val;
}
if ( val == '%CONFIRMLINK%' ) {
text = strConfirmLinkText;
} else if ( val == '%UNSUBSCRIBELINK%&ALL' ) {
text = strUnsubscribeAllText;
} else if ( val == '%UNSUBSCRIBELINK%' ) {
text = strUnsubscribeText;
} else if ( val == '%UPDATELINK%' ) {
text = strSubscriberUpdateText;
} else if ( val == '%WEBCOPY%' || val == '%WEBCOPY-NOSOCIAL%' ) {
text = strWebCopyText;
} else if ( val == '%FORWARD2FRIEND%' ) {
text = strForward2FriendText;
} else if ( val == '%SOCIALSHARE%' ) {
//text = strForward2FriendText; // don't prompt for anything, just use val
} else if ( val == '%TODAY*%' ) {
var entered = prompt(strEnterRange, '+1');
if ( !entered ) return;
if ( !entered.match( /^[-+]?\d+$/ ) ) {
alert(strEnterRangeInvalid);
return;
}
if ( !entered.match(/^[-+].*$/) ) {
entered = '+' + entered;
}
val = '%TODAY' + entered + '%';
}
if ( text !== '' ) {
entered = prompt(strEnterText, text) || ''; // Coerce null to blank string if user cancels
if ( entered.trim() === '' ) {
entered = text;
}
if ( textonly ) {
val = entered + ' <' + val + '>';
} else {
val = '' + entered + '';
}
}
return val;
}
// Campaign Personalization
function campaign_personalization_open(editor) {
perstag_openmodal(editor);
}
function campaign_personalization_insert(value, editor) {
perstag_insert(editor, value);
}
// general personalize open
function form_editor_personalize_open(type, insertObj) {
if ( !insertObj ) insertObj = '';
// set type
$J('#personalize4').val(type);
$J('#personalize2').val(insertObj);
// open modal
$J('#message_personalize').toggle();
}
function form_editor_personalize_insert(value) {
if ( value == '' ) {
alert(strPersMissing);
return;
}
// close the modal
$J('#message_personalize').toggle();
// build the code
var code = form_editor_personalize_build(value);
if ( code == '' ) return;
// push it into needed editor
ac_editor_insert($J('#personalize2').attr("value"), ( $J('#personalize4').attr("value") == 'html' ? nl2br(code) : code ));
}
function form_editor_personalize_build(val) {
// what type of code to build
var type = $J('#personalize4').attr("value");
// now handle custom (html?) cases
var text = '';
// only today tag should be reset
if ( val.match( /^%TODAY[+-]\d+%$/ ) ) {
val = '%TODAY*%';
}
if ( val == '%CONFIRMLINK%' ) {
text = strConfirmLinkText;
} else if ( val == '%UNSUBSCRIBELINK%' ) {
text = strUnsubscribeText;
} else if ( val == '%UPDATELINK%' ) {
text = strSubscriberUpdateText;
} else if ( val == '%WEBCOPY%' ) {
text = strWebCopyText;
} else if ( val == '%FORWARD2FRIEND%' ) {
text = strForward2FriendText;
} else if ( val == '%SOCIALSHARE%' ) {
//text = strForward2FriendText; // don't prompt for anything, just use val
} else if ( val == '%TODAY*%' ) {
var entered = prompt(strEnterRange, '+1');
if ( !entered ) return;
if ( !entered.match( /^[-+]?\d+$/ ) ) {
alert(strEnterRangeInvalid);
return;
}
if ( !entered.match(/^[-+].*$/) ) {
entered = '+' + entered;
}
val = '%TODAY' + entered + '%';
}
if ( type === 'html' && text !== '' ) {
entered = prompt(strEnterText, text) || ''; // Coerce null to blank string if user cancels
if ( entered.trim() === '' ) {
entered = text
}
val = '' + entered + '';
}
return val;
}
function ac_editor_personalize_click() {
var ed = tinyMCE.activeEditor;
//tinyMCE.activeEditor.execCommand('mceInsertContent', false, form_editor_personalize_build());
form_editor_personalize_open('html');
}
/*
CONDITIONAL CONTENT
*/
function conditional_open(keyval) {
// reset first
$J("#cond_widget div.filtercontainer ul.filterblock:gt(0)").remove(); // remove all nodes but first
$J("#cond_widget input[name=value]").val(''); // clear out all inputs
$J("#cond_widget select[name=type]").val('and'); // set condition type to default "and"
$J("#cond_remove").hide(); // hide the "remove conditions" option
//var selects = $J("#cond_widget select");
if ( keyval ) {
$J("#cond_widget select[name=type]").val(keyval.type);
$J("#cond_remove").show();
for ( var i in keyval.conds ) {
var c = keyval.conds[i];
var obj = $J("#cond_widget div.filtercontainer ul.filterblock");
var operator = $J("select[name=operator]", obj).val();
if ( i > 0 ) {
// copy the node first
var node = obj.first().clone().insertAfter(obj.last());
} else {
var node = obj.first();
}
$J("select[name=field]", node).val(c.field).change();
$J("select[name=operator]", node).val(c.operator).change();
$J("input[name=value]", node).val(c.value);
if (c.field.match(/^%PLUS/)) {
var opt = $J(sprintf("option[value='%s']", c.field), node);
var plusin = designer.mv_plus_in[opt.data("internal-name")];
var html = '';
for (var i in plusin) {
if (plusin[i] == "") {
continue;
}
html += sprintf('', i, plusin[i]);
}
$J("select[name=value_select]", node).html(html).show();
$J("select[name=operator]", node).hide();
$J("input[name=value]", node).hide();
$J("select[name=value_select]", node).val(c.value);
} else if (c.field.match(/^%TAG/)) {
$J("select[name=value_select]", node).hide();
$J("select[name=operator]", node).hide();
$J("input[name=value]", node).show();
}
// ensure the value field is hidden when exists or not exist operator is selected
if (operator.match(/(?=.*VALUE-DOES)(?=.*EXIST).*/ig)) {
$J("input[name=value]", node).attr('disabled', true).addClass('disabled').hide();
} else {
$J("input[name=value]", node).attr('disabled', false).removeClass('disabled').show();
}
}
}
$J("#cond_widget").modal("show");
}
function conditional_insert(target) {
// if in designer, use designer's save func
if ( typeof designer != 'undefined' && designer.widget ) {
designer.widget.conditional_save();
return;
}
if(typeof target == "undefined") {
target = "messageEditor";
}
if (typeof campaign_obj == "undefined") {
var textonly = $J('#' + target).hasClass("text-messageEditor");
} else {
var textonly = ( campaign_is_text_based || $J('#' + target).hasClass("text-messageEditor") );
}
var conds = $J("#cond_widget div.filtercontainer ul.filterblock");
var type = $J("#cond_widget select[name=type]").val();
var ifs = [];
for ( var i = 0; i < conds.length; i++ ) {
var field = $J("select[name=field]", conds[i]).val();
var op = $J("select[name=operator]", conds[i]).val();
var val = $J("input[name=value]", conds[i]).val();
var field_type = "";
if ( typeof($J("select[name=field] option:selected", conds[i]).data('type')) != "undefined" ) {
field_type = $J("select[name=field] option:selected", conds[i]).data('type');
}
field = '$' + field.replace(/%/g, '').replace(/-/g, '_');
val = val.replace(/%/g, '~PERCENT~');
var orig_val = val;
val = "'" + val.replace(/'/g, '\\\'') + "'";
if ( op.indexOf('CONTAINS') != -1 ) {
var expr = 'in_string(' + val + ', ' + field + ')';
if ( op == 'DCONTAINS' ) expr = '!' + expr;
} else if (field == "$TAG_EXISTS") {
var expr = 'in_array(' + val + ', $TAGS)';
} else if (field == "$TAG_DOESNT_EXIST") {
var expr = '!in_array(' + val + ', $TAGS)';
} else if ( field_type == 'checkbox' || field_type == 'listbox' ) {
var expr = field + " " + op + " '||" + orig_val + "||'";
} else if (op === 'VALUE-DOES-EXIST' || op === 'VALUE-DOESNT-EXIST') {
expr = '!empty(' + field + ')';
if (op === 'VALUE-DOESNT-EXIST') {
expr = 'empty(' + field + ')';
}
} else {
var expr = field + ' ' + op + ' ' + val;
}
ifs.push(expr);
}
var conn = type == 'and' ? ' && ' : ' || ';
if ( !textonly ) {
var code =
'%IF ' + ifs.join(conn) + '%
\n' + editorConditionalText + '
\n%ELSE%
\n' + editorConditionalElseText + '
\n%/IF%
\n'
;
} else {
var code =
'%IF ' + ifs.join(conn) + '%\n' + editorConditionalText + '\n%ELSE%\n' + editorConditionalElseText + '\n%/IF%\n'
;
}
//if ( textonly ) code = nl2br(code);
// push it into needed editor
ac_editor_insert(target, code);
$J("#cond_widget").modal("hide");
}
function conditional_remove() {
return designer.widget.conditional_remove();
}
// Conditional
function campaign_conditional_open() {
var keyval = false;
conditional_open(keyval);
$J('#cond_save').html(jsInsert);
$J('#cond_remove').hide();
}
function campaign_conditional_insert() {
conditional_insert();
}
/*
TEMPLATES
*/
function form_editor_template_open(type, insertObj) {
if ( !insertObj ) insertObj = '';
// set type
$J('#editortemplate2').val(insertObj);
$J('#editortemplate4').val(type);
// set data
$J('#templateinsert').val(0);
$J('#editortemplatebutton').attr("disabled", true);
$J('#templateinsert').val(0);
// switch the template type
if(type == "html") {
$J('#templateinserthtml').show();
$J('#templateinserttext').hide();
} else if(type == "text") {
$J('#templateinserthtml').hide();
$J('#templateinserttext').show();
}
// open modal
$J('#message_template').modal("show");
}
function main_search(text) {
if (text != '') {
window.location.href = ac_js_site.p_link + sprintf('/app/contacts/?q=%s', text);
}
}
function help_search(text) {
if ( ac_str_trim(text) == '' ) return;
window.location.href = sprintf(help_search_url, text);
}
function status_click(statusid) {
ac.get("status.status_clicked", [statusid], function(data) {
if ( !data.tstamp_clicked ) {
status_decrement();
}
});
}
function status_decrement() {
var oldcnt = parseInt($J('#statuses_count').html(), 10);
if ( isNaN(oldcnt) ) return;
var newcnt = oldcnt - 1;
$J('#statuses_count').html(newcnt);
if ( newcnt == 0 ) $J('#statuses_count').remove();
}
function status_remove(statusid) {
ac.get("status.status_removed", [statusid], function(data) {
if ( !data.tstamp_clicked ) {
status_decrement();
}
$J('#status_row_' + data.id).remove();
var oldcnt = parseInt($J(".avatar .statuses_count").html(), 10);
if ( !oldcnt ) return;
var newcnt = oldcnt - 1;
$J(".avatar .statuses_count").html(newcnt);
$J(".ac-account-dropdown-alerts .ac_count").html(newcnt);
if ( !newcnt ) {
$J("#statusesModal").modal('hide');
$J(".ac-account-dropdown-alerts").remove();
$J(".avatar .statuses_count").remove();
$J(".actmenu_nav").css('paddingLeft', '12px');
}
});
return false;
}
function form_list_addmodal() {
$J("#form_list_addmodal_div").modal('show');
}
function form_add() {
if ($J("#add_name").val() == "") {
alert(strFormNameMissing);
return false;
}
if (!$J('#add_list').val()) {
alert(strFormListMissing);
return false;
}
window.location.href = sprintf("%s/admin/main.php?action=form_edit&new=1&listid=%s&name=%s", plink, $J("#add_list").val(), encodeURIComponent($J("#add_name").val()));
}
function form_tab_highlight(tabs, listid) {
// tabs looks like: ["sub", 0]. 0 is the