diff --git a/app/assets/javascripts/cancer_predict.js b/app/assets/javascripts/cancer_predict.js index f9af71b..882cb45 100644 --- a/app/assets/javascripts/cancer_predict.js +++ b/app/assets/javascripts/cancer_predict.js @@ -71,54 +71,84 @@ $(document).ready(function(){ }; }; }); - $('.cancer_table_btn').click(function(){ + $('.cancer_table_btn').off('click').on('click',function(){ var index = $(this).index()/2; - $(this).parent().find('>input').attr('value',0); - $(this).parent().find('>input').eq(index).attr('value',1); - $(this).parent().find('>button').removeClass('active'); + try{ + $(this).parent().find('>input').attr('value',0); + $(this).parent().find('>input').eq(index).attr('value',1); + $(this).parent().find('>button').removeClass('active'); + $(this).parent().removeClass('cancertable_empty'); + }catch{}; $(this).addClass('active'); - $(this).parent().removeClass('cancertable_empty'); }); $('#cancer_table_reset').click(function(){ $('.cancer_table_btn').removeClass('active'); $('.cancer-btn-group input').attr('value',0); $('.num_only').val(''); - $('.cancer_form_field').removeClass('cancertable_empty'); + $('#cancer_table .cancer_form_field').removeClass('cancertable_empty'); }); $('#cancer_table_submit').click(function(){ var flag; flag = 1; - for(var i = 0;i < $('.cancer_form_field').length;i++){ - if($('.cancer_form_field').eq(i).hasClass('num_only')){ - if($('.cancer_form_field').eq(i).val()==""){ + for(var i = 0;i < $('#cancer_table .cancer_form_field').length;i++){ + if($('#cancer_table .cancer_form_field').eq(i).hasClass('num_only')){ + if($('#cancer_table .cancer_form_field').eq(i).val()==""){ flag = 0; - $('.cancer_form_field').eq(i).addClass('cancertable_empty'); + $('#cancer_table .cancer_form_field').eq(i).addClass('cancertable_empty'); }else{ - $('.cancer_form_field').eq(i).removeClass('cancertable_empty'); + $('#cancer_table .cancer_form_field').eq(i).removeClass('cancertable_empty'); }; }else{ - if($('.cancer_form_field').eq(i).find('[value="1"]').length == 0){ + if($('#cancer_table .cancer_form_field').eq(i).find('[value="1"]').length == 0){ flag = 0; - $('.cancer_form_field').eq(i).addClass('cancertable_empty'); + $('#cancer_table .cancer_form_field').eq(i).addClass('cancertable_empty'); }else{ - $('.cancer_form_field').eq(i).removeClass('cancertable_empty'); + $('#cancer_table .cancer_form_field').eq(i).removeClass('cancertable_empty'); } }; } if(flag == 1){ var post_json= {}; - for(var i = 0;i < $('.cancer_form_field').length;i++){ - var name = $('.cancer_form_field').eq(i).attr('id') - if($('.cancer_form_field').eq(i).hasClass('num_only')) - post_json[name] = $('.cancer_form_field').eq(i).val(); + for(var i = 0;i < $('#cancer_table .cancer_form_field').length;i++){ + var name = $('#cancer_table .cancer_form_field').eq(i).attr('id') + if($('#cancer_table .cancer_form_field').eq(i).hasClass('num_only')) + post_json[name] = $('#cancer_table .cancer_form_field').eq(i).val(); else{ - var index = ($('.cancer_form_field').eq(i).find('[value="1"]').index()+1)/2; + var index = ($('#cancer_table .cancer_form_field').eq(i).find('[value="1"]').index()+1)/2; post_json[name] = index; }; }; var result = $.post("/cancerpredictResult",{"data":post_json}); result.done(function(){ - $('#result_table_content').html(result.responseJSON.table); + var load_heml = $('#result_table_content').html(result.responseJSON.table); + load_heml.ready(function(){ + $('#result_table_content .cancer_years').eq(0).addClass('active'); + $('.cancer_table_btn').off('click').on('click',function(){ + var index = $(this).index()/2; + try{ + $(this).parent().find('>input').attr('value',0); + $(this).parent().find('>input').eq(index).attr('value',1); + $(this).parent().find('>button').removeClass('active'); + $(this).parent().removeClass('cancertable_empty'); + }catch{}; + $(this).addClass('active'); + }); + }); + load_heml = $('#result_text_content').html(result.responseJSON.texts); + load_heml.ready(function(){ + $('#result_text_content .cancer_years').eq(0).addClass('active'); + $('.cancer_table_btn').off('click').on('click',function(){ + var index = $(this).index()/2; + try{ + $(this).parent().find('>input').attr('value',0); + $(this).parent().find('>input').eq(index).attr('value',1); + $(this).parent().find('>button').removeClass('active'); + $(this).parent().removeClass('cancertable_empty'); + }catch{}; + $(this).addClass('active'); + $('.surgery_year').html($(this).html()); + }); + }); }) } }); @@ -130,10 +160,19 @@ $(document).ready(function(){ }; $('.result_tab').click(function(){ var index = $(this).attr('index'); + $('.result_tab').removeClass('active'); + $(this).addClass('active'); $('.result_content').css('display','none'); $('.result_content[index="'+index+'"]').css('display','block'); }) - $('.num_only').focus + $('.num_only').keypress(function(event){ + console.log(event.keyCode) + return event.keyCode>=48&&event.keyCode<=57||(this.value.indexOf('.')<0?event.keyCode==46:false); + }); + /*$('.num_only').attr("onpaste","{console.log(clipboardData.getData('text'));return !event.clipboardData.getData('text').match(/\D/)}");*/ + /*$('.num_only').keyup(function(){ + $(this).val($(this).val().replace(/\D/g,'')); + });*/ for(var i=0;i<$('.num_only').length;i++) $('.num_only').eq(i).data('range') }); diff --git a/app/controllers/cancerpredicts_controller.rb b/app/controllers/cancerpredicts_controller.rb index d38125e..60ea65e 100644 --- a/app/controllers/cancerpredicts_controller.rb +++ b/app/controllers/cancerpredicts_controller.rb @@ -9,7 +9,7 @@ class CancerpredictsController < ApplicationController uid = OrbitHelper.params[:uid] rescue "" tags = OrbitHelper.widget_tags categories = OrbitHelper.widget_categories || [] - locale = OrbitHelper.get_site_locale.to_s + create_first_field result = {:result=>"123"} result['age1'] = -(params['data']['age'].to_f/100)**(-0.5) result['age2'] = -(params['data']['age'].to_f/100)**(-0.5)*Math.log(params['data']['age'].to_f/100,10) @@ -58,8 +58,37 @@ class CancerpredictsController < ApplicationController result['lpv'] = ((result['age1']-0.7276655)*(-10.87)+(result['age2']-0.4540707)*8.968+(result['size1']-0.643632)*0.7678+(result['nposit']-1.346932)*0.5339+ result['grade_2']*0.4795+result['grade_3']*0.818+result['subtype_HER2']*0.1806+result['subtype_triple']*0.6457+result['pstage_2']*0.5311+ result['pstage_3']*1.134+result['pstage_4']*2.172+result['lvi_yes']*0.3321-0.04 rescue 'error') - result['table'] = '此分析微針對已接受手術後病人,下表為此病人分別在第1年、3及5年下,根據選定的術後治療所估計的存活率' - #result['table'] += + result['table'] = '
此分析微針對已接受手術後病人,下表為此病人分別在第1年、3及5年下,根據選定的術後治療所估計的存活率
' + result['table'] += '第' + @years = ['1','3','5'] + result['years'] = @years + @years.each{|year| result['table'] += ('')} + result['table'] += '年' + @table_head = (I18n.locale.to_s == "zh_tw") ? ['治療','額外治療效益','總生存率(%)'] :['Treatment','Additional Benefit','Overall Survival(%)'] + @therapy_choices = (I18n.locale.to_s == "zh_tw") ? ['純手術'] :['Treatment'] + @form_to_show.form_show_in_result.values.each{|choice| @therapy_choices.push choice["name"][I18n.locale.to_s]} + @therapy_names = ['Treatment'] + @form_to_show.form_show_in_result.values.each{|choice| @therapy_names.push choice["variable"]} + result['table'] += '' + head + ' | ')} + result['table'] += '|
---|---|
' + choice + ' | ') + else + result['table'] += ('' + '-' + ' | ') + end + end + result['table'] += '