From 460e992f327a4698e9b59f5a9c304fd82e5a02a6 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 30 Dec 2012 18:50:23 -0500 Subject: [PATCH 1/7] added best_in_place gem --- Gemfile | 2 +- Gemfile.lock | 4 + app/assets/javascripts/jquery.purr.js | 180 ++++++++++++++++++++++++++ 3 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/jquery.purr.js diff --git a/Gemfile b/Gemfile index e0b8da89..23498fc9 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,7 @@ gem 'formula' gem 'formtastic' gem 'json' gem 'rails3-jquery-autocomplete' - +gem 'best_in_place' # Gems used only for assets and not required # in production environments by default. diff --git a/Gemfile.lock b/Gemfile.lock index df90c20c..b2a6b86e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -32,6 +32,9 @@ GEM authlogic (3.1.0) activerecord (>= 3.0.7) activerecord (>= 3.0.7) + best_in_place (2.0.2) + jquery-rails + rails (~> 3.1) builder (3.0.3) cancan (1.6.7) coffee-rails (3.2.2) @@ -118,6 +121,7 @@ PLATFORMS DEPENDENCIES authlogic + best_in_place cancan coffee-rails (~> 3.2.1) formtastic diff --git a/app/assets/javascripts/jquery.purr.js b/app/assets/javascripts/jquery.purr.js new file mode 100644 index 00000000..5acdab50 --- /dev/null +++ b/app/assets/javascripts/jquery.purr.js @@ -0,0 +1,180 @@ +/** + * jquery.purr.js + * Copyright (c) 2008 Net Perspective (net-perspective.com) + * Licensed under the MIT License (http://www.opensource.org/licenses/mit-license.php) + * + * @author R.A. Ray + * @projectDescription jQuery plugin for dynamically displaying unobtrusive messages in the browser. Mimics the behavior of the MacOS program "Growl." + * @version 0.1.0 + * + * @requires jquery.js (tested with 1.2.6) + * + * @param fadeInSpeed int - Duration of fade in animation in miliseconds + * default: 500 + * @param fadeOutSpeed int - Duration of fade out animationin miliseconds + default: 500 + * @param removeTimer int - Timeout, in miliseconds, before notice is removed once it is the top non-sticky notice in the list + default: 4000 + * @param isSticky bool - Whether the notice should fade out on its own or wait to be manually closed + default: false + * @param usingTransparentPNG bool - Whether or not the notice is using transparent .png images in its styling + default: false + */ + +( function( $ ) { + + $.purr = function ( notice, options ) + { + // Convert notice to a jQuery object + notice = $( notice ); + + // Add a class to denote the notice as not sticky + if ( !options.isSticky ) + { + notice.addClass( 'not-sticky' ); + }; + + // Get the container element from the page + var cont = document.getElementById( 'purr-container' ); + + // If the container doesn't yet exist, we need to create it + if ( !cont ) + { + cont = '
'; + } + + // Convert cont to a jQuery object + cont = $( cont ); + + // Add the container to the page + $( 'body' ).append( cont ); + + notify(); + + function notify () + { + // Set up the close button + var close = document.createElement( 'a' ); + $( close ).attr( + { + className: 'close', + href: '#close', + innerHTML: 'Close' + } + ) + .appendTo( notice ) + .click( function () + { + removeNotice(); + + return false; + } + ); + + // Add the notice to the page and keep it hidden initially + notice.appendTo( cont ) + .hide(); + + if ( jQuery.browser.msie && options.usingTransparentPNG ) + { + // IE7 and earlier can't handle the combination of opacity and transparent pngs, so if we're using transparent pngs in our + // notice style, we'll just skip the fading in. + notice.show(); + } + else + { + //Fade in the notice we just added + notice.fadeIn( options.fadeInSpeed ); + } + + // Set up the removal interval for the added notice if that notice is not a sticky + if ( !options.isSticky ) + { + var topSpotInt = setInterval( function () + { + // Check to see if our notice is the first non-sticky notice in the list + if ( notice.prevAll( '.not-sticky' ).length == 0 ) + { + // Stop checking once the condition is met + clearInterval( topSpotInt ); + + // Call the close action after the timeout set in options + setTimeout( function () + { + removeNotice(); + }, options.removeTimer + ); + } + }, 200 ); + } + } + + function removeNotice () + { + // IE7 and earlier can't handle the combination of opacity and transparent pngs, so if we're using transparent pngs in our + // notice style, we'll just skip the fading out. + if ( jQuery.browser.msie && options.usingTransparentPNG ) + { + notice.css( { opacity: 0 } ) + .animate( + { + height: '0px' + }, + { + duration: options.fadeOutSpeed, + complete: function () + { + notice.remove(); + } + } + ); + } + else + { + // Fade the object out before reducing its height to produce the sliding effect + notice.animate( + { + opacity: '0' + }, + { + duration: options.fadeOutSpeed, + complete: function () + { + notice.animate( + { + height: '0px' + }, + { + duration: options.fadeOutSpeed, + complete: function () + { + notice.remove(); + } + } + ); + } + } + ); + } + }; + }; + + $.fn.purr = function ( options ) + { + options = options || {}; + options.fadeInSpeed = options.fadeInSpeed || 500; + options.fadeOutSpeed = options.fadeOutSpeed || 500; + options.removeTimer = options.removeTimer || 4000; + options.isSticky = options.isSticky || false; + options.usingTransparentPNG = options.usingTransparentPNG || false; + + this.each( function() + { + new $.purr( this, options ); + } + ); + + return this; + }; +})( jQuery ); + From a7412cd1623468ebb4001e69cb93d787f3fe0576 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 30 Dec 2012 22:56:05 -0500 Subject: [PATCH 2/7] initialization code for best_in_place --- app/assets/javascripts/application.js | 2 ++ app/assets/javascripts/items.js.coffee | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index fcdd7576..d2332f6c 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,6 +12,8 @@ // //= require jquery //= require jquery-ui +//= require jquery.purr +//= require best_in_place //= require autocomplete-rails-uncompressed //= require jquery_ujs //= require_tree . diff --git a/app/assets/javascripts/items.js.coffee b/app/assets/javascripts/items.js.coffee index 416905ae..854c5d55 100644 --- a/app/assets/javascripts/items.js.coffee +++ b/app/assets/javascripts/items.js.coffee @@ -1,3 +1,6 @@ # Place all the behaviors and hooks related to the matching controller here. # All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ \ No newline at end of file +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ + +jQuery -> + $('.best_in_place').best_in_place() From abe34696da64ec22df67442481868d305df34818 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 30 Dec 2012 23:04:30 -0500 Subject: [PATCH 3/7] added an empty div at the bottom of the page containing nodes --- app/assets/stylesheets/application.css | 12 ++++++++++++ app/views/layouts/_nodeinfo.html.erb | 5 +++++ app/views/layouts/application.html.erb | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 app/views/layouts/_nodeinfo.html.erb diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 17610708..fc1f50e7 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -73,10 +73,22 @@ a { text-decoration:none; } +/* + * Utility + */ + .clearfloat { clear:both; } +.hidden { + display: none; +} + +/* + * Layout stuffs + */ + .new_session, .new_user, .new_map, diff --git a/app/views/layouts/_nodeinfo.html.erb b/app/views/layouts/_nodeinfo.html.erb new file mode 100644 index 00000000..fb41da0d --- /dev/null +++ b/app/views/layouts/_nodeinfo.html.erb @@ -0,0 +1,5 @@ + + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 4e99c171..2c28686a 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -60,5 +60,6 @@ <% end %> <%= render :partial => 'layouts/ga' if Rails.env.production? %> + <%= render :partial => 'layouts/nodeinfo' %> - \ No newline at end of file + From 5d552a5d0086e8fb425dbadeac9f20f496c48ea5 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 30 Dec 2012 23:05:33 -0500 Subject: [PATCH 4/7] added showcard partial view to items so we can load them with AJAX...\! --- app/views/items/_showcard.html.erb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 app/views/items/_showcard.html.erb diff --git a/app/views/items/_showcard.html.erb b/app/views/items/_showcard.html.erb new file mode 100644 index 00000000..69eec1de --- /dev/null +++ b/app/views/items/_showcard.html.erb @@ -0,0 +1,27 @@ +
+
+

+ <%= node.getData("itemcatname") %> +

+ <%= node.getData(" class="icon" height="50" src="<%= imgArray[node.getData("itemcatname")].src %>" width="50" /> +
+ + <%= node.name %> + + +
+

+ <%= node.getData('desc') %> +

+
+
+ + <%= node.getData('link') %> + +
+
From 8d1171c2c8d294b40f780eb3b74c2d789f5eb994 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 30 Dec 2012 23:30:18 -0500 Subject: [PATCH 5/7] made showcard into a non-partial view, in desperation --- app/controllers/items_controller.rb | 24 +++++++++++++++++------- app/views/items/_showcard.html.erb | 27 --------------------------- app/views/items/showcard.html.erb | 29 +++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 34 deletions(-) delete mode 100644 app/views/items/_showcard.html.erb create mode 100644 app/views/items/showcard.html.erb diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 90b7231d..b21a21f1 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -33,19 +33,29 @@ class ItemsController < ApplicationController # GET items/:id def show @current = current_user - @item = Item.find(params[:id]).authorize_to_show(@current) + @item = Item.find(params[:id]).authorize_to_show(@current) - if @item - @relatives = @item.network_as_json(@current).html_safe - else - redirect_to root_url and return - end + if @item + @relatives = @item.network_as_json(@current).html_safe + else + redirect_to root_url and return + end - respond_to do |format| + respond_to do |format| format.html { respond_with(@item, @user) } format.json { respond_with(@relatives) } end end + + # GET showcard/:id + def showcard + @current = current_user + @item = Item.find(params[:id]).authorize_to_show(@current) + + respond_to do |format| + format.json { respond_with(@item) } + end + end # POST items def create diff --git a/app/views/items/_showcard.html.erb b/app/views/items/_showcard.html.erb deleted file mode 100644 index 69eec1de..00000000 --- a/app/views/items/_showcard.html.erb +++ /dev/null @@ -1,27 +0,0 @@ -
-
-

- <%= node.getData("itemcatname") %> -

- <%= node.getData(" class="icon" height="50" src="<%= imgArray[node.getData("itemcatname")].src %>" width="50" /> -
- - <%= node.name %> - - -
-

- <%= node.getData('desc') %> -

-
-
- - <%= node.getData('link') %> - -
-
diff --git a/app/views/items/showcard.html.erb b/app/views/items/showcard.html.erb new file mode 100644 index 00000000..a1d0c508 --- /dev/null +++ b/app/views/items/showcard.html.erb @@ -0,0 +1,29 @@ +
+
+

+ <%= @item.item_category.name %> +

+ <%= @item.item_category.name %> +
+ + <%= node.name %> + + +
+

+ <%= @item.desc %> +

+
+
+ + <%= @item.link %> + +
+
From ae95cbf6f4aa2bd468eae02c6014027f0e9cb600 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 30 Dec 2012 23:33:08 -0500 Subject: [PATCH 6/7] I did something with config/routes.rb and now showcard/1 shows an empty html page instead of giving an error --- config/routes.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 6fac3130..cd1dafda 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,7 +9,9 @@ ISSAD::Application.routes.draw do match 'search', to: 'main#search', via: :get, as: :search match 'maps/:id/savelayout', to: 'maps#savelayout', via: :put, as: :savelayout - + + match 'showcard/:id', to: 'items#showcard', via: :get, as: :showcard + resource :session resources :items do From be1323ce85e2b54c35cdab8f8ea67ff9d4d39ce0 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 30 Dec 2012 23:40:43 -0500 Subject: [PATCH 7/7] got some hacky way of having the showcard show up on the page. TODO: figure out how to drop the application.html wrapper stuff and how to get this into Javascript --- app/controllers/items_controller.rb | 6 +++--- app/views/items/showcard.html.erb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index b21a21f1..9f122669 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -49,11 +49,11 @@ class ItemsController < ApplicationController # GET showcard/:id def showcard - @current = current_user - @item = Item.find(params[:id]).authorize_to_show(@current) + @user = current_user + @item = Item.find(params[:id]).authorize_to_show(@user) respond_to do |format| - format.json { respond_with(@item) } + format.html { respond_with(@item, @user) } end end diff --git a/app/views/items/showcard.html.erb b/app/views/items/showcard.html.erb index a1d0c508..11dfe657 100644 --- a/app/views/items/showcard.html.erb +++ b/app/views/items/showcard.html.erb @@ -8,12 +8,12 @@ class="icon" height="50" width="50" />