casey_jones 0.0.106 → 0.0.107

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,27 +10,22 @@ module AjaxLoading
10
10
  "$.growl('#{title}', '#{msg}', 'images/growl/#{type}.png');"
11
11
  end
12
12
 
13
- def loadbehind_link(name, object, association, options={})
13
+ # For loading associated objects.
14
+ def ajax_association_link(name, object, association, options={})
14
15
  # This should go to the controller for the association class!
15
16
  ass_info = object.class.reflect_on_association(association)
16
17
  ass_controller = options[:controller] ||= ass_info.klass.name.tableize
17
- controller_action = (ass_info.macro==:belongs_to) ? :show : :index
18
+ options[:controller] ||= ass_controller
19
+ options[:container] ||= object.element_id(association)
18
20
 
19
21
  if ass_info.macro == :belongs_to
20
- link_to name, :controller=>ass_controller,
21
- :action=>:show,
22
- :id=>object.send(ass_info.association_foreign_key),
23
- :container=>object.element_id(association),
24
- :remote=>true
22
+ options[:id] ||= object.send(ass_info.association_foreign_key)
23
+ options[:action] ||= :show
25
24
  else
26
- form_tag({:controller=>ass_controller, :action=>:index},
27
- :method=>:get, :remote=>true, :id=>object.element_id(:show, association)) do
28
- concat hidden_field(:associated, :class_name, :value=>object.class.name) +
29
- hidden_field(:associated, :id, :value=>object.id) +
30
- hidden_field(:associated, :association, :value=>association.to_s) +
31
- link_to(name,{},{:href=>"#", "data-submit"=>object.element_id(:show, association)})
32
- end
25
+ options[object.class.name.foreign_key] ||= object.id
26
+ options[:action] ||= :index
33
27
  end
28
+ link_to name, options, :remote=> true
34
29
  end
35
30
  end
36
31
  end
@@ -2,7 +2,7 @@ class LoadbehindGenerator < Rails::Generators::NamedBase
2
2
  source_root File.expand_path('../templates', __FILE__)
3
3
 
4
4
  IMAGES=["error", "growl_bottom", "growl_repeat", "growl_top", "info"]
5
- JAVASCRIPTS=["loadbehind", "jquery.growl"]
5
+ JAVASCRIPTS=["loadbehind", "jquery.growl", "jquery.ajax.enhance"]
6
6
 
7
7
  def generate_loadbehind
8
8
  view_dir = "app/views/#{plural_name}"
@@ -32,6 +32,11 @@ class LoadbehindGenerator < Rails::Generators::NamedBase
32
32
  template "#{file}.haml", "#{view_dir}/#{file}.haml"
33
33
  end
34
34
 
35
+ puts "Add the following code to your layout..."
36
+ JAVASCRIPTS.each do |j|
37
+ puts " = javascript_include_tag \"#{j}.js\""
38
+ end
39
+
35
40
  puts "**** Remember to add loadbehind.js and jquery.growl.js to the
36
41
  javascript tags, or add it to your own js files.
37
42
  You'll also need to add handling to see that all your
@@ -1,4 +1,4 @@
1
- $('##{@container}').html(#{raw render_js('<%= action_name%>')});
1
+ $('##{@container}').#{@ajax_function}(#{raw render_js('<%= action_name%>')});
2
2
  setUpDocument($('##{@container}'));
3
3
  - if @<%= singular_name %>.errors.any?
4
4
  = growl('Error', raw(render_js('errors')), :error)
@@ -0,0 +1,101 @@
1
+ /*!
2
+ * jQuery AJAX Enchance v0.9
3
+ * http://blog.istvan-antal.ro/
4
+ *
5
+ * Copyright 2010, István Miklós Antal
6
+ * Dual licensed under the MIT or GPL Version 3 licenses.
7
+ * see: license/mit.txt or license/gpl-3.0.txt
8
+ *
9
+ */
10
+
11
+ (function($,window,document,undefined) {
12
+
13
+ //function that thandles both POST and GET methods
14
+ var sendGeneric = function(method,url,func,dataType) {
15
+ //sort arguments
16
+ if ($.isFunction( url )) {
17
+ dataType = func;
18
+ func = url;
19
+ url = undefined;
20
+ }
21
+
22
+ if (func==undefined) {
23
+ func = $.noop;
24
+ }
25
+
26
+ //filter out non form elements
27
+ this.filter('form');
28
+
29
+ //filter out actioneless elements if URL was not specified
30
+ if (url==undefined) {
31
+ this.filter('[action]');
32
+ }
33
+
34
+ //abort if no elements found
35
+ if ( !this.length ) {
36
+ return this;
37
+ }
38
+
39
+
40
+
41
+ //execute
42
+ this.each(function() {
43
+ var aurl = url || $(this).attr('action');
44
+
45
+ switch (method) {
46
+ case 'post':
47
+ $.post(aurl, $(this).serialize(), function(data) {
48
+ func.call(this,data);
49
+ },dataType);
50
+ break;
51
+ case 'upload':
52
+ //check for YUI Connect
53
+ if (YAHOO && YAHOO.util && YAHOO.util.Connect) {
54
+ YAHOO.util.Connect.setForm(this, true);
55
+ YAHOO.util.Connect.asyncRequest('POST', aurl, {
56
+ upload: function(response) {
57
+ var data = response.responseText;
58
+ //Don't really feel that other data types actually make sense here
59
+ switch (dataType) {
60
+ case 'json':
61
+ data = $.parseJSON(data);
62
+ break;
63
+ case 'xml':
64
+ data = response.responseXML;
65
+ break;
66
+ default:
67
+ data = response.responseText;
68
+ }
69
+ func.call(this,data);
70
+ }
71
+ });
72
+ } else {
73
+ throw 'Uploading requires YUI Connection Manager';
74
+ }
75
+ break;
76
+ default:
77
+ $.get(aurl, $(this).serialize(), function(data) {
78
+ func.call(this,data);
79
+ },dataType);
80
+
81
+ }
82
+ });
83
+
84
+ //return
85
+ return this;
86
+ }
87
+
88
+ //Extend jQuery method space
89
+ $.fn.extend({
90
+ ajaxPost: function(url,func,dataType) {
91
+ sendGeneric.call(this,'post',url,func,dataType);
92
+ },
93
+ ajaxGet: function(url,func,dataType) {
94
+ sendGeneric.call(this,'get',url,func,dataType);
95
+ },
96
+ ajaxUpload: function(url,func,dataType) {
97
+ sendGeneric.call(this,'upload',url,func,dataType);
98
+ }
99
+ });
100
+
101
+ }(jQuery,window,document));
@@ -1,4 +1,4 @@
1
- $('##{@container}').html(#{raw render_js('<%= action_name%>')});
1
+ $('##{@container}').#{@ajax_function}(#{raw render_js('<%= action_name%>')});
2
2
  setUpDocument($('##{@container}'));
3
3
  - unless flash[:notice].empty?
4
4
  = growl("Success", flash[:notice])
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: casey_jones
3
3
  version: !ruby/object:Gem::Version
4
- hash: 203
4
+ hash: 201
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 106
10
- version: 0.0.106
9
+ - 107
10
+ version: 0.0.107
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tyler Gannon
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-23 00:00:00 -07:00
18
+ date: 2010-07-24 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -55,8 +55,12 @@ files:
55
55
  - lib/generators/loadbehind/templates/images/growl_repeat.png
56
56
  - lib/generators/loadbehind/templates/images/growl_top.png
57
57
  - lib/generators/loadbehind/templates/images/info.png
58
+ - lib/generators/loadbehind/templates/jquery.ajax.enhance.js
58
59
  - lib/generators/loadbehind/templates/jquery.growl.js
59
60
  - lib/generators/loadbehind/templates/loadbehind.js
61
+ - lib/generators/loadbehind/templates/showHide_border.gif
62
+ - lib/generators/loadbehind/templates/showHide_hide_box.gif
63
+ - lib/generators/loadbehind/templates/showHide_show_box.gif
60
64
  - lib/generators/loadbehind/templates/view.js.haml
61
65
  - test/anaf_habtm_test.rb
62
66
  - test/test_helper.rb