diff options
Diffstat (limited to 'public/javascripts/admin_interface.js')
| -rw-r--r-- | public/javascripts/admin_interface.js | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/public/javascripts/admin_interface.js b/public/javascripts/admin_interface.js index 41699a1..4107ce8 100644 --- a/public/javascripts/admin_interface.js +++ b/public/javascripts/admin_interface.js | |||
| @@ -159,13 +159,45 @@ cccms = { | |||
| 159 | page.cached_abstract = elements.abstract.val(); | 159 | page.cached_abstract = elements.abstract.val(); |
| 160 | page.cached_body = elements.body.html(); | 160 | page.cached_body = elements.body.html(); |
| 161 | 161 | ||
| 162 | $("#flash").append("<img src='/images/ajax-loader.gif' alt='' />"); | 162 | var data = this.serializeArray().filter(function(field) { |
| 163 | $.post(this.attr("action"), $(this).serialize(), null, "script"); | 163 | return field.name !== "_method"; |
| 164 | }); | ||
| 165 | data.push({ name: "_method", value: "put" }); | ||
| 166 | |||
| 167 | $.ajax({ | ||
| 168 | type: "POST", | ||
| 169 | url: this.attr("data-autosave-url"), | ||
| 170 | data: data, | ||
| 171 | error: function(xhr) { | ||
| 172 | if (xhr.status === 423) { | ||
| 173 | clearInterval(cccms.autosave_timer); | ||
| 174 | cccms.report_lock_lost($("#page_editor > form").attr("data-show-url")); | ||
| 175 | } | ||
| 176 | // any other failure: quietly retried on the next tick | ||
| 177 | } | ||
| 178 | }); | ||
| 164 | 179 | ||
| 165 | } | 180 | } |
| 166 | }; | 181 | }; |
| 167 | 182 | ||
| 168 | setInterval('$("#page_editor > form").submitWithAjax()', 7000); | 183 | cccms.autosave_timer = setInterval(function() { |
| 184 | $("#page_editor > form").submitWithAjax(); | ||
| 185 | }, 7000); | ||
| 186 | }, | ||
| 187 | |||
| 188 | report_lock_lost : function(show_url) { | ||
| 189 | var $flash = $("#flash"); | ||
| 190 | if ($flash.length === 0) { | ||
| 191 | $flash = $("<div>", { id: "flash" }).insertAfter(".admin_content_spacer"); | ||
| 192 | } | ||
| 193 | |||
| 194 | var $banner = $("<span>", { "class": "warning" }).text( | ||
| 195 | "This page is now locked by someone else — your changes here can no longer be saved. Copy anything you need, then " | ||
| 196 | ); | ||
| 197 | $banner.append($("<a>", { href: show_url }).text("return to the published page")); | ||
| 198 | $banner.append("."); | ||
| 199 | |||
| 200 | $flash.html($banner); | ||
| 169 | } | 201 | } |
| 170 | } | 202 | } |
| 171 | 203 | ||
