diff options
| author | hukl <contact@smyck.org> | 2009-04-16 12:14:45 +0200 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-04-16 12:14:45 +0200 |
| commit | 7fe358bfb11f1cba4ee9237c4ef4b7efc3cfba87 (patch) | |
| tree | a4ee5095b0ff151891d0ec402dc5b00bedb9a565 | |
| parent | 7176edae9b93eb00e7982ec2d9a69f5b28633907 (diff) | |
added autosave to node edit view. saves every 15 seconds
| -rw-r--r-- | app/controllers/nodes_controller.rb | 7 | ||||
| -rw-r--r-- | app/views/layouts/admin.html.erb | 2 | ||||
| -rw-r--r-- | app/views/nodes/_autosave.html.erb | 6 | ||||
| -rw-r--r-- | app/views/nodes/edit.html.erb | 2 | ||||
| -rw-r--r-- | app/views/nodes/update.js.erb | 3 | ||||
| -rw-r--r-- | public/images/ajax-loader.gif | bin | 0 -> 1737 bytes | |||
| -rw-r--r-- | public/javascripts/admin_interface.js | 14 | ||||
| -rw-r--r-- | public/stylesheets/admin.css | 28 |
8 files changed, 56 insertions, 6 deletions
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index 1796090..aba132b 100644 --- a/app/controllers/nodes_controller.rb +++ b/app/controllers/nodes_controller.rb | |||
| @@ -58,8 +58,11 @@ class NodesController < ApplicationController | |||
| 58 | @draft = @node.find_or_create_draft current_user | 58 | @draft = @node.find_or_create_draft current_user |
| 59 | @draft.tag_list = params[:tag_list] | 59 | @draft.tag_list = params[:tag_list] |
| 60 | if @draft.update_attributes( params[:page] ) | 60 | if @draft.update_attributes( params[:page] ) |
| 61 | flash[:notice] = "Draft has been updated" | 61 | flash[:notice] = "Draft has been saved: #{Time.now}" |
| 62 | redirect_to edit_node_path(@node) | 62 | respond_to do |format| |
| 63 | format.html { redirect_to edit_node_path(@node) } | ||
| 64 | format.js | ||
| 65 | end | ||
| 63 | else | 66 | else |
| 64 | render :action => :edit | 67 | render :action => :edit |
| 65 | end | 68 | end |
diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 469b18e..1fb9c2b 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb | |||
| @@ -7,8 +7,8 @@ | |||
| 7 | 7 | ||
| 8 | <title><%= "#{params[:controller]} | #{params[:action]}" %></title> | 8 | <title><%= "#{params[:controller]} | #{params[:action]}" %></title> |
| 9 | <%= stylesheet_link_tag 'admin' %> | 9 | <%= stylesheet_link_tag 'admin' %> |
| 10 | <%= javascript_include_tag 'tiny_mce/tiny_mce.js' %> | ||
| 11 | <%= javascript_include_tag 'jquery-1.3.2.min' %> | 10 | <%= javascript_include_tag 'jquery-1.3.2.min' %> |
| 11 | <%= javascript_include_tag 'tiny_mce/tiny_mce.js' %> | ||
| 12 | <%= javascript_include_tag 'admin_interface.js' %> | 12 | <%= javascript_include_tag 'admin_interface.js' %> |
| 13 | 13 | ||
| 14 | <script type="text/javascript"> | 14 | <script type="text/javascript"> |
diff --git a/app/views/nodes/_autosave.html.erb b/app/views/nodes/_autosave.html.erb new file mode 100644 index 0000000..583b374 --- /dev/null +++ b/app/views/nodes/_autosave.html.erb | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | |||
| 2 | <script type="text/javascript" charset="utf-8"> | ||
| 3 | $(document).ready(function() { | ||
| 4 | setInterval('$("#edit_node_<%= @node.id %>").submitWithAjax()', 15000); | ||
| 5 | }); | ||
| 6 | </script> \ No newline at end of file | ||
diff --git a/app/views/nodes/edit.html.erb b/app/views/nodes/edit.html.erb index d8fb8b4..0d0b0d3 100644 --- a/app/views/nodes/edit.html.erb +++ b/app/views/nodes/edit.html.erb | |||
| @@ -5,6 +5,8 @@ | |||
| 5 | <%= link_to 'Revisions', revision_path(params[:id]) %> | 5 | <%= link_to 'Revisions', revision_path(params[:id]) %> |
| 6 | <% end %> | 6 | <% end %> |
| 7 | 7 | ||
| 8 | <%= render :partial => 'autosave' %> | ||
| 9 | |||
| 8 | <div id="page_editor"> | 10 | <div id="page_editor"> |
| 9 | <% form_for(@node) do |f| %> | 11 | <% form_for(@node) do |f| %> |
| 10 | <%= f.error_messages %> | 12 | <%= f.error_messages %> |
diff --git a/app/views/nodes/update.js.erb b/app/views/nodes/update.js.erb new file mode 100644 index 0000000..be26fab --- /dev/null +++ b/app/views/nodes/update.js.erb | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | $("#flash").html( | ||
| 2 | "<span><%= escape_javascript(flash.delete(:notice)) %></span>" | ||
| 3 | ); \ No newline at end of file | ||
diff --git a/public/images/ajax-loader.gif b/public/images/ajax-loader.gif new file mode 100644 index 0000000..148005d --- /dev/null +++ b/public/images/ajax-loader.gif | |||
| Binary files differ | |||
diff --git a/public/javascripts/admin_interface.js b/public/javascripts/admin_interface.js index 5b51dfc..12a3ba6 100644 --- a/public/javascripts/admin_interface.js +++ b/public/javascripts/admin_interface.js | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | $(document).ready(function () { | 1 | $(document).ready(function () { |
| 2 | $("#metadata").attr("style", "display: none;") | 2 | $("#metadata").attr("style", "display: none;"); |
| 3 | 3 | ||
| 4 | $("#button").click(function () { | 4 | $("#button").click(function () { |
| 5 | $("#metadata").slideToggle("slow"); | 5 | $("#metadata").slideToggle("slow"); |
| @@ -11,4 +11,16 @@ $(document).ready(function () { | |||
| 11 | $("#button").attr("class", "unselected"); | 11 | $("#button").attr("class", "unselected"); |
| 12 | } | 12 | } |
| 13 | }); | 13 | }); |
| 14 | |||
| 15 | jQuery.ajaxSetup({ | ||
| 16 | 'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")} | ||
| 17 | }) | ||
| 18 | |||
| 19 | jQuery.fn.submitWithAjax = function() { | ||
| 20 | $("#flash").append("<img src='/images/ajax-loader.gif' alt='' />"); | ||
| 21 | $.post(this.attr("action"), $(this).serialize(), null, "script"); | ||
| 22 | }; | ||
| 23 | |||
| 24 | |||
| 25 | |||
| 14 | }); \ No newline at end of file | 26 | }); \ No newline at end of file |
diff --git a/public/stylesheets/admin.css b/public/stylesheets/admin.css index c3030d6..0495f65 100644 --- a/public/stylesheets/admin.css +++ b/public/stylesheets/admin.css | |||
| @@ -23,6 +23,25 @@ th { | |||
| 23 | width: 899px; | 23 | width: 899px; |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | #flash { | ||
| 27 | height: 12px; | ||
| 28 | line-height: 20px; | ||
| 29 | margin-top: 40px; | ||
| 30 | margin-bottom: 20px; | ||
| 31 | margin-left: 5px; | ||
| 32 | } | ||
| 33 | |||
| 34 | #flash span { | ||
| 35 | letter-spacing: 1px; | ||
| 36 | margin-right: 10px; | ||
| 37 | } | ||
| 38 | |||
| 39 | |||
| 40 | #flash img { | ||
| 41 | height: 12px; | ||
| 42 | width: 12px; | ||
| 43 | } | ||
| 44 | |||
| 26 | /* Pagination */ | 45 | /* Pagination */ |
| 27 | 46 | ||
| 28 | div.pagination { | 47 | div.pagination { |
| @@ -41,7 +60,7 @@ div.pagination span.current, div.pagination a:hover { | |||
| 41 | } | 60 | } |
| 42 | 61 | ||
| 43 | #navigation { | 62 | #navigation { |
| 44 | margin-left: -5px; | 63 | margin-left: 0px; |
| 45 | float: left; | 64 | float: left; |
| 46 | } | 65 | } |
| 47 | 66 | ||
| @@ -104,6 +123,11 @@ table#node_table td { | |||
| 104 | padding-left: 0px; | 123 | padding-left: 0px; |
| 105 | } | 124 | } |
| 106 | 125 | ||
| 126 | table#node_table .node_id { | ||
| 127 | padding-left: 10px; | ||
| 128 | padding-right: 15px; | ||
| 129 | } | ||
| 130 | |||
| 107 | table#node_table tr.header:hover { | 131 | table#node_table tr.header:hover { |
| 108 | background-color: #ffffff; | 132 | background-color: #ffffff; |
| 109 | } | 133 | } |
| @@ -218,6 +242,6 @@ td.description { | |||
| 218 | } | 242 | } |
| 219 | 243 | ||
| 220 | div#page_editor { | 244 | div#page_editor { |
| 221 | margin-top: 40px; | 245 | margin-top: 0px; |
| 222 | margin-left: 15px; | 246 | margin-left: 15px; |
| 223 | } \ No newline at end of file | 247 | } \ No newline at end of file |
