var usd_arr = []
var list_num={
"up"  : 1,
"up2"  : 1,
"down": 1,
"down2": 1,
"down_bkup":1
}
var list_sw={
"up"  : [""],
"up2"  : [""],
"down": [""],
"down2": [""],
"down_bkup":[""]
}
function show_usb_list(mod)
{
if(mod=='up')document.getElementById("usb"+mod+"_set_0").style.display = "none";
if(mod=='up2')document.getElementById("usb"+mod+"_set_0").style.display = "none";
document.getElementById("usb"+mod+"_set_1").style.display = "";
var table = $("#t_usfb_list_"+mod);
var table_count = $("#t_usfb_list_"+mod+" tr").length;
var str = "<tr><td><img src=/folder0.gif><a href=javascript:up_folder('"+mod+"');>Up folder"
+"</a></td></tr>";
var web_surdir = $("#t_storage_web_curdir_"+mod).val();
usd_arr = [];
for(var a=table_count-1;a>=0;a--)
{
$("#t_usfb_list_"+mod+" tr").eq(a).remove();
}
$.ajax({
url:"usb_fwug.xml?rc=",  /*S_STORAGE_WEB_CURDIR*/
type: 'POST',
data: {"S801f0334":web_surdir,"csrftok":get_csrf_token()},
dataType: 'xml',//資料型態可以不設定，且此型態不可是text或html
error: function(xml){
},
success: function(xml){
var data = $(xml).find("usb_data");
var data_length = $(xml).find("usb_data").length;
var data_content = "";
for(var a=0;a<data_length;a++)
{
data_content = data.eq(a).text();
if(data_content != "")
{
usd_arr.push(data_content);
}
}
list_num[mod]=1;
list_sw[mod].length=1;
for(var x=0;x<usd_arr.length;x++)
{
str += List(usd_arr[x],mod);
}
table.append(str);
}})
}
function List(v,mod){
var str = "";
var mod_func="";
var mod_click="x";
vsplt=v.split("|")
if((mod=='up')||(mod=='up2')){
mod_func="copyfd";
}else{
mod_func="copyfd_down";
mod_click=""
}
for(a=1;a<vsplt.length-1;a++)
{
df=vsplt[a].split(",");
if(df[0]=="D")  //folder
{
str += "<tr id='ttr_"+mod+"_"+list_num[mod]+"'><td><pre>&nbsp;&nbsp;<img src='/folder0.gif'>";
str += "<a href=javascript:select_tr("+list_num[mod]+",'"+mod+"'); ondblclick="+mod_func+"(1,"+list_num[mod]+",'"+mod+"'); "+mod_click+"OnClick="+mod_func+"(2,"+list_num[mod]+",'"+mod+"');>"+
"<font color=#695e4a><span id='show_"+mod+"_"+list_num[mod]+"'>"+df[1]+"</span></font></a>";
str += "</pre></td></tr>"
list_num[mod]++;
list_sw[mod].push(df[1]);
}
}
if(mod=='up'){
for(b=1;b<vsplt.length-1;b++)
{
df=vsplt[b].split(",");
if(df[0]=="F")  //file
{
str += "<tr id='ttr_"+mod+"_"+list_num[mod]+"'><td><pre>&nbsp;&nbsp;<img src='/item0.gif'>";
str += "<a href=javascript:select_tr("+list_num[mod]+",'"+mod+"'); ondblclick="+mod_func+"(2,'"+list_num[mod]+"');><font color=#695e4a><span id='show_"+mod+"_"+list_num[mod]+"'>"+
df[1]+"</span></font></a>";
str += "</pre></td></tr>";
list_num[mod]++;
list_sw[mod].push(df[1]);
}
}
}
if(mod=='up2'){
for(b=1;b<vsplt.length-1;b++)
{
df=vsplt[b].split(",");
if(df[0]=="F")  //file
{
str += "<tr id='ttr_"+mod+"_"+list_num[mod]+"'><td><pre>&nbsp;&nbsp;<img src='/item0.gif'>";
str += "<a href=javascript:select_tr("+list_num[mod]+",'"+mod+"'); ondblclick="+mod_func+"(2,'"+list_num[mod]+"','"+mod+"');><font color=#695e4a><span id='show_"+mod+"_"+list_num[mod]+"'>"+
df[1]+"</span></font></a>";
str += "</pre></td></tr>";
list_num[mod]++;
list_sw[mod].push(df[1]);
}
}
}
return str;
}
function select_tr(ind,mod){
init_color(mod);
$("#ttr_"+mod+"_"+ind).css("backgroundColor","#D2DDFE");
}
function copyfd(c,ind,mod){
if(mod == "up2")
{
var current_dir = $("#t_storage_web_curdir_up2");
var current_dir_val = $("#t_storage_web_curdir_up2").val();
var usb_file_name = $("#s_file_name2");
var usb_file_path = $("#t_usb_file_path2");
var h_file_name = $("#h_file_name3");
var chose_file = list_sw["up2"][ind];
var default_path = "/var/usb" + current_dir_val + chose_file;
if(c==1){ //double click folder
current_dir.val(current_dir_val + chose_file +"/");
show_usb_list('up2');
}
if(c==2){ //double click file
usb_file_name.html(chose_file);
h_file_name.val(chose_file);
usb_file_path.val(default_path)
document.getElementById("usbup2_set_0").style.display = "";
document.getElementById("usbup2_set_1").style.display = "none";
}
}
else
{
var current_dir = $("#t_storage_web_curdir_up");
var current_dir_val = $("#t_storage_web_curdir_up").val();
var usb_file_name = $("#s_file_name");
var usb_file_path = $("#t_usb_file_path");
var h_file_name = $("#h_file_name");
var chose_file = list_sw["up"][ind];
var default_path = "/var/usb" + current_dir_val + chose_file;
if(c==1){ //double click folder
current_dir.val(current_dir_val + chose_file +"/");
show_usb_list('up');
}
if(c==2){ //double click file
usb_file_name.html(chose_file);
h_file_name.val(chose_file);
usb_file_path.val(default_path)
document.getElementById("usbup_set_0").style.display = "";
document.getElementById("usbup_set_1").style.display = "none";
}
}
}
function init_color(mod)
{
for(c=1;c<200;c++)
{
if(!eval("document.getElementById('ttr_"+mod+"_"+c+"')")) break; //ttr? not exit
eval("document.getElementById('ttr_"+mod+"_"+c+"').style.backgroundColor='#FFFFFF'")
}
}
function up_folder(mod){
if(mod == "down2")
{
var current_dir = $("#t_storage_web_curdir_"+mod);
var bac= $("#t_storage_web_curdir_"+mod).val();
var usb_file_name = $("#s_file_name_down2");
var usb_file_name_bkup = $("#s_file_name_down_bkup");
var t_chose_file = $("#t_chose_file2");
var t_chose_file_bkup = $("#t_chose_file_bkup");
if(bac == "/"){
if(mod=='down2') usb_file_name.html("")
if(mod=='down_bkup') usb_file_name_bkup.html("")
return; //already the top folder
}else{
bac = bac.substring(0,bac.length-1) //remove last "/"
current_dir.val(bac.substring(0,bac.lastIndexOf("/")+1));
if(mod=='down2'){
var chose_file=current_dir.val().split("/");
t_chose_file.val(chose_file[chose_file.length-2]); //取得目前所在的file
usb_file_name.html(bac.substring(0,bac.lastIndexOf("/")))
}
if(mod=='down_bkup'){
var chose_file=current_dir.val().split("/");
t_chose_file_bkup.val(chose_file[chose_file.length-2]); //取得目前所在的file
usb_file_name_bkup.html(bac.substring(0,bac.lastIndexOf("/")))
}
show_usb_list(mod);
}
}
else
{
var current_dir = $("#t_storage_web_curdir_"+mod);
var bac= $("#t_storage_web_curdir_"+mod).val();
var usb_file_name = $("#s_file_name_down");
var usb_file_name_bkup = $("#s_file_name_down_bkup");
var t_chose_file = $("#t_chose_file");
var t_chose_file_bkup = $("#t_chose_file_bkup");
if(bac == "/"){
if(mod=='down') usb_file_name.html("")
if(mod=='down_bkup') usb_file_name_bkup.html("")
return; //already the top folder
}else{
bac = bac.substring(0,bac.length-1) //remove last "/"
current_dir.val(bac.substring(0,bac.lastIndexOf("/")+1));
if(mod=='down'){
var chose_file=current_dir.val().split("/");
t_chose_file.val(chose_file[chose_file.length-2]); //取得目前所在的file
usb_file_name.html(bac.substring(0,bac.lastIndexOf("/")))
}
if(mod=='down_bkup'){
var chose_file=current_dir.val().split("/");
t_chose_file_bkup.val(chose_file[chose_file.length-2]); //取得目前所在的file
usb_file_name_bkup.html(bac.substring(0,bac.lastIndexOf("/")))
}
show_usb_list(mod);
}
}
}
function check_file(mod)
{
if(mod == "css")
{
var file_name = $("#s_file_name2").html();
var file_name_check_array = ["wmqa01.css"];
var return_value = false;
var message = "Only  "+file_name_check_array.toString()+"  can upload!!";
for(var x=0;x<file_name_check_array.length;x++)
{
if(file_name == file_name_check_array[x])
{
return_value = true;
break;
}
}
if(!return_value)
{
alert(message);
}
return return_value;
}
else
{
var file_name = $("#s_file_name").html();
var file_name_check_array = ["logo.gif"];
var return_value = false;
var message = "Only  "+file_name_check_array.toString()+"  can upload!!";
for(var x=0;x<file_name_check_array.length;x++)
{
if(file_name == file_name_check_array[x])
{
return_value = true;
break;
}
}
if(!return_value)
{
alert(message);
}
return return_value;
}
}
function copyfd_down(c,ind,mod){
if(mod=="down"){
var current_dir = $("#t_storage_web_curdir_down");
var current_dir_val = $("#t_storage_web_curdir_down").val();
var usb_file_name = $("#s_file_name_down");
var h_file_name = $("#h_file_name");
var chose_file = list_sw["down"][ind];
var t_chose_file = $("#t_chose_file");
var default_path = current_dir_val + chose_file + "/";
}
else if(mod == "down2")
{
var current_dir = $("#t_storage_web_curdir_down2");
var current_dir_val = $("#t_storage_web_curdir_down2").val();
var usb_file_name = $("#s_file_name_down2");
var h_file_name = $("#h_file_name2");
var chose_file = list_sw["down2"][ind];
var t_chose_file = $("#t_chose_file");
var default_path = current_dir_val + chose_file + "/";
}
else{
var current_dir = $("#t_storage_web_curdir_down_bkup");
var current_dir_val = $("#t_storage_web_curdir_down_bkup").val();
var usb_file_name = $("#s_file_name_down_bkup");
var chose_file = list_sw["down_bkup"][ind];
var t_chose_file = $("#t_chose_file_bkup");
var default_path = current_dir_val + chose_file + "/";
}
if(c==1){ //double click folder
current_dir.val(current_dir_val + chose_file +"/");
show_usb_list(mod);
}
if(c==2){ //click folder
if(t_chose_file.val()!=chose_file){ //若目前所在的file不等於所選擇的file時，才更改路徑到s_file_name_down
usb_file_name.html(current_dir_val + chose_file );
t_chose_file.val(chose_file);
}
}
}