////////////////////// global var ////////////////////////
globobj = {}
globobj.maximumSearchCrit = 555;
globobj.itemsinSearchCrit = 1;
globobj.clickedblacklist = 0;
results_obj = {};
results_obj.aclids = [];
results_obj.userIDs = [];
results_obj.group_name = "";
//////////////////////////////////////////////////////////
$(document).ready(function(){
$('#btn_2col_submit').click(function() {
create_a_result_object();
});
$('.user_roll_button').click(function() {
var class_string = $(this).attr('class');
if(class_string.indexOf("mid_roundtangle_grey") == -1){
$(this).attr('class','mid_roundtangle user_roll_button mid_roundtangle_grey');
} else {
$(this).attr('class','mid_roundtangle user_roll_button mid_roundtangle_blue');
};
});
////////////////////////////////////////////////
////////////////////////////////////////////////
function create_a_result_object() {
results_obj = {};
results_obj.aclids = [];
results_obj.userIDs = [];
results_obj.group_name = "";
$('.two_col_text_bubble_right_content').find(".two_col_Slide_Item").each(function(key, value) {
// console.log($(this));
results_obj.userIDs.push($(this).attr('userid'));
});
$('#div_container_user_roles').find("div").each(function(key, value) {
if($(this).attr('class').indexOf("mid_roundtangle_blue") != -1){
results_obj.aclids.push($(this).attr('aclid'));
};
results_obj.group_name = $('#input_group_name').val();
});
if( results_obj.group_name.trim() === ''){
$('.group_name_error').css('opacity','1');
} else {
$('.group_name_error').css('opacity','0');
};
if(results_obj.group_name.trim() === '' || results_obj.aclids.length === 0){
console.log('form nto filled out');
} else {
console.log('success submit the form');
console.log(results_obj);
};
};
$("#btn_2col_remove").click(function() {
$(".two_col_text_bubble_right_content").find(".two_col_Slide_Item").remove();
search_sortIcons();
$("#div_addtext").css('visibility', 'hidden');
});
$("#btn_2col_submit").click(function() {
write_searchCrit_toObject();
});
//////////////////////////////////////////
///// when you click the add button //////
//////////////////////////////////////////
$("#btn_add_keyword").click(function() {
if(check_all_text_4match( $("#add_keyword_textbox").val()) == 0 ) {
$newdiv1 = $('
' + $("#add_keyword_textbox").val() + '
ADD TO BLACKLIST
');
$newdiv1.appendTo(".two_col_text_bubble_right_content");
search_sortIcons();
$newdiv1.find('#btn_blacklist').css('display', 'none');
//var d = new Date();
//$newdiv1.append("");
// CreateASlider(d.getTime());
$('.slide_outer_click_container').bind('click', function(e) {
e.stopPropagation();
});
$newdiv1.bind('click', function(e) {
$(this).remove();
search_sortIcons();
e.stopPropagation();
});
}
});
///// when you click an item inside a slide
$(".two_col_Slide_Item").click(function() {
tempVar = $(this).attr('title');
/// count the number of slides
tempvar = $(".two_col_text_bubble_right_content").find(".two_col_Slide_Item")
/// console.log(tempvar);
globobj.itemsinSearchCrit = 0;
$.each(tempvar, function(key, value) {
globobj.itemsinSearchCrit++
})
//console.log(globobj.itemsinSearchCrit + " : " + globobj.maximumSearchCrit);
//// this items is in the left col
if($(this).parent().parent().attr('class') != 'two_col_text_bubble_right' ) {
////// if the number of slide is less than max
if(globobj.itemsinSearchCrit <= globobj.maximumSearchCrit - 1) {
/// make sure it is not greyed out already;
if($(this).find('.two_col_Slide_plus_icon').css('background-position') != '-86px -31px' ) {
//////////////////// clone //////////////
tempVar1 = $(this).clone(true, true);
tempVar1.find(".two_col_Slide_plus_icon").attr('class', 'two_col_Slide_minus_icon');
tempVar1.appendTo(".two_col_text_bubble_right_content");
tempVar1.find('#btn_blacklist').css('display', 'none');
var d = new Date(); /// create a distinct id
tempVar1.append("");
//CreateASlider(d.getTime());
$('.slide_outer_click_container').bind('click', function(e) {
e.stopPropagation();
});
///// reformat the former item ///
$(this).find('.two_col_Slide_plus_text').css('color', '#9a9999');
$(this).find('.two_col_Slide_plus_icon').css('background-position', '-86px -31px');
}
}
//// this item is not in the Search Crit it is in Standard Items list in a Category
//// this item is in the left col
}
else {
tempVar = $(this).text().trim();
$(this).remove();
$('.two_col_text_bubble_left_content').find(".two_col_Slide_plus_icon:contains('" + tempVar + "')").css('background-position', '-2px -31px');
tempVar = $('.two_col_text_bubble_left_content').find(".two_col_Slide_plus_text:contains('" + tempVar + "')").css('color', '#14364B');
tempVar.parent().find(".two_col_Slide_plus_icon").css('background-position', '-2px -31px');
}
/// count the slides and disable buttons if first or last slide
search_count_searchCrit_items();
/// convert all icons to correct plus or minus
search_sortIcons();
/// write everything in search criteria to object
write_searchCrit_toObject();
});
/////////////////////////////////////////////////////////////////////////
///////////////////////// Sort Plus Minus Icons /////////////////////
/////////////////////////////////////////////////////////////////////////
function search_sortIcons() {
$(".two_col_text_bubble_right_content").find(".two_col_Slide_plus_icon").attr('class', 'two_col_Slide_minus_icon');
$(".two_col_text_bubble_left_content").find(".two_col_Slide_minus_icon").attr('class', 'two_col_Slide_plus_icon');
$(".two_col_Slide_minus_icon").css('background-position', ' -2px -60px');
//// turn everything on in the items list
$(".two_col_text_bubble_left_content").find('.two_col_Slide_plus_text').css('color', '#767f85');
$(".two_col_text_bubble_left_content").find('.two_col_Slide_plus_icon').css('background-position', '-2px -31px');
//// then go through and find items in search criteria and turn off in items;
$(".two_col_text_bubble_right_content").find(".two_col_Slide_minus_icon").each(function(i, value) {
tempvarSeachCritContent = $(this).parent().find('.two_col_Slide_plus_text').text().trim();
//////console.log('Search Crit:' + tempvarSeachCritTitle + " : " + tempvarSeachCritContent);
$(".two_col_text_bubble_left_content").find(".two_col_Slide_plus_icon").each(function(i, value) {
console.log();
tempvaruserID = $(this).parent().attr('userid').trim();
tempvarItemContent = $(this).parent().find('.two_col_Slide_plus_text').text().trim();
//////console.log('Reg Item:' + tempvarItemTitle + " : " + tempvarItemContent);
/// if both content and category match then convert it
if(tempvarSeachCritContent == tempvarItemContent ) {
// $(this).parent().find('.two_col_Slide_plus_text').css('color', '#9a9999');
$(this).css('background-position', '-86px -31px');
}
});
/// turn everything off
tempvar = $(".two_col_text_bubble_right_content").find(".two_col_Slide_Item")
globobj.itemsinSearchCrit = 0;
$.each(tempvar, function(key, value) {
globobj.itemsinSearchCrit++
})
// alert(globobj.itemsinSearchCrit)
// console.log(globobj.itemsinSearchCrit + " -:- " + globobj.maximumSearchCrit);
$("#div_addtext").css('visibility', 'hidden');
if(globobj.itemsinSearchCrit >= (globobj.maximumSearchCrit )) {
$("#div_addtext").css('visibility', 'hidden');
$(".two_col_text_bubble_left_content").find('.two_col_Slide_plus_text').css('color', '#9a9999');
$(".two_col_text_bubble_left_content").find('.two_col_Slide_plus_icon').css('background-position', '-86px -31px');
};
});
}
/////////////////////////////////////////////////////////////////////////
///////////////////////// Save Target to Object /////////////////////
/////////////////////////////////////////////////////////////////////////
function write_searchCrit_toObject() {
globobj.tempString55 = "";
tempvar = $(".two_col_text_bubble_right_content").find(".two_col_Slide_Item")
globobj.outputObj = [];
globobj.outputObjAclid = [];
$.each(tempvar, function(key, value) {
globobj.tempObj = {};
globobj.tempObj.content = $(this).find(".two_col_Slide_plus_text").text().trim();
globobj.tempObj.userID = $(this).attr('userID');
globobj.tempObj.groupID = $(this).attr('groupID');
globobj.tempString55 += $(this).attr('jsItem') + ",";
globobj.tempObj.SliderValue = $('#' + globobj.tempObj.jsID).slider( "value");
$('.two_col_slide_btnContainer > div').attr('aclid');
// globobj.tempObj.title = $(this).find(".two_col_Slide_plus_text").text().trim();
//tempObj.ItemText = $(value[key]).find(".two_col_Slide_plus_text").text().trim();
//tempObj.Category = $(value[key]).attr('title');
globobj.outputObj.push(globobj.tempObj)
});
tempvar = $("#div_container_user_roles").find("div");
$.each(tempvar, function(key, value) {
if($(this).attr('class').indexOf('mid_roundtangle_blue') !== -1){
globobj.outputObjAclid.push(parseInt($(this).attr('aclid')));
}
});
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
console.log('-- Output Items -- ');
console.log(globobj.outputObj);
console.log('-- User Roles : Aclid -- ');
console.log(globobj.outputObjAclid);
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
};
//////////////////////////// start sequence ////////////////////////////
search_sortIcons();
});
function search_count_searchCrit_items() {
tempvar = $(".two_col_text_bubble_right_content").find(".two_col_Slide_Item")
tempVarX1 = 0;
$.each(tempvar, function(key, value) {
tempVarX1++
})
if(tempVarX1 == 0) {
$('.btn_2col_remove').removeClass('btnTemplate_BtnLightGrey').addClass('btnTemplate_BtnDisabledGrey');
$('.btn_2col_test').removeClass('btnTemplate_BtnDarkGrey').addClass('btnTemplate_BtnDisabledGrey');
$('.btn_2col_search').removeClass('btnTemplate_BtnDarkGrey').addClass('btnTemplate_BtnDisabledGrey');
} else {
$('.btn_2col_remove').removeClass('btnTemplate_BtnDisabledGrey').addClass('btnTemplate_BtnLightGrey');
$('.btn_2col_test').removeClass('btnTemplate_BtnDisabledGrey').addClass('btnTemplate_BtnDarkGrey');
$('.btn_2col_search').removeClass('btnTemplate_BtnDisabledGrey').addClass('btnTemplate_BtnDarkGrey');
}
}
function check_all_text_4match(target_text_from_textbox){
var matched_item = 0;
$(".two_col_text_bubble_right_content").find(".two_col_Slide_plus_text").each(function(i, value) {
console.log($(this).text().trim());
console.log(target_text_from_textbox.trim() + " : " + $(this).text().trim());
if(target_text_from_textbox.trim() == $(this).text().trim()){
matched_item = 1;
}
});
return matched_item
}