hostname = "forum.maqs-inc.com";threads_no = ""; /* * onload * */ $(function(){ var initial_parent_id = 0; // init interface init_category_form(); load_each_category(initial_parent_id); $("select#category_layer01").change(function(){ //alert($(this).val()); //load_each_category($(this).val()); //set second category list init_select_options("category_layer02"); second_layer = get_category_id_list($(this).val()); set_json_to_option(second_layer,"category_layer02"); //set third category list init_select_options("category_layer03"); if (second_layer.length > 0) { third_layer = get_category_id_list(second_layer[0].category_id); set_json_to_option(third_layer,"category_layer03"); } }); $("select#category_layer02").change(function(){ //alert($(this).val()); //load_each_category($(this).val()); //set third category list init_select_options("category_layer03"); third_layer = get_category_id_list($(this).val()); set_json_to_option(third_layer,"category_layer03"); }); //init buttons $('a.btnChange1').click(function(){ first_id = $("#boxPopupCategory select#category_layer01").val(); second_id = $("#boxPopupCategory select#category_layer02").val(); third_id = $("#boxPopupCategory select#category_layer03").val(); threads_no; var post_data = { category_first_id : first_id, category_second_id : second_id, category_third_id : third_id, threads_id : threads_no } $.ajax({ url : './exec/threads/category_upd.php', type : 'POST', data : post_data, dataType: 'text', timeout : 4000, error : function(rtn) { //alert("Error occurred: cannot update categories of the thread."); }, success : function(rtn) { $('form#logingo').submit(); } }); }); }); /* * * */ function category_change(threads_id, category_first_id,category_first_name, category_second_id,category_second_name, category_third_id,category_third_name ){ // set click action // set each values to each category select $("span#category_first_name").text(category_first_name); $("span#category_second_name").text(category_second_name); $("span#category_third_name").text(category_third_name); $('#boxPopupCategory').dialog("open"); threads_no = threads_id; } /* * * */ function init_category_form() { $('#boxPopupCategory').dialog({ autoOpen: false, resizable: false, width: 600, height: 350, modal: true, overlay: { backgroundColor: '#999', opacity: '0.5' } }); } // // set each select options of category // function load_each_category(parent_id){ //set first category list first_layer = get_category_id_list(parent_id); init_select_options("category_layer01"); set_json_to_option(first_layer,"category_layer01"); //set second category list init_select_options("category_layer02"); if (first_layer.length > 0) { second_layer = get_category_id_list(first_layer[0].category_id); set_json_to_option(second_layer,"category_layer02"); } //set third category list init_select_options("category_layer03"); if (second_layer.length > 0) { third_layer = get_category_id_list(second_layer[0].category_id); set_json_to_option(third_layer,"category_layer03"); } } // // Set json to select option // // function set_json_to_option(json,cssid) { var cnt = json.length; var str; cssstr = "select#" + cssid + ""; for (i = 0; i < cnt; i++){ str = "\n"; $(cssstr).append(str); } } // // Initialize select option // // function init_select_options(cssid) { str = "select#" + cssid + ""; $(str).empty(); } // // get_category_id_list // return arr[0][name] // arr[0][category_id] function get_category_id_list(parent_id) { if (parent_id == undefined ){ //if (parent_id == undefined || typeof(parent_id) != "number"){ return ; } //alert (parent_id); var rtn; // DBからparent_idが該当のものを持ってくる target_url = "./exec/category/get_category_list.php?parent_id=" + parent_id; $.ajax({ url: target_url, type: 'POST', //dataType: 'text', dataType: 'json', async: false, timeout: 6000, error: function(){ //alert(parent_id ); alert('Error occurred: get_category_list().' ); }, success: function(json){ rtn = json; } }); //init_buttons(); return eval(rtn); }