|
11 | 11 | <div id="filemanager-editor">
|
12 | 12 | </div>
|
13 | 13 | <div id="technique-editor">
|
| 14 | + </div> |
14 | 15 | <script>
|
15 | 16 | var hasWriteRights = false;
|
16 | 17 | </script>
|
|
101 | 102 | });
|
102 | 103 |
|
103 | 104 | app.ports.storeDraft.subscribe(function(draft) {
|
104 |
| - draft.date = new Date().toISOString(); |
105 |
| - var drafts = JSON.parse(localStorage.getItem("drafts")) |
106 |
| - if (drafts === null) { drafts = {} } |
107 |
| - drafts[draft.id] = draft; |
108 |
| - localStorage.setItem("drafts", JSON.stringify(drafts)); |
| 105 | + try { |
| 106 | + draft.date = new Date().toISOString(); |
| 107 | + var drafts = JSON.parse(localStorage.getItem("drafts")) |
| 108 | + if (drafts === null) { drafts = {} } |
| 109 | + drafts[draft.id] = draft; |
| 110 | + localStorage.setItem("drafts", JSON.stringify(drafts)); |
| 111 | + } catch (error) { |
| 112 | + createErrorNotification("An error occurred while saving technique draft, it will not be persisted in your browser.\nYou can try to clean your browser local storage, but you'll lose existing drafts.\nError details: " + error) ; |
| 113 | + } |
109 | 114 | });
|
110 | 115 |
|
111 | 116 | app.ports.clearDraft.subscribe(function(key) {
|
112 |
| - var drafts = JSON.parse(localStorage.getItem("drafts")); |
113 |
| - delete drafts[key]; |
114 |
| - localStorage.setItem("drafts", JSON.stringify(drafts)); |
| 117 | + try { |
| 118 | + var drafts = JSON.parse(localStorage.getItem("drafts")); |
| 119 | + delete drafts[key]; |
| 120 | + localStorage.setItem("drafts", JSON.stringify(drafts)); |
| 121 | + } catch (error) { |
| 122 | + createErrorNotification("An error occurred while removing draft for technique '" + key +"'.\nYou can try to clean your browser local storage, but you'll lose existing drafts.\nError details: " + error) ; |
| 123 | + } |
115 | 124 | });
|
116 | 125 |
|
117 | 126 | app.ports.getDrafts.subscribe(function() {
|
118 |
| - var drafts = JSON.parse(localStorage.getItem("drafts")) |
119 |
| - if (drafts === null) { drafts = {} } |
120 |
| - app.ports.draftsResponse.send(drafts) |
| 127 | + try { |
| 128 | + var drafts = JSON.parse(localStorage.getItem("drafts")) |
| 129 | + if (drafts === null) { drafts = {} } |
| 130 | + app.ports.draftsResponse.send(drafts) |
| 131 | + } catch (error) { |
| 132 | + createErrorNotification("An error occurred while getting drafts.\nYou can try to clean your browser local storage, but you'll lose existing drafts.\nError details: " + error) ; |
| 133 | + } |
121 | 134 | });
|
122 | 135 | app.ports.successNotification.subscribe(function(str) {
|
123 | 136 | createSuccessNotification(str)
|
|
174 | 187 | return false;
|
175 | 188 | }
|
176 | 189 | </script>
|
177 |
| - </div> |
178 | 190 | </div>
|
179 | 191 | </lift:surround>
|
0 commit comments