Page Javascript same Grid Control Server.


function forceNumber(e, type) {
    
	//type = 1: real number, type = 2: interger number

	var unicode=e.charCode? e.charCode : e.keyCode;
	if(type==1 && unicode!=9)
    {
        if (unicode!=8 && unicode!=46 && unicode.keyCode!=37 && unicode.keyCode!=39 && (unicode40))
        { //if the key isn't the backspace key (which we should allow)
                if (unicode57) //if not a number
                return false; //disable key press
         }
    }
  if(type==2 && unicode!=9)
    {
        if (unicode!=8  && unicode.keyCode!=37 && unicode.keyCode!=39 && (unicode40))
        { //if the key isn't the backspace key (which we should allow)
                if (unicode57) //if not a number
                return false; //disable key press
         }
    }
}

function findIndexById(arr, id)
{
    for(var i=0; i<arr.length; i++)
    {
        if(arr[i].id == id) return i;
    }
    return -1;
}

var criterionGroup;
var criteria;
var histogram_height = 25;
var histogram_count_limit = 9;
var histogram_count = 0;

function initPage()
{
    //GetNameColumnsTables();
    initCriteria();
    
}

function initCriteria()
{
    StockSlider.Screener.GetCriterionGroup(getCriterionGroupCallback);
}

function getCriterionGroupCallback(res)
{
    criterionGroup = res.value;
    var html = new StringBuffer();
    html.append('');
    for(var i=0; i<criterionGroup.length; i++)
    {
        html.append('');
        html.append('');
        html.append('');
    }
    html.append('
' + criterionGroup[i].name + '
'); html.append(''); document.getElementById('divCriterionGroup').innerHTML = html; StockSlider.Screener.GetCriteria(getCriteriaCallback); } function getCriteriaCallback(res) { criteria = res.value; var html = new StringBuffer(); for(var i=0; i<criteria.length; i++) { html.append('
'); if(criteria[i].is_default) { addHistogram(i); html.append('
' + criteria[i].title + "

Added
"); } else { html.append('
' + criteria[i].title + "

Add
"); } html.append('
'); } document.getElementById('divHiddenCriterionShow').innerHTML = html; html = new StringBuffer(); for(var i=0; i<criterionGroup.length; i++) { var group = criterionGroup[i]; html.append('
'); for(var j=0; j<criteria.length; j++) { var child = criteria[j]; if(group.id == child.id_group) { html.append(''); html.append(''); html.append(''); } } html.append('
' + child.title + '
'); } document.getElementById('divHiddenCriterionChild').innerHTML = html; refreshCompanyList(); } function switchCriterionGroup(index) { var group = criterionGroup[index]; var id = "tdCriterionGroup_" + group.id; var hidOldId = document.getElementById('hidCurrentCriterionChildId'); var tdGroups = document.getElementById('divCriterionGroup').getElementsByTagName('td'); for(var i=0; i= 0) { if(tdGroups[i].id == id) { tdGroups[i].style.background = '#fff'; tdGroups[i].innerHTML = '
' + group.name + '
'; } else { tdGroups[i].style.background = '#F2F8FC'; if(tdGroups[i].innerHTML.indexOf('switchCriterionGroup') < 0 ) { var content = tdGroups[i].getElementsByTagName('div')[0].innerHTML; tdGroups[i].innerHTML = '
' + content + '
'; } } } } id = "divCriterionGroup_" + group.id; var divChilds = document.getElementById('divHiddenCriterionChild').getElementsByTagName('div'); var divChild = document.getElementById('divCriterionChild'); hidOldId.value = group.id; for(var i=0; i<divChilds.length; i++) { if(divChilds[i].id == id) { divChild.innerHTML = divChilds[i].innerHTML; break; } } document.getElementById('divCriterionShow').innerHTML = ''; document.getElementById('hidCurrentCriterionShowId').value = ''; } function switchCriterion(index) { var cr = criteria[index]; var id = 'tdCriterionChild_' + cr.id; var hidOldId = document.getElementById('hidCurrentCriterionShowId'); var tdChilds = document.getElementById('divCriterionChild').getElementsByTagName('td'); for(var i=0; i= 0) { if(tdChilds[i].id == id) { tdChilds[i].innerHTML = '
' + cr.title + '
'; } else { if(tdChilds[i].innerHTML.indexOf('switchCriterion') < 0 ) { var content = tdChilds[i].getElementsByTagName('div')[0].innerHTML; tdChilds[i].innerHTML = '
' + content + '
'; } } } } id = 'divCriterionShow_' + cr.id; var div_hid = document.getElementById(id); var div_show = document.getElementById('divCriterionShow'); div_show.innerHTML = div_hid.innerHTML; hidOldId.value = cr.id; } function addCriterion(index) { //var hid_count = document.getElementById('hid_histogram_count'); if(histogram_count >= histogram_count_limit) { alert('The limit of histogram is ' + histogram_count_limit); return; } var cr = criteria[index]; addHistogram(index); var div_show = document.getElementById('divCriterionShow'); var div_hid = document.getElementById('divCriterionShow_' + cr.id); var html = '
' + cr.title + "

Added
"; div_show.innerHTML = html; div_hid.innerHTML = html; refreshCompanyList(); } function closeCriterion(index) { var cr = criteria[index]; var div_his = document.getElementById('div_histogram_' + cr.id); div_his.parentNode.removeChild(div_his); histogram_count--; var hid_count = document.getElementById('hid_histogram_count'); hid_count.value = histogram_count; var div_hid = document.getElementById('divCriterionShow_' + cr.id); var html = '
' + cr.title + "

Add
"; div_hid.innerHTML = html; var hid_id = document.getElementById('hidCurrentCriterionShowId'); if(hid_id != null) { if(cr.id == hid_id.value) { var div_show = document.getElementById('divCriterionShow'); div_show.innerHTML = html; } } refreshCompanyList(); } var aname; var amin; var amax; var pindex; var psize; var sortby; var sorttype; function refreshCompanyList() { var count = document.getElementById('hid_histogram_count').value; var div = document.getElementById('divHistogram'); pindex = document.getElementById('hid_page_index').value; var selps = document.getElementById('selPSize'); psize = selps.options[selps.selectedIndex].value; aname = new Array(); amin = new Array(); amax = new Array(); var index = 0; for(var i=0; i<div.childNodes.length; i++) { var child = div.childNodes[i]; if(child.tagName == 'DIV') { var sid = child.getAttribute('id'); var id = sid.substring(14, sid.length); var name = document.getElementById('hid_name_' + id).value; var min = document.getElementById('hid_min_' + id).value; var max = document.getElementById('hid_max_' + id).value; aname[index] = name; amin[index] = min; amax[index] = max; index++; } } if(index == 0) { var div_top = document.getElementById('divTopPaging'); var div_bottom = document.getElementById('divBottomPaging'); div_top.innerHTML = div_bottom.innerHTML = ''; var div_com = document.getElementById('divComList'); div_com.innerHTML = ''; } var market = RegionFiller.GetMarket(); var catid = RegionFiller.GetIndustry(); StockSlider.Screener.GetPaging(aname, amin, amax, market, catid, pindex, psize, getPagingCallback); } function GetNameColumnsTables() { var _companyName=document.getElementById('').value; var _code=document.getElementById('').value; } function getCompaniesCallback(res) { var coms = res.value; var html = new StringBuffer(); var sort_sta = 'sort'; //var sort_sta = 'sort'; html.append(''); html.append(''); html.append(''); var div = document.getElementById('divHistogram'); for(var i=0; i<div.childNodes.length; i++) { var child = div.childNodes[i]; if(child.tagName == 'DIV') { var sid = child.getAttribute('id'); var id = sid.substring(14, sid.length); var name = document.getElementById('hid_name_' + id).value; var title = document.getElementById('hid_title_' + id).value; html.append(''); } } html.append('');//
_companyName'); if(sortby == 'name') html.append(sort_sta); html.append('
_code'); if(sortby == 'symbol') html.append(sort_sta); html.append('
' + title); if(sortby == name) html.append(sort_sta); html.append('
'); //html.append(''); for(var i=0; i<coms.length; i++) { html.append(''); html.append(''); html.append(''); for(var j=0; j<coms[i].indices.length; j++) { html.append(''); } html.append(''); } html.append('
' + coms[i].fullname + '' + coms[i].symbol + '' + coms[i].indices[j] + '
'); var div_com = document.getElementById('divComList'); div_com.innerHTML = html; delete aname; delete amin; delete amax; } function getPagingCallback(res) { var div_top = document.getElementById('divTopPaging'); var div_bottom = document.getElementById('divBottomPaging'); div_top.innerHTML = div_bottom.innerHTML = res.value; sortby = document.getElementById('hid_sort_by').value; sorttype = document.getElementById('hid_sort_type').value; var hid_valid_pi = document.getElementById('hid_valid_page_index'); if(hid_valid_pi != null) { pindex = hid_valid_pi.value; document.getElementById('hid_page_index').value = pindex; } else { pindex = 1; } var market = RegionFiller.GetMarket(); var catid = RegionFiller.GetIndustry(); document.getElementById('hid_page_index').value = pindex; StockSlider.Screener.GetCompanies(aname, amin, amax, market, catid, pindex, psize, sortby, sorttype, getCompaniesCallback); } function setSilderValue(obj) { var id = obj.id.substring(4, obj.id.length); var indicator_type = obj.id.substring(0, 3); var new_value = parseFloat(obj.value); var width = document.getElementById('hid_width_' + id).value - 5; var limit_min = parseFloat(document.getElementById('hid_limit_min_' + id).value); var limit_max = parseFloat(document.getElementById('hid_limit_max_' + id).value); var range = limit_max - limit_min; var cmin = parseFloat(document.getElementById('hid_min_' + id).value); var cmax = parseFloat(document.getElementById('hid_max_' + id).value); var min = cmin; var max = cmax; if(new_value limit_max) new_value = limit_max; if(indicator_type == 'min') { if(new_value > max) min = max; else min = new_value; } else { if(new_value < min) max = min; else max = new_value; } document.getElementById('min_' + id).value = min; document.getElementById('max_' + id).value = max; document.getElementById('hid_min_' + id).value = min; document.getElementById('hid_max_' + id).value = max; var min_pos = ((min-limit_min)/range)*width; var max_pos = ((max-limit_min)/range)*width; var cmin_pos = ((cmin-limit_min)/range)*width; var cmax_pos = ((cmax-limit_min)/range)*width; var min_dif = min_pos - cmin_pos; var max_dif = max_pos - cmax_pos; //if(min = limit_max) max_dif += 10; document.getElementById('hid_status_' + id).value = 'input'; //$('#slider_' + id).SliderSetValues([[min_dif,0.0],[max_dif,0.0]]); document.getElementById('hid_status_' + id).value = 'slide'; refreshCompanyList(); } function toggleCriteria() { //var img = document.getElementById('img_criteria_sign'); //var html = ''; if(document.getElementById('divCriteria').style.display == 'none') { //html += '-'; document.getElementById('divCriteria').style.display = 'inline'; //img.setAttribute('src', './images/acbs/add.gif'); } else { //html += '+'; document.getElementById('divCriteria').style.display = 'none'; //img.setAttribute('src', './images/acbs/add.gif'); } //html += ' Add criteria'; //document.getElementById('divAddCriteria').innerHTML = html; } function addHistogram(index) { var cr = criteria[index]; var div_histogram = document.createElement('div'); div_histogram.setAttribute('id', 'div_histogram_' + cr.id); var html = new StringBuffer(); html.append(''); html.append(''); html.append(''); html.append(''); html.append(''); html.append(''); html.append(''); html.append(''); html.append(''); html.append(''); html.append(''); html.append(''); html.append(''); html.append(''); html.append(''); html.append('
'); html.append('' + cr.title + ''); html.append(''); html.append('
'); html.append('
 
'); html.append('
'); html.append(''); var pixel_range = cr.segment_count * 2; var max_count = 1; for(var i=0; i<cr.segment_count; i++) { if(max_count < cr.counts[i]) max_count = cr.counts[i]; } for(var i=0; i<cr.segment_count; i++) { html.append(''); var height = cr.counts[i] * histogram_height / max_count; //if(height 0.0) height = 1.0; html.append(''); } html.append('
'); html.append('
 
'); html.append('
'); html.append('Close
'); div_histogram.innerHTML = html; document.getElementById('divHistogram').appendChild(div_histogram); var hid_count = document.getElementById('hid_histogram_count'); hid_count.value = parseInt(hid_count.value) + 1; histogram_count++; //$(document).ready(function () // { $('#slider_' + cr.id).Slider( { accept : '.indicator', restricted: true, //true: ko cho phep left indicator vuot qua right opacity: 0.8, onSlide : function(procx, procy, x, y) { var id = this.id.substring(10, this.id.length-2); var hid_status = document.getElementById('hid_status_' + id); if(hid_status.value != 'slide' && hid_status.value != 'jump') return; var limit_min = parseFloat(document.getElementById('hid_limit_min_' + id).value); var limit_max = parseFloat(document.getElementById('hid_limit_max_' + id).value); var range = limit_max - limit_min; var index = (limit_min + range * procx/100) + ''; var dot = index.indexOf('.'); if(dot >= 0) if(index.length-dot-1 > 2) index = index.substring(0, dot+3); document.getElementById((this.SliderIteration == 0 ? 'min_' : 'max_') + id).value = index; document.getElementById((this.SliderIteration == 0 ? 'hid_min_' : 'hid_max_') + id).value = index; if(hid_status.value == 'jump') { hid_status.value = 'slide'; refreshCompanyList(); } }, onChange : function(procx, procy, x, y) { refreshCompanyList(); }, //pham vi slider (pixel) values: [[0,0],[cr.segment_count*2+4,0]] } ); //}); } function sliderOnJumping(index) { var cr = criteria[index]; document.getElementById('hid_status_' + cr.id).value = 'jump'; } function pageIndexChange(pindex) { document.getElementById('hid_page_index').value = pindex; refreshCompanyList(); } //Next function pageIndexChange_Next(pindex) { document.getElementById('hid_page_index').value = pindex; refreshCompanyList(); } function pageSizeChange() { document.getElementById('hid_page_index').value = 1; refreshCompanyList(); } function gotoPage() { var pindex = parseInt(document.getElementById('txtTopGoto').value); document.getElementById('hid_page_index').value = pindex; document.getElementById('txtTopGoto').value = ''; refreshCompanyList(); } function sort(cur) { var sortby = document.getElementById('hid_sort_by').value; var sorttype = document.getElementById('hid_sort_type').value; var name = cur.id.substring(9, cur.id.length); if(name == sortby) { if(sorttype == 'asc') sorttype = 'desc'; else if(sorttype == 'desc') { sorttype = 'asc'; sortby = 'default'; } else { sorttype = 'asc'; } } else { sortby = name; } document.getElementById('hid_sort_by').value = sortby; document.getElementById('hid_sort_type').value = sorttype; document.getElementById('hid_page_index').value = 1; refreshCompanyList(); }

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: