////JQUERY JSON LIBRARY:
/*
* This document is licensed as free software under the terms of the
* MIT License: http://www.opensource.org/licenses/mit-license.php
*
* Adapted by Rahul Singla.
*
* Brantley Harris wrote this plugin. It is based somewhat on the JSON.org
* website's http://www.json.org/json2.js, which proclaims:
* "NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.", a sentiment that
* I uphold.
*
* It is also influenced heavily by MochiKit's serializeJSON, which is
* copyrighted 2005 by Bob Ippolito.
*/
/**
* jQuery.JSON.encode( json-serializble ) Converts the given argument into a
* JSON respresentation.
*
* If an object has a "toJSON" function, that will be used to get the
* representation. Non-integer/string keys are skipped in the object, as are
* keys that point to a function.
*
* json-serializble: The *thing* to be converted.
*/
var CookieHelper = (function($j, window, undefined){
return {
set: function(c_name, value, exdays){
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie = c_name + "=" + c_value + '; path=/';
},
get: function(c_name){
var i, x, y;
var ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++){
x = ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x = x.replace(/^\s+|\s+$/g,"");
if (x == c_name){
return unescape(y);
}
}
}
}
}(jQuery, window));
jQuery.JSON = {
encode: function(o) {
if (typeof (JSON) == 'object' && JSON.stringify)
return JSON.stringify(o);
var type = typeof (o);
if (o === null)
return "null";
if (type == "undefined")
return undefined;
if (type == "number" || type == "boolean")
return o + "";
if (type == "string")
return this.quoteString(o);
if (type == 'object') {
if (typeof o.toJSON == "function")
return this.encode(o.toJSON());
if (o.constructor === Date) {
var month = o.getUTCMonth() + 1;
if (month < 10)
month = '0' + month;
var day = o.getUTCDate();
if (day < 10)
day = '0' + day;
var year = o.getUTCFullYear();
var hours = o.getUTCHours();
if (hours < 10)
hours = '0' + hours;
var minutes = o.getUTCMinutes();
if (minutes < 10)
minutes = '0' + minutes;
var seconds = o.getUTCSeconds();
if (seconds < 10)
seconds = '0' + seconds;
var milli = o.getUTCMilliseconds();
if (milli < 100)
milli = '0' + milli;
if (milli < 10)
milli = '0' + milli;
return '"' + year + '-' + month + '-' + day + 'T' + hours + ':'
+ minutes + ':' + seconds + '.' + milli + 'Z"';
}
if (o.constructor === Array) {
var ret = [];
for (var i = 0; i < o.length; i++)
ret.push(this.encode(o[i]) || "null");
return "[" + ret.join(",") + "]";
}
var pairs = [];
for (var k in o) {
var name;
var type = typeof k;
if (type == "number")
name = '"' + k + '"';
else if (type == "string")
name = this.quoteString(k);
else
continue; // skip non-string or number keys
if (typeof o[k] == "function")
continue; // skip pairs where the value is a function.
var val = this.encode(o[k]);
pairs.push(name + ":" + val);
}
return "{" + pairs.join(", ") + "}";
}
},
/**
* jQuery.JSON.decode(src) Evaluates a given piece of json source.
*/
decode: function(src) {
if (typeof (JSON) == 'object' && JSON.parse)
return JSON.parse(src);
return eval("(" + src + ")");
},
/**
* jQuery.JSON.decodeSecure(src) Evals JSON in a way that is *more* secure.
*/
decodeSecure: function(src) {
if (typeof (JSON) == 'object' && JSON.parse)
return JSON.parse(src);
var filtered = src;
filtered = filtered.replace(/\\["\\\/bfnrtu]/g, '@');
filtered = filtered
.replace(
/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
']');
filtered = filtered.replace(/(?:^|:|,)(?:\s*\[)+/g, '');
if (/^[\],:{}\s]*$/.test(filtered))
return eval("(" + src + ")");
else
throw new SyntaxError("Error parsing JSON, source is not valid.");
},
/**
* jQuery.JSON.quoteString(string) Returns a string-repr of a string, escaping
* quotes intelligently. Mostly a support function for JSON.encode.
*
* Examples: >>> jQuery.JSON.quoteString("apple") "apple"
*
* >>> jQuery.JSON.quoteString('"Where are we going?", she asked.') "\"Where
* are we going?\", she asked."
*/
quoteString: function(string) {
if (string.match(this._escapeable)) {
return '"' + string.replace(this._escapeable, function(a) {
var c = this._meta[a];
if (typeof c === 'string')
return c;
c = a.charCodeAt();
return '\\u00' + Math.floor(c / 16).toString(16)
+ (c % 16).toString(16);
}) + '"';
}
return '"' + string + '"';
},
_escapeable: /["\\\x00-\x1f\x7f-\x9f]/g,
_meta: {
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"': '\\"',
'\\': '\\\\'
}
}
/*
* FUNCTIONS By 15 Green leaves
*
*/
var meta_marker='';//_value
var apm_show_attributes=false;
var filters={};
var sortby_ajax='default';
var sort_dir='ASC';
function setCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function deleteCookie(name) {
setCookie(name,"",-1);
}
var fgl_setAutoSetSaveTitle=function(obj){
form=jQuery('#post');
var ob=obj
jQuery('#post').attr('obj',obj);
jQuery('#post').live('submit',function(){
//alert(jQuery(this).attr('obj'));
///SEt POST TITLE FROM OTHER FIELDS FOLLOWING SCHEMA
postTitleObj=jQuery('input[name="post_title"]');
var str=ob.schema;
jQuery.each(ob.fields,function(index, field) {
//alert(index + ': ' + field.field+ ': ' + field.field_type);
fi=jQuery('input[name="'+field.field+meta_marker+'"]');
if(field.field_type!=='select'){
if(field.field_type=='autocomplete'){
fi=jQuery('input[name="'+field.field+'_displayvalue"]');
}
str=str.split('{'+field.field+'}').join(jQuery(fi).val());
} else {
o=jQuery('#'+field.field);
v=jQuery(o).find('option:selected').text();
str=str.split('{'+field.field+'}').join(v);
}
})
D=new Date();
str=str.split('[currentdate]').join(D.getFullYear()+"-"+D.getMonth()+"-"+D.getDate());
jQuery(postTitleObj).val(str);
//CHECK REQUIRED
var test=true;
fi=jQuery('input[class="apm_is_required"]');
jQuery.each(fi,function(index, field) {
if(jQuery(field).val()==""){
test=false;
jQuery(field).parent().parent().addClass('apm_invalid');
}
});
//CHECK EMAIL
fi=jQuery('input[class="apm_is_email"]');
jQuery.each(fi,function(index, field) {
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var address = jQuery(field).val();
if(reg.test(address) == false && address!=='') {
jQuery(field).parent().parent().addClass('apm_invalid');
test=false;
}
});
//CHECK NUMBERS
fi=jQuery('input[class="apm_is_numbers"]');
jQuery.each(fi,function(index, field) {
var num = jQuery(field).val();
if ( isNaN(num)) {
jQuery(field).parent().parent().addClass('apm_invalid');
test=false;
}
});
//CHECK PHONE
fi=jQuery('input[class="apm_is_phone"]');
jQuery.each(fi,function(index, field) {
var phone = jQuery(field).val();
var stripped = phone.replace(/[\(\)\.\-\+\ ]/g, '');
if (isNaN(stripped)) {
jQuery(field).parent().parent().addClass('apm_invalid');
test=false;
} else if (stripped.length <8 && stripped.length >0 ) {
jQuery(field).parent().parent().addClass('apm_invalid');
test=false;
}
});
if(test==false){
// alert("Some fields are invalid.")
flg_apm.setAlertPanel.addAlert('Error','Some fields are invalid...','error',3000);
return false;
}
});
}
var fgl_setAutoSetTitle=function(obj){
var inputs=jQuery(':input');
//alert(posttitle);
var myobj=obj;
var postTitleObj=null;
postTitleObj=jQuery('input[name="post_title"]');
var str=obj.schema;
jQuery.each(obj.fields,function(index, field) {
//alert(index + ': ' + field.field+ ': ' + field.field_type);
fi=jQuery('input[name="'+field.field+meta_marker+'"]');
if(field.field_type!=='select'){
if(field.field_type=='autocomplete'){
fi=jQuery('input[name="'+field.field+'_displayvalue"]');
}
str=str.split('{'+field.field+'}').join(jQuery(fi).val());
} else {
o=jQuery('#'+field.field);
v=jQuery(o).find('option:selected').text();
str=str.split('{'+field.field+'}').join(v);
}
})
D=new Date();
str=str.split('[currentdate]').join(D.getFullYear()+"-"+D.getMonth()+"-"+D.getDate());
jQuery(postTitleObj).val(str);
return;
}
var apm_convert=function(o,action,post_id,appname,post_type){
document.location.href="admin.php?page="+appname+"-main-menu&post_id="+post_id+"&action_name="+action+"&post-type="+post_type+"&action-type=convert";
}
var apm_actionbtn=function(o,action,post_id,appname,post_type){
var fields=jQuery(o).attr('fields');
oFields=eval(fields);
jQuery.each(oFields, function(key,field){
fieldToUpdate=jQuery('input[name="'+field[0]+meta_marker+'"]');
if(jQuery(fieldToUpdate).val()==undefined){
if(document.post[field[0]+meta_marker]!==undefined){//= is select
o=document.post[field[0]+meta_marker].options[0];
//document.post[field[0]+meta_marker].selectedIndex =5;
for (var i = 0; i < document.post[field[0]+meta_marker].length; i++)
{
if(Number(field[1])==NaN || field[2]=='text'){
//console.log(document.post[field[0]+meta_marker].options[i].text +"//"+ field[1]);
if (document.post[field[0]+meta_marker].options[i].text == field[1]){
document.post[field[0]+meta_marker].selectedIndex =i;
}
} else if (Number(document.post[field[0]+meta_marker].options[i].value) == Number(field[1]))
{
//alert(document.post[field[0]+meta_marker].options[i].value +'-'+ field[1]);
document.post[field[0]+meta_marker].selectedIndex =i;
//document.post[field[0]+meta_marker].selected = true;
}
}
}
if(tinyMCE.get(field[0]+meta_marker+'_comment')!==undefined){
txt=tinyMCE.get(field[0]+meta_marker+'_comment').getContent();//jQuery(commentBlock).attr("value");
//tinyMCE.get('content id').getContent()
tinyMCE.get(field[0]+meta_marker+'_comment').setContent(field[1]);
}
//jQuery(fieldToUpdate).val("3");
} else {
val=field[1];
if(val=='NOW()'){
do_update=true;
if(field[2]=="if_empty"){
do_update=false;
checkv=jQuery(fieldToUpdate).val();
if(checkv==""){
do_update=true;
}
}
if(do_update){
var myDate=new Date();
m=myDate.getMonth();
m++;
if(m<10){
m='0'+m;
}
d=myDate.getDate();
if(d<10){
d='0'+d;
}
val=m+"/"+d+"/"+myDate.getFullYear();
} else {
val="dont_update";
}
}
if(val=='TIME()'){
var myDate=new Date();
h=myDate.getHours();
m=myDate.getMinutes();
if(m<10){
m='0'+m;
}
if(h<10){
d='0'+h;
}
val=h+":"+m;
}
if(val!=="dont_update"){
jQuery(fieldToUpdate).val(val);
}
}
});
jQuery("#post").submit();
//document.location.href="admin.php?page="+appname+"-main-menu&post_id="+post_id+"&action_name="+action+"&post-type="+post_type+"&action-type=convert";
//return false;
}
var apm_add_notif=function(o){
var userList=jQuery(o).prev();
var notifField=jQuery(o).next();
//alert(userList.val());
if(notifField.val().indexOf(',')>-1){
var notifUsersList=notifField.val().split(',');
} else if(notifField.val()!==""){
var notifUsersList=[notifField.val()];
}
var userToAdd=userList.val();
var newNotifUsersList=[];
var already_exist=false;
if(notifField.val()!==""){
jQuery.each(notifUsersList, function(key,userid){
if(Number(userid)!==Number(userToAdd) && Number(userid)!==0){
newNotifUsersList.push(userid);
} else {
already_exist=true;
}
});
}
newNotifUsersList.push(userToAdd);
//alert(jQuery(o).next().next().html());
if(already_exist==false){
newUserStr=""+jQuery(o).prev().find("option:selected").text()+" 
Do you really want to TRASH this item?
'); $(modal).modal('show'); $(modal).find('.apm_confirm_no').off('click').on('click',function(e){ $(modal).modal('hide'); }); $(modal).find('.apm_confirm_yes').off('click').on('click',function(e){ $(modal).modal('hide'); $(alertB).html('Trashing post....'); flg_apm.do_show_submitting(alertB); flg_apm.do_update_status('trash',this,'admin.php?page=15CRM-ff_tasks'); }); }); $('.apm_open_preview').off('click').on('click',function(e){ e.preventDefault(); window.open($(this).attr('data-url')); }); $('.apm_update_post').off('click').on('click',function(e){ e.preventDefault(); //if(!flg_apm.setOfficeFields.setValidateForm()) //flg_apm.setAlertPanel.addAlert('Invalid Input','Please fill correctly the fields.','error',4000); //else{ alertB=$(this).parents('.topnav_bar').find('.alert-info'); $(alertB).html('Saving post....'); flg_apm.do_show_submitting(this); $('#publish').trigger('click'); $('#post').submit(); //} }); }; flg_apm.do_show_submitted=function(obj){ parent_obj=$(obj).parents('.topnav_bar'); alertS2=$(parent_obj).find('.alert-success'); alertB2=$(parent_obj).find('.alert-info'); $(alertB2).hide(); $(alertS2).fadeIn(200).delay(2000).fadeOut(200); }; flg_apm.do_show_submitting=function(obj){ parent_obj=$(obj).parents('.topnav_bar'); alertS3=$(parent_obj).find('.alert-success'); alertB3=$(parent_obj).find('.alert-info'); $(alertS3).hide(); $(alertB3).fadeIn(200); }; flg_apm.do_update_status=function(status,obj,redirect){ post_ID=$('#post_ID').val(); var do_redirect=false; if(redirect!==undefined){ do_redirect=redirect; } jQuery.ajax({ url: ajaxurl , type: "POST", data: "action=apm_udpate_status&status="+status+"&post_id="+post_ID, error: function(data){ // alert('An error occured, please try again'); flg_apm.setAlertPanel.addAlert('An error occured','An error occured, please try again...','error',3000); }, success: function(data){ dataStr=String(data); if(do_redirect!==false){ ur=ajaxurl.split(userSettings.url); ur2=ur[0]+userSettings.url+"wp-admin/"; document.location.href=ur2+do_redirect; } else { flg_apm.do_show_submitted(obj); /* alertS=$(alertB).parents('.topnav_bar').find('.alert-success'); $(alertB).hide(); $(alertS).fadeIn(200);*/ } //if() } }); } ///END TOPBAR var fgl_manageCategories=function(){//use all_categories jQuery.each(all_categories, function(key, categ){ categdiv=jQuery("#"+key+"div"); jQuery(categdiv).css('display','none'); }); // } var apm_rte_controls={}; var tabs_obj=[]; jQuery(document).ready(function(){ fgl_initChildTables(); fgl_initRTE(); fgl_initCommments(); flg_apm.initTopBar(); apm_rte_controls={ controls: { bold : { visible : true }, italic : { visible : true }, underline : { visible : true }, strikeThrough : { visible : true }, h4: { visible: true, className: 'h4', command: ($.browser.msie || $.browser.safari) ? 'formatBlock' : 'heading', arguments: ($.browser.msie || $.browser.safari) ? '
Status: Loading records');
//filters=param_filters==undefined? false:param_filters;
if(param_filter_key!==undefined && param_filter_key!==''){
filters[param_filter_key]=param_filter_value;
}
if(sortby!==undefined && sortby!==''){
sortby_ajax=sortby;
}
filters_str=jQuery.JSON.encode(filters);
jQuery.ajax({
url: ajaxurl ,
type: "POST",
data: "modulekey="+modulekey+"&action=apm_manage_grid_data&todo=get_data&filters="+filters_str+"&sortby_ajax="+sortby_ajax+"&sort_dir="+sort_dir,
success: function(data){
dataStr=String(data);
dataStr=dataStr.substring(0,dataStr.length-1);
dataCut=dataStr.split("//cutter//");
table.append(dataCut[0])
//alert(eval(dataCut[1]);
rtrnObj=jQuery.parseJSON( dataCut[1]);
if(rtrnObj.filters_results!==""){
status_zone.html('Status: Records loaded ('+rtrnObj.page_count+' / '+rtrnObj.total_count+'), filtered by: '+rtrnObj.filters_results+'');
}else {
status_zone.html('Status: Records loaded ('+rtrnObj.page_count+' / '+rtrnObj.total_count+')');
}
gridwrap=jQuery(grid).parents(".apm_datagrid_wrapper");
o=jQuery(gridwrap).find('.apm_grid_status_zone_container');
obj=jQuery(o[0]).find('.apm_page_first');
jQuery(o[0]).attr('last_page',rtrnObj.last_page);
//apm_paging_page_nb=new_apm_paging_page_nb;
//apm_paging_old_page_nb
apm_paging_last_page=rtrnObj.last_page;
if(Number(jQuery(o[0]).attr('initial_page'))>Number(rtrnObj.last_page)){
jQuery(o[0]).attr('initial_page',rtrnObj.last_page);
do_change_paging(Number(rtrnObj.last_page),obj[0],true);
//alert('oups');
} else {
do_change_paging(Number(jQuery(o[0]).attr('initial_page')),obj[0],true);
}
apm_paging_page_nb=Number(jQuery(o[0]).attr('initial_page'));
apm_paging_old_page_nb=apm_paging_page_nb;
//if()
}
});
}
}
jQuery.each(data_grids, function(key, data_grid){
p=jQuery(data_grid).parents(".apm_datagrid_wrapper");
sz=jQuery(p).find('.apm_grid_status_zone_container');
has_paging=Number(jQuery(sz[0]).attr('has_paging'));
if(has_paging==1){
apm_load_data_grid(data_grid,'page_nb',1);
} else {
apm_load_data_grid(data_grid);
}
});
///SET PAGING
var do_change_paging=function(page_nb,obj,norefresh){
o=jQuery(obj).parents('.apm_pagin_header_zone');
ochild=jQuery(o[0]).find('.apm_page_nb');
oapm_page_first_child=jQuery(o[0]).find('.apm_page_first');
oapm_page_prev_child=jQuery(o[0]).find('.apm_page_prev');
oapm_page_next_child=jQuery(o[0]).find('.apm_page_next');
oapm_page_last_child=jQuery(o[0]).find('.apm_page_last');
if(page_nb==1){
jQuery(oapm_page_first_child[0]).addClass('inactive');
jQuery(oapm_page_prev_child[0]).addClass('inactive');
} else {
jQuery(oapm_page_first_child[0]).removeClass('inactive');
jQuery(oapm_page_prev_child[0]).removeClass('inactive');
}
if(page_nb==get_last_page(obj)){
jQuery(oapm_page_next_child[0]).addClass('inactive');
jQuery(oapm_page_last_child[0]).addClass('inactive');
} else {
jQuery(oapm_page_next_child[0]).removeClass('inactive');
jQuery(oapm_page_last_child[0]).removeClass('inactive');
}
jQuery(ochild[0]).attr('value',page_nb);
gridwrap=jQuery(obj).parents(".apm_datagrid_wrapper");
var grid=gridwrap.find('.apm_grid_block_cls');
o=jQuery(obj).parents('.apm_grid_status_zone_container');
jQuery(o[0]).attr('initial_page',page_nb);
if(norefresh==undefined) {
refresh_grid(grid,'page_nb',page_nb);
}
}
var get_last_page=function(obj){
o=jQuery(obj).parents('.apm_grid_status_zone_container');
return Number(jQuery(o[0]).attr('last_page'));
}
////SEARCH
jQuery(".apm_search_btn_go").live('click', function(){
f=jQuery(this).parent().find('.apm_search_field');
seaStr=jQuery(f).attr('value');
if(seaStr!==''){
var gridparent=jQuery(this).parents('.apm_sidebar_block').parent();
var grid=jQuery(gridparent).find('.apm_grid_block_cls');
refresh_grid(grid,"free_search",seaStr);
}
//
});
jQuery(".apm_search_cancel_btn_go").live('click', function(){
f=jQuery(this).parent().find('.apm_search_field');
jQuery(f).attr('value','');
var gridparent=jQuery(this).parents('.apm_sidebar_block').parent();
var grid=jQuery(gridparent).find('.apm_grid_block_cls');
refresh_grid(grid,"free_search",'');
});
jQuery(".apm_advanced_search_cancel_btn_go").live('click', function(){
f=jQuery(this).parents('.content_advanced_search_fields');
f=f[0];
fields=jQuery(f).find('select');
jQuery.each(fields,function(index, field) {
options=jQuery(field).find('option');
count=0;
jQuery.each(options,function(index, option) {
if(count==0){
jQuery(option).attr('selected','selected');
} else{
jQuery(option).removeAttr('selected');
}
count++;
});
});
fields=jQuery(f).find('input.autocomplete_field_value');
jQuery.each(fields,function(index, field) {
jQuery(field).attr('value','');
});
fields=jQuery(f).find('input.autocomplete_field');
jQuery.each(fields,function(index, field) {
jQuery(field).attr('value','');
});
apm_do_advanced_search(this);
});
var apm_do_advanced_search=function(obj){
f=jQuery(obj).parents('.content_advanced_search_fields');
f=f[0];
fields=jQuery(f).find('select');
jQuery.each(fields,function(index, field) {
n=jQuery(field).attr('name');
if( n.substring(0,4) =='cat_' ){
v=jQuery(field).find('option:selected').text();
} else {
v=jQuery(field).find('option:selected').attr('value');
}
if(v!=='Show All' && v!=='Show All '){
filters[n]=v;
} else {
filters[n]='';
}
});
fields=jQuery(f).find('input.autocomplete_field_value');
jQuery.each(fields,function(index, field) {
n=jQuery(field).attr('name');
v=jQuery(field).attr('value');
if(v!=='' ){
filters[n]=v;
} else {
filters[n]='';
}
});
var gridparent=jQuery(obj).parents('.apm_sidebar_block').parent();
var grid=jQuery(gridparent).find('.apm_grid_block_cls');
refresh_grid(grid,"",'');
}
jQuery(".apm_advanced_search_btn_go").live('click', function(){
apm_do_advanced_search(this);
});
jQuery(".apm_open_advanced_search").live('click', function(){
var blockparent=jQuery(this).parents('.apm_sidebar_content_filter');
var blockadvancedsearch=jQuery(blockparent).parent();
jQuery(blockparent).hide();
blockadvancedsearch=jQuery(blockadvancedsearch).find('.apm_sidebar_content_advanced_search')
jQuery(blockadvancedsearch).show();
});
jQuery(".apm_close_advanced_search").live('click', function(){
var blockparent=jQuery(this).parents('.apm_sidebar_content_advanced_search');
var blockadvancedsearch=jQuery(blockparent).parent();
jQuery(blockparent).hide();
blockadvancedsearch=jQuery(blockadvancedsearch).find('.apm_sidebar_content_filter')
jQuery(blockadvancedsearch).show();
});
///PAGING
var apm_paging_old_page_nb=1;
var apm_paging_page_nb=1;
var apm_paging_last_page=10;
jQuery(".apm_page_nb").live('focus', function(){
apm_paging_old_page_nb=Number(jQuery(this).attr('value'));
});
jQuery(".apm_page_nb").live('blur', function(){
//alert('blur');
new_apm_paging_page_nb=Number(jQuery(this).attr('value'));
if(new_apm_paging_page_nb>0){
apm_paging_page_nb=new_apm_paging_page_nb;
apm_paging_old_page_nb=apm_paging_page_nb;
do_change_paging(apm_paging_page_nb,this);
} else {
jQuery(this).attr('value',apm_paging_old_page_nb)
}
});
//SET GRID HEIGHT TO FIT THE PAGE
o=jQuery('#mainGridZone');
if(jQuery(o).hasClass('apm_grid_zone')){
t=jQuery(o).offset().top;
//alert(t);
jQuery('#footer').hide();
jQuery('#wpfooter').hide();
w=jQuery(window);
wh=jQuery(w).height();
h=(wh-t-10);
jQuery(o).css('height',h+'px');
}
jQuery(".apm_page_nb").live('keypress', function(e){
if(e.which == 13){
jQuery(this).blur();
}
});
jQuery(".apm_page_first").live('click', function(e){
apm_paging_page_nb=1;
if(apm_paging_old_page_nb!==apm_paging_page_nb){
do_change_paging(apm_paging_page_nb,this);
apm_paging_old_page_nb=apm_paging_page_nb;
}
});
jQuery(".apm_page_prev").live('click', function(e){
apm_paging_page_nb-=1;
if(apm_paging_page_nb==0){
apm_paging_page_nb=1;
}
if(apm_paging_old_page_nb!==apm_paging_page_nb){
do_change_paging(apm_paging_page_nb,this);
apm_paging_old_page_nb=apm_paging_page_nb;
}
});
jQuery(".apm_page_next").live('click', function(e){
apm_paging_last_page=get_last_page(this);
if(apm_paging_page_nb+1<=apm_paging_last_page){
apm_paging_page_nb+=1;
if(apm_paging_old_page_nb!==apm_paging_page_nb){
do_change_paging(apm_paging_page_nb,this);
apm_paging_old_page_nb=apm_paging_page_nb;
}
}
});
jQuery(".apm_page_last").live('click', function(e){
apm_paging_last_page=get_last_page(this);
apm_paging_page_nb=apm_paging_last_page;
if(apm_paging_old_page_nb!==apm_paging_page_nb){
do_change_paging(apm_paging_page_nb,this);
apm_paging_old_page_nb=apm_paging_page_nb;
}
});
///SET A-Z filtering
jQuery(".apm_grid_az_header > li > a").live('click', function(){
letter=jQuery(this).attr('letter');
var grid=jQuery(this).parents('.apm_grid_block_cls');
refresh_grid(grid,"letter",letter);
});
var cb_clicked_store=[];
jQuery(".apm_grid_row_cb").live('click', function(){
post_id= jQuery(this).attr('post_id');
var do_check=false;
if(jQuery(this).attr('checked')=='checked'){
do_check=true;
pos=jQuery.inArray(post_id,cb_clicked_store);
if(pos==-1){
cb_clicked_store.push(post_id);
}
} else {
do_check=false;
pos=jQuery.inArray(post_id,cb_clicked_store);
if(pos>-1){
cb_clicked_store.splice(pos,1);
}
}
//alert(pos+"-"+post_id+"-"+do_check+"-"+cb_clicked_store);
});
jQuery(".apm_grid_head_cb").live('click', function(){
var do_check=false;
if(jQuery(this).attr('checked')=='checked'){
do_check=true;
}
div=jQuery(this).parents('.apm_grid_block_cls');//.parent().parent().parent().parent().parent();//.parent().next();
trs=div.find('table > tbody > tr');
cb_clicked_store=[];
jQuery.each(trs,function(index, tr) {
tds=jQuery(tr).find('td');
td=tds[0].firstChild;
post_id=jQuery(td).attr('post_id');
if(do_check){
jQuery(td).attr('checked','checked');
cb_clicked_store.push(post_id);
} else {
jQuery(td).removeAttr('checked');
}
});
});
var refresh_grid=function(grid,param_filter_key,param_filter_value,sort_by){
var data_grid=grid.find('tbody');
jQuery(data_grid).html("");
apm_load_data_grid(data_grid,param_filter_key,param_filter_value,sort_by);
}
jQuery(".apm_refresh_btn").on('click', function(){
var grid=jQuery(this).parents('.apm_grid_block_cls');//.parent().parent().parent();
refresh_grid(grid);
});
///SHOW LAYER ACTION ON DATA GRIDS
var countHideLayer=0;
var apm_selected_post_id=0;
var apm_selected_post_status=false;
var apm_selected_post_object=false;
var all_categories=false;
var grid=jQuery(apm_selected_post_object).parents('.apm_grid_block_cls');//.parent().parent().parent().parent().parent().parent();
apm_activate_grid_fields=function(){
//SET NEW GRID FILD AJAX INPUT
jQuery('.choice_li_ajax_select span').live('click', function(){
var t=jQuery(this);
s=t.parents('#apm_grid_block');
var status_zone=jQuery(s).find('.apm_grid_status_zone');
p=t.parent();
p=jQuery(p);
fieldname=p.data('fieldname');
id=p.data('id');
if(t.hasClass('apm_grid_field_unselected')){
sp=p.find('span');
sp=jQuery(sp);
sp.removeClass('apm_grid_field_selected');
sp.addClass('apm_grid_field_unselected');
t.removeClass('apm_grid_field_unselected');
t.addClass('apm_grid_field_selected');
val=t.data('val');
status_zone.html('Status: Saving...');
jQuery.ajax({
url: ajaxurl ,
type: "POST",//apm_manage_grid_data
data: "modulekey="+modulekey+"&action=apm_ajax_field_update&post_id="+id+"&fieldname="+fieldname+"&val="+val,
success: function(data){
status_zone.html('Status: Updated');
}//apm_get_grid_data
});
}
});
jQuery('.apm_act_grid').live('click', function(){
var t=jQuery(this);
s=t.parents('#apm_grid_block');
var status_zone=jQuery(s).find('.apm_grid_status_zone');
if(t.hasClass('apm_act_pub')){
t.removeClass('apm_act_pub');
t.addClass('apm_act_unpub');
val="0";
} else {
t.removeClass('apm_act_unpub');
t.addClass('apm_act_pub');
val="1";
}
fieldname=t.data('fieldname');
id=t.data('id');
status_zone.html('Status: Saving...');
jQuery.ajax({
url: ajaxurl ,
type: "POST",//apm_manage_grid_data
data: "modulekey="+modulekey+"&action=apm_ajax_field_update&post_id="+id+"&fieldname="+fieldname+"&val="+val,
success: function(data){
status_zone.html('Status: Updated');
}//apm_get_grid_data
});
});
jQuery('.ajax_input').live('blur', function(){
t=jQuery(this);
s=t.parents('#apm_grid_block');
var status_zone=jQuery(s).find('.apm_grid_status_zone');
fieldname=t.data('fieldname');
id=t.data('id');
v=t.val();
status_zone.html('Status: Saving...');
jQuery.ajax({
url: ajaxurl ,
type: "POST",//apm_manage_grid_data
data: "modulekey="+modulekey+"&action=apm_ajax_field_update&post_id="+id+"&fieldname="+fieldname+"&val="+v,
success: function(data){
status_zone.html('Status: Updated');
}//apm_get_grid_data
});
});
////
}
var apm_activateActionLayer=function(){
countHideLayer=0;
jQuery(".apm_act_action").live('mouseover', function(){
actionLayer=jQuery('#apm_grid_actions_layer');
thisObj=jQuery(this);
actionLayer.css("left",thisObj.position().left+20+"px").css("top",thisObj.position().top+"px");
apm_selected_post_id=jQuery(this).attr('post_id');
apm_selected_post_status=jQuery(this).attr('post_status');
actionLayer.show();
if(apm_selected_post_status=='publish'){
actionLayer.find('.apm_act_pub').hide();
actionLayer.find('.apm_act_unpub').show();
actionLayer.find('.apm_act_trash').show();
} else if(apm_selected_post_status=='pending' || apm_selected_post_status=='draft'){
actionLayer.find('.apm_act_pub').show();
actionLayer.find('.apm_act_unpub').hide();
actionLayer.find('.apm_act_trash').show();
}else if(apm_selected_post_status=='trash'){
actionLayer.find('.apm_act_pub').show();
actionLayer.find('.apm_act_unpub').show();
actionLayer.find('.apm_act_trash').hide();
}
countHideLayer=0;
apm_selected_post_object=this;
});
jQuery(".apm_act_action").live('mouseout', function(){
apm_startCountHideLayer('#apm_grid_actions_layer');
});
jQuery("#apm_grid_actions_layer > span").live('mouseout', function(){
apm_startCountHideLayer('#apm_grid_actions_layer');
})
jQuery("#apm_grid_actions_layer > span").live('mouseover', function(){
countHideLayer=0;
})
jQuery(".apm_act_edit").live('click', function(){
window.open('post.php?post='+apm_selected_post_id+'&action=edit','_blank');
});
jQuery(".apm_act_trash").live('click', function(){
if(jQuery(this).hasClass('apm_pad_icon')){
apm_multi_update_status_ajax(this,'trash_multirecs','Trashing','Trashed');
} else if(jQuery(this).hasClass('apm_filter_icon')){
apm_filter_status_ajax(this,'filter_trash');
}else {
jQuery(apm_selected_post_object).parent().parent().hide();
var grid=jQuery(apm_selected_post_object).parents('.apm_grid_block_cls');//.parent().parent().parent().parent().parent().parent();
var status_zone=grid.find('.apm_grid_status_zone');
var grid_tbody=grid.find('tbody');
var modulekey=grid_tbody.attr('modulekey');
status_zone.html('
Status: trashing Record Id '+apm_selected_post_id+' ');
jQuery.ajax({
url: ajaxurl ,
type: "POST",
data: "modulekey="+modulekey+"&action=apm_manage_grid_data&todo=trash_rec&post_id="+apm_selected_post_id,
success: function(data){
status_zone.html('Status: Record trashed');
}//apm_get_grid_data
});
}
});
jQuery(".apm_act_del").live('click', function(){
if(cb_clicked_store.length==0 && jQuery(this).hasClass('apm_pad_icon')){
flg_apm.setAlertPanel.addAlert('Error','Please select at least one record...','error',3000);
return;
}
if(jQuery(this).hasClass('apm_pad_icon')){
var answer = confirm('Are you sure that you want to delete the Record(s) # '+cb_clicked_store.join(', ')+' ?');
if (answer){
apm_multi_update_status_ajax(this,'del_multirecs','Deleting','Deleted');
}
} else {
var answer = confirm('Are you sure that you want to delete the Record ID '+apm_selected_post_id+' ?');
if (answer){
jQuery(apm_selected_post_object).parent().parent().hide();
var grid=jQuery(apm_selected_post_object).parents('.apm_grid_block_cls');//.parent().parent().parent().parent().parent().parent();
var status_zone=grid.find('.apm_grid_status_zone');
var grid_tbody=grid.find('tbody');
var modulekey=grid_tbody.attr('modulekey');
status_zone.html('
Status: deleting Record Id '+apm_selected_post_id+' ');
jQuery.ajax({
url: ajaxurl ,
type: "POST",
data: "modulekey="+modulekey+"&action=apm_manage_grid_data&todo=del_rec&post_id="+apm_selected_post_id,
success: function(data){
status_zone.html('Status: Record Deleted');
}//apm_get_grid_data
});
}
}
});
var apm_filter_status_ajax=function(obj,status_action){
gridwrap=jQuery(obj).parents(".apm_datagrid_wrapper");
var grid=gridwrap.find('.apm_grid_block_cls');
var status_zone=grid.find('.apm_grid_status_zone');
refresh_grid(grid,"post_status",status_action);
}
var apm_export_csv=function(obj,f,ak){
gridwrap=jQuery(obj).parents(".apm_datagrid_wrapper");
//alert(jQuery(obj).html());
var grid=gridwrap.find('.apm_grid_block_cls');
var table=gridwrap.find('.apm_table_tbody');
//alert(jQuery(grid).html());
//alert(jQuery(grid).parent().html());
modulekey=jQuery(table).attr('modulekey');
//var status_zone=grid.find('.apm_grid_status_zone');
//refresh_grid(grid,"post_status",status_action);
//f=f.join(',');
jQuery.fileDownload(ajaxurl+"/?modulekey="+modulekey+"&action=apm_manage_grid_data&todo=get_file_csv&filters="+filters_str+"&sortby_ajax="+sortby_ajax+"&sort_dir="+sort_dir+"&fields="+f+"&action_key="+ak, {
successCallback: function (url) {
flg_apm.setAlertPanel.addAlert('Download','You just got a file download dialog or ribbon for this URL :' + url,'ok',3000);
},
failCallback: function (html, url) {
flg_apm.setAlertPanel.addAlert('Error','Your file download just failed for this URL:' + url + '\r\n' +
'Here was the resulting error HTML: \r\n' + html,'error',5000);
}
});
};
jQuery.download = function(url, data, method){
//url and data options required
if( url && data ){
//data can be string of parameters or array/object
data = typeof data == 'string' ? data : jQuery.param(data);
//split params into form inputs
var inputs = '';
jQuery.each(data.split('&'), function(){
var pair = this.split('=');
inputs+='';
});
//send request
jQuery('')
.appendTo('body').submit().remove();
};
};
var apm_multi_update_special_ajax=function(obj,action,f,v){
if(cb_clicked_store.length==0){
flg_apm.setAlertPanel.addAlert('Error','Please select at least one record...','error',3000);
return;
}
p=jQuery(obj).parent();
var status_action=status_action;
modulekey=jQuery(p).attr('modulekey');
gridwrap=jQuery(obj).parents(".apm_datagrid_wrapper");
var grid=gridwrap.find('.apm_grid_block_cls');
var status_zone=grid.find('.apm_grid_status_zone');
html='
';
html+='Status: updating the '+cb_clicked_store.length+' record(s) ';//'+cb_clicked_store.join(', ')+'
status_zone.html(html);
jQuery.ajax({
url: ajaxurl ,
type: "POST",
data: "modulekey="+modulekey+"&action=apm_manage_grid_data&todo=special_action&post_ids="+cb_clicked_store.join(',')+"&f="+f+"&v="+v+"&a="+a,
success: function(data){
status_zone.html('Status: '+cb_clicked_store.length+' Record(s) updated');
cb_clicked_store=[];
refresh_grid(grid);
}
});
}
var apm_multi_update_status_ajax=function(obj,status_action,status_text1,status_text2){
if(cb_clicked_store.length==0){
flg_apm.setAlertPanel.addAlert('Error','Please select at least one record...','error',3000);
return;
}
p=jQuery(obj).parent();
var status_action=status_action;
modulekey=jQuery(p).attr('modulekey');
gridwrap=jQuery(obj).parents(".apm_datagrid_wrapper");
var grid=gridwrap.find('.apm_grid_block_cls');
var status_zone=grid.find('.apm_grid_status_zone');
html='
';
html+='Status: '+status_text1+' the '+cb_clicked_store.length+' record(s) '+cb_clicked_store.join(', ')+' ';
status_zone.html(html);
jQuery.ajax({
url: ajaxurl ,
type: "POST",
data: "modulekey="+modulekey+"&action=apm_manage_grid_data&todo="+status_action+"&post_ids="+cb_clicked_store.join(','),
success: function(data){
status_zone.html('Status: '+cb_clicked_store.length+' Record(s) '+status_text2+'');
switch(status_action){
default:
jQuery.each(cb_clicked_store, function(key,id){
tr=jQuery('.'+modulekey+"_"+id);
td_status=tr.find('.td_status');
switch(status_action){
case 'unpub_multirecs':
jQuery(td_status[0]).removeClass('apm_act_pub');
jQuery(td_status[0]).addClass('apm_act_unpub');
jQuery(td_status[0]).addClass('apm_act_trash');
break;
case 'pub_multirecs':
jQuery(td_status[0]).removeClass('apm_act_unpub');
jQuery(td_status[0]).addClass('apm_act_pub');
jQuery(td_status[0]).addClass('apm_act_trash');
break;
case 'trash_multirecs':
jQuery(td_status[0]).addClass('apm_act_unpub');
jQuery(td_status[0]).addClass('apm_act_pub');
jQuery(td_status[0]).removeClass('apm_act_trash');
break;
}
});
if(status_action=="trash_multirecs"){
refresh_grid(grid);
cb_clicked_store=[];
}
break;
/*case 'trash_multirecs':
break;*/
case 'del_multirecs':
refresh_grid(grid);
cb_clicked_store=[];
break;
}
//refresh_grid(grid);
}
});
}
var apm_update_status_ajax=function(status_action,status_text1,status_text2){
var grid=jQuery(apm_selected_post_object).parents('.apm_grid_block_cls');
apm_act_action=jQuery(apm_selected_post_object).parent().parent().find('.apm_act_action');
jQuery(apm_act_action).attr('post_status','draft')
td_status=jQuery(apm_selected_post_object).parent().parent().find('.td_status');
if(status_action=='unpub_rec'){
jQuery(td_status).removeClass('apm_act_pub');
jQuery(td_status).addClass('apm_act_unpub');
jQuery(td_status).addClass('apm_act_trash');
} else if(status_action=='pub_rec'){
jQuery(td_status).removeClass('apm_act_unpub');
jQuery(td_status).addClass('apm_act_pub');
jQuery(td_status).addClass('apm_act_trash');
} else if(status_action=='trash_multirecs'){
jQuery(td_status).addClass('apm_act_unpub');
jQuery(td_status).addClass('apm_act_pub');
jQuery(td_status).removeClass('apm_act_trash');
}
var status_zone=grid.find('.apm_grid_status_zone');
var grid_tbody=grid.find('tbody');
var modulekey=grid_tbody.attr('modulekey');
html='
';
html+='Status: '+status_text1+' Record Id '+apm_selected_post_id+' ';
status_zone.html(html);
jQuery.ajax({
url: ajaxurl ,
type: "POST",
data: "modulekey="+modulekey+"&action=apm_manage_grid_data&todo="+status_action+"&post_id="+apm_selected_post_id,
success: function(data){
status_zone.html('Status: Record '+status_text2+'');
}
});
}
jQuery(".apm_act_all").live('click', function(){
if(jQuery(this).hasClass('apm_filter_icon')){
apm_filter_status_ajax(this,'filter_all');
}
});
jQuery(".apm_act_unpub").live('click', function(){
if(jQuery(this).hasClass('apm_pad_icon')){
apm_multi_update_status_ajax(this,'unpub_multirecs','Unpublishing','Unpublished');
} else if(jQuery(this).hasClass('apm_filter_icon')){
apm_filter_status_ajax(this,'filter_unpub');
} else {
apm_update_status_ajax('unpub_rec','Unpublishing','Unpublished');
}
});
sort_dir='ASC';
jQuery(".sort_dir").live('click', function(){
$t=jQuery(this);
p=jQuery(this).parent();
as=jQuery(p).find(".sort_asc");
de=jQuery(p).find(".sort_desc");
if($t.hasClass('sort_desc')){
sort_dir='DESC';
jQuery(as).removeClass('sort_sel');
jQuery(de).removeClass('sort_unsel');
jQuery(as).addClass('sort_unsel');
jQuery(de).addClass('sort_sel');
} else {
sort_dir='ASC';
jQuery(de).removeClass('sort_sel');
jQuery(as).removeClass('sort_unsel');
jQuery(de).addClass('sort_unsel');
jQuery(as).addClass('sort_sel');
}
s=jQuery(p).find(".apm_sortby");
do_sort(s);
});
var do_sort=function(obj){
f=jQuery(obj).val();
gridwrap=jQuery(obj).parents(".apm_datagrid_wrapper");
var grid=gridwrap.find('.apm_grid_block_cls');
refresh_grid(grid,'','',f);
}
jQuery(".apm_sortby").live('change', function(){
do_sort(this);
//alert('sort..'+jQuery(this).val());
});
jQuery(".apm_act_specialaction").live('click', function(){
if(jQuery(this).hasClass('apm_pad_icon')){
a=jQuery(this).attr('data-act_name');
ak=jQuery(this).attr('data-act_key');
switch(a){
case 'export_csv':
f=jQuery(this).attr('data-fields');
apm_export_csv(this,f,ak);
break;
}
//t=jQuery(this).attr('data-tooltip');
//apm_multi_update_status_ajax(this,'unpub_multirecs','Unpublishing','Unpublished');
/*f=jQuery(this).attr('data-field');
v=jQuery(this).attr('data-value');
a=jQuery(this).attr('data-act_name');
apm_multi_update_special_ajax(this, a, f, v);*/
}
});
jQuery(".apm_act_specialaction").live('mouseover', function(){
if(jQuery(this).hasClass('apm_pad_icon')){
t=jQuery(this).attr('data-tooltip');
if(t!==undefined){
//alert(t);
}
}
});
jQuery(".apm_act_special").live('click', function(){
if(jQuery(this).hasClass('apm_pad_icon')){
//apm_multi_update_status_ajax(this,'unpub_multirecs','Unpublishing','Unpublished');
f=jQuery(this).attr('data-field');
v=jQuery(this).attr('data-value');
a=jQuery(this).attr('data-act_name');
apm_multi_update_special_ajax(this, a, f, v);
}
});
jQuery(".apm_act_pub").live('click', function(){
if(jQuery(this).hasClass('apm_pad_icon')){
apm_multi_update_status_ajax(this,'pub_multirecs','Publishing','Published');
} else if(jQuery(this).hasClass('apm_filter_icon')){
apm_filter_status_ajax(this,'filter_pub');
} else {
apm_update_status_ajax('pub_rec','Publishing','Published');
}
});
jQuery(".apm_act_view").live('click', function(){
//alert('view '+apm_selected_post_id);
});
}
apm_activateActionLayer();
apm_activate_grid_fields();
var apm_startCountHideLayer=function(obj_id){
var date = new Date();
countHideLayer=date.getTime();
setTimeout(apm_CheckHideLayer,500,obj_id);
}
var apm_CheckHideLayer=function(obj_id){
//alert(countHideLayer);
if(countHideLayer!==0){
actionLayer=jQuery(obj_id);
actionLayer.hide();
apm_selected_post_id=0;
apm_selected_post_object=false;
}
countHideLayer=0;
}
/////HANDLE Show the help layer on rollover on a ? icon
jQuery(".apm_help_btn").live('mouseover', function(){
//alert(jQuery(this).next());
// alert(jQuery(this).next().text());
helpTxt=jQuery(this).next().text();
helpObject=jQuery(this).next();
helpObject.css("left",jQuery(this).position().left+30+"px").css("top",jQuery(this).position().top+"px");
helpObject.show();
});
jQuery(".apm_help_btn").live('mouseout', function(){
helpObject=jQuery(this).next();
helpObject.hide();
});
//END
jQuery('.fileRemove').live('click',function(){
jQuery(this).parent().hide();
jQuery(this).next().val(jQuery(this).attr('fileid'));
fieldname=jQuery(this).attr('fieldname');
filednb=jQuery(this).attr('fieldnb');
filetype=jQuery(this).attr('filetype');
if(filetype=="main"){
jQuery("#"+fieldname).show();
}
});
//
jQuery('.fileAddDescription_btn').live('click',function(){
jQuery(this).next().next().show();
jQuery(this).next().next().css('display','block');
});
jQuery('.fileHelpLayer_btn').live('click',function(){
});
//
jQuery('.apm_add_upload').live('click',function(){
if(this.nbupload==undefined){
this.nbupload=0;
}
this.nbupload+=1;
fieldname=jQuery(this).attr('fieldname');
uploadfield=jQuery("#"+fieldname);
uploadfieldcount=jQuery("#"+fieldname+"_add_file");
jQuery(uploadfieldcount).val(this.nbupload);
//
uploadfieldnew=jQuery(this).parent().parent().append('');
uploadfieldnew.css('display','block');
});
/* a = jQuery('.autocomplete_field').autocomplete( {
serviceUrl:ajaxurl+"?callback=?&action=amp-ajax-autocomplete&fieldname="+jQuery(this).attr(),
minChars:2
});*/
$('.action_button').off('click').on('click',function(i, obj){
var fieldname=$(this).attr('data-fieldname');
var post_id=$(this).attr('data-post_id');
var appname=$(this).attr('data-fields');
var post_type=$(this).attr('data-post_type');
var fields=$(this).attr('data-fields');
var dont_save=false;
if(fieldname=="convert_lead"){
var gloWin= flg_apm.c_create_globalModalWin();
flg_apm.c_init_globalModalWin(gloWin,{
title:"Convert a Lead to an Account and a Contact",
actionTitle:'Convert',
closeTitle: 'Cancel',
content:"You will be redirected to a form to convert the current Lead to a new Account and a new Contact. 
Field required.
Senging....