//Add Multiple Users by Happy Nuclear
//Multiadd Actions
//compiled for AMU version 1.2.2
jQuery(document).ready(function() {
//FADE OUT WORDPRESS MESSAGES
if (jQuery('#message')) {
jQuery('#message').delay(3000).slideUp();
}
//prevent pressing enter from triggering general options
jQuery('.amuform').bind("keypress", function(e) {
if (e.keyCode == 13) {
if (jQuery('.textfillbox').is(':focus')) {
//allow enter
} else {
//disallow enter
return false;
}
}
});
//add dynamic emailer button to customisation box for testing email
if (jQuery('.emailcustbox')) {
jQuery('').appendTo('.emailcustbox');
jQuery('
Test emails will be sent to your administrator email.
').appendTo('.emailcustbox');
}
jQuery('.formresetter').click(function() {
//remove coloring
jQuery('.fieldsetwrap input').removeClass('amuvalid amuerror amushort amubad amugood amustrong amumatchuser');
//reset tooltips
jQuery('.validatefield').each(function() {
var fid = jQuery(this).attr('id');
if (jQuery(this).hasClass('valusername')) {
jQuery('#'+fid+'_tip').html('Empty (row will be skipped).');
}
if (jQuery(this).hasClass('valpassword')) {
jQuery('#'+fid+'_tip').html('Empty (password will be generated).');
}
if (jQuery(this).hasClass('valemail')) {
jQuery('#'+fid+'_tip').html('Empty (enter an email address).');
}
});
});
//send test email
jQuery('#testCustomEmail').click(function() {
//an action that matches the php function
var action = 'OptionTestEmail';
//get current variables from email customisation form
var test_custademail = jQuery('#custademail').val();
var test_custlogurl = jQuery('#custlogurl').val();
var test_custemailhead = jQuery('#custemailhead').val();
var test_customemailtext = jQuery('#customemailtext').val();
//send vars to php function in multiadd.php
jQuery.post( MySecureAjax.ajaxurl, {action: action, test_email: test_custademail, test_loginurl: test_custlogurl, test_mailhead: test_custemailhead, test_mailtext: test_customemailtext}, function() {
alert('Message sent! Please check your email. Your current settings have NOT YET been saved.');
});
});
//add extras row button
if (jQuery('.fieldsetwrap')) {
jQuery('').appendTo('.addextrasbutton');
}
//if that button is clicked...
jQuery('.addNewRow').click(function() {
//updated process number
var currentProcs = parseInt(jQuery('#processes').val());
jQuery('#processes').val(currentProcs+1)
//get next row number
var order = jQuery('.fieldsetwrap .formwrap').length +1;
var wrapcolor;
//define color
if (order & 1) {
wrapcolor = 'wrapwhite';
} else {
wrapcolor = 'wrapgrey';
}
jQuery('
'+order+'
Empty (row will be skipped.
Empty (password will be generated).
Empty (enter an email address).
').appendTo('.fieldsetwrap');
});
//LOAD INITIAL DATA FOR SORTING FUNCTION
if (document.getElementById('sortfield')) {
//add activation checkbox
jQuery('').appendTo('#sortfield');
//add textsorter wrap
jQuery('').appendTo('#sortfield');
}
if(document.getElementById('textsorter')) {
//create array of default values
var loadarray = new Array();
//push values
loadarray.push("username","password","email","role","firstname","lastname","website");
//push to creator
makeColumnsList(loadarray);
//hide
jQuery('#textsorter').hide();
}
//end opening function
//OPEN or CLOSE #textsorter on option change
jQuery('#opentextsorter').live('change', function() {
if (jQuery('#opentextsorter').attr('checked')) {
jQuery('#textsorter').slideDown();
} else {
jQuery('#textsorter').slideUp();
}
});
//on drop box changes
jQuery('#textsorter select').live('change', function() {
var chosen = jQuery(this).val();
checkDuplicates(chosen);
jQuery(this).attr('id',chosen);
});
//ADD NEW COLUMN
jQuery('.coladdnew').live('click', function() {
//id of clicked addnew span
var thisColID = jQuery(this).attr('id');
var thisColNum = parseInt(thisColID.substr(3));
//create array
var allCols = new Array();
//make array of existing cols
var countCols = 1;
jQuery('#textsorter select').each(function(i) {
var colval = jQuery(this).val();
if(countCols == thisColNum) {
allCols.push(colval);
allCols.push('ignore');
} else {
allCols.push(colval);
}
countCols++;
});
//push to creator
makeColumnsList(allCols);
});
//DELETE COLUMN
jQuery('.coldelete').live('click', function() {
//id of clicked addnew span
var thisColID = jQuery(this).attr('id');
var thisColNum = parseInt(thisColID.substr(3));
//create array
var allCols = new Array();
//make array of existing cols
jQuery('#textsorter select').each(function(i) {
var colval = jQuery(this).val();
allCols.push(colval);
});
//remove deleted entry
allCols.splice(thisColNum-1,1);
//push to creator
makeColumnsList(allCols);
});
//SHIFT COLUMN LEFT
jQuery('.colleft').live('click', function() {
//id of clicked addnew span
var thisColID = jQuery(this).attr('id');
var thisColNum = parseInt(thisColID.substr(3));
var allCols = new Array();
//countcolumns
jQuery('#textsorter select').each(function(i) {
var colval = jQuery(this).val();
allCols.push(colval);
});
//if far left column has been chosen, show error
if(thisColNum == 1) {
alert('Column cannot be shifted left!');
} else {
//swap position of chosen column with next
var prevColumn = allCols[thisColNum-2];
var thisColumn = allCols[thisColNum-1];
allCols.splice(thisColNum-2,2,thisColumn,prevColumn);
makeColumnsList(allCols);
}
});
//SHIFT COLUMN RIGHT
jQuery('.colright').live('click', function() {
//id of clicked addnew span
var thisColID = jQuery(this).attr('id');
var thisColNum = parseInt(thisColID.substr(3));
var allCols = new Array();
//countcolumns
var totalCols = 0;
jQuery('#textsorter select').each(function(i) {
var colval = jQuery(this).val();
allCols.push(colval);
totalCols++;
});
//if far right column has been chosen, show error
if (thisColNum == totalCols) {
alert('Column cannot be shifted right!');
} else {
//swap position of chosen column with next
var thisColumn = allCols[thisColNum-1];
var nextColumn = allCols[thisColNum];
allCols.splice(thisColNum-1,2,nextColumn,thisColumn);
makeColumnsList(allCols);
}
});
});
//makes or remakes all columns in the list
function makeColumnsList(colsarray) {
//clear existing text boxes
jQuery('#textsorter').html('');
//total number of cols in array
var arrayEntries = colsarray.length;
var i=0;
for (i=0; i
←→x+
').appendTo('#textsorter');
jQuery('select.sortoption'+j).val(colsarray[i]);
}
setIDs();
}
//set ids and names on fields
function setIDs() {
var namer = 1;
jQuery('#textsorter select').each(function(i) {
var targetSetID = jQuery(this).val();
jQuery(this).attr('id', targetSetID);
jQuery(this).attr('name', namer);
namer++;
});
}
//function to replace found duplicates
function checkDuplicates(chosen) {
var targetid = chosen;
jQuery('#'+targetid).val('ignore');
jQuery('#'+targetid).attr('id','ignore');
}