|
Server : Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/1.0.0-fips mod_auth_passthrough/2.1 mod_bwlimited/1.4 System : Linux server.jackjohnson.com 2.6.32-279.5.2.el6.x86_64 #1 SMP Fri Aug 24 01:07:11 UTC 2012 x86_64 User : jackjohn ( 502) PHP Version : 5.3.17 Disable Function : NONE Directory : /home/jackjohn/www/shopsite-images/en-AU/javascript/ |
Upload File : |
var products = [],form_parm1="missing",search_string,target_prefix,search_storage_container,override_display_mode,display_mode,preserved_search_element,last_rendered_product,total_number_of_loaded_products,currently_loading=0,active,clickable,start_index,need_more=false,selector_popup_counter,iframe_ready,to_load;
function detectIE() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
// IE 10 or older => return version number
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}
var trident = ua.indexOf('Trident/');
if (trident > 0) {
// IE 11 => return version number
var rv = ua.indexOf('rv:');
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
}
var edge = ua.indexOf('Edge/');
if (edge > 0) {
// IE 12 => return version number
return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
}
// other browser
return false;
}
var IE = detectIE();
var start_time = new Date().getTime();
//var matching_product_ids = "-1";
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(obj, start) {
for (var i = (start || 0), j = this.length; i < j; i++) {
if (this[i] === obj) { return i; }
}
return -1;
}
}
function cleanstr(str) {return str.replace(/"/g,'"');}
$(document).ajaxError(
function(event, jqXHR, ajaxSettings, thrownError) {
var html = 'We are sorry, an error has occurred: '+thrownError+ '<br><br>Offending request: <br>'+ ajaxSettings.url
$('.content').html(html);
finish_loading();
}
);
function error_check(response, request) {
if (response.search("bo_error_message") != -1) {
var ss = '<!-- ClientApp: bo_error_message -->';
var se = '<!-- ClientApp: bo_error_message_end -->';
var start = response.search(ss) + ss.length;
var end = response.search(se);
var html = 'We are sorry, an error has occurred:<br>'+response.substring(start,end);
$('.content').html(html);
finish_loading();
}
}
function hide_show_optgroup_labels(select_id, hidden_class) {
$('#'+select_id+' > optgroup').each (function() {
if ($(this).find('.'+hidden_class).length == $(this).children().length)
$(this).css({'display':'none'});
else
$(this).css({'display':''});
});
}
function restrict_search_domain(wipe) {
if (display_mode != 'W' && product_type != 3 && product_type != 4) {
var opt = $('.bo_search_fields').find('option:selected');
var section_index = opt.attr('section_index');
var field_index = opt.attr('field_index');
var type = sections[section_index].fields[field_index].type;
var domain;
var domain_html;
var domain_len;
var i;
if (wipe) {
$('.bo_search_string').replaceWith($(preserved_search_element));
$('select.bo_search_query option').prop('disabled',false).prop('selected',false);
$('.bo_search_string').prop('readonly',false).removeClass('bo_search_string_readonly').val('').attr('placeholder','Search');
search_string = "";
}
switch(type) {
case 2001://reviewaverage
case 2002://reviewcount
case 1001://money
case 1003://sale
case 1005://weight
case 1014://quantity
case 3:
case 4: //number
$('#qop0, #qop1').prop('disabled',true);
break;
case 22:
case 5: //checkbox
$('#qop0, #qop1, #qop4, #qop5').prop('disabled',true);
$('.bo_search_string').val('checked').prop('readonly',true).addClass('bo_search_string_readonly');
break;
case 7: //selectbox or color
domain = sections[section_index].fields[field_index].domain;
$('#qop4, #qop5').prop('disabled',true);
if (domain == 'color')
$('.bo_search_string').attr('placeholder','Search by color, for example #FFFFFF');
else {
$('#qop0, #qop1').prop('disabled',true);
domain_html = '<select class="bo_search_string" name="SearchString">';
domain_len = domain.length;
for (i = 0; i < domain_len; i++) {
domain_html += '<option value="'+domain[i]+'"'+((domain[i]==search_string)?' selected':'')+'>'+domain[i]+'</option>';
}
domain_html += "</select>";
$('.bo_search_string').replaceWith(domain_html);
}
break;
case 12:
case 20: //image
$('#qop2, #qop3, #qop4, #qop5').prop('disabled',true);
$('.bo_search_string').attr('placeholder','Search by image file name or image description');
break;
case 1010: //pages
$('.bo_search_string').attr('placeholder','Number of pages or page name'); break;
case 1012: //subproducts
$('.bo_search_string').attr('placeholder','Number of subproducts or subproduct name'); break;
case 2003: //parent products
$('.bo_search_string').attr('placeholder','Number of parent products or parent product name'); break;
case 2004: //product-specific coupons
$('.bo_search_string').attr('placeholder','Number of coupons or coupon name'); break;
case 24: //cross-sell
$('.bo_search_string').attr('placeholder','Number or name of cross-sold products'); break;
case 33: //options*/
$('.bo_search_string').attr('placeholder','Number of advanced product options or any option data'); break;
default:
break;
}
if (wipe)
$('select.bo_search_query option:enabled:first').prop('selected', true);
$('.bo_search').css({'visibility':'visible'});
$('#search_wrapper').css({'display':'block'});
}
}
function filter_button_helper() {
if (need_filter_helper)
{
var instructions =
"<h3>We noticed you clicked \"Refine Search Results\" button without changing the search criteria.</h3>"+
"This button narrows down your current search results further.<br>Your current criteria is <i>"+search_request_descriptor+"</i><br>";
if (search_request_descriptor.search("price") == -1)
instructions +=
"For example, change your search to \"Price\" – \"is greater than\" – \"10\" and click this button.<br>"+
"ShopSite will find all products that match <i>"+search_request_descriptor+"</i> AND cost more than "+currency_symbol+"10";
else
instructions +=
"For example, change your search to \"Disable Product\" – \"is\" – \"checked\" and click this button.<br>"+
"ShopSite will find all products that are disabled AND match <i>"+search_request_descriptor+"</i> ";
instructions +=
"<a id='close_filter_helper'>OK</a>";
/*"<a id='ack_filter_helper'>OK, got it, don't show this again.</a><br>"+
"<a id='close_filter_helper'>Alright, let me know if I do this again.</a>";*/
$('#button_filter').tutorial({instruction:instructions, instructionCss:{'width':700, 'text-align':'left'}});
$(document).one('click','#ack_filter_helper', function() {
$.ajax({
async: true,
data: "ajax=ack_helper&helper=filter"+("&form_parm1="+form_parm1),
url: "pageprod_ajax.cgi"
});
need_filter_helper = false;
$.tutorial.remove();
});
$(document).one('click','#close_filter_helper', function() {
$.tutorial.remove();
});
}
}
var search_request_descriptor = "";
function populate_search_form() {
let descriptor;
if (product_type != 3 && product_type != 4) {
var html = '<select id="bo_search_select" class="bo_search_fields" name="fields">';
var section_count = sections.length;
for (let s = 0; s < section_count; s++) {
var section = sections[s];
html += '<optgroup label="'+section.name+'">\n';
var field_count = section.fields.length;
for (let f = 0; f < field_count; f++) {
html += '<option value="'+section.fields[f].id+'" section_index="'+s+'" field_index="'+f+'"'+((section.fields[f].id == search_field)?'selected':'')+(section.fields[f].hidden?' class="hidden_field"':'')+'>'+section.fields[f].name+'</option>\n';
}
html += '</optgroup>\n';
}
html += '</select>\n';
$('select.bo_search_fields').replaceWith(html);
hide_show_optgroup_labels("bo_search_select", "hidden_field");
$(document).off('change','select.bo_search_fields');
$(document).on('change','select.bo_search_fields', function() {
restrict_search_domain(1);
});
if (search_list_all)
descriptor = "list all products";
else {
if (!( (search_query_type == 4 || search_query_type == 5) && isNumber(search_string) ))
var displayed_search_string = '"'+search_string+'"';
else
var displayed_search_string = search_string;
descriptor = $('.bo_search_fields option[value='+search_field+']').html().toLowerCase()+' '+$.trim($('.bo_search_query option[value='+search_query_type+']').html())+' '+displayed_search_string;
}
//console.log(descriptor);
if (search_request_descriptor == "") {
search_request_descriptor = '<span id="search_request_descriptor">'+descriptor+'</span>';
}
else if (search_request_descriptor.search(descriptor) == -1) {
search_request_descriptor = '<span id="search_request_descriptor">'+search_request_descriptor+', '+descriptor+'</span>';
}
}
}
function create_search_summary() {
$('#search_summary').remove();
var html = '<div id="search_summary"></div>';
$('.bo_search').append(html);
//$('#search_wrapper').append(html);
if (total_matching_products > total_number_of_loaded_products)
$('#search_summary').show();
}
function fill_search_summary() {
//var recursive_load_initiated = $('#simplemodal-data').length > 0;
var select_all_html = '<div id="op_select_vall2">select all '+total_matching_products+' matching products</div></div>';
var cselect_all_html = '<div id="op_select_vall2">Select all '+total_matching_products+' matching products</div></div>';
var vall_enabled = !(display_mode == 'A' || display_mode == 'O');
if (scroll_mode == "scrolling" || recursive_load_initiated)
{
if (vall_enabled)
var load_all_html = '<a id="load_all_products" class="depressed_load_all" title="Load all '+total_matching_products+' matching products to screen">Load All</a>';
else
var load_all_html = '<a id="load_all_products">Show All</a>';
var all_done = total_number_of_loaded_products >= total_matching_products;
if (all_done) {
$('#search_summary').html("Showing all products matching: <i>"+search_request_descriptor+"</i>. "+(vall_enabled?cselect_all_html:""));
}
else if (recursive_load_initiated) {
//$('#search_summary').html("Showing products matching: <i>"+search_request_descriptor+"</i>. <a id='load_all_products'>Show All</a>");
$('#search_summary').html('Showing '+total_number_of_loaded_products+' products matching: <i>'+search_request_descriptor+'</i>. '+(vall_enabled?(cselect_all_html+load_all_html):load_all_html));
} else {
//$('#search_summary').html("Showing products matching: <i>"+search_request_descriptor+"</i>. Scroll down to load more or <a id='load_all_products'>Show All</a>");
$('#search_summary').html('Showing '+total_number_of_loaded_products+' products matching: <i>'+search_request_descriptor+'</i>. '+'Scroll down to load more or '+(vall_enabled?(select_all_html+load_all_html):load_all_html));
}
$('#search_summary_shorthand').html(total_number_of_loaded_products+'/'+total_matching_products).attr('title','Showing '+total_number_of_loaded_products+' out of '+total_matching_products+' matching products');
} else {
if (vall_enabled)
var load_all_html = '<a id="load_all_products_pag" class="depressed_load_all" title="Load all '+total_matching_products+' matching products to screen">Load All</a>';
else
var load_all_html = '<a id="load_all_products_pag">Show All</a>';
var starting_product = offset + 1;
var ending_product = Math.min(starting_product + batch_size - 1,total_matching_products);
$('#search_summary_shorthand').html(starting_product+' – '+ending_product+'/'+total_matching_products).attr('title', 'Showing products '+starting_product+' – '+ending_product+' out of '+total_matching_products+' matching products');
//var html = "Showing products matching: <i>"+search_request_descriptor+"</i>.";
var html = 'Showing products '+starting_product+' – '+ending_product+' matching: <i>'+search_request_descriptor+'</i>.';
if (ending_product < total_matching_products)
//html += " Click bottom right buttons to see more products or "+(vall_enabled?(select_all_html+load_all_html):load_all_html);
//html += " Click bottom right buttons to see more products or <a id='load_all_products_pag'>Show All</a>"
html += ' Click bottom right buttons to see more products or '+(vall_enabled?(select_all_html):load_all_html);
$('#search_summary').html(html);
}
}
function make_shorthand() {
$('#search_summary_shorthand').remove();
$(document).off('click', '#search_summary_shorthand');
//if (scroll_mode == 'scrolling')
{
$('.bo_search').append('<div id="search_summary_shorthand"></div>');
$(document).off('click', '#search_summary_shorthand');
$(document).on('click', '#search_summary_shorthand', function() {
if ($('#search_summary').is(':hidden'))
$('#search_summary').slideDown(250);
else
$('#search_summary').slideUp(250);
});
}
}
function make_paginator() {
//$('.paginator_wrapper').remove();
$('.paginator_wrapper_bottom').remove();
$('#paginator_centralizer').remove();
//$('#bottom_setter').remove();
$(document).off('change','.paginator');
$(document).off('click','.pag_first');
$(document).off('click','.pag_last');
$(document).off('click','.pag_prev');
$(document).off('click','.pag_next');
if (scroll_mode == 'pagination') {
var num_pages = Math.ceil(total_matching_products / batch_size);
if (num_pages > 1) {
cur_page = offset / batch_size;
//console.log("pages:"+num_pages+" current:"+cur_page);
var html = '<div class="pag_arrow pag_first" title="Go to the first page"><div></div></div><div class="pag_arrow pag_prev" title="Go to the previous page"><div></div></div><select class="paginator">';
for (var page = 0; page < num_pages; page++) {
html += '<option value="'+page+'"'+((page==cur_page)?' selected':'')+'>'+(page+1)+'</option>';
}
html += '</select><div class="pag_arrow pag_next" title="Go to the next page"><div></div></div><div class="pag_arrow pag_last" title="Go to the last page"><div></div></div>';
if (!(display_mode == 'A' || display_mode == 'O')) {
html += '<div id="load_all_products_pag" class="load_all_icon" title="Load all '+total_matching_products+' matching products to screen"><div></div></div>';
}
//$('.bo_search').append("<div class='paginator_wrapper'>"+html+"</div>");
//$('#products_bottom_block').append(html);
//$('#products_bottom_block').append("<div class='paginator_wrapper_bottom' style='left:"+$('.paginator_wrapper').offset().left+"px'>"+html+"</div>");
$('#bottom_wrapper').append('<div class="paginator_wrapper_bottom">'+html+'</div>').append('<div id="paginator_centralizer"></div>').show();
//$('#products_bottom_block').append("<div id='bottom_setter'></div>");
var load_page = function(page) {
page = parseInt(page);
if (currently_loading || page == cur_page)
return;
$('body').addClass('wait');
products = [];
total_number_of_loaded_products = 0;
var html;
h=0;
$('#products .p').remove();
show_hide_operations();
start_loading();
stick();
var offset_to_load = page*batch_size;
currently_loading = 1;
var request = 'ajax=load_products&offset='+offset_to_load+'&batch_mode=scroll&load_saved_search=1&override_display_mode='+override_display_mode+'&search_storage_container='+search_storage_container+('&form_parm1='+form_parm1)
$.ajax({
async:true,
cache:false,
data: request,
url: "pageprod_ajax.cgi",
success:
function(data) {
error_check(data, request);
$('#products').append(data);
$('.loading').remove();
make_some_products_html(0, products.length);
if (display_mode == 'L') {
if (w != 0) {
$('#horizontal_scroll').scrollLeft(w);
}
}
var selected_option = $('.paginator').find('option:selected');
if (selected_option.val() != page) {
$('.paginator').find('option:selected').prop('selected',false);
$('.paginator').find('option[value='+page+']').prop('selected',true);
}
stick();
cur_page = page;
fill_search_summary();
//nailWidths();
finish_loading();
}
});
}
$(document).on('click', '.pag_first', function() {
load_page(0);
});
$(document).on('click', '.pag_last', function() {
load_page(num_pages-1);
});
$(document).on('click', '.pag_prev', function() {
if (cur_page > 0)
load_page(cur_page-1);
});
$(document).on('click', '.pag_next', function() {
if (cur_page < num_pages-1)
load_page(cur_page+1);
});
$(document).on('change','.paginator', function() {
var page = $(this).find('option:selected').val();
load_page(page);
});
}
}
}
function add_product(id, disabled, dump) {
if (display_mode == 'A' && target_prefix == "") {
var assigned_index;
if ((assigned_index = locate_product(id, assigned_products)) != null) {
//assigned_products[assigned_index] = product;
return;
}
}
var product = {
id: id,
disabled: disabled
};
for (var f=0; f < field_count; f++) {
product[product_fields[f].code] = dump[f]
}
products.push(product);
}
function nailWidth(code, width) {
width = parseInt(width);
var f = locate_field(code);
var do_setting = 0;
//width not set -- set from browser
var browser_width = $("#"+target_prefix+"product_field_heading_"+code).width();
var set_width = parseInt($("#"+target_prefix+"product_field_heading_"+code).css('width'));
if (width == -1) {
do_setting = 1;
width = browser_width;
} else if (width != set_width) {
do_setting = 1;
}
if (do_setting == 1) {
$("#"+target_prefix+"product_field_heading_"+code).css({'width':width, 'min-width':width, 'max-width':width});
var text_width = width;
if ($("#"+target_prefix+"product_field_heading_"+code).find('.sort').css('display') == 'block')
text_width -= 16;
$("#"+target_prefix+"product_field_heading_"+code+" .table_heading").css({'max-width':text_width});
$("#"+target_prefix+"product_field_manager_"+code).css({'width':width, 'max-width':width, 'min-width':width}).attr('width',width); //nail it really really really hard
$("#"+target_prefix+"col_define_"+code).css({'width':width, 'max-width':width, 'min-width':width}).attr('width',width);
product_fields[f].column_width = width;
}
browser_width = $("#"+target_prefix+"product_field_manager_"+code).width();
if (browser_width > width + 1 || width < 25) {
setTimeout(function() {
var result_width = $("#"+target_prefix+"product_field_manager_"+code).width();
if (width < 25 || width < result_width) {
width = Math.max(25,result_width);
text_width = width;
if ($("#"+target_prefix+"product_field_heading_"+code).find('.sort').css('display') == 'block')
text_width -= 16;
$("#"+target_prefix+"product_field_heading_"+code).css({'min-width':width, 'max-width':width, 'width':width});
$("#"+target_prefix+"product_field_heading_"+code+" .table_heading").css({'max-width':text_width});
$("#"+target_prefix+"product_field_manager_"+code).css({'width':width,'max-width':width, 'min-width':width}).attr('width',width);
$("#"+target_prefix+"col_define_"+code).css({'width':width,'max-width':width, 'min-width':width}).attr('width',width);
product_fields[f].column_width = width;
update_column_width(f, width);
}
},(IE==false)?0:1000);
}
return do_setting;
}
function nailWidths() {
var change = 0;
var changed;
if (display_mode == 'L' || display_mode == 'A' || display_mode == 'O') {
var width = Math.floor($("#"+target_prefix+"product_field_heading_select").width())/*-1*/;
$("#"+target_prefix+"product_field_manager_select").css({'width':width, 'max-width':width, 'min-width':width}).attr('width',width);
$("#"+target_prefix+"col_define_select").css({'width':width, 'max-width':width, 'min-width':width}).attr('width',width);
for (var f=0; f < field_count; f++) {
var code = product_fields[f].code;
var width = product_fields[f].column_width;
changed = nailWidth(code, width);
if (changed)
change = 1;
}
}
return change;
}
function saveWidths() {
if (target_prefix == "") {
for (var f=0; f < field_count; f++) {
code = product_fields[f].code;
product_fields[f].column_width = $('#product_field_heading_'+code).outerWidth()+1;
}
}
}
function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
function locate_product(id, optional_source) {
var source = products;
if (optional_source !== undefined)
source = optional_source;
var product_count = source.length;
for (let p = 0; p < product_count; p++) {
if (source[p].id == id)
return p;
}
return null;
}
function locate_field(code_or_id) {
if (isNumber(code_or_id)) {
for (var f=0; f < field_count; f++) {
if (product_fields[f].id == code_or_id)
return f;
}
} else {
for (var f=0; f < field_count; f++) {
if (product_fields[f].code == code_or_id)
return f;
}
}
return null;
}
function locate_field_indexes() {
let section_count = sections.length, fields_in_section, section_index, field_index;
for (let f = 0; f < field_count; f++) {
let id = product_fields[f].id;
section_index = -1;
field_index = -1;
for (let s = 0; s < section_count && section_index == -1; s++) {
fields_in_section = sections[s].fields.length;
for (let ff = 0; ff < fields_in_section && field_index == -1; ff++) {
if (sections[s].fields[ff].id == id) {
section_index = s;
field_index = ff;
product_fields[f].section_index = s;
product_fields[f].field_index = ff;
}
}
}
}
}
var ordered_fields = [];
function order_fields() {
ordered_fields = product_fields.slice();
ordered_fields.sort(function(p1, p2){
if (p1.column_order < p2.column_order) {
return -1;
} else {
return 1;
}
});
}
function color_rows() {
$('.selected_product').removeClass('selected_product');
if (display_mode == 'L') {
var sliding_product_collection = $('#sliding_products .p');
var fixed_product_collection = $('#fixed_products .p');
var index;
$('.ui-selected').each(function() {
index = fixed_product_collection.index($(this).closest('.p'));
$(fixed_product_collection[index]).addClass('selected_product');
$(sliding_product_collection[index]).addClass('selected_product');
});
}
if (display_mode == 'A' || display_mode == 'O') {
$('.ui-selected').each(function() {
$(this).closest('.p').addClass('selected_product');
});
}
}
function update_disable_button() {
if (display_mode == 'L')
var selected_class = '.selected_product';
else
var selected_class = '.ui-selected';
if ($(selected_class).length) {
if ($(selected_class).filter('.p_dis').length == $(selected_class).length)
$('#o_disable').attr('title', 'Enable products').attr('id','o_enable');
else
$('#o_enable').attr('title', 'Disable products').attr('id','o_disable');
} else
$('#o_enable').attr('title', 'Disable products').attr('id','o_disable');
}
var vall_selected = 0;
function show_hide_operations() {
if (display_mode == 'L' || display_mode == 'G' || display_mode == 'O') {
if (vall_selected == 2)
vall_selected = 1;
else
vall_selected = 0;
var selected_count = $('.ui-selected').length;
var operations_shown = $('#operations').length;
if (vall_selected)
selected_count = total_matching_products;
if (selected_count) {
var text = selected_count+" product"+((selected_count == 1)?"":"s")+" selected";
if (vall_selected)
text = '<b>'+text+'</b>';
var select_all_text = "";
if (!vall_selected && $('#p_sel_all').is(':checked') && selected_count == $('#fixed_products .p').length && selected_count < total_matching_products && display_mode != 'O') {
select_all_text = "select all "+total_matching_products+" matching products";
}
if (!operations_shown) {
var html = '<div id="o_deselect"><div></div>Back</div><div id="op_selection"><div id="op_text">'+text+'</div><div id="op_select_vall">'+select_all_text+'</div></div>';
if (display_mode == 'L' || display_mode == 'G') {
html +=
"<div id='operations'>";
html += '<div id="o_edit" class="op" title="Edit product information"></div><div id="o_poweredit" class="op" title="PowerEdit products"></div><div id="o_oa" class="op" title="Show order buttons"></div>';
if (product_type == 2) //pro-only
html += '<div id="o_download" class="op" title="Download products"></div><div id="o_disable" class="op" title="Disable products"></div>';
html +=
'<div id="o_copy" class="op" title="Copy product"></div>'+
'<div id="o_delete" class="op" title="Delete products"></div>' +
'<div id="more_operations" class="op" title="More..."></div>'+
'</div>';
html += '<div id="more_operations_open">'+
'<div id="o_layout">Edit product layout</div>'+
//'<div id="o_copy">Copy product</div>'+
'<div id="o_select_sub">Select subproducts</div>'+
'<div id="o_arrange_sub">Arrange subproducts</div>'+
'</div>\n';
}
if (display_mode == 'O') {
html +=
'<div id="operations"><div id="o_oa" class="op" title="Show order buttons"></div></div>';
}
$('#operations_container').append(html);
//$('.bo_search').replaceWith("<div id='operations_container'>"+html+"</div>");
$('.bo_search').css({'display':'none'}).after('<div id="operations_container">'+html+'</div>');
$('#search_wrapper').addClass('operations_wrapper');
update_disable_button();
//$('#search_summary').detach().appendTo('#operations_container');
} else {
$('#op_text').html(text);
$('#op_select_vall').html(select_all_text);
}
if (select_all_text != "") {
$('#op_selection').css({'margin-bottom':-8, 'top':-3});
$('#op_text').css({'line-height':'18px'});
} else {
$('#op_selection').removeAttr('style');
$('#op_text').removeAttr('style');
}
if (selected_count == 1) {
$('#o_copy').css({'display':''});
$('#more_operations').css({'visibility':'visible'});
} else {
$('#o_copy').css({'display':'none'});
$('#more_operations').css({'visibility':'hidden'});
}
if (vall_selected && selected_count > 50) {
$('#o_edit, #o_oa').css({'display':'none'});
} else
$('#o_edit, #o_oa').css({'display':''});
}
if (!selected_count && operations_shown) {
//$('#search_summary').detach().appendTo('.bo_search');
$('#operations_container').remove();
$('.bo_search').css({'display':''});
$('#search_wrapper').removeClass('operations_wrapper');
}
}
}
function load_all_sections() {
$.ajax({
async: false,
data: 'ajax=get_product_sections&form_parm1='+form_parm1,
url: 'pageprod_ajax.cgi',
success:
function(data) {
error_check(data, 'get_product_sections');
$('body').append(data);
}
});
}
var ctrl = false;
var shift = false;
var last_selected = false;
var sel_op = 1;
function create_selectable_control() {
if (display_mode != 'W' && ((product_type != 4 && product_type != 3) || display_mode == 'A' || display_mode == 'O')) {
sel_op = 1;
//$('#products').selectable("destroy");
$(document).off('click', '.p');
$(document).off('click', '.p_sel');
if (display_mode == 'G' || display_mode == 'W') {
$('#products').selectable({filter: '.p', distance:5, stop:function() { update_disable_button(); show_hide_operations();} });
$(document).on('click', '.p', function() {
//var count = parseInt($(this).attr('id').substr(8));
product_collection = $('.p');
var index = product_collection.index($(this));
if (!ctrl)
$('.ui-selected').removeClass('ui-selected');
if (shift && last_selected !== false) {
//alert(count+" "+last_selected);
if (index > last_selected) {
for (i = last_selected; i <= index; i++) {
$(product_collection[i]).addClass('ui-selected');
}
} else {
for (i = index; i <= last_selected; i++) {
$(product_collection[i]).addClass('ui-selected');
}
}
} else {
$(this).toggleClass('ui-selected');
last_selected = index;
}
update_disable_button();
show_hide_operations();
});
} else {
//console.log("creating selectable control");
$('#'+target_prefix+'fixed_products').selectable({
filter:'.p_sel',
cancel:".p td:nth-child(3),td:nth-child(4)",
distance:5,
//start:function(event,ui) { console.log("started selecting"); },
unselected:function(event, ui) {
el = $(ui.unselected);
if (el.prop('checked') == true)
el.addClass('ui-selected-preserved');
},
stop:function(event,ui) {
if ($('.ui-selected').length == $('.ui-selected:checked').length) {
$('.ui-selected').prop('checked',false);
$('.ui-selected').removeClass('ui-selected');
} else {
$('.ui-selected').prop('checked',true);
}
$('.ui-selected-preserved').addClass('ui-selected').removeClass('ui-selected-preserved');
color_rows();
update_disable_button();
update_assignment_buttons();
show_hide_operations();
last_selected = false;
selector_popup_counter = 0;
}
});
selector_popup_counter = 0;
$(document).on('click', '.p_sel', function(event) {
//var count = parseInt($(this).attr('id').substr(8));
var fixed_product_collection = $(this).closest('table').find('.p');//$('#fixed_products .p');
var index = fixed_product_collection.index($(this).closest('.p'));
//console.log("checkbox index:"+index);
if ($(this).is(':checked')) {
prev_sel_op = sel_op;
sel_op = 1;
} else {
prev_sel_op = sel_op;
sel_op = 0;
}
if (prev_sel_op != sel_op)
last_selected = false;
//console.log("Checkbox clicked. shift:"+shift+" sel_op:"+sel_op+" prev_sel_op:"+prev_sel_op+" last_selected:"+last_selected+" index:"+index)
if (shift && last_selected !== false) {
selector_popup_counter = 0;
if (sel_op) {
if (index > last_selected) {
for (i = last_selected; i <= index; i++) {
//$(product_collection[i]).addClass('ui-selected');
$(fixed_product_collection[i]).find('.p_sel').prop('checked',true).addClass('ui-selected');;
}
} else {
for (i = index; i <= last_selected; i++) {
//$(product_collection[i]).addClass('ui-selected');
$(fixed_product_collection[i]).find('.p_sel').prop('checked',true).addClass('ui-selected');;
}
}
} else {
if (index > last_selected) {
for (i = last_selected; i <= index; i++) {
//$(product_collection[i]).removeClass('ui-selected');
$(fixed_product_collection[i]).find('.p_sel').prop('checked',false).removeClass('ui-selected');;
}
} else {
for (i = index; i <= last_selected; i++) {
//$(product_collection[i]).removeClass('ui-selected');
$(fixed_product_collection[i]).find('.p_sel').prop('checked',false).removeClass('ui-selected');;
}
}
}
} else {
//$(this).closest('.p').toggleClass('ui-selected');
$(this).toggleClass('ui-selected');
if ($(this).hasClass('ui-selected')) {
if (last_selected == false || index == last_selected + 1)
selector_popup_counter++;
else
selector_popup_counter = 1;
if (need_selector_helper && selector_popup_counter == 4) {
var modalhtml =
'<h3>Did you know you can select multiple products at once?</h3>'+
'There are two ways to do this:'+
'<ol><li>Click anywhere on the product row. Then click on another product while holding down your Shift key.</li>'+
'<li>Hold your left mouse button when clicking on a checkbox. While holding the mouse button, drag your mouse across multiple checkboxes.</li></ol>'+
'<a id="ack_selector_helper">OK, got it!</a>';
$.modal(modalhtml,
{
closeHTML: "",
maxWidth: "600px",
minHeight:"200px",
overlayClose:false,
autoPosition: true,
autoResize: true,
containerId: "selector_helper",
onShow: function (dialog) { $('body').css({overflow:'hidden'}); },
onClose: function(dialog) { $.modal.close(); $('body').css({overflow:'auto'}); }
});
$(document).on('click','#ack_selector_helper', function() {
$.ajax({
async: true,
data: "ajax=ack_helper&helper=selector"+("&form_parm1="+form_parm1),
url: "pageprod_ajax.cgi"
});
need_selector_helper = false;
$.modal.close();
});
}
} else
selector_popup_counter = 0;
last_selected = index;
}
color_rows();
update_disable_button();
update_assignment_buttons();
show_hide_operations();
//console.log("After checkbox proc. shift:"+shift+" sel_op:"+sel_op+" prev_sel_op:"+prev_sel_op+" last_selected:"+last_selected+" index:"+index)
event.stopPropagation();
});
$(document).off('click', '.p > td, .p_name_l_select');
$(document).on('click', '.p > td, .p_name_l_select', function(event) {
if ($(this).closest('table').attr('id') == 'fixed_products')
var cb = $(this).closest('tr').find('.p_sel');
else {
var id = $(this).closest('.p').find('.pid').val();
var sliding_product_collection = $('#sliding_products .p');
var fixed_product_collection = $('#fixed_products .p');
var index = sliding_product_collection.index($(this).closest('.p'));
var cb = $(fixed_product_collection[index]).find('.p_sel');
}
$(cb).click();
event.stopPropagation();
});
}
$(document).off('click', '#p_sel_all, #as_p_sel_all, #op_select_vall, #op_select_vall2').on('click', '#p_sel_all, #as_p_sel_all, #op_select_vall, #op_select_vall2', function() {
var id = $(this).attr('id');
//console.log("YO "+$(this).attr('id'));
selector_popup_counter = 0;
if (id == "as_p_sel_all" || id == "p_sel_all") {
var prefix = "";
if (id == "as_p_sel_all")
prefix = "as_";
if (!$(this).is(':checked')) {
$('#'+prefix+'fixed_products .p_sel').prop('checked',false).removeClass('ui-selected');
} else {
$('#'+prefix+'fixed_products .p_sel').prop('checked',true).addClass('ui-selected');
}
} else {
vall_selected = 2;
if (display_mode == 'G' || display_mode == 'W') {
$('#products .p').addClass('ui-selected');
} else {
$('#fixed_products .p_sel').prop('checked',true).addClass('ui-selected');
$('#p_sel_all').prop('checked', true);
}
}
color_rows();
update_disable_button();
update_assignment_buttons();
show_hide_operations();
});
}
}
function stick_top(scrollh) {
var top_block = $('#products_top_block');
var top_stuck = top_block.hasClass('stuck_top');
var top_height = top_block.outerHeight();
var top_offset = $('#products').offset().top - top_height;
var window_height = $(window).height();
if (!top_stuck) {
if (scrollh > top_offset && $('#products').outerHeight() + top_height > window_height) {
top_block.addClass('stuck_top');
if (display_mode == 'A') {
$('#as_products').addClass('stuck_assigned').css({'left':$('#as_products_control').offset().left, 'top':top_height});
$('#as_buttons').addClass('stuck_assigned').css({'left':$('#asc_button').offset().left, 'top':top_height});
}
//console.log("sticking top");
}
}
else {
if (scrollh < top_offset) {
top_block.removeClass('stuck_top');
if (display_mode == 'A') {
$('#as_products').removeClass('stuck_assigned');
$('#as_buttons').removeClass('stuck_assigned');
}
//console.log("unsticking top");
}
}
if (display_mode == 'A') {
setTimeout(function(){
var scrollh = $(window).scrollTop();
var top_stuck = top_block.hasClass('stuck_top');
var top_height = top_block.outerHeight();
var top_offset = $('#products').offset().top - top_height;
var window_height = $(window).height();
if (!top_stuck) {
//console.log(window_height+" "+top_height+" "+top_offset+" "+scrollh+" "+$('#products_bottom_block').outerHeight());
var h = Math.min(window_height- top_height - top_offset + scrollh-$('#products_bottom_block').outerHeight(), window_height-200);
} else
var h = window_height-$('#products_top_block').outerHeight() - $('#footer').outerHeight()-$('#products_bottom_block').outerHeight();
//console.log("top_stuck:"+top_stuck+" adjusting bottom "+h);
$('#as_products').css({'max-height':h});
},IE?0:0);
}
}
function stick_bottom(scrollh) {
var bottom_scrollh = scrollh + $(window).height();
var bottom_block = $('#products_bottom_block');
var bottom_stuck = bottom_block.hasClass('stuck_bottom');
var bottom_offset = $('#products').offset().top + $('#products').outerHeight() + bottom_block.outerHeight();
if (!bottom_stuck) {
if (bottom_scrollh < bottom_offset) {
bottom_block.addClass('stuck_bottom');
//console.log("sticking bottom");
}
}
else {
if (bottom_scrollh > bottom_offset) {
bottom_block.removeClass('stuck_bottom');
//console.log("unsticking bottom");
}
}
}
function stick() {
var scrollh = $(window).scrollTop();
//console.log("SCROLL "+scrollh);
stick_top(scrollh);
stick_bottom(scrollh);
}
function ignore_assigned_products() {
var ignore_part = "";
if (display_mode == 'A' && typeof assigned_products !== 'undefined' && assigned_products.length > 0) {
assigned_products_list=[]
for (var p = 0; p < assigned_products.length; p++)
assigned_products_list.push(assigned_products[p].id);
assigned_products_list = assigned_products_list.join();
ignore_part = "&ignore="+assigned_products_list;
}
return ignore_part;
}
function request_type() {
if (display_mode == 'A' && typeof assigned_products !== 'undefined' && assigned_products.length > 10)
return "POST";
return "GET";
}
function infinite_scroll() {
/*console.log("is1 "+total_number_of_loaded_products+" "+total_matching_products);
console.log("is2 "+($(window).scrollTop() + $(window).height())+" "+$('#products').offset().top + $('#products').outerHeight() - 50);*/
if (scroll_mode == "scrolling" && total_number_of_loaded_products < total_matching_products && !currently_loading && $(window).scrollTop() + $(window).height() > $('#products').offset().top + $('#products').outerHeight() - 50) {
//console.log("infinite scroll");
start_loading();
stick();
var request = "ajax=load_products&offset="+total_number_of_loaded_products+"&batch_mode=scroll&load_saved_search=1&override_display_mode="+override_display_mode+"&search_storage_container="+search_storage_container+("&form_parm1="+form_parm1);
$.ajax({
async:true,
cache:false,
data: request,
type: request_type(),
url: "pageprod_ajax.cgi",
success:
function(data) {
error_check(data, request);
//console.log(data);
var previous_length = products.length;
//console.log("previous_length "+previous_length);
$('#products').append(data);
//console.log("length now "+products.length);
make_some_products_html(previous_length, products.length);
//total_number_of_loaded_products = products.length; //can't do this because on assignment interface they may have assigned some products, emptying out products array
total_number_of_loaded_products += products_loaded_in_last_batch;
//console.log("total_number_of_loaded_products "+total_number_of_loaded_products);
/*if (display_mode == 'A')
total_number_of_loaded_products += assigned_products.length;*/
fill_search_summary();
//nailWidths();
stick();
finish_loading();
}
});
}
}
var w = 0, h = 0;
function create_scroll_control() {
$(window).off('scroll');
$(window).on('scroll',function() {
infinite_scroll();
stick();
});
}
function constrain_slider(reboot) {
if (reboot) {
w = 0;
$('#sliding_control, #sliding_products').css({'left':0});
}
$('#horizontal_scroll').off('scroll');
$('#horizontal_scroll').remove();
//$('#products_bottom_block').height($('#products_bottom_block').outerHeight()-15);
if (display_mode == 'L' || display_mode == 'A' || display_mode == 'O') {
var left_offset = $('#fixed_products').outerWidth();
var allowed_width = $(window).width() - left_offset;
var total_width = $('#sliding_products').outerWidth();
$('#sliding_products_wrapper').css({'max-width':allowed_width});
$('#sliding_control_wrapper').css({'max-width':allowed_width});
if (allowed_width < total_width) {
var html = '<div id="horizontal_scroll" style="width:'+allowed_width+'px;left:'+left_offset+'px"><div style="width:'+total_width+'px"></div></div>';
$('table#as_fixed_products td:last-child, table#fixed_products td:last-child').css({'border-right-color':'#CCCCCC'});
$('table#fixed_control th:last-child').css({'border-image':'linear-gradient(to top, #CCCCCC, rgba(0, 0, 0, 0)) 0 100%'});
$('#products_bottom_block').prepend(html);
//$('#products_bottom_block').height($('#products_bottom_block').outerHeight()+15);
} else {
$('table#as_fixed_products td:last-child, table#fixed_products td:last-child').css({'border-right-color':''});
$('table#fixed_control th:last-child').css({'border-image':''});
}
$('#horizontal_scroll').on('scroll',function() {
w = $(this).scrollLeft();
$('#sliding_control, #sliding_products').css({'left':-w});
});
}
}
/*adjusts heights for table cells to make sure they match in fixed part and sliding part:
1) Remove previously set heights
2) Measure natural heights that browser assigns
3) Detach both tables
4) Apply maximum of natural heights to detached cells
5) Reattach tables
Is much faster than just applying heights one by one and redrawing DOM in a loop
*/
function adjust_product_heights(start,end, adjust_empties) {
if (display_mode == 'L' || display_mode == 'A' || display_mode == 'O') {
if (adjust_empties && start_index == field_count) {
var fixed_product_collection = $("#fixed_products .p").slice(start,end);
var sliding_product_collection = $("#sliding_products .p").slice(start,end);
fixed_product_collection.css({'height':''});
sliding_product_collection.css({'height':''});
}
if ($('#sliding_products').length == 0 || start_index == field_count)
return;
var fixed_height;
var sliding_height;
var fixed_part;
var sliding_part;
var fixed_product_collection = $("#fixed_products .p").slice(start,end);
var sliding_product_collection = $("#sliding_products .p").slice(start,end);
var len = sliding_product_collection.length;
//console.log("collection length:"+len);
fixed_product_collection.css({'height':''});
sliding_product_collection.css({'height':''});
var fixed_heights = [];
var sliding_heights = [];
for (var p = 0; p < len; p++) {
fixed_part = $(fixed_product_collection[p]);
sliding_part = $(sliding_product_collection[p]);
fixed_height = fixed_part.height()+1; //IE has partial pixels. Of course it does.
sliding_height = sliding_part.height()+1;
fixed_heights.push(fixed_height);
sliding_heights.push(sliding_height);
//console.log(fixed_part.height()+" "+fixed_part.innerHeight()+" "+fixed_part.children('td').height()+" "+fixed_part.children('td:last_child').children().height());
}
fixed_product_collection = fixed_product_collection.detach();
sliding_product_collection = sliding_product_collection.detach();
for (var p = 0; p < len; p++) {
fixed_part = $(fixed_product_collection[p]);
sliding_part = $(sliding_product_collection[p]);
fixed_height = fixed_heights[p];
sliding_height = sliding_heights[p];
if (fixed_height < sliding_height) {
fixed_part.css({'height':sliding_height});
sliding_part.css({'height':sliding_height});
} else if (fixed_height > sliding_height) {
sliding_part.css({'height':fixed_height});
fixed_part.css({'height':fixed_height});
}
}
$("#fixed_products").append(fixed_product_collection);
$("#sliding_products").append(sliding_product_collection);
}
}
function update_column_order() {
if (display_mode == 'L') {
var column_order = "0:0";
for (var f=start_index; f < field_count; f++) {
var index = $('#sliding_control .product_field_heading').index($('#product_field_heading_'+product_fields[f].code))+500;
product_fields[f].column_order = index;
column_order += (","+product_fields[f].id+":"+index)
}
$.ajax({
async: true,
data: "ajax=update_column_order&column_order="+column_order+("&form_parm1="+form_parm1),
cache:false,
url: "pageprod_ajax.cgi"
});
}
}
function update_column_width(field, width) {
data = "ajax=update_column_width&fieldNum="+product_fields[field].id+"&width="+width+("&form_parm1="+form_parm1);
$.ajax({
async: true,
//type: "POST",
data: data,
cache:false,
url: "pageprod_ajax.cgi"
});
}
function create_screen_resize_control() {
var resizeTimer;
$(window).off('resize');
$(window).on('resize', function(e) {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function() {
stick();
constrain_slider(1);
/*if ($('.paginator_wrapper').length)
$('.paginator_wrapper_bottom').css({'left':$('.paginator_wrapper').offset().left});*/
if (display_mode == 'A') {
var top_block = $('#products_top_block');
var top_stuck = top_block.hasClass('stuck_top');
var top_height = top_block.outerHeight();
if (top_stuck) {
$('#as_products').css({'left':$('#as_products_control').offset().left, 'top':top_height});
$('#as_buttons').css({'left':$('#asc_button').offset().left, 'top':top_height});
}
}
}, 500);
});
}
function create_sortable_control() {
if (display_mode == 'A' && allow_assigned_sorting) {
$(document).on('mouseenter','#as_fixed_products .p', function() { $(this).attr('title','Drag to re-order');});
$('#as_fixed_products').sortable({
containment:'parent',
items:'tr.p',
placeholder:'ui-placeholder-highlight',
forcePlaceholderSize:true,
tolerance:'pointer',
helper:function(e,
ui){ui.children().each(function(){$(this).addClass('dragging');$(this).width($(this).width());});return ui;},
stop:function(ev,ui){$('.dragging').removeClass('dragging');}});
}
}
var column_control_exists = 0;
function create_column_control() {
$('#products_control').remove();
column_control_exists = 0;
var fields, field, table_heading_html, start_index;
if (display_mode == 'L' || display_mode == 'A' || display_mode == 'O') {
//console.log("creating column control with prefix "+target_prefix);
fields = ordered_fields;
table_heading_html = '<table id="'+target_prefix+'products_control"><tr><td>';
table_heading_html += '<div id="'+target_prefix+'fixed_control_wrapper">';
table_heading_html += '<table id="'+target_prefix+'fixed_control"><tr class="product_list_headings">';
table_heading_html += '<th class="product_field_heading" id="'+target_prefix+'product_field_heading_select"><input type="checkbox" id="'+target_prefix+'p_sel_all"></th>';
start_index = 1;
if (target_prefix == "") {
if (search_field > 0) {
start_index++;
}
}
for (var f=0; f < start_index; f++) {
field = fields[f];
table_heading_html += '<th class="product_field_heading'+((field.id==search_field)?' searched_product_field':'')+'" id="'+target_prefix+'product_field_heading_'+field.code+'"><span class="table_heading">'+field.name+'</span>';
table_heading_html += '<span class="sort sort_asc" id="'+target_prefix+'sort_'+field.code+'"></span>';
table_heading_html += '</th>';
}
table_heading_html += '</tr></table></div></td>';
if (display_mode == 'L') {
table_heading_html += '<td><div id="sliding_control_wrapper">';
table_heading_html += '<table id="sliding_control"><tr class="product_list_headings">';
for (var f=start_index; f < field_count; f++) {
field = fields[f];
table_heading_html += '<th class="product_field_heading'+((field.id==search_field)?' searched_product_field':'')+'" id="product_field_heading_'+field.code+'"><span class="table_heading">'+field.name+'</span>';
table_heading_html += '<span class="sort sort_asc" id="sort_'+field.code+'"></span>';
table_heading_html += '</th>';
}
table_heading_html += '</tr></table></div></td>';
}
table_heading_html += '</tr></table>';
if (display_mode == 'L' || display_mode == 'O')
$('#search_wrapper').after(table_heading_html);
else if (display_mode == 'A') {
if (target_prefix == "")
$('#asc_unassigned').append(table_heading_html);
else
$('#asc_assigned').append(table_heading_html);
}
if (target_prefix == "" && product_type !=3 && product_type != 4) {
var sort_field_index = locate_field($('#sort_op').val());
if (sort_field_index != null) {
var sort_field = product_fields[sort_field_index].code;
//var order = "asc";
if ($('#sortasc_op').val() == 0) {
//order = "desc";
$('#sort_'+sort_field).removeClass('sort_asc').addClass('sort_desc');
}
$('#sort_'+sort_field).addClass('current_sort');
}
$('#products_control .product_field_heading').hover(
function() {
//if ($('.ui-resizable-helper').length == 0)
{
//console.log("on");
var ar = $(this).find('.sort');
if (!ar.hasClass('current_sort')) {
var heading = $(this).find('.table_heading');
var w = parseInt(heading.css('max-width'));
//console.log(w);
heading.css({'max-width':w-16});
ar.css({'display':'block'});
}
}
},
function() {
//if ($('.ui-resizable-helper').length == 0)
{
//console.log("off");
var ar = $(this).find('.sort');
if (!ar.hasClass('current_sort')) {
var heading = $(this).find('.table_heading');
var w = parseInt(heading.css('max-width'));
heading.css({'max-width':w+16});
ar.css({'display':'none'});
}
}
}
);
$('#products_control .current_sort').hover(
function() {
$(this).toggleClass('sort_asc').toggleClass('sort_desc');
},
function() {
$(this).toggleClass('sort_asc').toggleClass('sort_desc');
}
);
}
$('.product_list_headings').disableSelection();
//alsoResize: ".product_field_"+$(this).attr('id').substr(23)
//if (target_prefix == "")
{
$('#'+target_prefix+'products_control .product_field_heading:not(#'+target_prefix+'product_field_heading_select)').resizable({
autoHide: true,
//maxHeight:30,
handles: 'e',
ghost:true,
helper: "ui-resizable-helper",
/*start: function(event,ui) {
//$('#products_control table').removeAttr('style');
//ui.helper.height(ui.element.height());
console.log("resizable helper height:"+ui.helper.height());
},*/
stop: function(event, ui) {
var width = ui.size.width-8;
if (display_mode == 'A' && ui.element.attr('id').substr(0,3) == "as_")
target_prefix = "as_";
code = ui.element.attr('id').substr(22+target_prefix.length);
var changed = nailWidth(code, width);
if (changed) {
field = locate_field(code);
update_column_width(field, width);
}
if (display_mode == 'A') {
/*var total_width = $("#"+target_prefix+"products_control").outerWidth();
var header = $("#"+target_prefix+"products_control").prev();
if (parseInt(header.css('min-width')) == 0) {
header.css({'display':'inline'});
var minwidth = header.outerWidth()+2;
header.css({'min-width':minwidth});
header.css({'display':'block'});
if (target_prefix == "")
$('#asp_unassigned').css({'min-width':minwidth});
else
$('#asp_assigned').css({'min-width':minwidth});
}
header.width(total_width);
$("#"+target_prefix+"products").width(total_width);*/
if (target_prefix != "") {
$('#as_products').css({'left':$('#as_products_control').offset().left});
}
}
if (changed)
adjust_product_heights(0,1000000,false);
stick();
constrain_slider(1);
target_prefix = "";
}
});
$('.product_field_heading:not(#product_field_heading_select)').on('resize', function (e) {
e.stopPropagation();
});
}
if (display_mode == 'L') {
$('#sliding_control .product_list_headings').sortable({
delay: 300,
placeholder: "column_placeholder",
helper:"clone",
//forceHelperSize:true,
opacity: 0.6,
//axis:"x",
cursorAt: { right:-10},
//cancel: '#product_field_heading_delete',
items: ".product_field_heading:not(#product_field_heading_delete)",//can't move product name, can't move search field
tolerance:'pointer',
start: function(event,ui) {
code = ui.item.attr('id').substr(22);
field = locate_field(code);
ui.placeholder.width(product_fields[field].column_width);
},
stop: function(event,ui) {
code = ui.item.attr('id').substr(22);
{
start_time = new Date().getTime();
var idx = $('#sliding_manager .product_field_manager').index($("#product_field_manager_"+code));
var product_collection = $("#sliding_products .p");
len = product_collection.length;
var prod;
var cells;
product_collection = product_collection.detach();
var neighbor = ui.item.next();
var switcher_func = function(dest, src) { dest.before(src) };
var text = "before";
if (!neighbor.length) {
neighbor = ui.item.prev();
switcher_func = function(dest, src) { dest.after(src) };
text = "after";
}
var neighbor_code = neighbor.attr('id').substr(22);
var neightbor_idx = $('#sliding_manager .product_field_manager').index($("#product_field_manager_"+neighbor_code));
//console.log("Insert "+idx+" "+text+" "+neightbor_idx);
switcher_func($("#product_field_manager_"+neighbor_code), $("#product_field_manager_"+code));
switcher_func($("#col_define_"+neighbor_code), $("#col_define_"+code));
for (var p = 0; p < len; p++) {
prod = $(product_collection[p]);
cells = prod.children('td');
switcher_func($(cells[neightbor_idx]), $(cells[idx]));
//$(cells[neightbor_idx]).func($(cells[idx]));
}
update_column_order();
order_fields();
$('#sliding_products').append(product_collection);
//console.log("Time it took:"+(new Date().getTime()-start_time));
}
},
});
}
column_control_exists = 1;
}
if (display_mode == 'G' && column_control_exists) {
$('#products_control').remove();
column_control_exists = 0;
}
}
function create_field_control() {
$(document).off('click','div#add_field');
$(document).off('click','a#close_add_field');
$(document).off('change','#add_field_open select');
$(document).off('click','div#remove_field');
$(document).off('click','a#close_remove_field');
$(document).off('change','#remove_field_open select');
$(document).off('mouseleave','.field_menu');
$(document).off('mouseenter','.field_menu');
$('#field_control').remove();
if (display_mode == 'L') {
//$('.products_top_block').prepend
var html = '<div id="field_control"><div id="add_field" title="Add Column" class="field_clicker"><div></div></div><div id="remove_field" title="Remove Column" class="field_clicker"><div></div></div></div>';
$('.display_mode').after(html);
$(document).on('click','div#add_field', function() {
var section_count = sections.length;
var left_offset = $(this).parent().offset().left;
var html = '<div id="add_field_open" class="field_menu" style="left:'+left_offset+'px"><a id="close_add_field" class="close_field_menu"></a><select id="add_field_select" size=20>';
var field_on_screen;
for (var s = 0; s < section_count; s++) {
var section = sections[s];
html += "<optgroup label=\""+section.name+"\">\n";
var field_count = section.fields.length;
for (var f = 0; f < field_count; f++) {
field_on_screen = locate_field(section.fields[f].id);
html += '<option '+(field_on_screen!=null?'class="present" disabled':(section.fields[f].hidden?'class="hidden_field"':''))+' value="'+section.fields[f].id+'" section_index="'+s+'" field_index="'+f+'">'+section.fields[f].name+'</option>\n';
}
html += '</optgroup>\n';
}
html += '</select></div>\n';
$(this).parent().replaceWith(html);
hide_show_optgroup_labels('add_field_select', 'hidden_field');
});
$(document).on('click','a#close_add_field, a#close_remove_field', function() {
$(this).parent().replaceWith(html);
});
/* menus to add or remove columns automatically close when cursor leaves, with some leeway for reentry */
var leavetimeout = false;
$(document).on('mouseleave','.field_menu', function() {
leavetimeout = setTimeout(function() {
$('.field_menu').replaceWith(html);
},
500);
});
$(document).on('mouseenter','.field_menu', function() { clearTimeout(leavetimeout);});
$(document).on('change','#add_field_open select', function() {
//console.log("new field");
var o=$(this).find('option:selected'), request = "ajax=add_field&field="+o.val()+("&form_parm1="+form_parm1);
o.addClass('present').attr('disabled','disabled').removeAttr('selected');
$.ajax({
async: false,
data: request,
cache:false,
url: "pageprod_ajax.cgi",
success: function(data) {
error_check(data, request);
load_products("load_saved_search=1", false);
}
});
});
$(document).on('click','div#remove_field', function() {
var left_offset = $(this).parent().offset().left;
var html = '<div id="remove_field_open" class="field_menu" style="left:'+left_offset+'px"><a id="close_remove_field" class="close_field_menu"></a><select size=20>';
var fields = ordered_fields;
for (var f = 0; f < start_index; f++) {
html += '<option value='+fields[f].id+' class="present" disabled>'+fields[f].name+'</option>\n';
}
for (var f = start_index; f < field_count; f++) {
html += '<option value='+fields[f].id+'>'+fields[f].name+'</option>\n';
}
html += '</select></div>\n';
$(this).parent().replaceWith(html);
});
/*$(document).on('click','a#close_remove_field', function() {
$(this).parent().replaceWith(html);
});*/
$(document).on('change','#remove_field_open select', function() {
//console.log("remove field");
var field;
var option = $(this).find('option:selected');
var id = option.val();
var code = "f"+id;
var idx = $('#sliding_manager .product_field_manager').index($("#product_field_manager_"+code));
//console.log("removing "+idx+" code "+code);
var product_collection = $("#sliding_products .p");
var len = product_collection.length;
for (var p = 0; p < len; p++) {
$($(product_collection[p]).children()[idx+1]).remove();
}
$("#product_field_heading_"+code).remove();
$("#col_define_"+code).remove();
$("#product_field_manager_"+code).remove();
option.remove();
field = locate_field(code);
var data = "ajax=remove_field&field="+id+("&form_parm1="+form_parm1);
//console.log(data);
$.ajax({
async: true,
data: data,
cache:false,
url: "pageprod_ajax.cgi"
});
product_fields.splice(field, 1);
field_count--;
order_fields();
adjust_product_heights(0,1000000,true);
stick();
constrain_slider(1);
});
}
}
function make_some_products_html(start,end, ignore_widths) {
var sliding_html = "";
var fixed_html = "";
if (display_mode == 'L') {
var fixslide_pair;
var change;
for (var p = start; p < end; p++) {
fixslide_pair = make_product_html(products[p]);
fixed_html += fixslide_pair[0];
sliding_html += fixslide_pair[1];
}
$('#fixed_products').append(fixed_html);
$('#sliding_products').append(sliding_html);
if (!ignore_widths) {
change = nailWidths();
if (change) {
//console.log("change");
start = 0;
}
}
setTimeout(function() {
adjust_product_heights(start,end,true);
}, (IE == false)?0:500);
} else if (display_mode == 'A' || display_mode == 'O') {
start_index = 1;
if (target_prefix == "") {
if (search_field > 0) {
start_index++;
}
}
for (var p = start; p < end; p++) {
/*if (display_mode == 'A' && target_prefix == "") {
var assigned_index;
if ((assigned_index = locate_product(products[p].id, assigned_products)) != null) {
//assigned_products[assigned_index] = product;
continue;
}
}*/
fixed_html += make_product_html(products[p]);
}
$('#'+target_prefix+'fixed_products').append(fixed_html);
if (!ignore_widths) {
nailWidths();
}
}
else {
for (var p = start; p < end; p++) {
sliding_html += make_product_html(products[p]);
}
$('#products').append(sliding_html);
}
}
function make_all_products_html() {
var field, f;
if (display_mode == 'L' || display_mode == 'A' || display_mode == 'O') {
start_index = 1;
if (target_prefix == "") {
if (search_field > 0) {
start_index++;
}
}
var prefix = target_prefix;
var fields = ordered_fields;
var col_define_html = '<colgroup id="'+prefix+'fixed_colgroup">';
var manager_html = '<tr class="products_manager" id="'+prefix+'fixed_manager">';
col_define_html += '<col id="'+prefix+'col_define_select">';
manager_html += '<td class="product_field_manager" id="'+prefix+'product_field_manager_select"></td>';
for (f=0; f < start_index; f++) {
field = fields[f];
manager_html += '<td class="product_field_manager '+((fields[f].id == search_field)?'sc':'')+'" id="'+prefix+'product_field_manager_'+field.code+'"> </td>';
col_define_html += '<col id="'+prefix+'col_define_'+field.code+'">';
}
manager_html += '</tr>';
col_define_html += '</colgroup>';
$('#'+prefix+'fixed_products').empty();
$('#'+prefix+'fixed_products').append(col_define_html);
$('#'+prefix+'fixed_products').append(manager_html);
//console.log("appending manager html to "+prefix+'fixed_products');
if (display_mode == 'L') {
col_define_html = '<colgroup id="sliding_colgroup">';
manager_html = '<tr class="products_manager" id="sliding_manager">';
for (f=start_index; f < field_count; f++) {
field = fields[f];
manager_html += '<td class="product_field_manager" id="product_field_manager_'+field.code+'"> </td>';
col_define_html += '<col id="col_define_'+field.code+'">';
}
manager_html += '</tr>';
col_define_html += '</colgroup>';
$('#sliding_products').empty();
$('#sliding_products').append(col_define_html);
$('#sliding_products').append(manager_html);
}
//nailWidths();
}
$('.nomatch').remove();
if (display_mode == 'A' && target_prefix !="") {
temporary_storage = products;
products = assigned_products;
}
if (total_matching_products > 0 || display_mode == 'A') {
make_some_products_html(0, products.length);
} else {
var html = '<div class="nomatch">No matching products found.</div>';
$('#products').before(html);
//console.log("none");
$('#products_control').css({'display':'none'});
}
if (display_mode == 'A' && target_prefix !="") {
products = temporary_storage;
}
//initial_width = $('.content').width() - $('#fixed_control').width();
//console.log("iw "+initial_width);
}
function make_product_html(p) {
if (display_mode == 'G' || display_mode == 'W') {
var id = p.id;
var html = '<div class="p'+((p.disabled)?' p_dis':'')+'">';
html += '<div class="p_img" id="p_'+id+'_img">';
//image
if(p.f20[1] != '') {
var img = p.f20[1]+'?'+Math.random();
var image_paths = get_image_paths(img, false,false);
html += '<img src="'+image_paths[0]+'" alt="">';
}
html += "</div>";
//sku
var sku = p.f19[1];
if (sku.length > 0)
html += '<div class="p_sku" title="'+cleanstr(sku)+'">'+sku+'</div>';
//name
var name = p.f0[1];
html += '<a class="p_name" id="p_'+id+'_name" title="Edit this product" pid="'+id+'" href="products.cgi?dbname=products&Edit+Product+Info.x=1&recs='+id+'&edit_mode='+edit_mode+'">'+name+'</a>';
var price = p.f1[1];
html += '<div class="p_price">'+currency_symbol+price+'</div>';
html += '<a class="del_p" id="del_'+id+'_p"></a>';
html += '<input type="hidden" class="pid" value="'+id+'">';
if (display_mode == 'G') {
html += '<div class="o_e_oa" title="Show order button"></div>';
}
html += '</div>';
} else {
var fields = ordered_fields;
var fixed_html = '<tr class="p'+((p.disabled)?' p_dis':'')+'">';
fixed_html += '<input type="hidden" class="pid" value="'+p.id+'">';
fixed_html += '<td><input type="checkbox" class="p_sel"></td>';
for (var f=0; f < start_index; f++) {
fixed_html += make_product_field_html(fields[f], p);
}
fixed_html += '</tr>';
if (display_mode == 'L') {
var sliding_html = '<tr class="p'+((p.disabled)?' p_dis':'')+'">';
sliding_html += '<input type="hidden" class="pid" value="'+p.id+'">';
for (var f=start_index; f < field_count; f++) {
sliding_html += make_product_field_html(fields[f], p);
}
sliding_html += '</tr>';
var html = [fixed_html, sliding_html];
} else
var html = fixed_html;
}
return html;
}
function make_product_field_html(field, product) {
var html = "";
if (field.id == search_field)
html += '<td class="sc">';
else
html += '<td>';
//console.log(product.id+ " | " +field.code);
need_more = parseInt(product[field.code][0]);
var val = product[field.code].slice(1);
if (field.hasOwnProperty("postprocess") && field.postprocess != null) {
val = field.postprocess(val);
} else {
val = postprocess_value(0, val, product, field);
}
if (field.id == 0) {
if (display_mode == 'L')
if (name_click == 'edit')
val = '<a class="p_name_l" title="Edit this product" pid="'+product.id+'" href="products.cgi?dbname=products&Edit+Product+Info.x=1&recs='+product.id+'&edit_mode='+edit_mode+'">'+val+'</a>';
else
val = '<a class="p_name_l p_name_l_select" title="Select this product" pid="'+product.id+'">'+val+'</a>';
else if (display_mode == 'O')
val = '<a class="p_name_l" title="Show order buttons for this product" pid="'+product.id+'" href="easyembed.cgi?dbname=products&Show+Code.x=1&recs='+product.id+'">'+val+'</a>';
}
html += val;
if (need_more) {
html += '<br>';
html += '<a class="p_ld" id="p_ld_'+product.id+'_'+field.id+'">show more</a>';
}
html += '</td>';
return html;
}
function get_image_paths(ss_image_path, element, fallback) {
var thumb_path = false;
var whole_path = false;
if (ss_image_path.search(/\[shopsite-images\]/) != -1) {
thumb_path = ss_image_path.replace("[shopsite-images]",everpresent_images_url);
} else
if (ss_image_path.search("://") == -1) {
var filename_index = Math.max(ss_image_path.lastIndexOf("/"),ss_image_path.lastIndexOf("\\"));
var filename = "/"+ss_image_path;
var directory = "";
if (filename_index != -1) {
filename = ss_image_path.substr(filename_index);
directory = "/"+ss_image_path.substr(0,filename_index);
}
//console.log("idx "+filename_index+" filename "+filename +" directory "+directory);
if (display_mode == 'L' || display_mode == 'A' || display_mode == 'O')
thumb_path = outputurl +"/media" + directory + list_image + filename;
else
thumb_path = outputurl +"/media" + directory + grid_image + filename;
whole_path = outputurl +"/media" + directory + filename;
if (element != false) {
var img = new Image();
img.src = thumb_path;
img.onerror = function() {
if ($(element).length == 0)
var to_replace = $('#full_field').contents().find(element);
else
var to_replace = $(element);
var replacement = $(fallback);
to_replace.replaceWith(replacement);
adjust_size_to_content(replacement);
}
img.onload = function() {
adjust_size_to_content($(element));
}
}
} else {
whole_path = ss_image_path;
}
return [thumb_path, whole_path];
}
function adjust_size_to_content(new_content) {
if (display_mode == 'L' || display_mode == 'O' || display_mode == 'A') {
var parent_product = new_content.closest('.p');
var parent_section = parent_product.closest('#sliding_products, #fixed_products');
var parent_collection = parent_section.find('.p');
var index = parent_collection.index(parent_product);
var fixed_product = $($('#fixed_products .p')[index]);
var sliding_product = $($('#sliding_products .p')[index]);
var fixed_height = fixed_product.height();
var sliding_height = sliding_product.height();
if (fixed_height < sliding_height) {
fixed_product.css({'height':sliding_height});
sliding_product.css({'height':sliding_height});
} else if (fixed_height > sliding_height) {
sliding_product.css({'height':fixed_height});
fixed_product.css({'height':fixed_height});
}
/*
var target_prefix = "";
if (display_mode == 'A')
target_prefix = "as_";
var parent_cell = new_content.closest('td');
var width = parent_cell.width();
var field_index = parent_product.find('td').index(parent_cell);
var manager = $((parent_section.find('.products_manager').find('.product_field_manager'))[field_index]);
var code = manager.attr('id').substr(22+target_prefix.length);
//console.log(field_index+ " "+code);
if ($('#'+target_prefix+'product_field_heading_'+code).width() < width) {
//console.log($(target_prefix+"product_field_heading_"+code).width()+" vs "+width+" Nailing width on image load");
nailWidth(code, width);
}
//console.log(code);
*/
}
}
//if field is a number, it's actually a type. Otherwise type is inferred from field object.
function postprocess_value(mode, val, product, field_or_type) {
var newval = "";
var entity = "product";
var type = field_or_type;
var field = field_or_type;
if (typeof field_or_type === 'object') {
type = sections[field.section_index].fields[field.field_index].type;
}
var preprocess_qb = function(val, qb_fields) {
var re;
var rv = '';
for (var qi = 0; qi < qb_fields.length; qi++) {
re = new RegExp("\\[#"+qb_fields[qi][0]+"=(.+?)#\\]", "i");
var matches = val.match(re);
if (matches && matches[1] != "~") {
rv += qb_fields[qi][1]+": "+matches[1]+"<br>";
}
}
return rv;
};
//for dropping to base type
var go_to_numbers = 0;
var go_to_text = 0;
var go_to_images = 0;
var go_to_connected = 0;
//mode 1 for full field contents
if (mode == 1) {
iframe_ready = 1;
switch(type) {
//images, need to wait for image to load before displaying iframe
case 12:
case 20:
iframe_ready = 0;
break;
//doba
case 26:
newval = '<table>';
newval += '<tr><td>Item ID</td><td>'+val[0]+'</td></tr>';
newval += '<tr><td>Inventory List ID</td><td>'+val[1]+'</td></tr>';
newval += '<tr><td>Stock</td><td>'+val[4]+'</td></tr>';
newval += '<tr><td>MSRP</td><td>'+currency_symbol+val[8]+'</td></tr>';
newval += '<tr><td>Whole Sale Price</td><td>'+currency_symbol+val[5]+'</td></tr>';
newval += '<tr><td>Pre Pay Price</td><td>'+currency_symbol+val[6]+'</td></tr>';
newval += '<tr><td>Ship Cost</td><td>'+currency_symbol+val[9]+'</td></tr>';
newval += '<tr><td>Drop Ship Fee</td><td>'+currency_symbol+val[10]+'</td></tr>';
newval += '<tr><td>Minimum Advertised Price</td><td>'+currency_symbol+val[7]+'</td></tr>';
newval += '<tr><td>Supplier</td><td>'+val[2]+'</td></tr>';
newval += '<tr><td>Supplier Notes</td><td>'+val[3]+'</td></tr>';
newval += '<tr><td>Last Updated</td><td>'+val[11]+'</td></tr>';
newval += '</table>';
val = newval;
break;
//options
case 33:
if (val[0] == 0 && val[16] == "") return "";
//console.log(val);
newval = "";
if (val[0] != 0) {
var num_opt = parseInt(val[0]);
var len = val.length; //can fluctuate depending on cutoff
var num_col = val[len-4];
var headers = val[len-5].split("|");
newval = '<style>table {border-collapse:collapse;} table td {border:1px solid #DFDFDF; padding:2px;};</style>';
if (val[len-2] == "checked") {
newval += "Cascading menus are enabled.<br>";
}
if (val[len-3] == "checked") {
newval += "Option SKU is appended to the product SKU.<br>";
}
if (val[len-1] != "") {
newval += "Text before option descriptions:\""+val[len-1]+"\"<br>";
}
newval += '<table id="options"><tr><td>Use</td>';
for (var h = 0; h < num_col; h++) {
var header = "";
if (headers.length > h*2)
header = headers[h*2];
newval += '<td>'+header+'</td>';
}
//newval += "<td>Append Text</td><td>SKU</td><td>Price Mod.</td><td>Weight Mod.</td><td>Qty on Hand</td><td>Low Stock</td><td>Out of Stock</td><td>Image</td></tr>";
var need_columns = [0,0,0,0,0,0,0,0,0,0];
var column_names = ["Append Text","SKU","Price Mod.","Weight Mod.","Qty on Hand","Low Stock","Out of Stock","GTIN/UPC","Image", "QuickBooks Item"];
var count_m_subfields = 6;
var count_subfields = column_names.length + count_m_subfields - 1;
var opt_offset;
var o_idx;
var subfield_val;
for (var o = 0; o < num_opt; o++) {
opt_offset = o*count_subfields;
for (o_idx = count_m_subfields; o_idx <= count_subfields; o_idx++) {
subfield_val = val[opt_offset+o_idx];
if (!(subfield_val == '' || subfield_val == 'none')) {
need_columns[o_idx-count_m_subfields] = 1;
}
}
}
for (var c = 0; c < column_names.length; c++) {
if (need_columns[c])
newval += '<td>'+column_names[c]+'</td>';
}
for (var o = 0; o < num_opt; o++) {
opt_offset = o*count_subfields;
o_idx = 1;
newval += '<tr>';
newval += '<td>'+postprocess_value(0, val[opt_offset+o_idx++],'',5)+'</td>'; //checkbox
for (var h = 0; h < num_col; h++) {
newval += '<td>'+val[opt_offset+o_idx++]+'</td>';
}
for (o_idx = 6; o_idx <= 13; o_idx++) {
if (need_columns[o_idx-6])
newval += '<td>'+val[opt_offset+o_idx]+'</td>';
}
if (need_columns[8]) {
newval += '<td>';
var image_path = val[opt_offset+14];
//console.log("image:"+image_path);
if (!(image_path == '' || image_path == 'none')) {
var image_paths = get_image_paths(image_path,'#opt_image_'+o, '<img class="opt_image" id="opt_image_'+o+'" src="'+whole_path+'" style="max-width:80px; max-height:80px;">');
//console.log(image_paths.toString());
var thumb_path = image_paths[0];
var whole_path = image_paths[1];
//$('#full_field').contents().find('#opt_image_'+o)
if (thumb_path)
newval += '<img class="opt_image" id="opt_image_'+o+'" src="'+thumb_path+'">';
else if (whole_path)
newval += '<img class="opt_image" id="opt_image_'+o+'" src="'+whole_path+'" style="max-width:80px; max-height:80px;">';
}
newval += '</td>';
}
if (need_columns[9]) {
var qb = preprocess_qb(val[opt_offset+15], [['NAME', "Name"], ["DESC", "Description"], ["QBID", "List ID"]]);
newval += '<td>'+qb+'</td>';
}
newval += '</tr>';
}
newval += '</table>';
//newval = val.toString();
/*if (num_col > 1) {
newval = num_col + " pull-down menus<br>";
}
newval += num_opt + " advanced options";*/
} else {
newval = 'Has basic options:<br>'+val[16];
}
val = newval;
break;
//product on pages -- drops down to cross-sell
case 1010:
if (!go_to_connected) {
entity = "page";
go_to_connected = 1;
}
//product-specific coupons
case 2004:
if (!go_to_connected)
entity = "coupon";
//parent products
case 2003:
//subproducts
case 1012:
//cross-sell -- base type for simple connected fields
case 24:
if (val == "" || val == "," || val[0] == 0) return "";
newval = val[0] +" "+ entity + ((val[0] > 1)?"s":"")+":<br>";
var len = val.length;
for (var c = 1; c < len; c++)
newval += val[c]+"<br>";
val = newval;
break;
default:
if (val == "" || val == ",")
val = "";
val = val.toString();
}
return val;
}
//for numbers
var prepend = "";
var append = "";
var immediate_append = 0;
//ORDER MATTERS. HEAVY USE OF CASE CASCADES.
switch(type) {
//weight -- drops down to numbers
case 1005:
if (val == "" || val == "," || val == "0") return '<span class="int">Not set</span>';
append = weight_locale;
go_to_numbers = 1;
//vat -- drops down to numbers
case 25:
if (!go_to_numbers) {
if (val == "" || val == ",") return "";
append = "%";
//immediate_append = 1;
go_to_numbers = 1;
}
//sale amount -- drops down to money or numbers
case 1003:
if (!go_to_numbers) {
if (val == "" || val == ",") return "";
val = val.toString();
if (val[val.length-1] == '%') {
append = "%";
immediate_append = 1;
val = val.slice(0, - 1);
go_to_numbers = 1;
}
}
//money -- drops down to numbers
case 1001:
if (!go_to_numbers) {
if (val == "" || val == ",") return "";
prepend = currency_symbol;
}
//real numbers -- uses prepend and append defined above -- base field type, does not drop down
case 4:
if (val == "" || val == ",") return "";
//val = parseFloat(val);
val = val.toString();
//console.log(val);
var whole;
var fraction = " ";
var frac_index = val.indexOf(decimal_separator);
//console.log("Field "+field.id+" product "+product.id+" "+val+" "+frac_index);
if (frac_index != -1) {
//fraction = parseInt(val.substr(frac_index+1,2));
//fraction = val.substr(frac_index+1,2);
fraction = val.substr(frac_index+1);
if (fraction.length > 2) {
fraction = fraction.substr(0,2);
//fraction = (Math.round(parseFloat("0."+fraction)*100)/100).toString().substr(2); //if you want to try rounding fractions, but it does not carry over to whole
}
if (parseInt(fraction) == 0) {
whole = val.substr(0,val.length-3);
frac_index = -1;
fraction = " ";
} else {
/*if (fraction < 10) {
fraction = "0"+fraction;
}*/
if (fraction.length == 1) {
fraction = fraction + "0";
}
whole = val.substr(0,frac_index);
}
} else
whole = val;
var hide_class = " hid";
if (immediate_append)
hide_class = " shid";
/*newval += "<span class='frac"+((frac_index == -1)?hide_class:"")+"'>";
newval += fraction;
newval += "</span>";
newval += "<span class='dot"+((frac_index == -1)?hide_class:"")+"'>";
newval += ".";
newval += "</span>";
newval += "<span class='int'>"+whole+"</span>";*/
newval += '<span class="int">'+whole+'</span>';
newval += '<span class="dot'+((frac_index == -1)?hide_class:'')+'">';
newval += decimal_separator;
newval += '</span>';
newval += '<span class="frac'+((frac_index == -1)?hide_class:'')+'">';
newval += fraction;
newval += '</span>';
if (prepend != "") {
prepend = '<span class="flr">'+prepend+'</span>';
}
if (append != "")
append = '<span class="flr">'+append+'</span>';
//val = "<span class='ub'>"+append+newval+prepend+"</span>";
val = '<span class="ub">'+prepend+newval+append+'</span>';
break;
//integer
case 3:
if (val == "" || val == ",") return "";
val = val.toString();
val = '<span class="int">'+val+'</span>';
break;
//selectbox or color -- if color use it
case 7:
if (val == "" || val == ",") return "";
var domain = sections[field.section_index].fields[field.field_index].domain;
if (typeof domain !== undefined && domain == 'color') {
val = '<div class="clr" style="background-color:'+val+'">'+val+'</div>';
}
break;
//buttons
//drops down to images depending on selection
case 1011:
if (val == "" || val == ",") return "";
if (val[1] == 0) {
val = "Button text: \""+val[0]+"\"";
break;
} else {
go_to_images = 1;
val = [val[2],val[3]];
}
//size & fit
//drops down to images or text depending on selection
case 36:
if (!go_to_images) {
if (val[0] == "I") {
if (val[1] == "none")
val = "";
else
val = [val[1],val[3]];
} else {
val = val[2];
go_to_text = 1;
}
}
//images -- 2 elements
case 12:
case 20:
if (!go_to_text) {
if (val == "" || val == ",") return "";
need_more = false;
var image_paths = get_image_paths(val[0], '#p_ld_'+product.id+'_'+field.id, '<a class="p_ld" id="p_ld_'+product.id+'_'+field.id+'">Click to show</a>');
var thumb_path = image_paths[0];
var whole_path = image_paths[1];
if (thumb_path)
newval = '<img class="p_ld'+(whole_path?'':'_u')+'" id="p_ld_'+product.id+'_'+field.id+'" src="'+thumb_path+'" alt="'+cleanstr(val[1])+'">';
else
newval = '<a class="p_ld" id="'+'p_ld_'+product.id+'_'+field.id+'">Click to show</a>';
if (whole_path) {
whole_path = whole_path.replace(/("|\\)/g,"\\$1");
var wholeval = '<img src="'+whole_path+'" alt="">';
var extra_height = 0;
if (val[1] != "") {
wholeval += "<br>"+val[1];
extra_height == 30;
}
window.ssGetWidth=function(x){return Math.min(Math.max(x+36,300),$(window).width()-40)};
window.ssGetHeight=function(x){return Math.min(Math.max(x+116+extra_height,200),$(window).height()-40)};
//resize parent iframe to image size
var self_resize_script =
'<scr'+'ipt>'+
'var img = new Image(); img.src="'+whole_path+'";'+
"img.onload=function() {"+
"var ifr = window.parent.document.getElementById('full_field');"+
"let w=top.ssGetWidth(this.width),h=top.ssGetHeight(this.height);"+
"ifr.style.height = h-100 +'px'; ifr.style.width = w-20 +'px';"+
"var modal = window.parent.document.getElementById('field_display_modal');"+
"modal.style.width = (w) + 'px';"+
"modal.style.height = (h) + 'px';"+
"modal.style.top = '10px';"+
"modal.style.left = '10px';"+
"var iframedoc = ifr.contentDocument || ifr.contentWindow.document,iframecontent=iframedoc.getElementById('iframe_contents');"+
"iframecontent.innerHTML='';iframecontent.append(this);\n"+
"window.parent.iframe_ready = 1;"+
"};"+
"img.onerror=function() {"+
"var ifr = window.parent.document.getElementById('full_field');"+
"var iframedoc = ifr.contentDocument || ifr.contentWindow.document;"+
"iframedoc.getElementById('iframe_contents').innerHTML = 'Image file "+whole_path+" not found.';"+
"window.parent.iframe_ready = 1;"+
"}"+
"<\/scr"+"ipt>";
wholeval = self_resize_script;
product[field.code+"_full"] = wholeval;
}
val = newval;
break;
}
//text -- add ellipsis
case 0:
case 19:
if (val == "" || val == ",") return "";
val = val.toString().replace(/</g,"<").replace(/>/g,">");
if (need_more)
val = val + "...";
break;
//checkbox
case 22: //default checked
if (val == "")
val = "checked";
case 5: //default unchecked
val = val.toString().toLowerCase();
if (val == "checked" || val == "on")
val = '<input type=checkbox checked disabled>';
else
val = '<input type=checkbox disabled>';
break;
//search destination
case 1004:
if (val[1] == "selected")
val = val[0];
else
val = val[2];
break;
//recurring payments -- 9 elements
case 30:
if (val == "" || val == ",") return "";
need_more = false;
if (val[0] != "checked") {
val = "disabled";
} else
{
newval = "";
if (val[2] != "")
newval += currency_symbol + val[2] + " " + val[1] + " ";
else
newval += "Recurring " + val[1] + " ";
if (val[3] == "9999" || val[3] == "never" || val[3] =="")
newval += "forever";
else
newval += "for "+val[3]+" periods";
newval += ", billed on ";
if (val[4] == "order_date" || val[4] == 0)
newval += "order date";
else
newval += "day "+val[4];
if (val[5] == "checked") {
newval += "<br>Trial period: " +currency_symbol + val[6] +" " +val[1] + " for " + val[7] + " periods";
}
if (val[8] == "checked") {
newval += "<br>Setup fee: "+currency_symbol + val[9];
}
val = newval;
}
break;
//variable price -- 4 elements
case 1002:
if (val[0] == "checked") {
newval = "Variable:<br>price";
if (val[1] == "checked")
newval += ", name";
if (val[2] == "checked")
newval += ", SKU";
if (val[3] == "checked")
newval += ", weight";
val = newval;
} else
val = "off";
break;
//doba -- a buttload of elements
case 26:
if (val[0] == "") return "";
need_more = true;
newval = "Wholesale price: "+currency_symbol+val[5]+"<br>"+val[4].charAt(0).toUpperCase()+val[4].slice(1)+" as of "+val[11].substr(0,10);
val = newval;
break;
//quantity pricing -- many-to-many array, 3 elements per row
case 31:
var claimed_count = val[0];
var len = val.length;
for (var el_idx = 1; el_idx < len; el_idx+= 3) {
var sale = 0;
var count = 1;
var price = 0;
if (!isNaN(count = parseInt(val[el_idx])) && !isNaN(price = parseFloat(val[el_idx+1])) && price != 0) {
//console.log("pqp "+count +" "+price);
if (newval == "")
newval += "<table>";
nextcount = "+";
if (el_idx + 3 < len && !isNaN(parseInt(val[el_idx+3])))
nextcount = "–"+val[el_idx+3];
newval += "<tr><td>"+count+nextcount+"</td><td>"+currency_symbol+val[el_idx+1];
if (!isNaN(sale = parseFloat(val[el_idx+2]))) {
newval += "/"+val[el_idx+2];
}
newval += "</td></tr>";
}
}
if (newval != "")
newval += "</table>";
else
newval = "off";
val = newval;
break;
//shipping dimensions
case 1006:
if (val == "" || val == "," || val[0] == 1 || val[0] == 0) return "";
if (val[0] == 2)
val = val[1];
else
val = val[2];
break;
//USPS container -- string field with a variety of stuff
case 1008:
if (val == "" || val == ",") return "";
val = val.toString();
var duo = val.split("|");
newval = duo[0];
var idx = duo[1].search("GIRTH");
if (idx != -1) {
newval += "; Girth: " +parseFloat(duo[1].slice(idx+6)) +" inches";
}
if (duo[1].search("EXTRA_POSTAGE") != -1 || duo[1].search("GXG_ENVELOPE") != -1 || duo[1].search("FCMI_LARGE_ENVELOPE") != -1) {
need_more = 1;
var wholeval = newval;
if (duo[1].search("EXTRA_POSTAGE") != -1) {
wholeval += "<br>Apply extra postage for non-machinable Parcel Post.";
}
if (duo[1].search("GXG_ENVELOPE") != -1) {
wholeval += "<br>Use USPS GXG Envelope for Global Express Guaranteed® shipping.";
}
if (duo[1].search("FCMI_LARGE_ENVELOPE") != -1) {
wholeval += "<br>Use Large Envelope for First Class Mail® International shipping.";
}
product[field.code+"_full"] = wholeval;
}
val = newval;
break;
//prohibited shipping methods
case 35:
if (val == "" || val == ",") return "";
val = val.toString();
if (val.search("shopex") != -1)
val = "GlobalShopex";
break;
//options
case 33:
if (val[0] == 0 && val[2] == "") return "";
newval = "";
if (val[0] != 0) {
need_more = true;
var num_opt = val[0];
var len = val.length; //can fluctuate depending on cutoff
var num_col = val[len-4];
if (num_col > 1) {
newval = num_col + " pull-down menus<br>";
}
newval += num_opt + " advanced options";
} else {
newval = "Has basic options:<br>"+val[2];
}
val = newval;
break;
//customer text entry box
case 18:
if (val == "" || val == ",") return "";
val = "Columns: "+val[0]+"; rows: "+val[1];
break;
//froogle variant options
case 34:
if (val == "" || val == ",") return "";
if (val[0] == "checked") {
newval = "";
if (val[1] != "none")
newval += "Color: "+val[1]+" menu<br>";
if (val[2] != "none")
newval += "Size: "+val[2]+" menu<br>";
if (val[3] != "none")
newval += "Pattern: "+val[3]+" menu<br>";
if (val[4] != "none")
newval += "Material: "+val[4]+" menu<br>";
val = newval;
} else val = "";
break;
//product on pages -- drops down to cross-sell
case 1010:
if (!go_to_connected) {
entity = "page";
go_to_connected = 1;
}
//product-specific coupons
case 2004:
if (!go_to_connected)
entity = "coupon";
//parent products
case 2003:
//subproducts
case 1012:
//cross-sell -- base type for simple connected fields
case 24:
if (val == "" || val == "," || val[0] == 0) return "";
newval = val[0] +" "+ entity + ((val[0] > 1)?"s":"")+":<br>";
var len = val.length;
for (var c = 1; c < len; c++)
newval += val[c]+"<br>";
if (need_more)
newval += "...<br>";
val = newval;
break;
//sitemap
case 17:
if (val == "" || val == ",") return "";
if (val[0] == "unchecked")
newval = "Not in sitemap";
else {
newval = "In sitemap, ";
if (val[1] == "Google Default")
newval += "default priority";
else
newval += "priority "+val[1];
}
val = newval;
break;
//quickbooks
case 1013:
if (val == "" || val == ",") return "";
val = preprocess_qb(val.toString(), [['NAME', "Name"], ["DESC", "Description"], ["QBID", "List ID"], ["TYPE", "Type"], ["ACCNT", "Account"]]);
break;
default:
if (val == "" || val == ",")
val = "";
val = val.toString();
}
return val;
}
function delete_product(id, product_index, shutup) {
//delete products["product_"+id];
//$('#product_'+product_index).remove();
products.splice(product_index,1);
$('.pid[value='+id+']').closest('.p').remove();
{
$.ajax({
async: true,
cache:false,
data: {"ajax":"delete_products", product_id:id, shutup:shutup, form_parm1: form_parm1},
url: "pageprod_ajax.cgi",
success:
function(data) {
error_check(data, "delete_products");
//error handling here
flip_publish();
}
});
}
}
function flip_publish() {
if (!(display_mode == 'W')) {
var html = '<a href="generate.cgi" target="_top" >Publish<span> Changes</span></a>';
$('#nav_publish').html(html);
}
}
var recursive_load_initiated = 0;
function load_batches_recursively() {
if (!stop_loading_products && total_number_of_loaded_products < total_matching_products) {
//$('body').addClass('wait');
//console.log("wait");
recursive_load_initiated = 1;
request = "ajax=load_products&offset="+total_number_of_loaded_products+"&batch_mode=load&load_saved_search=1&override_display_mode="+override_display_mode+"&search_storage_container="+search_storage_container+("&form_parm1="+form_parm1);
$.ajax({
async: true,
data: request,
cache:false,
url: "pageprod_ajax.cgi",
success: function(data) {
error_check(data, request);
var previous_length = products.length;
$('#products').append(data);
make_some_products_html(previous_length, products.length);
//nailWidths();
total_number_of_loaded_products += products_loaded_in_last_batch;
/*total_number_of_loaded_products = products.length;
if (display_mode == 'A')
total_number_of_loaded_products += assigned_products.length;*/
fill_search_summary();
$( "#products_progressbar" ).progressbar( "option", "value", total_number_of_loaded_products );
var indicator_image = '<img id="indicator_image" style="display:none;" onload="last_rendered_product='+total_number_of_loaded_products+'; $(this).remove();" src="'+everpresent_images_url+'/plus.gif?'+total_number_of_loaded_products+'" />';
$('body').append($(indicator_image));
//console.log(total_number_of_loaded_products);
load_batches_recursively();
},
});
} else {
if (!stop_loading_products) {
fill_search_summary();
$.modal.close();
$('body').removeClass('wait');
}
recursive_load_initiated = 0;
}
}
function refresh_display() {
var id = this.id;
if (id == 'display_mode_grid')
display_mode = 'G';
else
display_mode = 'L';
search_request_descriptor = "";
load_products("load_saved_search=1&display_mode="+display_mode);
create_field_control();
}
function set_display_mode() {
//console.log("setting display mode to "+display_mode);
$('.display_mode').remove();
$(document).off('click','#display_mode_grid', refresh_display);
$(document).off('click','#display_mode_list', refresh_display);
if (display_mode == 'G' || display_mode == 'L') {
var html = '<div class="display_mode"><a id="display_mode_grid" title="Grid View">grid</a> <a id="display_mode_list" title="List View">list</a></div>';
$('.bo_search').append(html);
$('.display_mode a').removeClass('current_display_mode');
}
if (display_mode == 'G') {
active = "#display_mode_grid";
clickable = "#display_mode_list";
$('#search_wrapper').addClass('grid_mode_search').removeClass('list_mode_search');
$('#products').replaceWith('<div id="products"></div>');
} else if (display_mode == 'L') {
active = "#display_mode_list";
clickable = "#display_mode_grid";
$('#search_wrapper').removeClass('grid_mode_search').addClass('list_mode_search');
$('#products').replaceWith('<div id="products"><table><tr><td><div id="fixed_products_wrapper"><table id="fixed_products"></table></div></td><td><div id="sliding_products_wrapper"><table id="sliding_products"></table></div></td></tr></table></div>');
} else if (display_mode == 'A') {
$('#search_wrapper').removeClass('grid_mode_search').addClass('list_mode_search');
} else if (display_mode == 'W') {
$('#search_wrapper').removeClass('list_mode_search').addClass('grid_mode_search');
} else if (display_mode == 'O') {
$('#search_wrapper').removeClass('grid_mode_search').addClass('list_mode_search');
$('#products').replaceWith('<div id="products"><table><tr><td><div id="fixed_products_wrapper"><table id="fixed_products"></table></div></td></tr></table></div>');
}
if (display_mode == 'G' || display_mode == 'L') {
$(active).addClass('current_display_mode');
$(document).on('click',clickable, refresh_display);
}
}
function start_loading() {
currently_loading = 1;
$('body').addClass('wait');
$('.nomatch').remove();
var html = '<div class="loading">Loading products...</div>';
$('#products').append(html);
$('#products_bottom_block').css({'visibility':'hidden'});
$('.paginator_wrapper_bottom').css({'visibility':'hidden'});
}
function finish_loading() {
$('body').removeClass('wait');
$('.loading').remove();
$('#products_bottom_block').css({'visibility':''});
$('.paginator_wrapper_bottom').css({'visibility':''});
currently_loading = 0;
}
function load_products(to_load, optional_sync) {
last_rendered_product = 0;
var async = true;
if (optional_sync !== undefined)
async = optional_sync;
start_loading();
$('#products .p').remove();
products = [];
total_number_of_loaded_products = 0;
$('#search_summary').html("");
var request = "ajax=load_products&batch_mode=scroll&"+to_load+"&override_display_mode="+override_display_mode+"&search_storage_container="+search_storage_container+ignore_assigned_products()+("&form_parm1="+form_parm1);
//alert(data);
//console.log(data);
stick();
var filter_clicked = false;
var previous_descriptor = search_request_descriptor;
if (to_load.search("filter=yes") != -1) {
filter_clicked = true;
}
var first_load = false;
if (to_load.search("first_load") != -1) {
first_load = true;
}
var tutorial = false;
if (location.href.search("tutorial=") != -1) {
tutorial = true;
}
$.ajax({
async: async,
type: request_type(),
data: request,
cache:false,
url: "pageprod_ajax.cgi",
success:
function(data) {
error_check(data, request);
//console.log("Received "+data);
$('#products').append(data); //this creates field_count and calls order_fields();
set_display_mode();
populate_search_form();
if (filter_clicked && previous_descriptor == search_request_descriptor) {
filter_button_helper();
}
restrict_search_domain(0);
//if (product_type !=3 && product_type != 4 && display_mode != "W")
//$('#search_wrapper').css({'display':'block'});
total_number_of_loaded_products += products_loaded_in_last_batch;
//total_number_of_loaded_products = products.length;
/*if (display_mode == 'A')
total_number_of_loaded_products += assigned_products.length;*/
create_column_control();
create_screen_resize_control();
make_all_products_html();
show_hide_operations();
create_selectable_control();
create_sortable_control();
create_scroll_control();
make_shorthand();
make_paginator();
if(first_load)create_field_control();
create_search_summary();
fill_search_summary();
$(window).scrollTop(0);
stick();
constrain_slider(0);
h=0;
if (w != 0) {
$('#horizontal_scroll').scrollLeft(w);
}
update_column_order();
//nailWidths();
finish_loading();
infinite_scroll();
if (tutorial && first_load && display_mode == 'G') {
/*if (product_type != 3 && product_type != 4) {
$('.p:first').tutorial({instruction:"One of your products is to the left. Click somewhere OTHER than its name to select it.", placement:"right", instructionCss:{'text-align':'left'}});
$(document).one('click','.p:first', function() {
$.tutorial.remove(true);
$('.p:first').click();
$('#operations').tutorial({instruction:"Above are various things you can do with this product. Click on the cart icon to see its order button."});
});
} else */
{
$('.p:first').tutorial({instruction:"One of your products is to the left. Click on the small cart icon in the bottom-right corner to see its order button.", placement:"right", instructionCss:{'text-align':'left', 'width':500}});
}
}
}
});
}
function retrieve_assigned_products() {
if (display_mode == "A") {
if (typeof search_field === "undefined")
search_field = 0;
var needs_sorting = 0;
//var assigned_products_list;
//haven't requested assigned products list from server yet -- do it
if (assigned_products_first_loaded == 0) {
needs_sorting = 1;
if (typeof assignment_field === 'undefined')
assignment_field = "";
var data = "ajax=load_products&batch_mode=all&fields="+assignment_field+"&query_op=2&SearchString=id%3A"+entity_id+"&sort_op=0&sortasc_op=1&new_search=1&override_display_mode="+override_display_mode+"&assigned=1&search_storage_container="+search_storage_container+("&form_parm1="+form_parm1);
if (entity_popup) {
if (entity_id_appended)
var assigned_products_el = window.opener.$("textarea[name='assigned_products"+entity_id+"']");
else
var assigned_products_el = window.opener.$("textarea[name='assigned_products']");
} else
var assigned_products_el = $("textarea[name='assigned_products"+entity_id+"']");
if (assigned_products_el.length) {
assigned_products_list = assigned_products_el.html().replace(/\|/g,",");
if (assigned_products_list.length > 0)
assigned_products_list = assigned_products_list.substr(1, assigned_products_list.length-2);
//console.log("processed passed assigned products >"+assigned_products_list+"<");
data = "ajax=load_products&batch_mode=all&fields=0&query_op=0&SearchString=&sort_op=0&sortasc_op=1&new_search=1&override_display_mode="+override_display_mode+"&assigned=1&search_storage_container="+search_storage_container+"&filter=list:"+assigned_products_list+("&form_parm1="+form_parm1);
}
} else {
assigned_products_list = [];
/*for (var p = 0; p < assigned_products.length; p++)
assigned_products_list.push(assigned_products[p].id);*/
$('#as_fixed_products .pid').each(function() {
assigned_products_list.push($(this).val());
});
assigned_products_list = assigned_products_list.join();
//console.log(assigned_products_list);
data = "ajax=load_products&batch_mode=all&fields=0&primary_field="+$('#bo_search_select').val()+"&query_op=0&SearchString=&sort_op=0&sortasc_op=1&new_search=1&override_display_mode="+override_display_mode+"&assigned=1&search_storage_container="+search_storage_container+"&filter=list:"+assigned_products_list+("&form_parm1="+form_parm1);
}
var request = data;
//console.log("Retrieving assigned " +data);
$.ajax({
async: false,
data: request,
type: request_type(),
cache:false,
url: "pageprod_ajax.cgi",
success:
function(data) {
error_check(data, request);
//console.log("Received (assigned) "+data);
temporary_storage = products;
products = [];
var temporary_prefix = target_prefix;
target_prefix = "as_";
/*var data_duo = data.split("~",2);
var data;
if (data_duo.length > 1) {
assigned_products_list = data_duo[0];
data = data_duo[1];
} else
data = data_duo[0];*/
$('#products').append(data);
target_prefix = temporary_prefix;
assigned_products = products;
products = temporary_storage;
assigned_products_first_loaded = 1;
}
});
}
}
function sort_assigned_products() {
if (display_mode == "A" && allow_assigned_sorting) {
//console.log("manual sorting: "+assigned_products_list);
var sort_order = assigned_products_list.split(",");
for (var so = 0; so < sort_order.length; so++)
sort_order[so] = parseInt(sort_order[so]);
var sort_order_comparator = function(p1,p2) {
return sort_order.indexOf(p1.id) - sort_order.indexOf(p2.id);
}
assigned_products.sort(sort_order_comparator);
}
}
$(window).on('load',function() {
if ($('#form_parm1').length > 0)
form_parm1 = $('#form_parm1').val();
search_string = "";
target_prefix = "";
search_storage_container = "prod";
override_display_mode = 0;
if (typeof display_mode !== 'undefined')
override_display_mode = display_mode;
else
display_mode = "L";
//we are on config screen -- just need sections stuff
if (display_mode == 'C') {
load_all_sections();
var section_count = sections.length;
var hidden_state;
var html = "";
for (var s = 0; s < section_count; s++) {
var section = sections[s];
hidden_state = section.section_hidden_state;
html += "<optgroup label=\""+section.name+"\">\n";
var field_count = section.fields.length;
for (var f = 0; f < field_count; f++) {
html += "<option value="+section.fields[f].id+" section_index="+s+" field_index="+f+" class='"+(section.fields[f].hidden?"hidden_field":"shown_field")+"'>"+section.fields[f].name+"</option>\n";
}
html += "</optgroup>\n";
}
$('#fields_config').append(
'<table><tr><th>Searchable fields</th><th></th><th>Non-searchable fields</th></tr>'+
'<tr><td><select id="shown_fields" multiple>'+html+'</select></td>'+
'<td><div id="hs_buttons"><div id="button_hide" class="button hs_button_off">Hide fields</div><div id="button_show" class="button hs_button_off">Display fields</div></div></td>'+
'<td><select id="hidden_fields" multiple>'+html+'</select></td></tr></table>');
$('#shown_fields option').first().addClass('mandatory');//prop('disabled',true);
hide_show_optgroup_labels("hidden_fields", "shown_field");
hide_show_optgroup_labels("shown_fields", "hidden_field");
$(document).on('change','#shown_fields', function() {
$('option.mandatory').prop('selected',false);
if ($(this).find('option:selected').length > 0)
$('#button_hide').removeClass('hs_button_off');
else
$('#button_hide').addClass('hs_button_off');
});
$(document).on('change','#hidden_fields', function() {
if ($(this).find('option:selected').length > 0)
$('#button_show').removeClass('hs_button_off');
else
$('#button_show').addClass('hs_button_off');
});
$(document).on('click','#fields_config option', function(event) {
event.stopPropagation();
});
$(document).on('click','optgroup', function () {
$(this).parent().find('option').prop('selected',false);
$(this).children().prop('selected',true);
$('option.mandatory').prop('selected',false);
if ($(this).closest('select').attr('id') == 'shown_fields')
$('#button_hide').removeClass('hs_button_off');
else
$('#button_show').removeClass('hs_button_off');
});
$(document).on('click','#button_hide', function () {
$('#shown_fields').find('option:selected').each(function() {
$('#hidden_fields').find('option[value='+$(this).val()+']').addClass('hidden_field').removeClass('shown_field');
});
$('#shown_fields').find('option:selected').addClass('hidden_field').removeClass('shown_field').prop('selected',false);
$('#button_hide').addClass('hs_button_off');
hide_show_optgroup_labels("hidden_fields", "shown_field");
hide_show_optgroup_labels("shown_fields", "hidden_field");
});
$(document).on('click','#button_show', function () {
$('#hidden_fields').find('option:selected').each(function() {
$('#shown_fields').find('option[value='+$(this).val()+']').removeClass('hidden_field').addClass('shown_field');
});
$('#hidden_fields').find('option:selected').removeClass('hidden_field').addClass('shown_field').prop('selected',false);
$('#button_show').addClass('hs_button_off');
hide_show_optgroup_labels("hidden_fields", "shown_field");
hide_show_optgroup_labels("shown_fields", "hidden_field");
});
$('form').submit(function() {
//console.log('submitting form');
var id_list = [];
$('#shown_fields .hidden_field').each(function() {
id_list.push($(this).val());
});
$('form').append('<input type="hidden" name="hidden_fields" value="'+id_list.join()+'">');
//console.log("hidden list: "+ id_list.join());
return true;
});
return;
}
var html = '<div id="add_products_block">';
if (display_mode != 'O' && display_mode != 'A') {
html += '<div id="add_product" title="Add a product"><div></div>Add</div>';
if (display_mode != 'W')
html += '<a id="add_multiple_products" title="Add multiple products">Add Multiple</a>'
}
html += "</div>";
$('.page_name').after(html);
var html = '<div id="right_links_block">';
if (display_mode != 'A' && display_mode != 'W' && display_mode != 'O') {
html += '<a id="configure_products_screen" title="Configure this screen"></a>';
$(document).on('click', '#configure_products_screen', function () { go_to('products.cgi?configure=1'); });
} else if (display_mode == 'O') {
$('#search_wrapper').css({'display':'block'});
html += '<a id="configure_products_screen" title="Configure order buttons"></a>';
html += '<a id="show_cart_url">View Cart URL</a>';
$(document).on('click', '#show_cart_url', function () { go_to('easyembed.cgi?Show Cart URL.x=1'); });
$(document).on('click', '#configure_products_screen', function () { go_to('easyembed.cgi?Config.x=Config'); });
}
html += "</div>";
$('.page_name').after(html);
if (display_mode != "W") {
$('#footer').before('<div id="products_bottom_block"><div id="bottom_wrapper" style="display:none"></div></div>');
search_string = $('.bo_search_string').val();
if (search_string != '' && search_string != '*')
$('#button_filter').css({'display':'block'});
preserved_search_element = $('.bo_search_string')[0].outerHTML;
}
load_all_sections();
if (display_mode == 'O') {
search_storage_container = "easy";
}
//We are on assign-product-to-entity screen.
if (display_mode == "A") {
assigned_products_first_loaded = 0;
target_prefix = "as_";
allow_assigned_sorting = 0;
switch (entity_type) {
case "coupon":
assignment_field = 2004; //field for connected entities. See pageprod_ajax.c
search_storage_container = "c_prod"; //search prefix for bo_search.aa
var destination_cgi = "coupon"; //where form submits to
var save_buttons = [{name:"coupon_product_list.x", value:"Save Changes", id:"button_save_changes"}];
break;
case "page":
assignment_field = 85;
search_storage_container = "pageprod";
var destination_cgi = "pages";
var save_buttons = [
{name:"Choose Assign Items.x",value:"Assign Items",id:"button_assign_items"},
{name:"Choose Arrange Items.x",value:"Arrange Items",id:"button_arrange_items"},
{name:"Choose Save Changes.x",value:"Save Changes", id:"button_save_changes"}];
break;
case "subproduct":
assignment_field = 2003;
search_storage_container = "subprod";
var destination_cgi = "products";
var save_buttons = [
{name:"Choose Save Changes.x",value:"Save Changes", id:"button_save_changes"},
{name:"Choose Arrange Subproducts.x",value:"Arrange Subproducts",id:"button_arrange_subproducts"}];
allow_assigned_sorting = 1;
break;
case "cross-sell":
assignment_field = 106;
search_storage_container = "selcs";
var destination_cgi = "selectproduct";
var save_buttons = [{name:"OK.x", value:"OK", id:"button_ok"}];
var global_name = "Global Cross-sell";
allow_assigned_sorting = 1;
break;
//does not require field because the list of assigned products is always provided
case "category":
search_storage_container = "selpd";
var destination_cgi = "selectproduct";
var save_buttons = [{name:"OK.x", value:"OK", id:"button_ok"}];
var name_element = "ss_CategoryName";
break;
}
entity_id_appended = 0;
if (typeof entity_popup !== 'undefined') {
if (window.opener.$("input[name='assigned_name"+entity_id+"']").length)
entity_id_appended = 1;
} else
entity_popup = 0;
//get entity name
var entity_name = "";
if (typeof entity_global !== 'undefined' && entity_global == 1) {
entity_name = global_name;
}
else
if (entity_popup) {
if (entity_id_appended)
var entity_name_el = window.opener.$("input[name='assigned_name"+entity_id+"']");
else
var entity_name_el = window.opener.$("input[name='assigned_name']");
if (entity_name_el.length)
entity_name = decodeURIComponent(entity_name_el.val());
if (entity_name == "")
entity_name = decodeURIComponent(window.opener.$("input[name='"+name_element+"']").val());
} else {
if (entity_name == "") {
//console.log("Requesting entity name");
var request = "ajax=get_entity_name&entity_id="+entity_id+"&field="+assignment_field+("&form_parm1="+form_parm1);
$.ajax({
async: false,
data: request,
url: "pageprod_ajax.cgi",
success:
function(data) {
error_check(data,request);
entity_name = data;
}
});
}
}
$('.item_head').html(entity_name);
//retrieve list of products already assigned to entity -- needs to be called after each new search in case new search is by a different field (and we don't know that field's contents for assigned products)
retrieve_assigned_products();
//create necessary layout structures
$('#products').replaceWith(
'<table id="assignment_splitter_products"><tr>'+
'<td id="asp_assigned"><div id="as_products"><table><tr><td><div id="as_fixed_products_wrapper"><table id="as_fixed_products"></table></div></td></tr></table></div></td>' +
'<td id="asp_button"><div id="as_buttons">'+
'<div class="as_button as_button_off" id="button_assign"><div class="as_arrow"></div>Assign selected</div>'+
'<div class="as_button as_button_off" id="button_unassign"><div class="as_arrow"></div>Remove selected</div></div></td>'+
'<td id="asp_unassigned"><div id="products"><table><tr><td><div id="fixed_products_wrapper"><table id="fixed_products"></table></div></td></tr></table></div></td>'+
'</tr></table>');
$('#search_wrapper').after(
'<table id="assignment_splitter_control"><tr>'+
'<td id="asc_assigned"><div class="as_header">Products assigned to '+entity_name+':</div></td>'+
'<td id="asc_button"></td>'+
'<td id="asc_unassigned"><div class="as_header">Products not assigned to '+entity_name+':</div></td></tr>'+
'</tr></table>');
//create save/cancel buttons and form
var form_html =
'<form id="assignment_form" action="'+destination_cgi+'.cgi" method="POST">'+
'<input type=hidden name=form_parm1 value="'+form_parm1+'">'+
'<input type=hidden name=record value='+entity_id+'>'+
'<input type=hidden name=recs value='+entity_id+'>'+
'<input type=hidden name=dbname value=products>'+
'<input type=hidden name=choosedbname value=products>'+
'<input type=hidden name=assigned_products_t1 id=assigned_products_t1 value="|">'+
'<ul class="button_block horizontal">';
for (var sb = 0; sb < save_buttons.length; sb++) {
var bt = save_buttons[sb];
form_html += '<li><input id ="'+bt.id+'" class="button" type="submit" value="'+bt.value+'" name="'+bt.name+'"></li>';
}
form_html += '<li><input id ="button_cancel" class="cancel button" type="submit" value="Cancel" name="cancel_list.x" onclick="window.close();"></li></ul></form>';
$('#bottom_wrapper').prepend(form_html).show();
create_column_control();
sort_assigned_products();
make_all_products_html();
create_selectable_control();
create_sortable_control();
target_prefix = "";
//assign/unassign items
$(document).off('click','#button_assign, #button_unassign');
$(document).on('click','#button_assign, #button_unassign', function() {
id_list = [];
indexes = [];
var source_table = 'fixed_products';
var source_structure = products;
//var destination_table = 'as_fixed_products';
var destination_structure = assigned_products;
target_prefix = "as_";
if ($(this).attr('id') == 'button_unassign') {
target_prefix = "";
source_table = 'as_fixed_products';
source_structure = assigned_products;
//destination_table = 'fixed_products';
destination_structure = products;
}
var prior_length = destination_structure.length;
$('#'+source_table+' .ui-selected').each(function() {
var index = locate_product($(this).parent().prev().val(), source_structure);
indexes.push(index);
destination_structure.push(source_structure[index]);
//$(this).closest('.p').appendTo('#'+destination_table);
$(this).closest('.p').remove();
});
for (i = indexes.length-1; i >=0; i--) {
source_structure.splice(indexes[i],1);
}
temporary_storage = products;
products = destination_structure;
make_some_products_html(prior_length, destination_structure.length, true);
products = temporary_storage;
//$('.p_sel').prop('checked',false).removeClass('ui-selected');
$('#p_sel_all, #as_p_sel_all').prop('checked',false);
//color_rows();
update_assignment_buttons();
target_prefix = "";
});
//submit form
for (var sb = 0; sb < save_buttons.length; sb++) {
var id = save_buttons[sb].id;
$(document).off('click','#'+id);
$(document).on('click','#'+id, function() {
var assigned_products_val = "|";
var assigned_products_names = "";
var product_count = 0;
/*$('#as_fixed_products .pid').each(function() {
var id = $(this).val();
assigned_products_val += id + "|";
product_count++;
});*/
$('#as_fixed_products tr.p').each(function() {
var id = $(this).find('.pid').val();
var name = $(this).find('td').last().html();
assigned_products_val += id + "|";
assigned_products_names += name +"<br>";
product_count++;
});
//console.log(assigned_products_val);
//console.log(assigned_products_names);
if (entity_popup) {
var assigned_products_field_selector = "textarea[name='assigned_products']";
var assigned_count_field_selector = "input[name='assigned_count']";
var assigned_names_field_selector = "#assigned_products_name_list";
if (entity_id_appended) {
assigned_products_field_selector = "textarea[name='assigned_products"+entity_id+"']";
assigned_count_field_selector = "input[name='assigned_count"+entity_id+"']";
}
window.opener.$(assigned_products_field_selector).html(assigned_products_val);
window.opener.$(assigned_count_field_selector).val(product_count);
if (window.opener.$(assigned_names_field_selector).length > 0)
window.opener.$(assigned_names_field_selector).html(assigned_products_names);
} else
$('#assigned_products_t1').val(assigned_products_val);
return true;
});
}
}
if (display_mode != "W") {
load_products("load_saved_search=1&new_search=1&first_load=1");
} else {
//wait for products to upload
var check_products_ready = setInterval(function() {
//console.log("check "+products_ready);
if (products_ready == 1) {
clearInterval(check_products_ready);
load_products("new_search=1&load_all_pages=1");
}
}, 100);
}
$(document).on('keydown',function(event){
if(event.which=="17")
ctrl = true;
if(event.which=="16") {
shift = true;
$('.p').disableSelection();
}
if (event.which=="13" && $('.bo_search_string').length && $('.bo_search_string').is(':focus')) {
$('#button_search').trigger('click');
}
});
$(document).on('keyup',function(event){
if(event.which=="17")
ctrl = false;
if(event.which=="16") {
shift = false;
$('.p').enableSelection();
}
});
/*if ($('#max_id').length > 0) {
max_id = parseInt($('#max_id').val());
max_existing_id = parseInt($('#max_existing_id').val());
}*/
$(document).on('click', '#button_cancel', function() {
$.modal.close();
});
$(document).on('click', '.del_p' ,function() {
id = $(this).closest('.p').find('.pid').val();//parseInt($(this).attr('id').substring(7));
//console.log(id);
product_index = locate_product(id);
//console.log(product_index);
product = products[product_index];
var name = product.f0[1];
if (confirm_deletes) {
var modalhtml =
'<div class="confirm_delete_header">Are you sure you want to delete <b>' + name + '</b>?</div>';
if (delmo)
modalhtml += '<div class="confirm_delete_message">MoreInfo page will also be deleted</div>';
if (delgra)
modalhtml += '<div class="confirm_delete_message">Product images will be deleted as well</div>';
if (delrev)
modalhtml += '<div class="confirm_delete_message">Reviews for this product will also be deleted</div>';
modalhtml += '<div class="confirm_delete_clickers"><a class="delete_option" id="confirm_delete">Yes</a><a class="delete_option" id="no_delete">Cancel</a></div><a class="delete_option" id="confirm_delete_shutup">Yes, and don\'t ask again</a>';
$.modal(modalhtml,
{
closeHTML: "",
minWidth: "400px",
overlayClose:false,
autoPosition: true,
autoResize: true,
containerId: "confirm_delete_modal",
onShow: function (dialog) { $('body').css({overflow:'hidden'}); },
onClose: function(dialog) { $.modal.close(); $('body').css({overflow:'auto'}); }
});
$('.delete_option').one('click', function() {$.modal.close();});
//if in basic editing, delete immediately
$('#confirm_delete').one('click', function () {
delete_product(id,product_index,0);
});
$('#confirm_delete_shutup').one('click', function () {
delete_product(id,product_index,1);
confirm_deletes = 0;
});
} else {
delete_product(id,product_index,0);
}
});
//search
$(document).off('click', '#button_search, #button_list_all_products, #button_filter, .sort_asc, .sort_desc, #load_all_products, #load_all_products_pag, #stop_loading_products, .p_ld');
$(document).on('click', '#button_search, #button_list_all_products, #button_filter', function() {
if (this.id == 'button_search' || this.id == 'button_filter') {
$('.bo_search').wrap('<form id="ser_form"/>');
to_load = $('#ser_form').serialize();
$('.bo_search').unwrap();
search_string = $('.bo_search_string').val();
if (search_string != '' && search_string != '*')
$('#button_filter').css({'display':'block'});
if (this.id == 'button_search') {
search_request_descriptor = "";
} else {
to_load += "&filter=yes"; //may also be a list of numbers in assignment mode
}
} else {
to_load = "ListAll.x=1&sort_op="+$('#sort_op').val()+"&sortasc_op="+$('#sortasc_op').val();
$('.bo_search_string').val('*');
$('#button_filter').css({'display':'none'});
$('.bo_search_query option').prop('disabled',false).prop('selected',false);
$('.bo_search_fields option:selected').prop('selected',false);
$('.bo_search_string').prop('readonly',false)
search_request_descriptor = "";
//matching_product_ids = "-1";
}
to_load += "&new_search=1";
//console.log(to_load);
retrieve_assigned_products();
load_products(to_load);
});
$(document).on('click', '.sort_asc, .sort_desc', function() {
$(this).off('mouseenter mouseleave')
if ($(this).hasClass('sort_asc')) {
asc = 1;
$(this).removeClass('sort_desc').addClass('sort_asc');
} else {
asc = 0;
$(this).removeClass('sort_asc').addClass('sort_desc');
}
code = $(this).attr('id').substr(5);
field = locate_field(code);
id = product_fields[field].id;
$('#sort_op').val(id);
$('#sortasc_op').val(asc);
$('.current_sort').removeClass('current_sort');
$(this).addClass('current_sort');
load_products("load_saved_search=1&search_clicked=true&sort_op="+id+"&sortasc_op="+asc);
});
$(document).on('click', '#load_all_products, #load_all_products_pag', function() {
$('body').addClass('wait');
//if in pagination mode, remove pagination, start loading from the beginning, and allow to stop and restart loading
if ($(this).attr('id') == 'load_all_products_pag' && $('.paginator_wrapper_bottom').length > 0) {
total_number_of_loaded_products = 0;
$('#products .p').remove();
products = [];
$('.paginator_wrapper_bottom').remove();
$('#paginator_centralizer').remove();
}
stop_loading_products = 0;
if (total_matching_products - total_number_of_loaded_products > 500) {
modalhtml = '<div class="loading">Loading products, please wait.</div><div id="products_progressbar"></div><a id="stop_loading_products">Stop loading products</a>';
$.modal(modalhtml,
{
closeHTML: "",
minWidth: "500px",
overlayClose:false,
escClose: false,
autoPosition: true,
autoResize: true,
containerId: "progressbar_modal"
});
$( "#products_progressbar" ).progressbar({ value: total_number_of_loaded_products, max: total_matching_products });
} else {
//$('body').addClass('wait');
}
start_time = new Date().getTime();
load_batches_recursively();
});
$(document).on('click', '#stop_loading_products', function() {
stop_loading_products = 1;
$('#stop_loading_products').replaceWith("Please wait, rendering loaded products...");
$( document ).ajaxComplete(function( event, xhr, settings ) {
var check_products_ready = setInterval(function() {
//console.log("check "+last_rendered_product);
if (last_rendered_product == total_number_of_loaded_products) {
clearInterval(check_products_ready);
$.modal.close();
$('body').removeClass('wait');
$(document).off('ajaxComplete');
}
}, 200);
});
});
$(document).on('click', '.p_ld', function(event) {
var string = $(this).attr('id');
var product_id = parseInt(string.substr(5));
var products_storage = products;
if (display_mode == 'A' && $(this).closest('#as_fixed_products').length)
products_storage = assigned_products;
var product = products_storage[locate_product(product_id, products_storage)];
var field_id = parseInt(string.substr(string.lastIndexOf("_")+1));
var field = product_fields[locate_field(field_id)];
if (!product.hasOwnProperty(field.code+"_full")) {
//console.log(product_id+"|"+field_id);
$.ajax({
async:false,
cache:true,
data: {"ajax":"get_full_field_content", product_id:product_id, field_id:field_id, form_parm1: form_parm1},
url: "pageprod_ajax.cgi",
success:
function(data) {
error_check(data, "get_full_field_content");
//console.log(data);
product[field.code+"_full"] = JSON.parse(data).slice(1);
}
});
}
var val = product[field.code+"_full"];
//console.log("val:"+val);
if (field.hasOwnProperty("postprocess") && field.postprocess != null) {
val = field.postprocess(val);
} else
val = postprocess_value(1, val, product, field);
//console.log("Postprocessed full val:"+val);
//var iframedoc = false;
var iframe_element = $('<iframe />', { id: 'full_field', height: 300}).on('load',function(e){
//console.log("full_field loaded");
$(this).contents().find('body').html('<div id="iframe_contents">'+val+'</div>');
var checkIframeReady = setInterval(function() {
//console.log("iframe_ready:" +iframe_ready);
if (iframe_ready == 1) {
clearInterval(checkIframeReady);
$('#field_display_modal').css({'visibility':'visible'});
}
}, 10);
});
var md = $('<div id="modal_content"><div id="full_field_header">'+field.name+' for '+product['f0'][1]+'</div><div id="button_cancel">OK</div></div>');
md.find('#full_field_header').after(iframe_element);
//md.append(iframe_element);
$.modal(md,
{
closeHTML: "",
minWidth: "650px",
minHeight:"400px",
overlayClose:true,
escClose:true,
autoPosition: true,
autoResize: true,
containerId: "field_display_modal",
//onOpen: function (dialog) {dialog.css({'display':'none'});},
onShow: function (dialog) {
$('body, #as_products').css({overflow:'hidden'});
},
onClose: function(dialog) { $.modal.close(); $('body').css({overflow:'auto'}); $('#as_products').css({overflow:''}); }
});
event.stopPropagation();
});
//operations
//this goes to another url. If post is true, it posts a form there. If shift is held, URL opens in a new window. If in OA tutorial, continue tutorial.
function go_to(url, post) {
if (location.href.search("tutorial=OA") != -1) {
url += "&tutorial=OA";
}
if (post !== undefined && post == true) {
var urlpair = url.split("?");
var cgi = urlpair[0];
var params = urlpair[1].split("&");
var formhtml = '<form id="redirect_form" action="'+cgi+'" method="post" style="display:none;"';
var window_id = 0;
if (shift) {
window_id = Math.floor((Math.random() * 10000) + 1);
formhtml += ' target="newWindow_'+window_id+'" ';
}
formhtml += ">";
for (var i = 0; i < params.length; i++) {
parampair = params[i].split("=");
formhtml += '<input type="hidden" name="'+parampair[0].replace(/\+/g,' ')+'" value="'+parampair[1]+'">';
}
formhtml += '</form>';
//console.log(formhtml);
$('body').append(formhtml);
if (shift) {
window.open('', 'newWindow_'+window_id);
shift = false;
} else
$('body').addClass('wait');
$('#redirect_form').submit();
$('#redirect_form').remove();
return;
}
if (shift) {
window.open(url,'_blank');
shift = false;
} else {
$('body').addClass('wait');
location.href = url;
}
}
function disable_operation(selected_class, id_list, indexes, do_disable) {
var count = id_list.length;
$('body').addClass('wait');
if (do_disable == 1) {
var ajax_token = "disable_products";
} else {
var ajax_token = "enable_products";
}
$.ajax({
async: true,
cache:false,
type: "POST",
data: {"ajax":ajax_token, "vall_selected":vall_selected, product_ids:id_list.join(), form_parm1: form_parm1},
url: "pageprod_ajax.cgi",
success:
function(data) {
error_check(data, ajax_token);
for (i = 0; i < count; i++) {
products[indexes[i]].disabled = do_disable;
}
if (do_disable == 1)
$(selected_class).addClass('p_dis');
else
$(selected_class).removeClass('p_dis');
update_disable_button();
flip_publish();
$('body').removeClass('wait');
}
});
}
function delete_operation(selected_class, id_list, indexes) {
var modalhtml = "";
var count = id_list.length;
if (vall_selected) {
count = total_matching_products;
}
if (count == 1) {
if (!confirm_deletes) {
var id = id_list[0];
product_index = locate_product(id);
delete_product(id,product_index,0);
return;
}
var product = products[indexes[0]];
modalhtml += '<div class="confirm_delete_header">Are you sure you want to delete <b>' + product.f0[1] + '</b>?</div>';
} else {
modalhtml += '<div class="confirm_delete_header">Are you sure you want to delete ' + count + ' products?</div>';
if (!vall_selected) {
modalhtml += '<div id="confirm_delete_list">';
for (i = 0; i < count; i++) {
var product = products[indexes[i]];
modalhtml += '<div><b>'+product.f0[1]+'</b></div>';
}
modalhtml += '</div>';
}
}
if (delmo)
modalhtml += '<div class="confirm_delete_message">MoreInfo pages will also be deleted</div>';
if (delgra)
modalhtml += '<div class="confirm_delete_message">Product images will be deleted as well</div>';
if (delrev)
modalhtml += '<div class="confirm_delete_message">Reviews for this product will also be deleted</div>';
modalhtml += '<div class="confirm_delete_clickers">';
modalhtml += '<a class="delete_option" id="confirm_delete">Yes, delete '+count+' product'+((count>1)?'s':'')+'</a>';
modalhtml += '<a class="delete_option" id="no_delete">Cancel</a></div>';
$.modal(modalhtml,
{
closeHTML: "",
minWidth: "400px",
overlayClose:false,
autoPosition: true,
autoResize: true,
containerId: "confirm_delete_modal",
onShow: function (dialog) { $('body').css({overflow:'hidden'}); },
onClose: function(dialog) { $.modal.close(); $('body').css({overflow:'auto'}); }
});
$('.delete_option').one('click', function() {$.modal.close();});
$('#confirm_delete').one('click', function () {
$.ajax({
async: true,
cache:false,
type: "POST",
data: {"ajax":"delete_products", "vall_selected":vall_selected, product_ids:id_list.join(), form_parm1: form_parm1},
url: "pageprod_ajax.cgi",
success:
function(data) {
error_check(data, "delete_products");
$(selected_class).remove();
if (!vall_selected) {
for (i = count-1; i >=0; i--) {
products.splice(indexes[i],1);
}
show_hide_operations();
} else {
$('#button_search').click();
}
flip_publish();
}
});
});
}
$(document).off('click', '.p_name, .p_name_l');
$(document).on('click', '.p_name, .p_name_l', function() {
if (display_mode != 'W') {
if (shift == true) //shift-clicked, default to browser behavior for <a> tag
return true;
var id = $(this).attr('pid');
if (display_mode == 'O')
go_to("easyembed.cgi?dbname=products&Show+Code.x=1&recs="+id);
else if (name_click == 'edit' || display_mode != 'L')
go_to('products.cgi?dbname=products&Edit+Product+Info.x=1&recs='+id+'&edit_mode='+edit_mode);
}
return false;
});
$(document).off('click','#more_operations');
$(document).on('click','#more_operations', function() {
if ($('#more_operations_open').css('display') == 'none') {
var right_offset = $(window).width()-$(this).offset().left-$(this).outerWidth();
$('#more_operations_open').css({'right':right_offset, 'display':'block'});
$(document).one('click', function () { $('#more_operations_open').css({'display':'none'}); });
}
});
$(document).off('click', '.o_e_oa');
$(document).on('click', '.o_e_oa', function() {
var id = $(this).closest('.p').find('.pid').val();
go_to("easyembed.cgi?dbname=products&Show+Code.x=1&from_products=1&recs="+id);
});
$(document).off('click','#o_deselect, div.op, #more_operations_open > div');
$(document).on('click','#o_deselect, div.op, #more_operations_open > div', function() {
selector_popup_counter = 0;
var id_list =[];
var selected_class;
if (display_mode == 'L' || display_mode == 'O') {
selected_class = '.selected_product';
$('.ui-selected').each(function() {
id_list.push($(this).parent().prev().val());
});
} else if (display_mode == 'G'){
selected_class = '.ui-selected';
$('.ui-selected').each(function() {
id_list.push($(this).find('.pid').val());
});
}
var count = id_list.length;
var indexes = [];
for (i = 0; i < count; i++) {
var product_index = locate_product(id_list[i]);
//console.log("index for product id "+id_list[i]+": "+product_index);
indexes.push(product_index);
}
var operation = $(this).attr('id').substr(2);
//console.log("operation:"+operation+" id list:"+id_list.join());
switch (operation) {
case "deselect":
$('.p_sel').prop('checked',false);
$('#p_sel_all').prop('checked',false);
$('.ui-selected').removeClass('ui-selected');
color_rows();
update_disable_button();
show_hide_operations();
break;
case "edit":
go_to("products.cgi?dbname=products&Edit+Product+Info.x=1&recs="+id_list.join()+"&edit_mode="+((id_list.length > 1)?"advanced":edit_mode), true);
break;
case "poweredit":
go_to("products.cgi?dbname=products&vall_selected="+vall_selected+"&Power+Edit.x=1&recs="+id_list.join(), true);
break;
case "oa":
go_to("easyembed.cgi?dbname=products&Show+Code.x=1&"+((display_mode == 'O')?"":"from_products=1&")+"recs="+id_list.join(), true);
break;
case "download":
go_to("database.cgi?dbname=products&vall_selected="+vall_selected+"&from_products=1&download_recs="+id_list.join(), true);
break;
case "disable":
disable_operation(selected_class, id_list, indexes, 1);
break;
case "enable":
disable_operation(selected_class, id_list, indexes, 0);
break;
case "delete":
delete_operation(selected_class, id_list, indexes);
break;
//more operations
case "layout":
go_to("products.cgi?dbname=products&Edit+Product+Layout.x=1&recs="+id_list[0]);
break;
case "copy":
go_to("products.cgi?dbname=products&Copy+Product.x=1&recs="+id_list[0]);
break;
case "select_sub":
go_to("products.cgi?dbname=products&Select+Subproducts.x=1&recs="+id_list[0]);
break;
case "arrange_sub":
go_to("products.cgi?dbname=products&Arrange+Subproducts.x=1&recs="+id_list[0]);
break;
}
return;
});
$(document).off('click','#add_product, #add_multiple_products');
$(document).on('click','#add_product', function() {
if (display_mode != 'W')
go_to("products.cgi?Add a Product.x=1&dbname=products&edit_mode="+edit_mode);
});
$(document).on('click','#add_multiple_products', function() {
go_to("products.cgi?Add Several Products.x=1&dbname=products&edit_mode=advanced");
});
});
/*Stuff specific to assignment screen*/
function update_assignment_buttons() {
if (display_mode == 'A') {
if ($('#products .selected_product').length > 0) {
$('#button_assign').removeClass('as_button_off');
} else {
$('#button_assign').addClass('as_button_off');
}
if ($('#as_products .selected_product').length > 0) {
$('#button_unassign').removeClass('as_button_off');
} else {
$('#button_unassign').addClass('as_button_off');
}
}
}