OneDriveFile.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. // $Id = DropboxFile.js,v 1.12 2010-01-02 09 =45 =14 gaudenz Exp $
  2. // Copyright (c) 2006-2014, JGraph Ltd
  3. /**
  4. * Constructs a new point for the optional x and y coordinates. If no
  5. * coordinates are given, then the default values for <x> and <y> are used.
  6. * @constructor
  7. * @class Implements a basic 2D point. Known subclassers = {@link mxRectangle}.
  8. * @param {number} x X-coordinate of the point.
  9. * @param {number} y Y-coordinate of the point.
  10. */
  11. OneDriveFile = function(ui, data, meta)
  12. {
  13. DrawioFile.call(this, ui, data);
  14. this.meta = meta;
  15. };
  16. //Extends mxEventSource
  17. mxUtils.extend(OneDriveFile, DrawioFile);
  18. /**
  19. * Translates this point by the given vector.
  20. *
  21. * @param {number} dx X-coordinate of the translation.
  22. * @param {number} dy Y-coordinate of the translation.
  23. */
  24. OneDriveFile.prototype.getHash = function()
  25. {
  26. return 'W' + encodeURIComponent(this.meta.id);
  27. };
  28. /**
  29. * Translates this point by the given vector.
  30. *
  31. * @param {number} dx X-coordinate of the translation.
  32. * @param {number} dy Y-coordinate of the translation.
  33. */
  34. OneDriveFile.prototype.getMode = function()
  35. {
  36. return App.MODE_ONEDRIVE;
  37. };
  38. /**
  39. * Overridden to enable the autosave option in the document properties dialog.
  40. */
  41. OneDriveFile.prototype.isAutosaveOptional = function()
  42. {
  43. return true;
  44. };
  45. /**
  46. * Translates this point by the given vector.
  47. *
  48. * @param {number} dx X-coordinate of the translation.
  49. * @param {number} dy Y-coordinate of the translation.
  50. */
  51. OneDriveFile.prototype.getTitle = function()
  52. {
  53. return this.meta.name;
  54. };
  55. /**
  56. * Translates this point by the given vector.
  57. *
  58. * @param {number} dx X-coordinate of the translation.
  59. * @param {number} dy Y-coordinate of the translation.
  60. */
  61. OneDriveFile.prototype.isRenamable = function()
  62. {
  63. return true;
  64. };
  65. /**
  66. * Translates this point by the given vector.
  67. *
  68. * @param {number} dx X-coordinate of the translation.
  69. * @param {number} dy Y-coordinate of the translation.
  70. */
  71. OneDriveFile.prototype.save = function(revision, success, error)
  72. {
  73. this.doSave(this.getTitle(), success, error);
  74. };
  75. /**
  76. * Translates this point by the given vector.
  77. *
  78. * @param {number} dx X-coordinate of the translation.
  79. * @param {number} dy Y-coordinate of the translation.
  80. */
  81. OneDriveFile.prototype.saveAs = function(title, success, error)
  82. {
  83. this.doSave(title, success, error);
  84. };
  85. /**
  86. * Translates this point by the given vector.
  87. *
  88. * @param {number} dx X-coordinate of the translation.
  89. * @param {number} dy Y-coordinate of the translation.
  90. */
  91. OneDriveFile.prototype.doSave = function(title, success, error)
  92. {
  93. DrawioFile.prototype.save.apply(this, arguments);
  94. this.saveFile(title, false, success, error);
  95. };
  96. /**
  97. * Translates this point by the given vector.
  98. *
  99. * @param {number} dx X-coordinate of the translation.
  100. * @param {number} dy Y-coordinate of the translation.
  101. */
  102. OneDriveFile.prototype.saveFile = function(title, revision, success, error)
  103. {
  104. if (!this.isEditable())
  105. {
  106. if (success != null)
  107. {
  108. success();
  109. }
  110. }
  111. else if (!this.savingFile)
  112. {
  113. this.savingFile = true;
  114. if (this.getTitle() == title)
  115. {
  116. // Makes sure no changes get lost while the file is saved
  117. var prevModified = this.isModified;
  118. var modified = this.isModified();
  119. this.setModified(false);
  120. this.ui.oneDrive.saveFile(this, mxUtils.bind(this, function(meta)
  121. {
  122. this.savingFile = false;
  123. this.isModified = prevModified;
  124. this.meta = meta;
  125. this.contentChanged();
  126. if (success != null)
  127. {
  128. success();
  129. }
  130. }),
  131. mxUtils.bind(this, function(resp)
  132. {
  133. this.savingFile = false;
  134. this.isModified = prevModified;
  135. this.setModified(modified || this.isModified());
  136. if (error != null)
  137. {
  138. error(resp);
  139. }
  140. }));
  141. }
  142. else
  143. {
  144. this.ui.oneDrive.insertFile(title, this.getData(), mxUtils.bind(this, function(file)
  145. {
  146. this.savingFile = false;
  147. if (success != null)
  148. {
  149. success();
  150. }
  151. this.ui.fileLoaded(file);
  152. }),
  153. function()
  154. {
  155. this.savingFile = false;
  156. if (error != null)
  157. {
  158. error();
  159. }
  160. });
  161. }
  162. }
  163. else if (error != null)
  164. {
  165. error({code: App.ERROR_BUSY});
  166. }
  167. };
  168. /**
  169. * Translates this point by the given vector.
  170. *
  171. * @param {number} dx X-coordinate of the translation.
  172. * @param {number} dy Y-coordinate of the translation.
  173. */
  174. OneDriveFile.prototype.rename = function(title, success, error)
  175. {
  176. this.ui.oneDrive.renameFile(this, title, mxUtils.bind(this, function(meta)
  177. {
  178. if (!this.hasSameExtension(title, this.getTitle()))
  179. {
  180. this.meta = meta;
  181. this.save(true, success, error);
  182. }
  183. else
  184. {
  185. this.meta = meta;
  186. this.descriptorChanged();
  187. if (success != null)
  188. {
  189. success();
  190. }
  191. }
  192. }), error);
  193. };
  194. /**
  195. * Translates this point by the given vector.
  196. *
  197. * @param {number} dx X-coordinate of the translation.
  198. * @param {number} dy Y-coordinate of the translation.
  199. */
  200. OneDriveFile.prototype.move = function(folderId, success, error)
  201. {
  202. this.ui.oneDrive.moveFile(this.meta.id, folderId, mxUtils.bind(this, function(meta)
  203. {
  204. this.meta = meta;
  205. this.descriptorChanged();
  206. if (success != null)
  207. {
  208. success(meta);
  209. }
  210. }), error);
  211. };