DropboxClient.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. /**
  2. * Copyright (c) 2006-2017, JGraph Ltd
  3. * Copyright (c) 2006-2017, Gaudenz Alder
  4. */
  5. DropboxClient = function(editorUi)
  6. {
  7. DrawioClient.call(this, editorUi, 'dbauth');
  8. this.client = new Dropbox({clientId: App.DROPBOX_APPKEY});
  9. this.client.setAccessToken(this.token);
  10. };
  11. // Extends DrawioClient
  12. mxUtils.extend(DropboxClient, DrawioClient);
  13. /**
  14. * FIXME: How to find name of app folder for current user. The Apps part of the
  15. * name is internationalized so this hardcoded check does not work everywhere.
  16. */
  17. DropboxClient.prototype.appPath = '/drawio/';
  18. /**
  19. * Executes the first step for connecting to Google Drive.
  20. */
  21. DropboxClient.prototype.extension = '.html';
  22. /**
  23. * Executes the first step for connecting to Google Drive.
  24. */
  25. DropboxClient.prototype.writingFile = false;
  26. /**
  27. * Executes the first step for connecting to Google Drive.
  28. */
  29. DropboxClient.prototype.maxRetries = 4;
  30. /**
  31. * Authorizes the client, gets the userId and calls <open>.
  32. */
  33. DropboxClient.prototype.logout = function()
  34. {
  35. this.client.authTokenRevoke().then(mxUtils.bind(this, function()
  36. {
  37. this.client.setAccessToken(null);
  38. this.clearPersistentToken();
  39. this.setUser(null);
  40. this.token = null;
  41. }));
  42. };
  43. /**
  44. * Checks if the client is authorized and calls the next step.
  45. */
  46. DropboxClient.prototype.updateUser = function(success)
  47. {
  48. var acceptResponse = true;
  49. var timeoutThread = window.setTimeout(mxUtils.bind(this, function()
  50. {
  51. acceptResponse = false;
  52. this.ui.handleError({code: App.ERROR_TIMEOUT});
  53. }), this.ui.timeout);
  54. var promise = this.client.usersGetCurrentAccount();
  55. promise.then(mxUtils.bind(this, function(response)
  56. {
  57. window.clearTimeout(timeoutThread);
  58. if (acceptResponse)
  59. {
  60. this.setUser(new DrawioUser(response.account_id, response.email, response.name.display_name));
  61. if (success != null)
  62. {
  63. success();
  64. }
  65. }
  66. }));
  67. // Workaround for IE8/9 support with catch function
  68. promise['catch'](mxUtils.bind(this, function(err)
  69. {
  70. if (err != null && err.status === 401)
  71. {
  72. this.client.setAccessToken(null);
  73. this.execute(success);
  74. }
  75. else
  76. {
  77. window.clearTimeout(timeoutThread);
  78. if (acceptResponse)
  79. {
  80. this.setUser(null);
  81. this.ui.handleError(err);
  82. }
  83. }
  84. }));
  85. };
  86. /**
  87. * Authorizes the client, gets the userId and calls <open>.
  88. */
  89. DropboxClient.prototype.execute = function(fn)
  90. {
  91. if (this.client.getAccessToken() != null)
  92. {
  93. if (this.user == null)
  94. {
  95. this.updateUser(fn);
  96. }
  97. else
  98. {
  99. fn();
  100. }
  101. }
  102. else
  103. {
  104. this.ui.showAuthDialog(this, false, mxUtils.bind(this, function(remember, success)
  105. {
  106. this.authenticate(mxUtils.bind(this, function()
  107. {
  108. if (success != null)
  109. {
  110. success();
  111. }
  112. if (this.client.getAccessToken() != null)
  113. {
  114. this.updateUser(fn, mxUtils.bind(this, function(err)
  115. {
  116. this.ui.handleError(e);
  117. }));
  118. }
  119. }));
  120. }));
  121. }
  122. };
  123. /**
  124. * Authorizes the client, gets the userId and calls <open>.
  125. */
  126. DropboxClient.prototype.authenticate = function(fn)
  127. {
  128. window.open(this.client.getAuthenticationUrl('https://' +
  129. window.location.host + '/dropbox.html'), 'oauth');
  130. window.onDropboxCallback = mxUtils.bind(this, function(token, authWindow)
  131. {
  132. try
  133. {
  134. window.onDropboxCallback = null;
  135. if (authWindow != null)
  136. {
  137. authWindow.close();
  138. }
  139. if (token == null)
  140. {
  141. this.ui.hideDialog();
  142. this.ui.handleError({message: mxResources.get('cannotLogin')});
  143. }
  144. else
  145. {
  146. this.client.setAccessToken(token);
  147. this.setPersistentToken(token);
  148. fn();
  149. }
  150. }
  151. catch (e)
  152. {
  153. this.ui.handleError(e);
  154. }
  155. });
  156. };
  157. /**
  158. * Checks if the client is authorized and calls the next step.
  159. */
  160. DropboxClient.prototype.getLibrary = function(path, success, error)
  161. {
  162. this.getFile(path, success, error, true);
  163. };
  164. /**
  165. * DenyConvert is ignored in this client, just added for API compatibility.
  166. */
  167. DropboxClient.prototype.getFile = function(path, success, error, asLibrary)
  168. {
  169. asLibrary = (asLibrary != null) ? asLibrary : false;
  170. var fn = mxUtils.bind(this, function()
  171. {
  172. this.execute(mxUtils.bind(this, function()
  173. {
  174. if (/^https:\/\//i.test(path) || /\.vsdx$/i.test(path) || /\.gliffy$/i.test(path) || /\.png$/i.test(path))
  175. {
  176. var tokens = path.split('/');
  177. var name = (tokens.length > 0) ? tokens[tokens.length - 1] : path;
  178. this.ui.convertFile(path, name, null, this.extension, success, error);
  179. }
  180. else
  181. {
  182. var arg = {path: '/' + path};
  183. if (urlParams['rev'] != null)
  184. {
  185. arg.rev = urlParams['rev'];
  186. }
  187. this.readFile(arg, mxUtils.bind(this, function(data, response)
  188. {
  189. success((asLibrary) ? new DropboxLibrary(this.ui, data, response) :
  190. new DropboxFile(this.ui, data, response));
  191. }), error);
  192. }
  193. }));
  194. });
  195. fn();
  196. };
  197. /**
  198. * Translates this point by the given vector.
  199. *
  200. * @param {number} dx X-coordinate of the translation.
  201. * @param {number} dy Y-coordinate of the translation.
  202. */
  203. DropboxClient.prototype.readFile = function(arg, success, error)
  204. {
  205. var acceptResponse = true;
  206. var timeoutThread = window.setTimeout(mxUtils.bind(this, function()
  207. {
  208. acceptResponse = false;
  209. error({code: App.ERROR_TIMEOUT});
  210. }), this.ui.timeout);
  211. // TODO: Find catch for file does not exist in filesDownload below
  212. // This will have significant impact on performance!
  213. // LATER: Catch "file not found" error without metadata check?
  214. this.checkExists(arg.path.substring(1), mxUtils.bind(this, function(checked, exists)
  215. {
  216. window.clearTimeout(timeoutThread);
  217. if (acceptResponse)
  218. {
  219. if (!exists)
  220. {
  221. error({message: mxResources.get('fileNotFound')});
  222. }
  223. else
  224. {
  225. timeoutThread = window.setTimeout(mxUtils.bind(this, function()
  226. {
  227. acceptResponse = false;
  228. error({code: App.ERROR_TIMEOUT});
  229. }), this.ui.timeout);
  230. var promise = this.client.filesDownload(arg);
  231. promise.then(mxUtils.bind(this, function(response)
  232. {
  233. window.clearTimeout(timeoutThread);
  234. if (acceptResponse)
  235. {
  236. try
  237. {
  238. var reader = new FileReader();
  239. reader.onload = mxUtils.bind(this, function(event)
  240. {
  241. success(reader.result, response);
  242. });
  243. reader.readAsText(response.fileBlob);
  244. }
  245. catch (e)
  246. {
  247. error(e);
  248. }
  249. }
  250. }));
  251. // Workaround for IE8/9 support with catch function
  252. promise['catch'](function(err)
  253. {
  254. window.clearTimeout(timeoutThread);
  255. if (acceptResponse)
  256. {
  257. error(e);
  258. }
  259. });
  260. }
  261. }
  262. }), true);
  263. };
  264. /**
  265. * Translates this point by the given vector.
  266. *
  267. * @param {number} dx X-coordinate of the translation.
  268. * @param {number} dy Y-coordinate of the translation.
  269. */
  270. DropboxClient.prototype.checkExists = function(filename, fn, noConfirm)
  271. {
  272. var promise = this.client.filesGetMetadata({path: '/' + filename.toLowerCase(), include_deleted: false});
  273. promise.then(mxUtils.bind(this, function(response)
  274. {
  275. if (noConfirm)
  276. {
  277. fn(false, true, response);
  278. }
  279. else
  280. {
  281. this.ui.confirm(mxResources.get('replaceIt', [filename]), function()
  282. {
  283. fn(true, true, response);
  284. }, function()
  285. {
  286. fn(false, true, response);
  287. });
  288. }
  289. }));
  290. // Workaround for IE8/9 support with catch function
  291. promise['catch'](function(err)
  292. {
  293. fn(true, false);
  294. });
  295. };
  296. /**
  297. * Translates this point by the given vector.
  298. *
  299. * @param {number} dx X-coordinate of the translation.
  300. * @param {number} dy Y-coordinate of the translation.
  301. */
  302. DropboxClient.prototype.renameFile = function(file, filename, success, error)
  303. {
  304. if (/[\\\/:\?\*"\|]/.test(filename))
  305. {
  306. error({message: mxResources.get('dropboxCharsNotAllowed')});
  307. }
  308. else
  309. {
  310. // Appends working directory of source file
  311. if (file != null && filename != null)
  312. {
  313. var path = file.stat.path_display.substring(1);
  314. var idx = path.lastIndexOf('/');
  315. if (idx > 0)
  316. {
  317. filename = path.substring(0, idx + 1) + filename;
  318. }
  319. }
  320. if (file != null && filename != null && file.stat.path_lower.substring(1) !== filename.toLowerCase())
  321. {
  322. // Checks if file exists
  323. this.execute(mxUtils.bind(this, function()
  324. {
  325. this.checkExists(filename, mxUtils.bind(this, function(checked, exists, response)
  326. {
  327. if (checked)
  328. {
  329. var thenHandler = mxUtils.bind(this, function(deleteResponse)
  330. {
  331. // Uses write and remove because move does not allow overwriting an existing target
  332. var move = this.client.filesMove({from_path: file.stat.path_display, to_path: '/' +
  333. filename, autorename: false});
  334. move.then(mxUtils.bind(this, function(response)
  335. {
  336. success(response);
  337. }))
  338. // Workaround for IE8/9 support with catch function
  339. move['catch'](error);
  340. });
  341. // API fails on same name with different upper-/lowercase
  342. if (!exists || response.path_lower.substring(1) === filename.toLowerCase())
  343. {
  344. thenHandler();
  345. }
  346. else
  347. {
  348. // Deletes file first to avoid conflict in filesMove (non-atomic)
  349. var promise = this.client.filesDelete({path: '/' + filename.toLowerCase()});
  350. promise.then(thenHandler);
  351. // Workaround for IE8/9 support with catch function
  352. promise['catch'](error);
  353. }
  354. }
  355. else
  356. {
  357. error();
  358. }
  359. }));
  360. }));
  361. }
  362. else
  363. {
  364. // Same name with different upper-/lowercase
  365. // is not supported by Dropbox API
  366. error({message: mxResources.get('invalidName')});
  367. }
  368. }
  369. };
  370. /**
  371. * Translates this point by the given vector.
  372. *
  373. * @param {number} dx X-coordinate of the translation.
  374. * @param {number} dy Y-coordinate of the translation.
  375. */
  376. DropboxClient.prototype.insertLibrary = function(filename, data, success, error)
  377. {
  378. this.insertFile(filename, data, success, error, true);
  379. };
  380. /**
  381. * Translates this point by the given vector.
  382. *
  383. * @param {number} dx X-coordinate of the translation.
  384. * @param {number} dy Y-coordinate of the translation.
  385. */
  386. DropboxClient.prototype.insertFile = function(filename, data, success, error, asLibrary)
  387. {
  388. asLibrary = (asLibrary != null) ? asLibrary : false;
  389. this.execute(mxUtils.bind(this, function()
  390. {
  391. this.checkExists(filename, mxUtils.bind(this, function(checked)
  392. {
  393. if (checked)
  394. {
  395. this.writeFile(filename, data, mxUtils.bind(this, function(stat)
  396. {
  397. if (asLibrary)
  398. {
  399. success(new DropboxLibrary(this.ui, data, stat));
  400. }
  401. else
  402. {
  403. success(new DropboxFile(this.ui, data, stat));
  404. }
  405. }), error);
  406. }
  407. else
  408. {
  409. error();
  410. }
  411. }));
  412. }));
  413. };
  414. /**
  415. * Translates this point by the given vector.
  416. *
  417. * @param {number} dx X-coordinate of the translation.
  418. * @param {number} dy Y-coordinate of the translation.
  419. */
  420. DropboxClient.prototype.saveFile = function(filename, data, success, error)
  421. {
  422. this.execute(mxUtils.bind(this, function()
  423. {
  424. this.writeFile(filename, data, success, error);
  425. }));
  426. };
  427. /**
  428. * Translates this point by the given vector.
  429. *
  430. * @param {number} dx X-coordinate of the translation.
  431. * @param {number} dy Y-coordinate of the translation.
  432. */
  433. DropboxClient.prototype.writeFile = function(filename, data, success, error)
  434. {
  435. if (/[\\\/:\?\*"\|]/.test(filename))
  436. {
  437. if (error != null)
  438. {
  439. error({message: mxResources.get('dropboxCharsNotAllowed')});
  440. }
  441. }
  442. else if (data.length >= 150000000 /*150MB*/)
  443. {
  444. if (error != null)
  445. {
  446. error({message: mxResources.get('drawingTooLarge') + ' (' +
  447. this.ui.formatFileSize(data.length) + ' / 150 MB)'});
  448. }
  449. }
  450. else if (this.writingFile)
  451. {
  452. if (error != null)
  453. {
  454. error({code: App.ERROR_BUSY});
  455. }
  456. }
  457. else
  458. {
  459. this.writingFile = true;
  460. var acceptResponse = true;
  461. var timeoutThread = null;
  462. var retryCount = 0;
  463. // Cancels any pending requests
  464. if (this.requestThread != null)
  465. {
  466. window.clearTimeout(this.requestThread);
  467. }
  468. var fn = mxUtils.bind(this, function()
  469. {
  470. if (timeoutThread != null)
  471. {
  472. window.clearTimeout(timeoutThread);
  473. }
  474. timeoutThread = window.setTimeout(mxUtils.bind(this, function()
  475. {
  476. this.writingFile = false;
  477. acceptResponse = false;
  478. if (error != null)
  479. {
  480. error({code: App.ERROR_TIMEOUT, retry: fn});
  481. }
  482. }), this.ui.timeout);
  483. var promise = this.client.filesUpload({path: '/' + filename, mode: {'.tag': 'overwrite'},
  484. contents: new Blob([data], {type: 'text/plain'})});
  485. promise.then(mxUtils.bind(this, function(response)
  486. {
  487. window.clearTimeout(timeoutThread);
  488. if (acceptResponse)
  489. {
  490. this.writingFile = false;
  491. try
  492. {
  493. if (success != null)
  494. {
  495. success(response);
  496. }
  497. }
  498. catch (e)
  499. {
  500. if (error != null)
  501. {
  502. error(e);
  503. }
  504. }
  505. }
  506. }));
  507. // Workaround for IE8/9 support with catch function
  508. promise['catch'](mxUtils.bind(this, function(err)
  509. {
  510. window.clearTimeout(timeoutThread);
  511. if (acceptResponse)
  512. {
  513. // LATER: Check error codes where a retry makes sense
  514. if (retryCount < this.maxRetries)
  515. {
  516. retryCount++;
  517. var jitter = 1 + 0.1 * (Math.random() - 0.5);
  518. this.requestThread = window.setTimeout(fn, Math.round(Math.pow(2, retryCount) * jitter * 1000));
  519. }
  520. else
  521. {
  522. this.writingFile = false;
  523. if (error != null)
  524. {
  525. error(err);
  526. }
  527. }
  528. }
  529. }));
  530. });
  531. fn();
  532. }
  533. };
  534. /**
  535. * Translates this point by the given vector.
  536. *
  537. * @param {number} dx X-coordinate of the translation.
  538. * @param {number} dy Y-coordinate of the translation.
  539. */
  540. DropboxClient.prototype.pickLibrary = function(fn)
  541. {
  542. // Authentication will be carried out on open to make sure the
  543. // autosave does not show an auth dialog. Showing it here will
  544. // block the second dialog (the file picker) so it's too early.
  545. Dropbox.choose(
  546. {
  547. linkType : 'direct',
  548. cancel: mxUtils.bind(this, function()
  549. {
  550. // do nothing
  551. }),
  552. success : mxUtils.bind(this, function(files)
  553. {
  554. if (this.ui.spinner.spin(document.body, mxResources.get('loading')))
  555. {
  556. var error = mxUtils.bind(this, function(e)
  557. {
  558. this.ui.spinner.stop();
  559. this.ui.handleError(e);
  560. });
  561. var tmp = files[0].link.indexOf(this.appPath);
  562. if (tmp > 0)
  563. {
  564. // Checks if file is in app folder by loading file from there and comparing relative path and size
  565. // KNOWN: This check fails if a file is inside a drawio directory with same relative path and size
  566. this.execute(mxUtils.bind(this, function()
  567. {
  568. var rel = decodeURIComponent(files[0].link.substring(tmp + this.appPath.length - 1));
  569. this.readFile({path: rel}, mxUtils.bind(this, function(data, stat)
  570. {
  571. if (stat != null && parseInt(files[0].bytes) === parseInt(stat.size) && rel === stat.path_display)
  572. {
  573. // No need to load file a second time
  574. try
  575. {
  576. this.ui.spinner.stop();
  577. fn(rel.substring(1), new DropboxLibrary(this.ui, data, stat));
  578. }
  579. catch (e)
  580. {
  581. this.ui.handleError(e);
  582. }
  583. }
  584. else
  585. {
  586. this.createLibrary(files[0], fn, error);
  587. }
  588. }), error);
  589. }));
  590. }
  591. else
  592. {
  593. this.execute(mxUtils.bind(this, function()
  594. {
  595. this.createLibrary(files[0], fn, error);
  596. }));
  597. }
  598. }
  599. })
  600. });
  601. };
  602. /**
  603. * Translates this point by the given vector.
  604. *
  605. * @param {number} dx X-coordinate of the translation.
  606. * @param {number} dy Y-coordinate of the translation.
  607. */
  608. DropboxClient.prototype.createLibrary = function(file, success, error)
  609. {
  610. this.ui.confirm(mxResources.get('note') + ': ' + mxResources.get('fileWillBeSavedInAppFolder', [file.name]), mxUtils.bind(this, function()
  611. {
  612. this.ui.loadUrl(file.link, mxUtils.bind(this, function(data)
  613. {
  614. this.insertFile(file.name, data, mxUtils.bind(this, function(newFile)
  615. {
  616. try
  617. {
  618. this.ui.spinner.stop();
  619. success(newFile.getHash().substring(1), newFile);
  620. }
  621. catch (e)
  622. {
  623. error(e);
  624. }
  625. }), error, true);
  626. }), error);
  627. }), mxUtils.bind(this, function()
  628. {
  629. this.ui.spinner.stop();
  630. }));
  631. };
  632. /**
  633. * Translates this point by the given vector.
  634. *
  635. * @param {number} dx X-coordinate of the translation.
  636. * @param {number} dy Y-coordinate of the translation.
  637. */
  638. DropboxClient.prototype.pickFile = function(fn, readOnly)
  639. {
  640. if (Dropbox.choose != null)
  641. {
  642. fn = (fn != null) ? fn : mxUtils.bind(this, function(path, file)
  643. {
  644. this.ui.loadFile((path != null) ? 'D' + encodeURIComponent(path) : file.getHash(), null, file);
  645. });
  646. // Authentication will be carried out on open to make sure the
  647. // autosave does not show an auth dialog. Showing it here will
  648. // block the second dialog (the file picker) so it's too early.
  649. Dropbox.choose(
  650. {
  651. linkType : 'direct',
  652. cancel: mxUtils.bind(this, function()
  653. {
  654. // do nothing
  655. }),
  656. success : mxUtils.bind(this, function(files)
  657. {
  658. if (this.ui.spinner.spin(document.body, mxResources.get('loading')))
  659. {
  660. // File used for read-only
  661. if (readOnly)
  662. {
  663. this.ui.spinner.stop();
  664. fn(files[0].link);
  665. }
  666. else
  667. {
  668. var error = mxUtils.bind(this, function(e)
  669. {
  670. this.ui.spinner.stop();
  671. this.ui.handleError(e);
  672. });
  673. var success = mxUtils.bind(this, function(path, file)
  674. {
  675. this.ui.spinner.stop();
  676. fn(path, file);
  677. });
  678. if ((/\.vsdx$/i.test(files[0].name) || /\.gliffy$/i.test(files[0].name) ||
  679. /\.png$/i.test(files[0].name)))
  680. {
  681. success(files[0].link);
  682. }
  683. else
  684. {
  685. var tmp = files[0].link.indexOf(this.appPath);
  686. if (tmp > 0)
  687. {
  688. // Checks if file is in app folder by loading file from there and comparing relative path and size
  689. // KNOWN: This check fails if a file is inside a drawio directory with same relative path and size
  690. this.execute(mxUtils.bind(this, function()
  691. {
  692. var rel = decodeURIComponent(files[0].link.substring(tmp + this.appPath.length - 1));
  693. this.readFile({path: rel}, mxUtils.bind(this, function(data, stat)
  694. {
  695. if (stat != null && parseInt(files[0].bytes) === parseInt(stat.size) && rel === stat.path_display)
  696. {
  697. this.ui.spinner.stop();
  698. // No need to load file a second time
  699. fn(rel.substring(1), new DropboxFile(this.ui, data, stat));
  700. }
  701. else
  702. {
  703. this.createFile(files[0], success, error);
  704. }
  705. }));
  706. }));
  707. }
  708. else
  709. {
  710. this.execute(mxUtils.bind(this, function()
  711. {
  712. this.createFile(files[0], success, error);
  713. }));
  714. }
  715. }
  716. }
  717. }
  718. })
  719. });
  720. }
  721. else
  722. {
  723. this.ui.handleError({message: mxResources.get('serviceUnavailableOrBlocked')});
  724. }
  725. };
  726. /**
  727. * Translates this point by the given vector.
  728. *
  729. * @param {number} dx X-coordinate of the translation.
  730. * @param {number} dy Y-coordinate of the translation.
  731. */
  732. DropboxClient.prototype.createFile = function(file, success, error)
  733. {
  734. this.ui.loadUrl(file.link, mxUtils.bind(this, function(data)
  735. {
  736. if (data != null && data.length > 0)
  737. {
  738. this.ui.confirm(mxResources.get('note') + ': ' + mxResources.get('fileWillBeSavedInAppFolder', [file.name]), mxUtils.bind(this, function()
  739. {
  740. this.insertFile(file.name, data, mxUtils.bind(this, function(newFile)
  741. {
  742. success(file.name, newFile);
  743. }), error);
  744. }), mxUtils.bind(this, function()
  745. {
  746. this.ui.spinner.stop();
  747. }));
  748. }
  749. else
  750. {
  751. this.ui.spinner.stop();
  752. if (error != null)
  753. {
  754. error({message: mxResources.get('errorLoadingFile')});
  755. }
  756. }
  757. }), error, /(\.png)$/i.test(file.name));
  758. };