jawert

sdupload.js 5776

Jan 12th, 2014
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.50 KB | None | 0 0
  1. // JavaScript Document
  2. var ERROR_SD_UPLOAD_STATUS = 114007;
  3. function showUploadStatus(upload_state) {
  4. var message = '';
  5. if (SD_FILE_UPLOAD_SUCCESS == upload_state) {
  6. message = sd_hint_upload_file_success;
  7. }
  8. else if (SD_FILE_UPLOAD_FAIL == upload_state) {
  9. message = sd_hint_upload_file_failed;
  10. }
  11. else if (SD_FILE_UPLOAD_FAIL_NOSPACE == upload_state) {
  12. message = sd_hint_not_enough_space_available;
  13. }
  14. else if (SD_FILE_UPLOAD_FAIL_NOSD == upload_state) {
  15. message = sd_label_no_sd_card;
  16. }
  17. else if (SD_FILE_UPLOAD_FAIL_2GB == upload_state) {
  18. message = sd_hint_file_size_over_2gb;
  19. }
  20. else if (SD_FILE_UPLOAD_FAILED_WRONG_FILENAME == upload_state) {
  21. message = sd_hint_wrong_file_name;
  22. }
  23. else if (SD_FILE_UPLOAD_FAILED_SD_REMOVED == upload_state) {
  24. message = sd_hint_sd_card_removed;
  25. }
  26. else if (SD_FILE_UPLOAD_FAILED_NAME_LONGER == upload_state) {
  27. message = IDS_sd_file_name_longer;
  28. }
  29. else if (SD_FILE_UPLOAD_FAILED_ACCESS_RIGHTS == upload_state) {
  30. message = IDS_sd_no_access_rights;
  31. }
  32. else {
  33. message = sd_hint_upload_file_failed;
  34. }
  35.  
  36. initSdCardCapacity();
  37. showInfoDialog(message);
  38. }
  39.  
  40. function showUploadProgressDialog(UploadProgress,repaint_flag)
  41. {
  42. var dialogHtml = '';
  43. if(repaint_flag){
  44. $('#div_wrapper').remove();
  45. if ($('#div_wrapper').size() < 1) {
  46. dialogHtml += "<div id='div_wrapper'><iframe id='ifream_dialog' src= '' frameborder= '0' style= 'background:#bcbcbc; position:absolute; width:100%; height:100%; z-index:-1; display: block;'> </iframe></div>";
  47. }
  48. dialogHtml += "<div class='dialog'>";
  49. dialogHtml += " <div class='dialog_top'></div>";
  50. dialogHtml += " <div class='dialog_content'>";
  51. dialogHtml += " <div class='dialog_header'>";
  52. dialogHtml += " <span class='dialog_header_left'>" + sd_label_upload + '</span>';
  53. dialogHtml += " <span class='dialog_header_right'><a href='javascript:void(0);' title='' class='dialog_close_btn'><img src='../res/dialog_close_btn.png' title='' alt='' /></a></span>";
  54. dialogHtml += " </div>";
  55. dialogHtml += " <div class='dialog_table'>" ;
  56. dialogHtml += " <table cellspacing='0' cellpadding='0' class='get_table' width='400'>" ;
  57. dialogHtml += " <tr>";
  58. dialogHtml += " <td><span id='uploadInfo'></span></td>";
  59. dialogHtml += " </tr>";
  60. dialogHtml += " <tr>";
  61. dialogHtml += " <td>";
  62. dialogHtml += " <div class='graph'>";
  63. dialogHtml += " <div class='persent_download'><img src='../res/persent_download.jpg' class='press'/></div>";
  64. dialogHtml += " </div>";
  65. dialogHtml += " </td>";
  66. dialogHtml += " </tr>";
  67. dialogHtml += " <tr>";
  68. dialogHtml += " <td><span id='downloadProcess'></span></td>";
  69. dialogHtml += " </tr>";
  70. dialogHtml += " </table>";
  71. dialogHtml += " </div>";
  72. dialogHtml += " <div class='dialog_table_bottom'>";
  73. dialogHtml += " <div class='dialog_table_r'>";
  74. dialogHtml += " <span class='button_wrapper pop_Cancel' id='pop_Cancel'>";
  75. dialogHtml += " <span class='button_left'>";
  76. dialogHtml += " <span class='button_right'>";
  77. dialogHtml += " <span class='button_center'><a href='javascript:void(0);' title=''>" + common_cancel + '</a></span>';
  78. dialogHtml += " </span></span></span>";
  79. dialogHtml += " </div>";
  80. dialogHtml += " </div>";
  81. dialogHtml += " </div>";
  82. dialogHtml += " <div class='dialog_bottom'></div>";
  83. dialogHtml += "</div>";
  84.  
  85. $('.dialog_close_btn,#pop_Cancel').live('click', function() {
  86. window.location.href = 'sdcardsharing.html?' + rfc3986_url_resolveSpecialChar(folder_path.CurrentPath).replace(/\//g, '%2F');
  87. });
  88. $('.body_bg').before(dialogHtml);
  89. $('#uploadInfo').html(sd_label_uploading);
  90. hiddenSelect(true);
  91. reputPosition($('.dialog'), $('#div_wrapper'));
  92. disableTabKey();
  93. }
  94. var current_progress = UploadProgress;
  95. var persent = formatFloat(parseInt(current_progress, 10) / 100, 2);
  96. var update_width = $('.graph').width() - 8;
  97. update_width = parseInt(update_width * persent, 10);
  98. $('.press').css({'width': update_width + 'px'});
  99. $('#downloadProcess').html(UploadProgress + '%');
  100. if(parseInt(current_progress, 10) < 100){
  101. button_enable('pop_Cancel', '1');
  102. }else{
  103. button_enable('pop_Cancel', '0');
  104. }
  105. setTimeout(function(){getUploadState(false); }, 2000);
  106. }
  107.  
  108.  
  109. function getUploadState(repaint_flag) {
  110. getAjaxData('api/sdcard/sdfilestate', function($xml) {
  111. var filestate_ret = xml2object($xml);
  112. if ('response' == filestate_ret.type) {
  113. var upload_state = filestate_ret.response.sduploadstatus.State;
  114. var upload_progress = filestate_ret.response.sduploadstatus.UploadProgress;
  115. if (SD_FILE_UPLOADING == upload_state) {
  116. showUploadProgressDialog(upload_progress,repaint_flag);
  117. }else {
  118. //window.location.replace("sdcardsharing.html?result="+upload_state);
  119. clearDialog();
  120. showUploadStatus(upload_state);
  121. if (SD_FILE_UPLOAD_SUCCESS == upload_state) {
  122. folderlists(folder_path.CurrentPath);
  123. }
  124. if (LOGIN_STATE_NOMAL == login_state.response.State) {
  125. startLogoutTimer();
  126. }
  127. $('#upload_dialog').remove();
  128. }
  129. }
  130. },
  131. {
  132. errorCB: function()
  133. {
  134. clearDialog();
  135. showInfoDialog(sd_hint_upload_file_failed);
  136. if (LOGIN_STATE_NOMAL == login_state.response.State) {
  137. startLogoutTimer();
  138. }
  139. $('#upload_dialog').remove();
  140. }
  141. });
  142. }
  143.  
  144. function doUploadFile() {
  145. if (LOGIN_STATE_NOMAL == login_state.response.State) {
  146. cancelLogoutTimer();
  147. }
  148. var current_date = new Date();
  149. var upload_date = {
  150. Year: current_date.getFullYear(),
  151. Month: current_date.getMonth() + 1,
  152. Day: current_date.getDate(),
  153. Hour: current_date.getHours(),
  154. Min: current_date.getMinutes(),
  155. Sec: current_date.getSeconds()
  156. };
  157. $('#wait_dialog_btn').show().bind('click', function() {
  158. //window.location.reload();
  159. window.location.href = 'sdcardsharing.html?' + rfc3986_url_resolveSpecialChar(folder_path.CurrentPath).replace(/\//g, '%2F');
  160. });
  161. $('#cur_path').val('<' + folder_path.CurrentPath + '>');
  162. $('#page').val('sdcardsharing.html');
  163. $('#upload_year').val(upload_date.Year);
  164. $('#upload_month').val(upload_date.Month);
  165. $('#upload_day').val(upload_date.Day);
  166. $('#upload_hours').val(upload_date.Hour);
  167. $('#upload_minutes').val(upload_date.Min);
  168. $('#upload_secondes').val(upload_date.Sec);
  169. $('#upload_file_form').submit();
  170. getUploadState(true);
  171. }
  172.  
  173. function cancle_upload()
  174. {
  175. getAjaxData("api/sdcard/Check_file_exist");
  176. }
  177.  
  178. function getUploadStatus(){
  179. var upload_flagObj = {
  180. Uploadflag : 1
  181. };
  182. var upload_flag = object2xml('request', upload_flagObj);
  183. saveAjaxData('api/sdcard/uploadflag', upload_flag, function($xml) {
  184. var res = xml2object($xml);
  185. if ('response' == res.type && 'OK' == res.response)
  186. {
  187. doUploadFile();
  188. }
  189. else if ('response' == res.type && 0 == res.response.Uploadflag){
  190. doUploadFile();
  191. }
  192. else if ('response' == res.type && 1 == res.response.Uploadflag){
  193. showInfoDialog(IDS_sd_message_uploading_file_conflict);
  194. return false;
  195. }
  196. else if('error' == res.type && ERROR_SD_UPLOAD_STATUS == res.error.code){
  197. showInfoDialog(IDS_sd_message_uploading_file_conflict);
  198. return false;
  199. }
  200. else{
  201. showInfoDialog(common_fail);
  202. return false;
  203. }
  204. });
  205. }
  206.  
  207. function confirm_exist(obj) {
  208. $('#upload_dialog').css({'z-index': '-1000'}).hide();
  209. folder_path.CurrentPath = $('.micro_sd').children().html();
  210. var upload_xml = object2xml('request', obj);
  211. saveAjaxData('api/sdcard/Check_file_exist', upload_xml, function($xml) {
  212. var exist_state = xml2object($xml);
  213. if ('response' == exist_state.type) {
  214. if ('OK' == exist_state.response) {
  215. getUploadStatus();
  216. }
  217. else {
  218. showInfoDialog(common_failed);
  219. return false;
  220. }
  221. }
  222. else if ('error' == exist_state.type && '114001' == exist_state.error.code) {
  223. $('.dialog_close_btn').live('click',function() {
  224. getAjaxData("api/sdcard/Check_file_exist");
  225. });
  226. $("#pop_confirm").die("click");
  227. $("#pop_Cancel").die("click");
  228. showConfirmDialog(sd_hint_overwrite_existed_file, getUploadStatus, cancle_upload, 0);
  229. }
  230. else {
  231. showInfoDialog(common_failed);
  232. return false;
  233. }
  234. });
  235. }
  236.  
  237. function getFileName(szFile) {
  238. var szFileName = '';
  239. var fIndex = 0;
  240.  
  241. fIndex = szFile.lastIndexOf('\\');
  242. if (fIndex > 0) {
  243. szFileName = szFile.substr(fIndex + 1);
  244. }
  245. else {
  246. fIndex = szFile.lastIndexOf('/');
  247. if (fIndex > 0) {
  248. szFileName = szFile.substr(fIndex + 1);
  249. }
  250. else {
  251. return szFile;
  252. }
  253. }
  254.  
  255. return szFileName;
  256. }
  257.  
  258. function uploadfile() {
  259. var upload_path = $('.micro_sd').children().html();
  260. upload_path = upload_path == '' ? '/' : upload_path;
  261. var upload_file = $('#fileField2').val();
  262. upload_file = getFileName(upload_file);
  263. upload_file = resolveXMLEntityReference(upload_file);
  264. var upload_folder = {
  265. CurrentPath: upload_path,
  266. FileName: upload_file
  267. };
  268. confirm_exist(upload_folder);
  269. }
Advertisement
Add Comment
Please, Sign In to add comment