1var g_support_html5 = 0; 2var g_reload_page = 1; 3var m = new lang(); 4var g_storage = new myStorage(); 5var g_listview = (g_storage.get('listview') == undefined) ? 0 : g_storage.get('listview'); 6var g_modal_url; 7var g_modal_window_width = 200; 8var g_modal_window_height = 80; 9var timer_idle; 10var g_show_modal = 0; 11var g_time_out = 900000; //- 15min 12var g_time_count = 0; 13var g_select_mode = 0; 14var g_select_array; 15var g_upload_mode = 0; 16var g_folder_array; 17var g_file_array; 18var g_opening_uid = ''; 19var g_on_button_animation = 0; 20var g_on_rescan_samba = 0; 21var g_rescan_samba_timer = 0; 22var g_rescan_samba_count = 0; 23var g_aidisk_name = "usbdisk"; 24var g_enable_aidisk = 0; 25var g_support_lan = new Array('en-us', 'zh-tw', 'zh-cn', 'cz', 'pl', 'ru', 'de', 'fr', 'tr', 'th', 'ms', 'no', 'fi', 'da', 'sv', 'br', 'jp', 'es', 'it', 'uk'); 26var g_bInitialize = false; 27 28var g_showAudioList = false; 29var g_jplayer_solution = "html"; 30var g_jplayer_supplied = "mp3"; 31var g_audio_playlist = []; 32var g_current_index = 0; 33 34var g_timer_filelist; 35 36var newMenu = null; //variable to store menu instance 37 38var client = new davlib.DavClient(); 39client.initialize(); 40 41// Check for the various File API support. 42if (window.File && window.FileReader && window.FileList && window.Blob) { 43 // Great success! All the File APIs are supported. 44 g_support_html5 = 1; 45} else { 46 g_support_html5 = 0; 47} 48 49function openImageViewer(loc){ 50 51 var image_array = new Array(); 52 for(var i=0;i<g_file_array.length;i++){ 53 var file_ext = getFileExt(g_file_array[i].href); 54 if(file_ext=="jpg"||file_ext=="jpeg"||file_ext=="png"||file_ext=="gif") 55 image_array.push(g_file_array[i]); 56 } 57 58 var image_array_count = image_array.length; 59 60 if(image_array_count==0){ 61 alert(m.getString("msg_no_image_list")); 62 return; 63 } 64 65 var default_index = 0; 66 for(var i=0;i<image_array.length;i++){ 67 if( loc == image_array[i].href ) 68 default_index = i; 69 } 70 71 var div_html=''; 72 var page_size = getPageSize(); 73 74 div_html += '<div id="image_slide_show" class="barousel unselectable" style="height: 0; width: 0; position: fixed; background-color: rgb(0, 0, 0); left: ' + page_size[0]/2 + 'px; top: ' + page_size[1]/2 + 'px; z-index: 2999;">'; 75 div_html += '<div class="barousel_image">'; 76 77 for(var i=0;i<image_array.length;i++){ 78 79 var img_url = window.location.protocol + "//" + window.location.host + image_array[i].href; 80 81 if(i==default_index) 82 div_html += '<img src="" path="' + img_url + '" alt="" class="default"/>'; 83 else 84 div_html += '<img src="" path="' + img_url + '" alt="" class=""/>'; 85 } 86 87 div_html += '</div>'; 88 89 div_html += '<div class="barousel_nav">'; 90 91 div_html += '<div class="barousel_content transparent" style="display: block; ">'; 92 93 for(var i=0;i<image_array.length;i++){ 94 div_html += '<div class="'; 95 96 if(i==default_index) 97 div_html += 'default'; 98 99 div_html += '" style="display: none; ">'; 100 101 div_html += '<p class="header">' + image_array[i].name + '</p>'; 102 div_html += '</div>'; 103 } 104 105 div_html += '</div>'; 106 107 div_html += '</div>'; 108 109 div_html += '<div class="barousel_loading" style="position:absolute;display:none;z-index=99;"><img src="/smb/css/load.gif" width="18px" height="18px"/></div>'; 110 111 div_html += '</div>'; 112 113 $(div_html) 114 .animate({width:"100%", height:"100%", left:"0px", top:"0px"},200, null, null ) 115 .appendTo("body"); 116 117 var close_handler = function(){ 118 self.file_array = null; 119 self.settings = null; 120 }; 121 122 var init_handler = function(settings){ 123 self.settings = settings; 124 }; 125 126 $('#image_slide_show').barousel({ 127 name: 'image_slide_show', 128 manualCarousel: 1, 129 contentResize:0, 130 startIndex:default_index, 131 storage: g_storage, 132 stringTable: m, 133 enableExifFunc: 0, 134 enableShareFunc: 0, 135 closeHandler: null, 136 initCompleteHandler: null 137 }); 138 /* 139 $('#image_slide_show').barousel({ 140 navType: 2, 141 manualCarousel: 1, 142 contentResize:0, 143 startIndex:default_index 144 }); 145 */ 146 147 image_array = null; 148} 149 150function openDialog(effect, role_target){ 151 $.mobile.changePage('#dialog', {transition: effect, role: role_target}); 152} 153 154function closeDialog(){ 155 $.mobile.changePage('#mainpage', "popup", true, true); 156} 157 158function openLoginWindow(open_url){ 159 var dialog_title = ""; 160 var dologin = function(){ 161 var user = $('#table_content input#username').val(); 162 var pass = $('#table_content input#password').val(); 163 var auth = "Basic " + Base64.encode(user + ":" + pass); 164 closeDialog(); 165 doLOGIN(open_url, auth); 166 }; 167 168 if(open_url=='/') 169 dialog_title = m.getString('title_login') + " - AiCloud"; 170 else 171 dialog_title = m.getString('title_login') + " - " + open_url.substring(0, 35); 172 173 $("#dialog").remove(); 174 175 var dialog_html = ''; 176 dialog_html += "<div data-role='dialog' id='dialog' data-theme='a' data-transition='flip'>"; 177 dialog_html += "<div data-role='header'>"; 178 dialog_html += "<h1 id='dialog-title'>" + dialog_title + "</h1>"; 179 dialog_html += "</div>"; 180 dialog_html += "<div data-role='content' id='dialog-content'>"; 181 182 dialog_html += '<table id="table_content" width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0" style="overflow:hidden;">'; 183 dialog_html += '<tr>'; 184 dialog_html += '<td>'; 185 dialog_html += '<form name="form_login">'; 186 dialog_html += '<fieldset>'; 187 dialog_html += '<table width="100%">'; 188 dialog_html += '<tr>'; 189 dialog_html += '<td width="80px"><label id="username">' + m.getString('title_username') + ':</label></td><td><input name="username" type="text" id="username" size="35" autocapitalize="off"></td>'; 190 dialog_html += '</tr>'; 191 dialog_html += '<tr>'; 192 dialog_html += '<td width="80px"><label id="password">' + m.getString('title_password') + ':</label></td><td><input name="password" type="password" id="password" size="35"></td>'; 193 dialog_html += '</tr>'; 194 dialog_html += '</table>'; 195 dialog_html += '</fieldset>'; 196 dialog_html += '</form>'; 197 dialog_html += '</td>'; 198 dialog_html += '</tr>'; 199 dialog_html += '<tr style="height:10px"></tr>'; 200 dialog_html += '<tr>'; 201 dialog_html += '<td>'; 202 dialog_html += '<div class="table_block_footer" style="text-align:right">'; 203 dialog_html += '<button id="ok" class="btnStyle">' + m.getString('btn_ok') + '</button>'; 204 dialog_html += '<button id="cancel" class="btnStyle">' + m.getString('btn_cancel') + '</button>'; 205 dialog_html += '</div>'; 206 dialog_html += '</td>'; 207 dialog_html += '</tr>'; 208 dialog_html += '</table>'; 209 210 dialog_html += "</div>"; 211 dialog_html += "</div>"; 212 213 $("body").append(dialog_html); 214 215 $('#table_content input#password').keydown(function(e){ 216 if(e.keyCode==13){ 217 dologin(); 218 } 219 }); 220 221 $("#table_content #ok").click(function(){ 222 dologin(); 223 }); 224 225 $("#table_content #cancel").click(function(){ 226 closeDialog(); 227 }); 228 229 openDialog("pop", "dialog"); 230} 231 232function openShareWindow(open_url){ 233 var dialog_title = ""; 234 235 $("#dialog").remove(); 236 237 var share_array = open_url.split(";"); 238 239 var dialog_html = ''; 240 dialog_html += "<div data-role='dialog' id='dialog' data-theme='a' data-transition='flip'>"; 241 dialog_html += "<div data-role='header'>"; 242 dialog_html += "<h1 id='dialog-title'>" + m.getString('btn_sharelink') + "</h1>"; 243 dialog_html += "</div>"; 244 dialog_html += "<div data-role='content' id='dialog-content'>"; 245 246 dialog_html += '<table id="table_content" width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0" style="overflow:hidden;">'; 247 dialog_html += '<tr>'; 248 dialog_html += '<td>'; 249 250 dialog_html += '<textarea id="share_link">'; 251 for(var i=0; i<share_array.length; i++){ 252 dialog_html += decodeURI(share_array[i]); 253 dialog_html += "\n\n"; 254 } 255 dialog_html += '</textarea>'; 256 257 dialog_html += '</td>'; 258 dialog_html += '</tr>'; 259 dialog_html += '<tr>'; 260 dialog_html += '<td>'; 261 dialog_html += '<div class="table_block_footer" style="text-align:right">'; 262 dialog_html += '<button id="email-sharelink" class="btnStyle">' + m.getString("title_share_by_email") + '</button>'; 263 //dialog_html += '<button id="sms-sharelink" class="btnStyle">Share by SMS</button>'; 264 //dialog_html += '<button id="copy-sharelink" class="btnStyle">Copy Share</button>'; 265 dialog_html += '<button id="cancel" class="btnStyle">' + m.getString('btn_cancel') + '</button>'; 266 dialog_html += '</div>'; 267 dialog_html += '</td>'; 268 dialog_html += '</tr>'; 269 dialog_html += '</table>'; 270 271 dialog_html += "</div>"; 272 dialog_html += "</div>"; 273 274 $("body").append(dialog_html); 275 276 $("#table_content #email-sharelink").click(function(){ 277 278 var sMailTo = "mailto:"; 279 var sBody = ""; 280 var newline = "%0D%0A%0D%0A"; 281 282 sBody += m.getString('msg_sharelink_desc1'); 283 sBody += newline; 284 285 for(var i=0; i<share_array.length; i++){ 286 sBody += "<a href='" + share_array[i] + "'>" + share_array[i] + "</a>"; 287 sBody += newline; 288 } 289 290 sBody += m.getString('msg_sharelink_desc2'); 291 292 sMailTo += "?subject=" + m.getString('email_subject') + "&body=" + sBody; 293 294 document.location.href = sMailTo; 295 }); 296 297 $("#table_content #sms-sharelink").click(function(){ 298 299 var sSMSTo = "sms:"; 300 var sBody = ""; 301 var newline = "%0D%0A%0D%0A"; 302 303 sBody += m.getString('msg_sharelink_desc1'); 304 sBody += newline; 305 306 for(var i=0; i<share_array.length; i++){ 307 sBody += "<a href='" + share_array[i] + "'>" + share_array[i] + "</a>"; 308 sBody += newline; 309 } 310 311 sBody += m.getString('msg_sharelink_desc2'); 312 313 sSMSTo += "?subject=" + m.getString('email_subject') + "&body=" + sBody; 314 315 document.location.href = sSMSTo; 316 }); 317 318 $("textarea#share_link").click(function(){ 319 $(this).select(); 320 }); 321 322 $("#table_content #cancel").click(function(){ 323 closeDialog(); 324 }); 325 326 openDialog("pop", "dialog"); 327} 328 329function getLatestVersion(){ 330 331 if(client==null) 332 return; 333 334 $("#update").text(m.getString('msg_check_latest_ver')); 335 336 client.GETLATESTVER("/", function(error, content, statusstring){ 337 if(error==200){ 338 var data = parseXml(statusstring); 339 var x = $(data); 340 341 var ver = x.find("version").text(); 342 var a = ver.split("_"); 343 var build_no = a[1]; 344 345 var cur_ver = g_storage.get('router_version'); 346 var b = cur_ver.split("."); 347 var cur_build_no = b[3]; 348 349 if(build_no>cur_build_no) 350 $("#update").text(m.getString('msg_update_latest_ver')); 351 else 352 $("#update").text(m.getString('msg_latest_ver')); 353 } 354 else{ 355 $("#update").text(m.getString('msg_check_latest_ver_error')); 356 } 357 }); 358} 359 360function refreshShareLinkList(){ 361 if(client==null) 362 return; 363 364 client.GSLL("/", function(error, content, statusstring){ 365 if(error==200){ 366 var data = parseXml(statusstring); 367 368 $(".sharelink").empty(); 369 370 var encode_filename = parseInt($(data).find('encode_filename').text()); 371 372 var table_html = "" 373 374 var i = 0; 375 $(data).find('sharelink').each(function(){ 376 377 var filename = ""; 378 var filetitle = ""; 379 380 if(encode_filename==1){ 381 filename = $(this).attr("filename"); 382 filetitle = decodeURIComponent(filename); 383 } 384 else{ 385 filetitle = $(this).attr("filename"); 386 filename = encodeURIComponent($(this).attr("filename")); 387 } 388 389 var url = window.location.protocol + "//" + window.location.host + "/" + $(this).attr("url") + "/" + filename; 390 var createtime = $(this).attr("createtime"); 391 var expiretime = $(this).attr("expiretime"); 392 var lefttime = parseFloat($(this).attr("lefttime")); 393 var hour = parseInt(lefttime/3600); 394 var minute = parseInt(lefttime%3600/60); 395 396 table_html = "<li><a href='#' data-icon='delete'>"; 397 table_html += "<h3>" + filetitle + "</h3>"; 398 //table_html += "<a id='rescan' data-role='button'>test</a>"; 399 400 table_html += "<p class='ui-li-desc'>"; 401 table_html += m.getString('table_createtime') + ": "; 402 table_html += createtime; 403 table_html += "</p>"; 404 405 table_html += "<p class='ui-li-desc'>"; 406 table_html += m.getString('table_expiretime') + ": "; 407 if(expiretime==0) 408 table_html += m.getString('title_unlimited'); 409 else 410 table_html += expiretime; 411 table_html += "</p>"; 412 413 table_html += "<p class='ui-li-desc'>"; 414 table_html += m.getString('table_lefttime') + ": "; 415 if(expiretime==0) 416 table_html += m.getString('title_unlimited'); 417 else 418 table_html += hour + " hours " + minute + " mins"; 419 420 table_html += "</p>"; 421 422 table_html += "</a><a href='#' class='dellink' link='" + $(this).attr("url") + "'></a></li>"; 423 424 $("ul.sharelink").append(table_html).find("li:last").hide(); 425 $('ul.sharelink').listview('refresh'); 426 $("ul.sharelink").find("li:last").slideDown(300); 427 }); 428 429 $(".dellink").click(function(){ 430 var r=confirm(m.getString('msg_confirm_delete_sharelink')); 431 if (r==true){ 432 client.REMOVESL("/", $(this).attr("link"), function(error, content, statusstring){ 433 if(error==200){ 434 refreshShareLinkList(); 435 } 436 else 437 alert("Fail to delete sharelink!"); 438 }); 439 } 440 }); 441 } 442 }); 443} 444 445function openSettingWindow(){ 446 var dialog_title = ""; 447 var loc_lan = String(window.navigator.userLanguage || window.navigator.language).toLowerCase(); 448 var lan = ( g_storage.get('lan') == undefined ) ? loc_lan : g_storage.get('lan'); 449 450 $("#dialog").remove(); 451 452 var dialog_html = ''; 453 dialog_html += "<div data-role='page' id='dialog' data-theme='a'>"; 454 455 dialog_html += "<div data-role='header'>"; 456 dialog_html += "<h1 id='dialog-title'>" + m.getString('title_setting') + "</h1>"; 457 dialog_html += "<a id='back' data-role='button'>" + m.getString("btn_prevpage") + "</a>"; 458 dialog_html += "</div>"; 459 460 dialog_html += "<div data-role='content' id='dialog-content' class='setting-set'>"; 461 462 dialog_html += "<div data-role='collapsible-set'>"; 463 464 //- ShareLink manager 465 dialog_html += "<div data-role='collapsible' data-collapsed='true'>"; 466 dialog_html += "<h2>" + m.getString('title_sharelink') + "</h2>"; 467 dialog_html += "<ul data-role='listview' data-inset='true' class='sharelink' data-theme='a' data-split-theme='a' data-split-icon='delete'></ul>"; 468 dialog_html += "</div>"; 469 470 //- Version 471 dialog_html += "<div data-role='collapsible'>"; 472 dialog_html += "<h2>" + m.getString('title_version') + "</h2>"; 473 dialog_html += "<span id='version'>AiCloud " + m.getString('title_version') + ": " + g_storage.get('aicloud_version') + "</span>"; 474 dialog_html += "<br><span id='version'>FW " + m.getString('title_version') + ": " + g_storage.get('router_version') + "</span>"; 475 dialog_html += "<br><span id='update' style='color:red'></span>"; 476 dialog_html += "</div>"; 477 478 //- Language 479 dialog_html += "<div data-role='collapsible'>"; 480 dialog_html += "<h2>" + m.getString('title_language') + "</h2>"; 481 dialog_html += "<div data-role='controlgroup'>"; 482 for( var i = 0; i < g_support_lan.length; i++ ){ 483 dialog_html += "<label for='" + g_support_lan[i] + "'>" + m.getString('lan_' + g_support_lan[i]) + "</label>"; 484 dialog_html += "<input type='radio' id='" + g_support_lan[i] + "' name='group_lan' value='" + g_support_lan[i] + "'"; 485 486 if(g_support_lan[i] == lan){ 487 dialog_html += " checked"; 488 } 489 490 dialog_html += ">"; 491 } 492 dialog_html += "</div>"; 493 dialog_html += "</div>"; 494 495 //- Rescan samba 496 dialog_html += "<a id='rescan' data-role='button'>" + m.getString('title_rescan') + "</a>"; 497 498 //- Desktop View 499 dialog_html += "<a id='desktop_view' data-role='button'>" + m.getString('title_desktop_view') + "</a>"; 500 501 dialog_html += "</div>"; 502 503 dialog_html += "</div>"; 504 dialog_html += "</div>"; 505 506 $("body").append(dialog_html); 507 508 //getLatestVersion(); 509 refreshShareLinkList(); 510 511 $("#rescan").click(function(){ 512 var r=confirm(m.getString('title_desc_rescan')); 513 514 if (r==true) 515 doRescanSamba(); 516 }); 517 518 $("#desktop_view").click(function(){ 519 var url = window.location.href; 520 url = url.substr(0, url.lastIndexOf("?")); 521 window.location = url + '?desktop=1'; 522 }); 523 524 $("#back").click(function(){ 525 closeDialog(); 526 }); 527 528 $("input[type=radio]").click(function(){ 529 var lan = $(this).attr("id"); 530 g_storage.set('lan', lan); 531 window.location.reload(); 532 }); 533 534 openDialog("flip", "page"); 535} 536 537function showHideAudioList(bshow){ 538 if(bshow){ 539 $(".jp-playlist").css("display", "block"); 540 } 541 else{ 542 $(".jp-playlist").css("display", "none"); 543 } 544 545 g_showAudioList = bshow; 546} 547 548function showHideAudioInterface(bshow){ 549 if(bshow){ 550 $("#jp_interface_1").css("display","block"); 551 } 552 else{ 553 $("#jp_interface_1").css("display","none"); 554 } 555} 556 557function openAudioPlayer(loc){ 558 559 var audio_array = new Array(); 560 for(var i=0;i<g_file_array.length;i++){ 561 var file_ext = getFileExt(g_file_array[i].href); 562 if(file_ext=="mp3"){ 563 audio_array.push(g_file_array[i]); 564 } 565 } 566 567 var audio_array_count = audio_array.length; 568 569 if(audio_array_count==0){ 570 alert(m.getString("msg_no_image_list")); 571 return; 572 } 573 574 showHideLoadStatus(true); 575 576 var this_audio_list = []; 577 var this_audio = loc; 578 g_current_index = 0; 579 for(var i=0;i<audio_array.length;i++){ 580 581 var the_loc = audio_array[i].href; 582 583 if( loc == the_loc ) 584 g_current_index = i; 585 586 this_audio_list.push(the_loc); 587 } 588 589 var audio_array_count = this_audio_list.length; 590 591 if(audio_array_count==0){ 592 alert(m.getString("msg_no_image_list")); 593 return; 594 } 595 596 g_audio_playlist = []; 597 598 $("#audio_dialog").remove(); 599 600 var audio_html = ""; 601 audio_html += '<div data-role="dialog" id="audio_dialog">'; 602 audio_html += '<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">'; 603 audio_html += '<tr style="height:180px">'; 604 audio_html += '<td>'; 605 audio_html += '<div id="container" style="width:300px;margin:auto">'; 606 audio_html += '<div id="jquery_jplayer_1" class="jp-jplayer"></div>'; 607 audio_html += '<div id="jp_container_1" class="jp-audio">'; 608 audio_html += '<div class="jp-type-playlist">'; 609 audio_html += '<div id="jp_title_1" class="jp-title">'; 610 audio_html += '<ul>'; 611 audio_html += '<li></li>'; 612 audio_html += '</ul>'; 613 audio_html += '</div>'; 614 audio_html += '<div id="jp_interface_1" class="jp-gui jp-interface">'; 615 audio_html += '<ul class="jp-controls">'; 616 audio_html += '<li><a href="javascript:;" class="jp-previous" tabindex="1">previous</a></li>'; 617 audio_html += '<li><a href="javascript:;" class="jp-play" tabindex="1" style="display: block; ">play</a></li>'; 618 audio_html += '<li><a href="javascript:;" class="jp-pause" tabindex="1" style="display: block; ">pause</a></li>'; 619 audio_html += '<li><a href="javascript:;" class="jp-next" tabindex="1">next</a></li>'; 620 audio_html += '<li><a href="javascript:;" class="jp-stop" tabindex="1">stop</a></li>'; 621 audio_html += '<li><a href="javascript:;" class="jp-mute" tabindex="1" title="mute">mute</a></li>'; 622 audio_html += '<li><a href="javascript:;" class="jp-volume-max" tabindex="1" title="max volume">max volume</a></li>'; 623 audio_html += '</ul>'; 624 audio_html += '<div class="jp-progress">'; 625 audio_html += '<div class="jp-seek-bar" style="width: 100%; ">'; 626 audio_html += '<div class="jp-play-bar" style="width: 46.700506341691536%;"></div>'; 627 audio_html += '</div>'; 628 audio_html += '</div>'; 629 audio_html += '<div class="jp-volume-bar">'; 630 audio_html += '<div class="jp-volume-bar-value" style="width: 31.979694962501526%; "></div>'; 631 audio_html += '</div>'; 632 audio_html += '<div class="jp-duration">00:00</div>'; 633 audio_html += '<div class="jp-split">/</div>'; 634 audio_html += '<div class="jp-current-time">00:00</div>'; 635 audio_html += '</div>'; 636 637 audio_html += '<div id="jp_playlist_1" class="jp-playlist">'; 638 audio_html += '<ul></ul>'; 639 audio_html += '</div>'; 640 641 audio_html += '<div class="jp-no-solution" style="display: none; ">'; 642 audio_html += '<span>Update Required</span>'; 643 audio_html += 'To play the media you will need to either update your browser to a recent version or update your <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>.'; 644 audio_html += '</div>'; 645 646 audio_html += '</div>'; 647 audio_html += '</div>'; 648 audio_html += '</div>'; 649 audio_html += '</td>'; 650 audio_html += '</tr>'; 651 audio_html += '<tr style="height:10px"></tr>'; 652 audio_html += '<tr>'; 653 audio_html += '<td>'; 654 audio_html += '<div class="table_block_footer" style="text-align:right">'; 655 audio_html += '<button id="playlist" class="btnStyle">PlayList</button>'; 656 audio_html += '<button id="cancel" class="btnStyle">Close</button>'; 657 audio_html += '</div>'; 658 audio_html += '</td>'; 659 audio_html += '</tr>'; 660 audio_html += '</table>'; 661 audio_html += '</div>'; 662 663 $("body").append(audio_html); 664 665 $("#jp_title_1 li").text("Loading..."); 666 $("#playlist").css("visibility","hidden"); 667 668 $("#audio_dialog #playlist").click(function(){ 669 showHideAudioList(!g_showAudioList); 670 }); 671 672 $("#audio_dialog #cancel").click(function(){ 673 $("#jquery_jplayer_1").jPlayer("stop"); 674 $("#jquery_jplayer_1").jPlayer("clearMedia"); 675 $.mobile.changePage('#mainpage', 'popup', true, true); 676 }); 677 678 var current_query_index = 0; 679 var on_query = false; 680 generate_sharelink=1; 681 682 if(generate_sharelink==1){ 683 var media_hostName = window.location.host; 684 if(media_hostName.indexOf(":")!=-1) 685 media_hostName = media_hostName.substring(0, media_hostName.indexOf(":")); 686 media_hostName = "http://" + media_hostName + ":" + g_storage.get("http_port") + "/"; 687 688 var timer = setInterval(function(){ 689 690 if(on_query==false){ 691 692 if(current_query_index<0||current_query_index>this_audio_list.length-1){ 693 clearInterval(timer); 694 initJPlayer(); 695 showHideLoadStatus(false); 696 $.mobile.changePage('#audio_dialog', {transition: 'pop', role: 'dialog'}); 697 return; 698 } 699 700 var this_audio = this_audio_list[current_query_index]; 701 var this_file_name = this_audio.substring( this_audio.lastIndexOf("/")+1, this_audio.length ); 702 var this_url = this_audio.substring(0, this_audio.lastIndexOf('/')); 703 704 on_query = true; 705 client.GSL(this_url, this_url, this_file_name, 0, 0, function(error, content, statusstring){ 706 if(error==200){ 707 var data = parseXml(statusstring); 708 var share_link = $(data).find('sharelink').text(); 709 share_link = media_hostName + share_link; 710 711 on_query = false; 712 713 var obj = []; 714 obj['name'] = mydecodeURI(this_file_name); 715 obj['mp3'] = share_link; 716 g_audio_playlist.push(obj); 717 718 current_query_index++; 719 } 720 }); 721 } 722 }, 100); 723 } 724 else{ 725 for(var i=0; i < this_audio_list.length;i++){ 726 var this_audio = this_audio_list[i]; 727 var this_file_name = this_audio.substring( this_audio.lastIndexOf("/")+1, this_audio.length ); 728 var this_url = this_audio.substring(0, this_audio.lastIndexOf('/')); 729 730 var obj = []; 731 obj['name'] = mydecodeURI(this_file_name); 732 obj['mp3'] = this_audio; 733 g_audio_playlist.push(obj); 734 } 735 736 initJPlayer(); 737 738 showHideLoadStatus(false); 739 740 $.mobile.changePage('#audio_dialog', {transition: 'pop', role: 'dialog'}); 741 } 742} 743 744function doRescanSamba(){ 745 var openurl = addPathSlash(g_storage.get('openurl')); 746 747 closeDialog(); 748 showHideLoadStatus(true); 749 750 client.RESCANSMBPC(openurl, function(error){ 751 if(error[0]==2){ 752 g_storage.setl("onRescanSamba", 1); 753 g_storage.setl("onRescanSambaCount", 0); 754 g_storage.set("HostList", ""); 755 doPROPFIND("/"); 756 } 757 }); 758} 759 760function doMKDIR(name){ 761 var openurl = addPathSlash(g_storage.get('openurl')); 762 var this_url = openurl + myencodeURI(name); 763 764 var already_exists = 0; 765 766 $('li#list_item').each(function(index) { 767 768 if($(this).attr("isdir")=="1"){ 769 770 if(name==$(this).attr("title")){ 771 already_exists = 1; 772 alert(m.getString('folder_already_exist_msg')); 773 return; 774 } 775 776 } 777 }); 778 779 if(already_exists==1) 780 return; 781 782 client.MKCOL(this_url, function(error){ 783 if(error[0]==2){ 784 doPROPFIND(openurl); 785 } 786 else 787 alert(m.getString(error)); 788 }); 789} 790 791function doRENAME(old_name, new_name){ 792 793 var already_exists = 0; 794 var openurl = addPathSlash(g_storage.get('openurl')); 795 var this_url = openurl + new_name; 796 797 $('li#list_item').each(function(index) { 798 if(new_name==myencodeURI($(this).attr("title"))){ 799 already_exists = 1; 800 801 if($(this).attr("isdir")=="1") 802 alert(m.getString('folder_already_exist_msg')); 803 else 804 alert(m.getString('file_already_exist_msg')); 805 return; 806 } 807 }); 808 809 if(already_exists==1) 810 return; 811 812 //alert(old_name + '-> ' + this_url); 813 814 client.MOVE(old_name, this_url, function(error){ 815 if(error[0]==2){ 816 doPROPFIND(openurl); 817 } 818 else 819 alert(m.getString(error) + " : " + decodeURI(old_name)); 820 }, null, false); 821} 822 823function getFileViewHeight(){ 824 return $("#fileview").height(); 825} 826 827function closeUploadPanel(v){ 828 g_upload_mode = 0; 829 g_reload_page=v; 830 831 g_storage.set('stopLogoutTimer', "0"); 832 833 $("div#btnNewDir").css("display", "block"); 834 if(g_support_html5==1) 835 $("div#btnUpload").css("display", "block"); 836 $("div#btnSelect").css("display", "block"); 837 $("#btnPlayImage").css("display", "block"); 838 839 $("div#btnCancelUpload").css("display", "none"); 840 841 $("#function_help").text(""); 842 843 $("#upload_panel").animate({left:"1999px"},"slow", null, function(){ 844 $("#upload_panel").css("display", "none"); 845 adjustLayout(); 846 }); 847 848 if(v==1){ 849 var openurl = addPathSlash(g_storage.get('openurl')); 850 doPROPFIND(openurl); 851 } 852} 853 854function openSelectMode(){ 855 if(g_select_mode==1) 856 return; 857 858 $("li#list_item").removeClass("ui-btn-active"); 859 $("li#list_item").removeClass("selected"); 860 861 $("li#list_item #icon").addClass("selectmode"); 862 863 $("#navbar").css("display","none"); 864 $("#navbar2").css("display","block"); 865 866 $('#btn-delete').addClass('ui-disabled'); 867 $('#btn-rename').addClass('ui-disabled'); 868 $('#btn-share').addClass('ui-disabled'); 869 870 g_select_mode = 1; 871} 872 873function cancelSelectMode(){ 874 if(g_select_mode==0) 875 return; 876 877 $("#navbar").css("display","block"); 878 $("#navbar2").css("display","none"); 879 880 $("li#list_item #icon").removeClass("selectmode"); 881 $("li#list_item #icon").removeClass("checked"); 882 $("li#list_item").removeClass("ui-btn-active"); 883 $("li#list_item").removeClass("selected"); 884 885 g_select_mode = 0; 886} 887 888function adjustLayout(){ 889 890 var page_size = getPageSize(); 891 var page_width = page_size[0]; 892 var page_height = page_size[1]; 893 894 var page_width = $(".ui-mobile-viewport").width(); 895 var page_height = $(".ui-mobile-viewport").height(); 896 897 $("div#content").css("height", page_height - 898 $("#header").height() - 899 $("#footer").height() - 900 $("#btnParent").height() - 901 parseInt($("#content").css("padding"))*2 ); 902} 903 904function closeJqmWindow(v){ 905 g_reload_page=v; 906 var $modalWindow = $('div#modalWindow'); 907 908 var $modalContainer = $('iframe', $modalWindow); 909 $modalContainer.attr('src', ''); 910 911 if($modalWindow) 912 $modalWindow.jqmHide(); 913 914 showHideLoadStatus(false); 915} 916 917function resizeJqmWindow(w,h){ 918 var $modalWindow = $('.jqmWindow'); 919 if($modalWindow){ 920 $modalWindow.css("width", w + "px"); 921 $modalWindow.css("height", h + "px"); 922 } 923} 924 925function fullscreenJqmWindow(v){ 926 var $modalWindow = $('div#modalWindow'); 927 if($modalWindow){ 928 $modalWindow.css("left", "0px"); 929 $modalWindow.css("top", "0px"); 930 $modalWindow.css("width", window.width + "px"); 931 $modalWindow.css("height", window.height + "px"); 932 } 933} 934 935function doLOGOUT(){ 936 doPROPFIND("/", function(){ 937 var openurl = addPathSlash(g_storage.get('openurl')); 938 client.LOGOUT("/", function(error){ 939 if(error[0]==2){ 940 g_storage.set('openhostuid', '0'); 941 window.location.reload(); 942 } 943 }); 944 }, 0); 945} 946 947function resetTimer(){ 948 949 clearInterval(timer_idle); 950 951 g_time_count = 0; 952 953 timer_idle = setInterval( function(){ 954 955 if(g_storage.get('stopLogoutTimer')=="1"||g_show_modal==1){ 956 g_time_count = 0; 957 return; 958 } 959 960 g_time_count++; 961 962 if( (g_time_count*1000) > g_time_out){ 963 g_time_count=0; 964 doLOGOUT(); 965 } 966 }, 1000 ); 967} 968 969function createOpenUrlUI(open_url){ 970 if(open_url==undefined) 971 open_url = "/"; 972 973 var s = mydecodeURI(open_url); 974 var b = ""; 975 var c = ""; 976 var tmp = ""; 977 var urlregion_width = $("#urlregion-url").width(); 978 979 if(s!="/"){ 980 var aa = s.split('/'); 981 var bb = open_url.split('/'); 982 983 for(var i=0; i<aa.length; i++){ 984 if(aa[i]==""|| 985 (g_enable_aidisk==1 && aa[i]==g_aidisk_name)) 986 continue; 987 988 c += "/" + bb[i]; 989 990 tmp += " / <a id='url_path' uhref='" + c + "'>" + aa[i] + "</a>"; 991 992 var cur_width = String(tmp).width($("p#openurl").css('font')); 993 if(cur_width>urlregion_width){ 994 b += " / ..."; 995 break; 996 } 997 998 if(aa[1]==g_aidisk_name&&g_enable_aidisk==1) 999 b += " / <a id='url_path' uhref='/" + g_aidisk_name + c + "'>" + aa[i] + "</a>"; 1000 else 1001 b += " / <a id='url_path' uhref='" + c + "'>" + aa[i] + "</a>"; 1002 1003 tmp = b; 1004 } 1005 } 1006 1007 $("p#openurl").empty(); 1008 $("p#openurl").append(b); 1009 1010 $("a#url_path").click(function(){ 1011 doPROPFIND($(this).attr("uhref")); 1012 }); 1013} 1014 1015function doPROPFIND(open_url, complete_handler, auth){ 1016 if(client==null) 1017 return; 1018 1019 showHideLoadStatus(true); 1020 1021 try{ 1022 1023 client.PROPFIND(open_url, auth, function(error, statusstring, content){ 1024 if(error){ 1025 1026 if(error==207){ 1027 1028 cancelSelectMode(); 1029 closeUploadPanel(); 1030 1031 var parser; 1032 var xmlDoc; 1033 1034 g_folder_array = new Array(); 1035 g_file_array = new Array(); 1036 1037 if (window.DOMParser){ 1038 parser=new DOMParser(); 1039 xmlDoc=parser.parseFromString(content,"text/xml"); 1040 } 1041 else { // Internet Explorer 1042 xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); 1043 xmlDoc.async="false"; 1044 xmlDoc.loadXML(content); 1045 1046 if(!xmlDoc.documentElement){ 1047 alert("Fail to load xml!"); 1048 showHideLoadStatus(false); 1049 return; 1050 } 1051 } 1052 1053 var i, j, k, l, n; 1054 var x = xmlDoc.documentElement.childNodes; 1055 1056 var this_query_type = xmlDoc.documentElement.getAttribute('qtype'); //- 2: query host, 1: query share, 0: query file 1057 var this_folder_readonly = xmlDoc.documentElement.getAttribute('readonly'); 1058 var this_router_username = xmlDoc.documentElement.getAttribute('ruser'); 1059 var this_computer_name = xmlDoc.documentElement.getAttribute('computername'); 1060 var this_isusb = xmlDoc.documentElement.getAttribute('isusb'); 1061 1062 //- D:Response 1063 for (i=0;i<x.length;i++){ 1064 var this_href = ""; 1065 var this_contenttype = ""; 1066 var this_uniqueid = ""; 1067 var this_name = ""; 1068 var this_short_name = ""; 1069 var this_online = ""; 1070 var this_lastmodified = ""; 1071 var this_contentlength = ""; 1072 var this_ip = ""; 1073 var this_mac = ""; 1074 var this_type = ""; 1075 var this_attr_readonly = ""; 1076 var this_attr_hidden = ""; 1077 var this_uncode_name; 1078 var this_router_sync_folder = "0"; 1079 1080 var y = x[i].childNodes; 1081 for (j=0;j<y.length;j++){ 1082 if(y[j].nodeType==1&&y[j].nodeName=="D:propstat"){ 1083 1084 var z = y[j].childNodes; 1085 1086 for (k=0;k<z.length;k++) 1087 { 1088 if(z[k].nodeName=="D:prop"){ 1089 1090 var a = z[k].childNodes; 1091 1092 for (l=0;l<a.length;l++) 1093 { 1094 if(a[l].childNodes.length<=0) 1095 continue; 1096 1097 if(a[l].nodeName=="D:getcontenttype"){ 1098 this_contenttype = String(a[l].childNodes[0].nodeValue); 1099 } 1100 else if(a[l].nodeName=="D:getuniqueid"){ 1101 this_uniqueid = String(a[l].childNodes[0].nodeValue); 1102 } 1103 else if(a[l].nodeName=="D:getonline"){ 1104 this_online = String(a[l].childNodes[0].nodeValue); 1105 } 1106 else if(a[l].nodeName=="D:getlastmodified"){ 1107 this_lastmodified = String(a[l].childNodes[0].nodeValue); 1108 } 1109 else if(a[l].nodeName=="D:getcontentlength"){ 1110 this_contentlength = String( size_format(parseInt(a[l].childNodes[0].nodeValue))); 1111 } 1112 else if(a[l].nodeName=="D:getmac"){ 1113 this_mac = String(a[l].childNodes[0].nodeValue); 1114 } 1115 else if(a[l].nodeName=="D:getip"){ 1116 this_ip = String(a[l].childNodes[0].nodeValue); 1117 } 1118 else if(a[l].nodeName=="D:gettype"){ 1119 this_type = String(a[l].childNodes[0].nodeValue); 1120 } 1121 else if(a[l].nodeName=="D:getattr"){ 1122 var bb = a[l].childNodes; 1123 for (n=0;n<bb.length;n++){ 1124 if(bb[n].nodeName=="D:readonly") 1125 this_attr_readonly = bb[n].childNodes[0].nodeValue; 1126 else if(bb[n].nodeName=="D:hidden") 1127 this_attr_hidden = bb[n].childNodes[0].nodeValue; 1128 } 1129 } 1130 else if(a[l].nodeName=="D:getroutersync"){ 1131 this_router_sync_folder = String(a[l].childNodes[0].nodeValue); 1132 } 1133 } 1134 } 1135 } 1136 } 1137 else if(y[j].nodeType==1&&y[j].nodeName=="D:href"){ 1138 this_href = String(y[j].childNodes[0].nodeValue); 1139 1140 var cur_host = ""; 1141 1142 if(this_href.match(/^http/)) 1143 cur_host = window.location.protocol + "//" + window.location.host; 1144 1145 var cururl = cur_host + addPathSlash(open_url); 1146 1147 if(this_href!=cururl){ 1148 var o_url = open_url; 1149 1150 this_href = this_href.replace(cur_host,""); 1151 1152 //this_name = this_href.replace( addPathSlash(o_url),""); 1153 this_name = this_href.substring( this_href.lastIndexOf("/")+1, this_href.length ); 1154 1155 if(this_name!=""){ 1156 this_uncode_name = this_name; 1157 1158 this_name = mydecodeURI(this_name); 1159 this_short_name = this_name; 1160 /* 1161 var len = (g_listview==0) ? 12 : 45; 1162 1163 if(this_short_name.length>len){ 1164 this_short_name = this_short_name.substring(0, len) + "..."; 1165 } 1166 */ 1167 } 1168 else{ 1169 this_href=""; 1170 } 1171 } 1172 else{ 1173 this_href=""; 1174 } 1175 } 1176 } 1177 1178 if(this_href!=""){ 1179 if( this_contenttype=="httpd/unix-directory" ){ 1180 g_folder_array.push({ contenttype: this_contenttype, 1181 href: this_href, 1182 name: this_name, 1183 uname: this_uncode_name, 1184 shortname: this_short_name, 1185 online: this_online, 1186 time: this_lastmodified, 1187 size: this_contentlength, 1188 ip: this_ip, 1189 mac: this_mac, 1190 uid: this_uniqueid, 1191 type: this_type, 1192 freadonly: this_attr_readonly, 1193 fhidden: this_attr_hidden, 1194 routersyncfolder: this_router_sync_folder }); 1195 } 1196 else{ 1197 g_file_array.push({ contenttype: this_contenttype, 1198 href: this_href, 1199 name: this_name, 1200 uname: this_uncode_name, 1201 shortname: this_short_name, 1202 online: this_online, 1203 time: this_lastmodified, 1204 size: this_contentlength, 1205 ip: this_ip, 1206 mac: this_mac, 1207 uid: this_uniqueid, 1208 type: this_type, 1209 freadonly: this_attr_readonly, 1210 fhidden: this_attr_hidden, 1211 routersyncfolder: this_router_sync_folder }); 1212 } 1213 } 1214 } 1215 1216 //- Sort By Name 1217 g_folder_array.sort(sortByName); 1218 g_file_array.sort(sortByName); 1219 1220 //- Move the usbdisk to first 1221 var index; 1222 for(index=0; index<g_folder_array.length; index++){ 1223 if(g_folder_array[index].type == "usbdisk"){ 1224 arraymove(g_folder_array, index, 0); 1225 //break; 1226 } 1227 } 1228 1229 //- parent url 1230 var parent_url = addPathSlash(open_url); 1231 if(parent_url!="/"){ 1232 parent_url = parent_url.substring(0, parent_url.length-1); 1233 parent_url = parent_url.substring(0, parent_url.lastIndexOf("/")); 1234 if( parent_url=="" ) parent_url="/"; 1235 } 1236 1237 if(parent_url=="/"+g_storage.get('modalname')) parent_url = "/"; 1238 1239 //- Create list view 1240 createListView(this_query_type, parent_url, g_folder_array, g_file_array); 1241 1242 if(this_query_type==1&&this_isusb==0) 1243 $("#btn-changeuser").show(); 1244 else 1245 $("#btn-changeuser").hide(); 1246 1247 if(this_query_type==0) 1248 $("#btn-select").show(); 1249 else 1250 $("#btn-select").hide(); 1251 1252 $("span#username").text(this_router_username); 1253 1254 adjustLayout(); 1255 1256 closeDialog(); 1257 1258 g_storage.set('openurl', open_url); 1259 $(".ui-listview").attr("path", open_url); 1260 1261 if(complete_handler!=undefined){ 1262 complete_handler(); 1263 } 1264 } 1265 else if(error==501){ 1266 doPROPFIND(open_url); 1267 } 1268 else if(error==401){ 1269 setTimeout(openLoginWindow(open_url), 1000); 1270 } 1271 else{ 1272 alert(m.getString(error)); 1273 } 1274 1275 showHideLoadStatus(false); 1276 } 1277 }, null, 1); 1278 1279 resetTimer(); 1280 } 1281 catch(err){ 1282 //Handle errors here 1283 alert('catch error: '+ err); 1284 } 1285} 1286 1287function doLOGIN(path, auth){ 1288 doPROPFIND(path, function(){ 1289 1290 }, auth); 1291} 1292 1293function createListView(query_type, parent_url, folder_array, file_array){ 1294 1295 clearInterval(g_timer_filelist); 1296 $("ul#list").empty(); 1297 1298 $("#btnParent").remove(); 1299 1300 //- Parent Path 1301 if(query_type == 0 || query_type == 1) { 1302 var html = ""; 1303 1304 html += '<div id="btnParent" class="ui-btn-text ui-btn-parent" data-icon="home" data-role="button" data-iconpos="left" '; 1305 html += ' online="0" qtype="1" isdir="1" uhref="' + parent_url + '"><span>'; 1306 html += m.getString("btn_prevpage"); 1307 html += '</span></div>'; 1308 1309 $('#content').before(html); 1310 } 1311 1312 //- Folder List 1313 for(var i=0; i<folder_array.length; i++){ 1314 var html = ""; 1315 html += '<li id="list_item" qtype="'; 1316 html += query_type; 1317 html += '" isdir="1" uhref="'; 1318 html += folder_array[i].href; 1319 html += '" title="'; 1320 html += folder_array[i].name; 1321 html += '" online="'; 1322 html += folder_array[i].online; 1323 html += '" ip="" mac="'; 1324 html += folder_array[i].mac; 1325 html += '" uid="'; 1326 html += folder_array[i].uid; 1327 html += '" freadonly="'; 1328 html += folder_array[i].freadonly; 1329 html += '" fhidden="'; 1330 html += folder_array[i].fhidden; 1331 1332 if(folder_array[i].type == "usbdisk") 1333 html += '" isusb="1"'; 1334 else 1335 html += '" isusb="0"'; 1336 1337 html += '" data-icon="cloud-arrow-r">'; 1338 1339 //html += "<input type='checkbox' name='checkbox-0' />"; 1340 1341 html += "<a href='#' data-transition='slide' class='ui-btn-icon-left'>"; 1342 1343 //- ICON 1344 if(query_type==2){ 1345 if(folder_array[i].type == "usbdisk") 1346 html += "<span id='icon' class='sicon usbdisk ui-folder-icon ui-li-thumb "; 1347 else if(folder_array[i].type == "sambapc"){ 1348 if(folder_array[i].online==1) 1349 html += "<span id='icon' class='sicon sambapc ui-folder-icon ui-li-thumb "; 1350 else 1351 html += "<span id='icon' class='sicon sambapcoff ui-folder-icon ui-li-thumb "; 1352 } 1353 } 1354 else{ 1355 html += "<span id='icon' class='sicon folder ui-folder-icon ui-li-thumb "; 1356 } 1357 1358 if(g_select_mode==1) 1359 html += "selectmode"; 1360 1361 html += "'>"; 1362 1363 if(folder_array[i].routersyncfolder == "1"){ 1364 html += "<div id='icon' class='sicon routerync'/>"; 1365 } 1366 1367 html += "</span>"; 1368 1369 html += "<h3>" + folder_array[i].shortname; 1370 1371 if(folder_array[i].online == "0" && query_type == "2") 1372 html += "(" + m.getString("title_offline") + ")"; 1373 1374 html += "</h3>"; 1375 1376 if(query_type == "0"){ 1377 html += "<p class='ui-li-desc'>"; 1378 html += m.getString("table_time") + ": " + folder_array[i].time; 1379 html += "</p>"; 1380 } 1381 1382 html += "</a>"; 1383 1384 html += '</li>'; 1385 1386 $("ul#list").append(html).find("li:last").hide(); 1387 $('ul#list').listview('refresh'); 1388 $("ul#list").find("li:last").slideDown(300); 1389 } 1390 1391 /* 1392 //- File List 1393 for(var i=0; i<file_array.length; i++){ 1394 var this_title = m.getString("table_filename") + ": " + file_array[i].name + "\n" + 1395 m.getString("table_time") + ": " + file_array[i].time + "\n" + 1396 m.getString("table_size") + ": " + file_array[i].size; 1397 1398 //- get file ext 1399 var file_path = String(file_array[i].href); 1400 var file_ext = getFileExt(file_path); 1401 if(file_ext.length>5)file_ext=""; 1402 1403 var html = ""; 1404 html += '<li data-theme="c" id="list_item" qtype="1" isdir="0" uhref="'; 1405 html += file_array[i].href; 1406 html += '" title="'; 1407 html += file_array[i].name; 1408 html += '" uid="'; 1409 html += file_array[i].uid; 1410 html += '" ext="'; 1411 html += file_ext; 1412 html += '" freadonly="'; 1413 html += file_array[i].freadonly; 1414 html += '" fhidden="'; 1415 html += file_array[i].fhidden; 1416 html += '">'; 1417 1418 html += "<div id='file_item'>"; 1419 1420 //- ICON 1421 if(file_ext=="jpg"||file_ext=="jpeg"||file_ext=="png"||file_ext=="gif"||file_ext=="bmp") 1422 html += "<span id='icon' class='sicon ui-li-thumb imgfileDiv'/>"; 1423 else if(file_ext=="mp3"||file_ext=="m4a"||file_ext=="m4r"||file_ext=="wav") 1424 html += "<span id='icon' class='sicon ui-li-thumb audiofileDiv'/>"; 1425 else if(file_ext=="mp4"||file_ext=="rmvb"||file_ext=="m4v"||file_ext=="wmv"||file_ext=="avi"||file_ext=="mpg"|| 1426 file_ext=="mpeg"||file_ext=="mkv"||file_ext=="mov"||file_ext=="flv"||file_ext=="3gp"||file_ext=="m2v"||file_ext=="rm") 1427 html += "<span id='icon' class='sicon ui-li-thumb videofileDiv'/>"; 1428 else if(file_ext=="doc"||file_ext=="docx") 1429 html += "<span id='icon' class='sicon ui-li-thumb docfileDiv'/>"; 1430 else if(file_ext=="ppt"||file_ext=="pptx") 1431 html += "<span id='icon' class='sicon ui-li-thumb pptfileDiv'/>"; 1432 else if(file_ext=="xls"||file_ext=="xlsx") 1433 html += "<span id='icon' class='sicon ui-li-thumb xlsfileDiv'/>"; 1434 else if(file_ext=="pdf") 1435 html += "<span id='icon' class='sicon ui-li-thumb pdffileDiv'/>"; 1436 else 1437 html += "<span id='icon' class='sicon ui-li-thumb fileDiv'/>"; 1438 1439 html += file_array[i].shortname; 1440 html += "</div>"; 1441 1442 html += '</li>'; 1443 1444 $("ul#list").append(html).find("li:last").hide(); 1445 $('ul#list').listview('refresh'); 1446 $("ul#list").find("li:last").slideDown(300); 1447 } 1448 */ 1449 1450 var current_list_index = 0; 1451 1452 g_timer_filelist = setInterval(function(){ 1453 1454 if(current_list_index<0||current_list_index>file_array.length-1){ 1455 clearInterval(g_timer_filelist); 1456 return; 1457 } 1458 1459 var i = current_list_index; 1460 var this_title = m.getString("table_time") + ": " + file_array[i].time + "\n" + 1461 m.getString("table_size") + ": " + file_array[i].size; 1462 1463 //- get file ext 1464 var file_path = String(file_array[i].href); 1465 var file_ext = getFileExt(file_path); 1466 if(file_ext.length>5)file_ext=""; 1467 1468 var html = ""; 1469 html += '<li data-theme="c" id="list_item" qtype="1" isdir="0" uhref="'; 1470 html += file_array[i].href; 1471 html += '" title="'; 1472 html += file_array[i].name; 1473 html += '" uid="'; 1474 html += file_array[i].uid; 1475 html += '" ext="'; 1476 html += file_ext; 1477 html += '" freadonly="'; 1478 html += file_array[i].freadonly; 1479 html += '" fhidden="'; 1480 html += file_array[i].fhidden; 1481 html += '">'; 1482 1483 //- ICON 1484 if(file_ext=="jpg"||file_ext=="jpeg"||file_ext=="png"||file_ext=="gif"||file_ext=="bmp") 1485 html += "<span id='icon' class='sicon ui-li-thumb ui-file-icon imgfileDiv "; 1486 else if(file_ext=="mp3"||file_ext=="m4a"||file_ext=="m4r"||file_ext=="wav") 1487 html += "<span id='icon' class='sicon ui-li-thumb ui-file-icon audiofileDiv "; 1488 else if(file_ext=="mp4"||file_ext=="rmvb"||file_ext=="m4v"||file_ext=="wmv"||file_ext=="avi"||file_ext=="mpg"|| 1489 file_ext=="mpeg"||file_ext=="mkv"||file_ext=="mov"||file_ext=="flv"||file_ext=="3gp"||file_ext=="m2v"||file_ext=="rm") 1490 html += "<span id='icon' class='sicon ui-li-thumb ui-file-icon videofileDiv "; 1491 else if(file_ext=="doc"||file_ext=="docx") 1492 html += "<span id='icon' class='sicon ui-li-thumb ui-file-icon docfileDiv "; 1493 else if(file_ext=="ppt"||file_ext=="pptx") 1494 html += "<span id='icon' class='sicon ui-li-thumb ui-file-icon pptfileDiv "; 1495 else if(file_ext=="xls"||file_ext=="xlsx") 1496 html += "<span id='icon' class='sicon ui-li-thumb ui-file-icon xlsfileDiv "; 1497 else if(file_ext=="pdf") 1498 html += "<span id='icon' class='sicon ui-li-thumb ui-file-icon pdffileDiv "; 1499 else 1500 html += "<span id='icon' class='sicon ui-li-thumb ui-file-icon fileDiv "; 1501 1502 if(g_select_mode==1) 1503 html += "selectmode"; 1504 1505 html += "'/>"; 1506 1507 html += "<div id='file_item' class='ui-btn-text'>"; 1508 1509 html += "<h3>" + file_array[i].shortname + "</h3>"; 1510 1511 html += "<p class='ui-li-desc'>"; 1512 html += m.getString("table_time") + ": " + file_array[i].time; 1513 html += "</p>"; 1514 1515 html += "<p class='ui-li-desc'>"; 1516 html += m.getString("table_size") + ": " + file_array[i].size; 1517 html += "</p>"; 1518 1519 html += "</div>"; 1520 1521 html += '</li>'; 1522 1523 $("ul#list").append(html).find("li:last").hide(); 1524 $('ul#list').listview('refresh'); 1525 $("ul#list").find("li:last").slideDown(300); 1526 1527 current_list_index++; 1528 1529 }, 200); 1530} 1531 1532function sortByName(a, b) { 1533 var x = a.name.toLowerCase(); 1534 var y = b.name.toLowerCase(); 1535 return ((x < y) ? -1 : ((x > y) ? 1 : 0)); 1536} 1537 1538function arraymove(arr, fromIndex, toIndex) { 1539 var element = arr[fromIndex]; 1540 arr.splice(fromIndex,1); 1541 arr.splice(toIndex,0,element); 1542} 1543 1544function showHideLoadStatus(bshow){ 1545 if(bshow) 1546 $.mobile.showPageLoadingMsg(); 1547 else 1548 $.mobile.hidePageLoadingMsg(); 1549} 1550 1551function openSelItem(item){ 1552 var loc = item.attr("uhref"); 1553 var qtype = item.attr("qtype"); 1554 var isdir = item.attr("isdir"); 1555 var isusb = item.attr("isusb"); 1556 var this_full_url = item.attr("uhref"); 1557 var this_file_name = item.attr("title"); 1558 1559 g_storage.set('openuid', item.attr("uid")); 1560 g_storage.set('opentype', isusb); 1561 1562 if(qtype==2){ 1563 var online = item.attr("online"); 1564 if(online==0){ 1565 var r=confirm(m.getString('wol_msg')); 1566 1567 if (r==true){ 1568 var this_mac = item.attr("mac"); 1569 1570 client.WOL("/", this_mac, function(error){ 1571 if(error==200) 1572 alert(m.getString('wol_ok_msg')); 1573 else 1574 alert(m.getString('wol_fail_msg')); 1575 }); 1576 } 1577 1578 return; 1579 } 1580 } 1581 1582 if(isdir=="1"){ 1583 doPROPFIND(loc, null, null); 1584 return; 1585 } 1586 1587 var fileExt = getFileExt(loc); 1588 var webdav_mode = g_storage.get('webdav_mode'); 1589 1590 /* 1591 if( fileExt=="mp4" || 1592 fileExt=="m4v" || 1593 fileExt=="wmv" || 1594 fileExt=="avi" || 1595 fileExt=="rmvb"|| 1596 fileExt=="rm" || 1597 fileExt=="mpg" || 1598 fileExt=="mpeg"|| 1599 fileExt=="mkv" || 1600 fileExt=="mov" || 1601 fileExt=="flv" ) { 1602 1603 //- webdav_mode=0-->enable http, webdav_mode=2-->both enable http and https 1604 if( webdav_mode==0 || webdav_mode==2 ){ 1605 1606 if( isWinOS() ){ 1607 if( isBrowser("msie") && 1608 getInternetExplorerVersion() <= 7 ){ 1609 //- The VLC Plugin doesn't support IE 7 or less 1610 alert(m.getString('msg_vlcsupport')); 1611 } 1612 else{ 1613 var $modalWindow = $("div#modalWindow"); 1614 1615 this_file_name = myencodeURI(this_file_name); 1616 this_url = this_full_url.substring(0, this_full_url.lastIndexOf('/')); 1617 1618 var media_hostName = window.location.host; 1619 if(media_hostName.indexOf(":")!=-1) 1620 media_hostName = media_hostName.substring(0, media_hostName.indexOf(":")); 1621 media_hostName = "http://" + media_hostName + ":" + g_storage.get("http_port") + "/"; 1622 1623 client.GSL(this_url, this_url, this_file_name, 0, 0, function(error, content, statusstring){ 1624 if(error==200){ 1625 var data = parseXml(statusstring); 1626 var share_link = $(data).find('sharelink').text(); 1627 var open_url = ""; 1628 1629 share_link = media_hostName + share_link; 1630 open_url = '/smb/css/vlc_video.html?v=' + share_link; 1631 1632 open_url += '&showbutton=1'; 1633 g_modal_url = open_url; 1634 g_modal_window_width = 655; 1635 g_modal_window_height = 500; 1636 $('#jqmMsg').css("display", "none"); 1637 $('#jqmTitleText').text(m.getString('title_videoplayer')); 1638 if($modalWindow){ 1639 $modalWindow.jqmShow(); 1640 } 1641 } 1642 }); 1643 1644 return; 1645 } 1646 } 1647 } 1648 1649 } 1650 */ 1651 if( fileExt=="mp3" ) { 1652 openAudioPlayer(loc); 1653 return; 1654 } 1655 1656 if( fileExt=="doc" || fileExt=="docx" || 1657 fileExt=="ppt" || fileExt=="pptx" || 1658 fileExt=="xls" || fileExt=="xlsx" || 1659 fileExt=="pdf") { 1660 1661 var location_host = window.location.host; 1662 1663 //- It will open with google doc viewer when OS is window or mac and using public ip. 1664 if( ( isWinOS() || isMacOS() ) && !isPrivateIP() ){ 1665 1666 this_file_name = myencodeURI(this_file_name); 1667 this_url = this_full_url.substring(0, this_full_url.lastIndexOf('/')); 1668 1669 client.GSL(this_url, this_url, this_file_name, 0, 0, function(error, content, statusstring){ 1670 if(error==200){ 1671 var data = parseXml(statusstring); 1672 var share_link = $(data).find('sharelink').text(); 1673 var open_url = ""; 1674 1675 share_link = window.location.protocol + "//" + window.location.host+ "/" + share_link; 1676 open_url = 'https://docs.google.com/viewer?url=' + share_link; 1677 1678 window.open(open_url); 1679 } 1680 }); 1681 1682 return; 1683 } 1684 } 1685 1686 if( fileExt=="jpg" || 1687 fileExt=="jpeg"|| 1688 fileExt=="png" || 1689 fileExt=="gif" ){ 1690 openImageViewer(loc); 1691 return; 1692 } 1693 1694 window.open(loc); 1695} 1696 1697function createLayout(){ 1698 1699 var loc_lan = String(window.navigator.userLanguage || window.navigator.language).toLowerCase(); 1700 var lan = ( g_storage.get('lan') == undefined ) ? loc_lan : g_storage.get('lan'); 1701 m.setLanguage(lan); 1702 1703 $("#btn-home .ui-btn-text").text(m.getString('btn_homepage')); 1704 $("#btn-refresh .ui-btn-text").text(m.getString('btn_refresh')); 1705 $("#btn-logout .ui-btn-text").text(m.getString('title_logout')); 1706 $("#btn-setting .ui-btn-text").text(m.getString('title_setting')); 1707 $("#btn-delete .ui-btn-text").text(m.getString('btn_delselect')); 1708 $("#btn-rename .ui-btn-text").text(m.getString('btn_rename')); 1709 $("#btn-share .ui-btn-text").text(m.getString('btn_sharelink')); 1710 $("#btn-createfolder .ui-btn-text").text(m.getString('btn_newdir')); 1711 1712 $("#btn-changeuser").hide(); 1713 $("#btn-select").hide(); 1714} 1715 1716function addtoFavorite(){ 1717 var favorite_title = "AiCloud"; 1718 var favorite_url = "https://" + g_storage.get('ddns_host_name'); 1719 var isIEmac = false; 1720 var isMSIE = isBrowser("msie"); 1721 1722 if(favorite_url==""||favorite_url==undefined){ 1723 favorite_url="https://router.asus.com/"; 1724 } 1725 1726 if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) { 1727 window.sidebar.addPanel(favorite_title, favorite_url, ""); 1728 return false; 1729 } 1730 else if (isMSIE && typeof window.external == "object") { 1731 window.external.AddFavorite(favorite_url, favorite_title); 1732 return false; 1733 } 1734 else { 1735 window.location = favorite_url; 1736 1737 var ua = navigator.userAgent.toLowerCase(); 1738 var str = ''; 1739 var isWebkit = (ua.indexOf('webkit') != - 1); 1740 var isMac = (ua.indexOf('mac') != - 1); 1741 1742 if (ua.indexOf('konqueror') != - 1) { 1743 str = 'CTRL + B'; // Konqueror 1744 } 1745 else if (window.home || isWebkit || isIEmac || isMac) { 1746 str = (isMac ? 'Command/Cmd' : 'CTRL') + ' + D'; // Netscape, Safari, iCab, IE5/Mac 1747 } 1748 1749 str = ((str) ? m.getString('msg_add_favorite1') + str + m.getString('msg_add_favorite2') : str); 1750 1751 alert(str); 1752 } 1753 1754} 1755 1756function getRouterInfo(){ 1757 client.GETROUTERINFO("/", function(error, statusstring, content){ 1758 if(error==200){ 1759 var data = parseXml(content); 1760 var x = $(data); 1761 g_storage.set('webdav_mode', x.find("webdav_mode").text()); 1762 g_storage.set('http_port', x.find("http_port").text()); 1763 g_storage.set('https_port', x.find("https_port").text()); 1764 g_storage.set('misc_http_enable', x.find("misc_http_enable").text()); 1765 g_storage.set('misc_http_port', String(x.find("misc_http_port").text()).replace("\n","")); 1766 g_storage.set('last_login_info', x.find("last_login_info").text()); 1767 g_storage.set('ddns_host_name', x.find("ddns_host_name").text()); 1768 g_storage.set('router_version', x.find("version").text()); 1769 g_storage.set('aicloud_version', x.find("aicloud_version").text()); 1770 g_storage.set('modalname', x.find("modalname").text()); 1771 1772 var login_info = g_storage.get('last_login_info'); 1773 if(login_info!=""&&login_info!=undefined){ 1774 var login_info_array = String(login_info).split(">"); 1775 var info = m.getString('title_logininfo')+ login_info_array[1] + ", " + m.getString('title_ip') + login_info_array[2]; 1776 $("#login_info").text(info); 1777 } 1778 } 1779 }); 1780} 1781 1782function createMenu(menuId, parentId, options, menuHandler){ 1783 //create a containing div 1784 var div = $("<div id='" + menuId + "div'></div>").appendTo("#"+parentId).show(); 1785 1786 //create select tag 1787 var menuElm = $("<select id='" + menuId + "' data-inline='true' data-native-menu='false'></select>").appendTo(div); 1788 //var menuElm = $("<select id='" + menuId + "' data-inline='true' data-native-menu='false'></select>").appendTo("#"+parentId).hide(); 1789 1790 //add options 1791 var optionsArray = options.split(","); 1792 for (var i = 0; i < optionsArray.length; i++) 1793 $("<option>" + optionsArray[i] + "</option>").appendTo("#"+menuId); 1794 1795 //convert to JQueryMobile menu 1796 $("#" + menuId).selectmenu(); 1797 1798 //find custom menu that JQM creates 1799 var menus = $(".ui-selectmenu"); 1800 for (var i = 0; i < menus.length; i++) 1801 { 1802 if ($(menus[i]).children("ul:#" + menuId + "-menu").length > 0) 1803 { 1804 newMenu = $(menus[i]); 1805 break; 1806 } 1807 } 1808 1809 if (newMenu == null) 1810 { 1811 alert("Error creating menu"); 1812 return; 1813 } 1814 1815 //Associate click handler with menu items, i.e. anchor tags 1816 $(newMenu).find(".ui-selectmenu-list li a").click(menuHandler); 1817 1818 //Add Close option 1819 var menuHeader = $(newMenu).find(".ui-header"); 1820 var closeLinkId = menuId + "_close_id"; 1821 menuHeader.prepend("<span style='position:relative;float:left'>" + 1822 "<a href='#' id='" + closeLinkId + "'>X</href></span>"); 1823 1824 $("#" + closeLinkId).click(function(e){ 1825 newMenu.hide(); 1826 }); 1827 1828 return newMenu.hide(); 1829} 1830 1831function showMenu(menu){ 1832 if (menu == null) 1833 return; 1834 1835 //show menu at center of the window 1836 var left = ($(window).width() - $(menu).width()) / 2; 1837 //consider vertical scrolling when calculating top 1838 var top = (($(window).height() - $(menu).height()) / 2) + $(window).scrollTop(); 1839 1840 left = 0; 1841 top = 0; 1842 1843 $(menu).css({ 1844 left: left, 1845 top: top 1846 }); 1847 1848 $(menu).show(); 1849} 1850 1851//Callback handler when menu item is clicked 1852function menuHandler(event){ 1853 if (newMenu != null) 1854 $(newMenu).hide(); 1855 1856 alert(event.srcElement.text); 1857} 1858 1859//document.addEventListener("touchmove", function(e){ 1860 //e.preventDefault(); 1861//}, false); 1862 1863(function($) { 1864 1865 $.widget('mobile.tabbar', $.mobile.navbar, { 1866 _create: function() { 1867 // Set the theme before we call the prototype, which will 1868 // ensure buttonMarkup() correctly grabs the inheritied theme. 1869 // We default to the "a" swatch if none is found 1870 var theme = this.element.jqmData('theme') || "a"; 1871 this.element.addClass('ui-footer ui-footer-fixed ui-bar-' + theme); 1872 1873 // Make sure the page has padding added to it to account for the fixed bar 1874 this.element.closest('[data-role="page"]').addClass('ui-page-footer-fixed'); 1875 1876 // Call the NavBar _create prototype 1877 $.mobile.navbar.prototype._create.call(this); 1878 }, 1879 1880 // Set the active URL for the Tab Bar, and highlight that button on the bar 1881 setActive: function(url) { 1882 // Sometimes the active state isn't properly cleared, so we reset it ourselves 1883 this.element.find('a').removeClass('ui-btn-active ui-state-persist'); 1884 this.element.find('a[href="' + url + '"]').addClass('ui-btn-active ui-state-persist'); 1885 } 1886 }); 1887 1888 $(document).bind('pagecreate create', function(e) { 1889 return $(e.target).find(":jqmData(role='tabbar')").tabbar(); 1890 }); 1891 1892 $(document).bind('pageinit', function(e) { 1893 1894 if(!g_bInitialize){ 1895 $.mobile.selectmenu.prototype.options.nativeMenu = false; 1896 1897 createLayout(); 1898 getRouterInfo(); 1899 1900 $.mobile.activeBtnClass = 'unused'; 1901 $.mobile.touchOverflowEnabled = true; 1902 //createMenu("dynamicMenu1","mainpage","Menus,menu1,menu2,menu3",menuHandler); 1903 //createMenu("dynamicMenu1", "select", "Menus,menu1,menu2,menu3", menuHandler); 1904 1905 g_bInitialize = true; 1906 } 1907 }); 1908 1909 $(":jqmData(role='page')").live('pageshow', function(e) { 1910 // Grab the id of the page that's showing, and select it on the Tab Bar on the page 1911 var tabBar, id = $(e.target).attr('id'); 1912 1913 if(id=="mainpage"){ 1914 var loc = g_storage.get('openurl'); 1915 loc = (loc==undefined) ? "/" : loc; 1916 1917 var curPath = $(".ui-listview").attr("path"); 1918 1919 if(loc!=curPath){ 1920 doPROPFIND( loc, function(){ 1921 adjustLayout(); 1922 }, 0); 1923 } 1924 } 1925 tabBar = $.mobile.activePage.find(':jqmData(role="tabbar")'); 1926 if(tabBar.length) { 1927 tabBar.tabbar('setActive', '#' + id); 1928 } 1929 }); 1930 1931 $("li#list_item").live("click", function() { 1932 if(g_select_mode==1){ 1933 1934 if($(this).hasClass("ui-btn-active")){ 1935 $(this).removeClass("ui-btn-active"); 1936 $(this).removeClass("selected"); 1937 $(this).find("#icon").removeClass("checked"); 1938 } 1939 else{ 1940 $(this).addClass("ui-btn-active"); 1941 $(this).addClass("selected"); 1942 $(this).find("#icon").addClass("checked"); 1943 } 1944 1945 var select_count = $("li#list_item.selected").size(); 1946 1947 if(select_count>0){ 1948 $('#btn-delete').removeClass('ui-disabled'); 1949 $('#btn-share').removeClass('ui-disabled'); 1950 } 1951 else{ 1952 $('#btn-delete').addClass('ui-disabled'); 1953 $('#btn-share').addClass('ui-disabled'); 1954 } 1955 1956 if(select_count==1) 1957 $('#btn-rename').removeClass('ui-disabled'); 1958 else 1959 $('#btn-rename').addClass('ui-disabled'); 1960 1961 return; 1962 } 1963 1964 $("li#list_item").removeClass("ui-btn-active"); 1965 $(this).addClass("ui-btn-active"); 1966 1967 openSelItem($(this)); 1968 }); 1969 1970 $("#btnParent").live("click", function() { 1971 1972 //$("li#list_item").removeClass("ui-btn-active"); 1973 //$(this).addClass("ui-btn-active"); 1974 1975 openSelItem($(this)); 1976 }); 1977 1978 $("a#btn-home").live("click", function() { 1979 doPROPFIND( "/", function(){ 1980 $("a#btn-home").removeClass("ui-btn-active"); 1981 }, 0); 1982 }); 1983 1984 $("a#btn-refresh").live("click", function() { 1985 var loc = g_storage.get('openurl'); 1986 loc = (loc==undefined) ? "/" : loc; 1987 doPROPFIND( loc, function(){ 1988 $("a#btn-refresh").removeClass("ui-btn-active"); 1989 }, 0); 1990 }); 1991 1992 $("a#btn-setting").live("click", function() { 1993 openSettingWindow(); 1994 }); 1995 1996 $("a#btn-share").live("click", function() { 1997 1998 //$("a#btn-share").removeClass("ui-btn-active"); 1999 $(this).removeClass("ui-btn-active"); 2000 2001 var share_link_array = new Array(); 2002 var complete_count = 0; 2003 var eml = ""; 2004 var subj = "?subject=" + m.getString('email_subject'); 2005 var bod = ""; 2006 var selectURL = ""; 2007 var selectFiles = ""; 2008 2009 $("li#list_item.selected").each(function(){ 2010 2011 var this_file_name = $(this).attr("title"); 2012 var this_full_url = $(this).attr("uhref"); 2013 var this_isdir = $(this).attr("isdir"); 2014 var this_url = window.location.href; 2015 2016 this_url = this_full_url.substring(0, this_full_url.lastIndexOf('/')); 2017 2018 selectURL = this_url; 2019 2020 selectFiles += encodeURI(this_file_name); 2021 selectFiles += ";"; 2022 }); 2023 2024 if(selectFiles==""){ 2025 alert("Please select files first."); 2026 return; 2027 } 2028 2029 var webdav_mode = g_storage.get('webdav_mode'); 2030 var ddns_host_name = g_storage.get('ddns_host_name'); 2031 var cur_host_name = window.location.host; 2032 var hostName = ""; 2033 2034 if(!isPrivateIP(cur_host_name)) 2035 hostName = cur_host_name; 2036 else 2037 hostName = (ddns_host_name=="") ? cur_host_name : ddns_host_name; 2038 2039 if(hostName.indexOf(":")!=-1) 2040 hostName = hostName.substring(0, hostName.indexOf(":")); 2041 2042 var is_private_ip = isPrivateIP(hostName); 2043 2044 if( webdav_mode == 0 ) //- Only enable http 2045 hostName = "http://" + hostName + ":" + g_storage.get("http_port"); 2046 else 2047 hostName = "https://" + hostName; 2048 //alert(selectURL + ", " + selectFiles); 2049 2050 client.GSL(selectURL, selectURL, selectFiles, 86400, 1, function(error, content, statusstring){ 2051 if(error==200){ 2052 var data = parseXml(statusstring); 2053 var result = $(data).find('sharelink').text(); 2054 2055 if(result==''){ 2056 alert("Fail to parse xml!"); 2057 return; 2058 } 2059 2060 var aa = result.split(";"); 2061 var len = aa.length; 2062 2063 for(var i=0; i<len; i++){ 2064 bod += hostName + "/" + aa[i]; 2065 if(i!=len-1) 2066 bod += ";"; 2067 } 2068 2069 openShareWindow(bod); 2070 } 2071 }); 2072 }); 2073 2074 $("a#btn-delete").live("click", function() { 2075 2076 var webdav_delfile_callbackfunction = function(error, statusstring, content){ 2077 2078 if(error){ 2079 if(error[0]==2){ 2080 } 2081 else{ 2082 alert(m.getString(error)+" : " + decodeURI(g_selected_files[0])); 2083 return; 2084 } 2085 } 2086 2087 g_selected_files.splice(0,1); 2088 2089 if(g_selected_files.length<=0){ 2090 var openurl = addPathSlash(g_storage.get('openurl')); 2091 doPROPFIND(openurl); 2092 return; 2093 } 2094 2095 client.DELETE(g_selected_files[0], webdav_delfile_callbackfunction); 2096 }; 2097 2098 g_selected_files = null; 2099 g_selected_files = new Array(); 2100 2101 $("li#list_item.selected").each(function(){ 2102 var this_full_url = $(this).attr("uhref"); 2103 g_selected_files.push( $(this).attr("uhref") ); 2104 }); 2105 2106 if(g_selected_files.length<=0) 2107 return; 2108 2109 var r=confirm(m.getString('del_files_msg')); 2110 if (r!=true){ 2111 return; 2112 } 2113 2114 client.DELETE(g_selected_files[0], webdav_delfile_callbackfunction ); 2115 }); 2116 2117 $("a#btn-rename").live("click", function() { 2118 2119 var this_file_name = $("li#list_item.selected").attr("title"); 2120 var this_full_url = $("li#list_item.selected").attr("uhref"); 2121 var this_isdir = $("li#list_item.selected").attr("isdir"); 2122 2123 $("#dialog").remove(); 2124 2125 var dialog_html = ''; 2126 dialog_html += "<div data-role='dialog' id='dialog' data-theme='a' data-transition='flip'>"; 2127 dialog_html += "<div data-role='header'>"; 2128 dialog_html += "<h1 id='dialog-title'>" + m.getString('title_rename') + "</h1>"; 2129 dialog_html += "</div>"; 2130 dialog_html += "<div data-role='content' id='dialog-content'>"; 2131 2132 dialog_html += '<table id="table_content" width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0" style="overflow:hidden;">'; 2133 2134 dialog_html += '<tr>'; 2135 dialog_html += '<td>'; 2136 dialog_html += '<input id="isdir" type="hidden" value="' + this_isdir + '"/>'; 2137 dialog_html += '<input id="source" type="hidden" value="' + this_full_url + '"/>'; 2138 dialog_html += '<input id="filename" type="text" value="' + this_file_name + '"/>'; 2139 dialog_html += '</td>'; 2140 dialog_html += '</tr>'; 2141 2142 dialog_html += '<tr>'; 2143 dialog_html += '<td>'; 2144 dialog_html += '<div class="table_block_footer" style="text-align:right">'; 2145 dialog_html += '<button id="ok" class="btnStyle">' + m.getString('btn_ok') + '</button>'; 2146 dialog_html += '<button id="cancel" class="btnStyle">' + m.getString('btn_cancel') + '</button>'; 2147 dialog_html += '</div>'; 2148 dialog_html += '</td>'; 2149 dialog_html += '</tr>'; 2150 dialog_html += '</table>'; 2151 2152 dialog_html += "</div>"; 2153 dialog_html += "</div>"; 2154 2155 $("body").append(dialog_html); 2156 2157 $("#table_content #ok").click(function(){ 2158 var oldFile = $('input#source').val(); 2159 var newName = $('input#filename').val(); 2160 var this_isdir = parseInt($('input#isdir').val()); 2161 2162 if(newName==''){ 2163 alert(m.getString('blankchar')); 2164 return; 2165 } 2166 2167 var regex = /[|\/\\?*"<>:`]/g; 2168 if(this_isdir==1) 2169 regex = /[|\/\\?*"<>:`.]/g; 2170 2171 if(newName.match(regex)) { 2172 alert(m.getString('illegalchar')); 2173 return; 2174 } 2175 2176 if(this_isdir==1){ 2177 if(oldFile.lastIndexOf('/')==oldFile.length-1) 2178 oldFile = oldFile.substring(0, oldFile.length-1); 2179 } 2180 2181 doRENAME(oldFile, myencodeURI(newName)); 2182 2183 }); 2184 2185 $("#table_content #cancel").click(function(){ 2186 closeDialog(); 2187 }); 2188 2189 openDialog("pop"); 2190 }); 2191 2192 $("a#btn-createfolder").live("click", function() { 2193 2194 $("#dialog").remove(); 2195 2196 var dialog_html = ''; 2197 dialog_html += "<div data-role='dialog' id='dialog' data-theme='a' data-transition='flip'>"; 2198 dialog_html += "<div data-role='header'>"; 2199 dialog_html += "<h1 id='dialog-title'>" + m.getString('title_newdir') +"</h1>"; 2200 dialog_html += "</div>"; 2201 dialog_html += "<div data-role='content' id='dialog-content'>"; 2202 2203 dialog_html += '<table id="table_content" width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0" style="overflow:hidden;">'; 2204 2205 dialog_html += '<tr>'; 2206 dialog_html += '<td>'; 2207 dialog_html += '<input id="dir_name" type="text" value="' + m.getString('default_dir_name') + '"/>'; 2208 dialog_html += '</td>'; 2209 dialog_html += '</tr>'; 2210 2211 dialog_html += '<tr>'; 2212 dialog_html += '<td>'; 2213 dialog_html += '<div class="table_block_footer" style="text-align:right">'; 2214 dialog_html += '<button id="ok" class="btnStyle">' + m.getString('btn_ok') + '</button>'; 2215 dialog_html += '<button id="cancel" class="btnStyle">' + m.getString('btn_cancel') + '</button>'; 2216 dialog_html += '</div>'; 2217 dialog_html += '</td>'; 2218 dialog_html += '</tr>'; 2219 dialog_html += '</table>'; 2220 2221 dialog_html += "</div>"; 2222 dialog_html += "</div>"; 2223 2224 $("body").append(dialog_html); 2225 2226 $("#table_content #ok").click(function(){ 2227 2228 var name = $('input#dir_name').val(); 2229 2230 if(name==''){ 2231 alert(m.getString('blankchar')); 2232 return; 2233 } 2234 2235 var regex = /[|~\/\\?*"<>:`.]/g; 2236 if(name.match(regex)) { 2237 alert(m.getString('illegalchar')); 2238 return; 2239 } 2240 2241 doMKDIR(name); 2242 }); 2243 2244 $("#table_content #cancel").click(function(){ 2245 closeDialog(); 2246 }); 2247 2248 openDialog("pop"); 2249 }); 2250 2251 $("#btn-select").live("click", function() { 2252 if(g_select_mode==0){ 2253 openSelectMode(); 2254 $(this).addClass("click"); 2255 } 2256 else if(g_select_mode==1){ 2257 cancelSelectMode(); 2258 $(this).removeClass("click"); 2259 } 2260 }); 2261 2262 $("#btn-changeuser").live("click", function() { 2263 var r=confirm(m.getString('msg_changeuser_confirm')); 2264 if (r!=true){ 2265 return; 2266 } 2267 var loc = g_storage.get('openurl'); 2268 client.LOGOUT(loc, function(error){ 2269 if(error==200){ 2270 doPROPFIND(loc); 2271 } 2272 }); 2273 }); 2274 2275 $("div#select").live("click", function() { 2276 2277 showMenu(newMenu); 2278 2279 //showMenu($("#dynamicMenu1")); 2280 /* 2281 if(g_select_mode==0) 2282 openSelectMode(); 2283 else if(g_select_mode==1) 2284 cancelSelectMode(); 2285 */ 2286 2287 }); 2288 2289 $("#select-choice-custom-button").live("click", function() { 2290 //alert("click"); 2291 //alert($("#select-choice-custom").val()); 2292 if(g_select_mode==0) 2293 openSelectMode(); 2294 else if(g_select_mode==1) 2295 cancelSelectMode(); 2296 }); 2297 2298 $("#btn-logout").live("click", function() { 2299 var r=confirm(m.getString('msg_logout_confirm')); 2300 if (r!=true){ 2301 return; 2302 } 2303 doLOGOUT(); 2304 }); 2305 2306 $(window).resize(adjustLayout); 2307 2308})(jQuery); 2309