Showing
1 changed file
with
68 additions
and
100 deletions
... | ... | @@ -8,10 +8,9 @@ |
8 | 8 | * @param {number} x X-coordinate of the point. |
9 | 9 | * @param {number} y Y-coordinate of the point. |
10 | 10 | */ |
11 | -LocalFile = function(ui, data, title, temp, fileHandle, desc) | |
12 | -{ | |
11 | +LocalFile = function (ui, data, title, temp, fileHandle, desc) { | |
13 | 12 | DrawioFile.call(this, ui, data); |
14 | - | |
13 | + | |
15 | 14 | this.title = title; |
16 | 15 | this.mode = (temp) ? null : App.MODE_DEVICE; |
17 | 16 | this.fileHandle = fileHandle; |
... | ... | @@ -27,8 +26,7 @@ mxUtils.extend(LocalFile, DrawioFile); |
27 | 26 | * @param {number} dx X-coordinate of the translation. |
28 | 27 | * @param {number} dy Y-coordinate of the translation. |
29 | 28 | */ |
30 | -LocalFile.prototype.isAutosave = function() | |
31 | -{ | |
29 | +LocalFile.prototype.isAutosave = function () { | |
32 | 30 | return this.fileHandle != null && !this.invalidFileHandle && DrawioFile.prototype.isAutosave.apply(this, arguments); |
33 | 31 | }; |
34 | 32 | |
... | ... | @@ -36,8 +34,7 @@ LocalFile.prototype.isAutosave = function() |
36 | 34 | * Specifies if the autosave checkbox should be shown in the document |
37 | 35 | * properties dialog. Default is false. |
38 | 36 | */ |
39 | -LocalFile.prototype.isAutosaveOptional = function() | |
40 | -{ | |
37 | +LocalFile.prototype.isAutosaveOptional = function () { | |
41 | 38 | return this.fileHandle != null; |
42 | 39 | }; |
43 | 40 | |
... | ... | @@ -47,8 +44,7 @@ LocalFile.prototype.isAutosaveOptional = function() |
47 | 44 | * @param {number} dx X-coordinate of the translation. |
48 | 45 | * @param {number} dy Y-coordinate of the translation. |
49 | 46 | */ |
50 | -LocalFile.prototype.getMode = function() | |
51 | -{ | |
47 | +LocalFile.prototype.getMode = function () { | |
52 | 48 | return this.mode; |
53 | 49 | }; |
54 | 50 | |
... | ... | @@ -58,8 +54,7 @@ LocalFile.prototype.getMode = function() |
58 | 54 | * @param {number} dx X-coordinate of the translation. |
59 | 55 | * @param {number} dy Y-coordinate of the translation. |
60 | 56 | */ |
61 | -LocalFile.prototype.getTitle = function() | |
62 | -{ | |
57 | +LocalFile.prototype.getTitle = function () { | |
63 | 58 | return this.title; |
64 | 59 | }; |
65 | 60 | |
... | ... | @@ -69,8 +64,7 @@ LocalFile.prototype.getTitle = function() |
69 | 64 | * @param {number} dx X-coordinate of the translation. |
70 | 65 | * @param {number} dy Y-coordinate of the translation. |
71 | 66 | */ |
72 | -LocalFile.prototype.isRenamable = function() | |
73 | -{ | |
67 | +LocalFile.prototype.isRenamable = function () { | |
74 | 68 | return true; |
75 | 69 | }; |
76 | 70 | |
... | ... | @@ -80,8 +74,7 @@ LocalFile.prototype.isRenamable = function() |
80 | 74 | * @param {number} dx X-coordinate of the translation. |
81 | 75 | * @param {number} dy Y-coordinate of the translation. |
82 | 76 | */ |
83 | -LocalFile.prototype.save = function(revision, success, error) | |
84 | -{ | |
77 | +LocalFile.prototype.save = function (revision, success, error) { | |
85 | 78 | this.saveAs(this.title, success, error); |
86 | 79 | }; |
87 | 80 | |
... | ... | @@ -91,8 +84,7 @@ LocalFile.prototype.save = function(revision, success, error) |
91 | 84 | * @param {number} dx X-coordinate of the translation. |
92 | 85 | * @param {number} dy Y-coordinate of the translation. |
93 | 86 | */ |
94 | -LocalFile.prototype.saveAs = function(title, success, error) | |
95 | -{ | |
87 | +LocalFile.prototype.saveAs = function (title, success, error) { | |
96 | 88 | this.saveFile(title, false, success, error); |
97 | 89 | }; |
98 | 90 | |
... | ... | @@ -102,24 +94,21 @@ LocalFile.prototype.saveAs = function(title, success, error) |
102 | 94 | * @param {number} dx X-coordinate of the translation. |
103 | 95 | * @param {number} dy Y-coordinate of the translation. |
104 | 96 | */ |
105 | -LocalFile.prototype.saveAs = function(title, success, error) | |
106 | -{ | |
97 | +LocalFile.prototype.saveAs = function (title, success, error) { | |
107 | 98 | this.saveFile(title, false, success, error); |
108 | 99 | }; |
109 | 100 | |
110 | 101 | /** |
111 | 102 | * Adds all listeners. |
112 | 103 | */ |
113 | -LocalFile.prototype.getDescriptor = function() | |
114 | -{ | |
104 | +LocalFile.prototype.getDescriptor = function () { | |
115 | 105 | return this.desc; |
116 | 106 | }; |
117 | 107 | |
118 | 108 | /** |
119 | 109 | * Updates the descriptor of this file with the one from the given file. |
120 | 110 | */ |
121 | -LocalFile.prototype.setDescriptor = function(desc) | |
122 | -{ | |
111 | +LocalFile.prototype.setDescriptor = function (desc) { | |
123 | 112 | this.desc = desc; |
124 | 113 | }; |
125 | 114 | |
... | ... | @@ -129,14 +118,11 @@ LocalFile.prototype.setDescriptor = function(desc) |
129 | 118 | * @param {number} dx X-coordinate of the translation. |
130 | 119 | * @param {number} dy Y-coordinate of the translation. |
131 | 120 | */ |
132 | -LocalFile.prototype.getLatestVersion = function(success, error) | |
133 | -{ | |
134 | - if (this.fileHandle == null) | |
135 | - { | |
121 | +LocalFile.prototype.getLatestVersion = function (success, error) { | |
122 | + if (this.fileHandle == null) { | |
136 | 123 | success(null); |
137 | 124 | } |
138 | - else | |
139 | - { | |
125 | + else { | |
140 | 126 | this.ui.loadFileSystemEntry(this.fileHandle, success, error); |
141 | 127 | } |
142 | 128 | }; |
... | ... | @@ -147,69 +133,60 @@ LocalFile.prototype.getLatestVersion = function(success, error) |
147 | 133 | * @param {number} dx X-coordinate of the translation. |
148 | 134 | * @param {number} dy Y-coordinate of the translation. |
149 | 135 | */ |
150 | -LocalFile.prototype.saveFile = function(title, revision, success, error, useCurrentData) | |
151 | -{ | |
152 | - if (title != this.title) | |
153 | - { | |
136 | +LocalFile.prototype.saveFile = function (title, revision, success, error, useCurrentData) { | |
137 | + if (title != this.title) { | |
154 | 138 | this.fileHandle = null; |
155 | 139 | this.desc = null; |
156 | 140 | } |
157 | - | |
141 | + | |
158 | 142 | this.title = title; |
159 | 143 | |
160 | 144 | // Updates data after changing file name |
161 | - if (!useCurrentData) | |
162 | - { | |
145 | + if (!useCurrentData) { | |
163 | 146 | this.updateFileData(); |
164 | 147 | } |
165 | - | |
148 | + | |
166 | 149 | var binary = this.ui.useCanvasForExport && /(\.png)$/i.test(this.getTitle()); |
167 | 150 | this.setShadowModified(false); |
168 | 151 | var savedData = this.getData(); |
169 | - | |
170 | - var done = mxUtils.bind(this, function() | |
171 | - { | |
152 | + | |
153 | + var done = mxUtils.bind(this, function () { | |
172 | 154 | this.setModified(this.getShadowModified()); |
173 | 155 | this.contentChanged(); |
174 | - | |
175 | - if (success != null) | |
176 | - { | |
156 | + | |
157 | + if (success != null) { | |
177 | 158 | success(); |
178 | 159 | } |
179 | 160 | }); |
180 | - | |
181 | - var doSave = mxUtils.bind(this, function(data) | |
182 | - { | |
183 | - if (this.fileHandle != null) | |
184 | - { | |
161 | + | |
162 | + var doSave = mxUtils.bind(this, function (data) { | |
163 | + if (this.fileHandle != null) { | |
185 | 164 | // Sets shadow modified state during save |
186 | - if (!this.savingFile) | |
187 | - { | |
165 | + if (!this.savingFile) { | |
188 | 166 | this.savingFileTime = new Date(); |
189 | 167 | this.savingFile = true; |
190 | - | |
191 | - var errorWrapper = mxUtils.bind(this, function(e) | |
192 | - { | |
168 | + | |
169 | + var errorWrapper = mxUtils.bind(this, function (e) { | |
193 | 170 | this.savingFile = false; |
194 | - | |
195 | - if (error != null) | |
196 | - { | |
171 | + | |
172 | + if (error != null) { | |
197 | 173 | // Wraps error object to offer save status option |
198 | - error({error: e}); | |
174 | + error({ error: e }); | |
199 | 175 | } |
200 | 176 | }); |
201 | - | |
177 | + | |
202 | 178 | // Saves a copy as a draft while saving |
203 | 179 | this.saveDraft(); |
204 | 180 | // 修改开始 |
205 | - try | |
206 | - { | |
181 | + try { | |
207 | 182 | //调用API,保存数据到数据库 |
208 | - var desc = {name: Editor.configurationName, | |
209 | - type: "", | |
210 | - webkitRelativePath: "", | |
211 | - lastModified: new Date().getTime(), | |
212 | - lastModifiedDate: new Date()}; | |
183 | + var desc = { | |
184 | + name: Editor.configurationName, | |
185 | + type: "", | |
186 | + webkitRelativePath: "", | |
187 | + lastModified: new Date().getTime(), | |
188 | + lastModifiedDate: new Date() | |
189 | + }; | |
213 | 190 | this.savingFile = false; |
214 | 191 | this.desc = desc; |
215 | 192 | this.fileSaved(savedData, this.desc, done, errorWrapper); |
... | ... | @@ -217,17 +194,20 @@ LocalFile.prototype.saveFile = function(title, revision, success, error, useCurr |
217 | 194 | // Deletes draft after saving |
218 | 195 | this.removeDraft(); |
219 | 196 | Editor.defaultContent = savedData; |
220 | - var configurationContentList=[]; | |
221 | - var configurationContent = {"name":"第 1 页", | |
222 | - "id":Editor.configurationContentId,"content":savedData,"type":1}; | |
197 | + var configurationContentList = []; | |
198 | + var configurationContent = { | |
199 | + "name": "第 1 页", | |
200 | + "id": Editor.configurationContentId, | |
201 | + "content": savedData, | |
202 | + "type": 1 | |
203 | + }; | |
223 | 204 | configurationContentList.push(configurationContent); |
224 | - var parmam = {"configurationId":Editor.configurationId,"configurationContentList":configurationContentList}; | |
225 | - defHttp.put("/yt/configuration/content",parmam).then(res=>{ | |
205 | + var parmam = { "configurationId": Editor.configurationId, "configurationContentList": configurationContentList }; | |
206 | + defHttp.put("/yt/configuration/content", parmam).then(res => { | |
226 | 207 | console.log(res) |
227 | 208 | }) |
228 | 209 | } |
229 | - catch (e) | |
230 | - { | |
210 | + catch (e) { | |
231 | 211 | errorWrapper(e); |
232 | 212 | } |
233 | 213 | // 修改结束 |
... | ... | @@ -277,20 +257,16 @@ LocalFile.prototype.saveFile = function(title, revision, success, error, useCurr |
277 | 257 | // }), errorWrapper); |
278 | 258 | } |
279 | 259 | } |
280 | - else | |
281 | - { | |
282 | - if (this.ui.isOfflineApp() || this.ui.isLocalFileSave()) | |
283 | - { | |
260 | + else { | |
261 | + if (this.ui.isOfflineApp() || this.ui.isLocalFileSave()) { | |
284 | 262 | this.ui.doSaveLocalFile(data, title, (binary) ? |
285 | 263 | 'image/png' : 'text/xml', binary); |
286 | 264 | } |
287 | - else | |
288 | - { | |
289 | - if (data.length < MAX_REQUEST_SIZE) | |
290 | - { | |
265 | + else { | |
266 | + if (data.length < MAX_REQUEST_SIZE) { | |
291 | 267 | var dot = title.lastIndexOf('.'); |
292 | 268 | var format = (dot > 0) ? title.substring(dot + 1) : 'xml'; |
293 | - | |
269 | + | |
294 | 270 | // Do not update modified flag |
295 | 271 | new mxXmlRequest(SAVE_URL, 'format=' + format + |
296 | 272 | '&xml=' + encodeURIComponent(data) + |
... | ... | @@ -298,31 +274,26 @@ LocalFile.prototype.saveFile = function(title, revision, success, error, useCurr |
298 | 274 | ((binary) ? '&binary=1' : '')). |
299 | 275 | simulate(document, '_blank'); |
300 | 276 | } |
301 | - else | |
302 | - { | |
303 | - this.ui.handleError({message: mxResources.get('drawingTooLarge')}, mxResources.get('error'), mxUtils.bind(this, function() | |
304 | - { | |
277 | + else { | |
278 | + this.ui.handleError({ message: mxResources.get('drawingTooLarge') }, mxResources.get('error'), mxUtils.bind(this, function () { | |
305 | 279 | mxUtils.popup(data); |
306 | 280 | })); |
307 | 281 | } |
308 | 282 | } |
309 | - | |
283 | + | |
310 | 284 | done(); |
311 | 285 | } |
312 | 286 | }); |
313 | - | |
314 | - if (binary) | |
315 | - { | |
287 | + | |
288 | + if (binary) { | |
316 | 289 | var p = this.ui.getPngFileProperties(this.ui.fileNode); |
317 | 290 | |
318 | - this.ui.getEmbeddedPng(mxUtils.bind(this, function(imageData) | |
319 | - { | |
291 | + this.ui.getEmbeddedPng(mxUtils.bind(this, function (imageData) { | |
320 | 292 | doSave(imageData); |
321 | 293 | }), error, (this.ui.getCurrentFile() != this) ? |
322 | 294 | savedData : null, p.scale, p.border); |
323 | 295 | } |
324 | - else | |
325 | - { | |
296 | + else { | |
326 | 297 | doSave(savedData); |
327 | 298 | } |
328 | 299 | }; |
... | ... | @@ -333,13 +304,11 @@ LocalFile.prototype.saveFile = function(title, revision, success, error, useCurr |
333 | 304 | * @param {number} dx X-coordinate of the translation. |
334 | 305 | * @param {number} dy Y-coordinate of the translation. |
335 | 306 | */ |
336 | -LocalFile.prototype.rename = function(title, success, error) | |
337 | -{ | |
307 | +LocalFile.prototype.rename = function (title, success, error) { | |
338 | 308 | this.title = title; |
339 | 309 | this.descriptorChanged(); |
340 | - | |
341 | - if (success != null) | |
342 | - { | |
310 | + | |
311 | + if (success != null) { | |
343 | 312 | success(); |
344 | 313 | } |
345 | 314 | }; |
... | ... | @@ -348,8 +317,7 @@ LocalFile.prototype.rename = function(title, success, error) |
348 | 317 | * Returns the location as a new object. |
349 | 318 | * @type mx.Point |
350 | 319 | */ |
351 | -LocalFile.prototype.open = function() | |
352 | -{ | |
320 | +LocalFile.prototype.open = function () { | |
353 | 321 | this.ui.setFileData(this.getData()); |
354 | 322 | this.installListeners(); |
355 | 323 | }; | ... | ... |