togo 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -57,7 +57,7 @@ module Togo
57
57
  redirect "/#{@model.name}"
58
58
  rescue => detail
59
59
  @errors = detail.to_s
60
- erb :edit
60
+ erb :new
61
61
  end
62
62
  end
63
63
 
@@ -157,34 +157,41 @@ body {
157
157
  #main form fieldset input[type=text]:focus {
158
158
  border: 1px solid #ABABAB;
159
159
  }
160
+ #main form fieldset.many_to_many,
160
161
  #main form fieldset.belongs_to,
161
162
  #main form fieldset.has_n {
162
163
  padding-right: 20px;
163
164
  }
165
+ #main form fieldset.many_to_many input[type=text],
164
166
  #main form fieldset.belongs_to input[type=text],
165
167
  #main form fieldset.has_n input[type=text] {
166
168
  width: 190px;
167
169
  }
170
+ #main form fieldset.many_to_many label,
168
171
  #main form fieldset.belongs_to label,
169
172
  #main form fieldset.has_n label {
170
173
  float: left;
171
174
  }
175
+ #main form fieldset.many_to_many div.search,
172
176
  #main form fieldset.belongs_to div.search,
173
177
  #main form fieldset.has_n div.search {
174
178
  display: none;
175
179
  width: 100%;
176
180
  text-align: right;
177
181
  }
182
+ #main form fieldset.many_to_many div.paging,
178
183
  #main form fieldset.belongs_to div.paging,
179
184
  #main form fieldset.has_n div.paging {
180
185
  float: right;
181
186
  margin-left: 10px;
182
187
  line-height: 30px;
183
188
  }
189
+ #main form fieldset.many_to_many .checkbox,
184
190
  #main form fieldset.belongs_to .checkbox,
185
191
  #main form fieldset.has_n .checkbox {
186
192
  display: none;
187
193
  }
194
+ #main form fieldset.many_to_many .active,
188
195
  #main form fieldset.belongs_to .active,
189
196
  #main form fieldset.has_n .active {
190
197
  display: table-cell;
@@ -221,7 +221,6 @@ AssociationManager.prototype.adjustRelatedList = function() {
221
221
  };
222
222
 
223
223
  AssociationManager.prototype.setToModifyState = function() {
224
- console.log('setToModifyState');
225
224
  ajax({
226
225
  url: "/search/" + this.model,
227
226
  success: this.searchResultsHandler(this)
@@ -293,7 +292,6 @@ AssociationManager.prototype.tableHandler = function(handler) {
293
292
  if (e.target.getAttribute('type') == 'radio') {
294
293
  handler.relatedIds = {};
295
294
  handler.relatedIds[e.target.value] = e.target.checked;
296
- console.log(handler.relatedIds);
297
295
  }
298
296
  };
299
297
  };
@@ -331,7 +329,6 @@ AssociationManager.prototype.searchResultsHandler = function(handler) {
331
329
  handler.pageCount = Math.ceil(handler.count/10);
332
330
  handler.pageCountField.innerHTML = handler.pageCount;
333
331
  handler.pageNumberField.innerHTML = handler.pageNumber;
334
- console.log(data);
335
332
  if (data.results.length > 0) {
336
333
  var out = [];
337
334
  for (var i = 0, len = data.results.length; i < len; i++) {
@@ -2,7 +2,7 @@
2
2
  <form action="/update/<%= @model.name %>/<%= @content.id %>" method="post" id="edit-form">
3
3
  <div class="wrapper">
4
4
  <% if @errors %><div id="save_errors" class="errors"><%= @errors %></div><% end %>
5
- <% @model.form_properties.each do |p| %>
5
+ <% @model.get_form_properties.each do |p| %>
6
6
  <fieldset id="property-<%= p.name %>" class="<%= @model.field_class_for(p) %>">
7
7
  <%= @model.form_for(p,@content) %>
8
8
  </fieldset>
@@ -1,6 +1,6 @@
1
1
  <h1><%= @model.display_name %></h1>
2
2
  <div id="paging">
3
- <%= @count %> items
3
+ <%= @count %> item<%= @count != 1 ? 's' : '' %>
4
4
  <% if @page_count > 1 %>
5
5
  Page <span class="page-number"><%= @p %></span> of <span class="page-count"><%= @page_count %></span>
6
6
  <% prev_link, next_link = paging_links(@p, @page_count, :q => params[:q]) %>
@@ -20,7 +20,7 @@
20
20
  <% if not @content.empty? %>
21
21
  <th></th>
22
22
  <% end %>
23
- <% @model.list_properties.each do |p| %>
23
+ <% @model.get_list_properties.each do |p| %>
24
24
  <th><%= p.name.to_s.humanize.titleize %></th>
25
25
  <% end %>
26
26
  </tr>
@@ -28,13 +28,13 @@
28
28
  <tbody>
29
29
  <% if @content.empty? %>
30
30
  <tr>
31
- <td colspan="<%= @model.list_properties.size %>"><% if params[:q] %>No results for '<%= params[:q] %>'<% else %>No content has been created yet.<% end %></td>
31
+ <td colspan="<%= @model.get_list_properties.size %>"><% if params[:q] %>No results for '<%= params[:q] %>'<% else %>No content has been created yet.<% end %></td>
32
32
  </tr>
33
33
  <% else %>
34
34
  <% @content.each do |c| %>
35
35
  <tr>
36
36
  <td class="checkbox"><input type="checkbox" name="selection[<%= c.id %>]" value="1" id="selection_<%= c.id %>" /></td>
37
- <% @model.list_properties.each_with_index do |p,i| %>
37
+ <% @model.get_list_properties.each_with_index do |p,i| %>
38
38
  <td><% if i == 0 %><a href="/edit/<%= @model.name %>/<%= c.id %>"><%= c.send(p.name.to_sym) || '-' %></a><% else %><%= c.send(p.name.to_sym) %><% end %></td>
39
39
  <% end %>
40
40
  </tr>
@@ -1,9 +1,9 @@
1
1
  <h1><a href="/<%= @model.name %>"><%= @model.display_name %></a> / New</h1>
2
- <form action="/create/<%= @model.name %>" method="post">
2
+ <form action="/create/<%= @model.name %>" method="post" id="edit-form">
3
3
  <div class="wrapper">
4
4
  <% if @errors %><div id="save_errors" class="errors"><%= @errors %></div><% end %>
5
- <% @model.form_properties.each do |p| %>
6
- <fieldset id="field_<%= p.name %>" class="<%= @model.field_class_for(p) %>">
5
+ <% @model.get_form_properties.each do |p| %>
6
+ <fieldset id="property-<%= p.name %>" class="<%= @model.field_class_for(p) %>">
7
7
  <%= @model.form_for(p,@content) %>
8
8
  </fieldset>
9
9
  <% end %>
@@ -12,3 +12,5 @@
12
12
  <button type="submit" class="create">Create</button>
13
13
  </div>
14
14
  </form>
15
+ <script type="text/javascript" src="/js/edit.js"></script>
16
+
@@ -9,6 +9,8 @@ module Togo
9
9
  base.extend ClassMethods
10
10
  base.send(:class_variable_set, :@@list_properties, [])
11
11
  base.send(:class_variable_set, :@@form_properties, [])
12
+ base.send(:class_variable_set, :@@user_list_properties, [])
13
+ base.send(:class_variable_set, :@@user_form_properties, [])
12
14
  base.send(:class_variable_set, :@@custom_form_templates, {})
13
15
  base.send(:class_variable_set, :@@property_options, {})
14
16
  if MODELS.include?(base) # support code reloading
@@ -22,12 +24,12 @@ module Togo
22
24
 
23
25
  # Let the user determine what properties to show in list view
24
26
  def list_properties(*args)
25
- pick_properties(:list,*args)
27
+ class_variable_set(:@@user_list_properties, args.to_a)
26
28
  end
27
29
 
28
30
  # Let the user determine what properties to show in form view
29
31
  def form_properties(*args)
30
- pick_properties(:form,*args)
32
+ class_variable_set(:@@user_form_properties, args.to_a)
31
33
  end
32
34
 
33
35
  def configure_property(property,opts = {})
@@ -52,9 +54,9 @@ module Togo
52
54
  def stage_content(content,attrs)
53
55
  content.attributes = properties.inject({}){|m,p| attrs[p.name.to_sym] ? m.merge!(p.name.to_sym => attrs[p.name.to_sym]) : m}
54
56
  relationships.each do |r|
55
- key = "related_#{r[0]}".to_sym
56
- next if not attrs[key] or attrs[key] == 'unset'
57
- content = RelationshipManager.new(content, r, :ids => attrs[key]).relate
57
+ val = attrs["related_#{r[0]}".to_sym]
58
+ next if not val or val == 'unset'
59
+ content = RelationshipManager.new(content, r, :ids => val).relate
58
60
  end
59
61
  content
60
62
  end
@@ -89,6 +91,14 @@ module Togo
89
91
  type_from_property(property)
90
92
  end
91
93
 
94
+ def get_list_properties
95
+ pick_properties(:list, class_variable_get(:@@user_list_properties))
96
+ end
97
+
98
+ def get_form_properties
99
+ pick_properties(:form, class_variable_get(:@@user_form_properties))
100
+ end
101
+
92
102
  private
93
103
 
94
104
  def custom_template_for(property,template)
@@ -99,6 +109,8 @@ module Togo
99
109
  case property
100
110
  when ::DataMapper::Property
101
111
  Extlib::Inflection.demodulize(property.type || property.class).downcase # type seems to be deprecated in 1.0
112
+ when ::DataMapper::Associations::ManyToMany::Relationship
113
+ 'many_to_many'
102
114
  when ::DataMapper::Associations::ManyToOne::Relationship
103
115
  'belongs_to'
104
116
  when ::DataMapper::Associations::OneToMany::Relationship
@@ -108,7 +120,7 @@ module Togo
108
120
  end
109
121
  end
110
122
 
111
- def pick_properties(selection,*args)
123
+ def pick_properties(selection, args)
112
124
  if class_variable_get(:"@@#{selection}_properties").empty?
113
125
  args = shown_properties.map{|p| p.name} if args.empty?
114
126
  class_variable_set(:"@@#{selection}_properties", args.collect{|a| shown_properties.select{|s| s.name == a}.first}.compact)
@@ -117,7 +129,8 @@ module Togo
117
129
  end
118
130
 
119
131
  def shown_properties
120
- properties.select{|p| not BLACKLIST.include?(p.name) and not p.name =~ /_id$/} + relationships.values
132
+ skip = relationships.values.collect{|r| r.through if r.respond_to?(:through) }.compact.uniq # don't include join models
133
+ properties.select{|p| not BLACKLIST.include?(p.name) and not p.name =~ /_id$/} + relationships.values.select{|r| not skip.include?(r)}
121
134
  end
122
135
 
123
136
  def search_properties
@@ -15,23 +15,18 @@
15
15
  <thead>
16
16
  <tr>
17
17
  <th class="checkbox"></th>
18
- <% related_model.list_properties.each do |p| %>
18
+ <% related_model.get_list_properties.each do |p| %>
19
19
  <th><%= p.name.to_s.humanize.titleize %></th>
20
20
  <% end %>
21
- <% if related_model.list_properties.size < 2 %>
22
- <th></th>
23
- <% end %>
24
21
  </tr>
25
22
  </thead>
26
23
  <tfoot>
27
24
  <tr>
28
25
  <td class="checkbox"></td>
29
- <td>
30
- <span class="associated-count-display" style="<%= (content_count == 0 or content_count < 10) ? 'display: none;' : '' %>">
26
+ <td colspan="<%= related_model.get_form_properties.size-2 %>">
27
+ <span class="associated-count-display" style="display: none;">
31
28
  ...and <span class="associated-count"><%= content_count-related_content.size %></span> more associated items
32
29
  </span>
33
- </td>
34
- <td colspan="<%= related_model.form_properties.size-1 %>">
35
30
  <button class="association-modify">Modify</button>
36
31
  </td>
37
32
  </tr>
@@ -39,13 +34,13 @@
39
34
  <tbody>
40
35
  <% if related_content.empty? %>
41
36
  <tr>
42
- <td colspan="<%= related_model.form_properties.size %>">No Content Associated.</td>
37
+ <td colspan="<%= related_model.get_form_properties.size %>">No Content Associated.</td>
43
38
  </tr>
44
39
  <% else %>
45
40
  <% related_content.each do |c| %>
46
41
  <tr>
47
42
  <td class="checkbox"><input type="radio" name="selection[<%= c.id %>]" value="<%= c.id %>" id="selection_<%= related_model.name %>_<%= c.id %>" checked="checked" /></td>
48
- <% related_model.list_properties.each_with_index do |p,i| %>
43
+ <% related_model.get_list_properties.each_with_index do |p,i| %>
49
44
  <td><% if i == 0 %><a href="/edit/<%= related_model.name %>/<%= c.id %>"><%= c.send(p.name.to_sym) || '-' %></a><% else %><%= c.send(p.name.to_sym) %><% end %></td>
50
45
  <% end %>
51
46
  </tr>
@@ -58,7 +53,7 @@
58
53
  relationship: 'belongs_to',
59
54
  name: '<%= property.name %>',
60
55
  model: '<%= related_model.name %>',
61
- fields: <%= related_model.list_properties.map(&:name).to_json %>,
56
+ fields: <%= related_model.get_list_properties.map(&:name).to_json %>,
62
57
  count: <%= content_count %>,
63
58
  related_ids: <%= related_ids.to_json %>
64
59
  });
@@ -1,2 +1,2 @@
1
1
  <label for="<%= property.name %>"><%= property.model.property_options[property.name][:label] rescue property.name.to_s.humanize.titleize %></label>
2
- <input type="text" name="<%= property.name %>" id="<%= property.name %>" value="<%= content.send(property.name.to_sym).strftime("%B %d, %Y %I:%M%p") rescue '' %>" />
2
+ <input type="text" name="<%= property.name %>" id="<%= property.name %>" value="<%= (content.send(property.name.to_sym) || Time.now).strftime("%B %d, %Y %I:%M%p") %>" />
@@ -15,7 +15,7 @@
15
15
  <thead>
16
16
  <tr>
17
17
  <th class="checkbox"></th>
18
- <% related_model.list_properties.each do |p| %>
18
+ <% related_model.get_list_properties.each do |p| %>
19
19
  <th><%= p.name.to_s.humanize.titleize %></th>
20
20
  <% end %>
21
21
  </tr>
@@ -28,7 +28,7 @@
28
28
  ...and <span class="associated-count"><%= content_count-related_content.size %></span> more associated items
29
29
  </span>
30
30
  </td>
31
- <td colspan="<%= related_model.form_properties.size-1 %>">
31
+ <td colspan="<%= related_model.get_form_properties.size-1 %>">
32
32
  <button class="association-modify">Modify</button>
33
33
  </td>
34
34
  </tr>
@@ -36,13 +36,13 @@
36
36
  <tbody>
37
37
  <% if related_content.empty? %>
38
38
  <tr>
39
- <td colspan="<%= related_model.form_properties.size %>">No Content Associated.</td>
39
+ <td colspan="<%= related_model.get_form_properties.size %>">No Content Associated.</td>
40
40
  </tr>
41
41
  <% else %>
42
42
  <% related_content.each do |c| %>
43
43
  <tr>
44
44
  <td class="checkbox"><input type="checkbox" name="selection[<%= c.id %>]" value="<%= c.id %>" id="selection_<%= related_model.name %>_<%= c.id %>" checked="checked" /></td>
45
- <% related_model.list_properties.each_with_index do |p,i| %>
45
+ <% related_model.get_list_properties.each_with_index do |p,i| %>
46
46
  <td><% if i == 0 %><a href="/edit/<%= related_model.name %>/<%= c.id %>"><%= c.send(p.name.to_sym) || '-' %></a><% else %><%= c.send(p.name.to_sym) %><% end %></td>
47
47
  <% end %>
48
48
  </tr>
@@ -55,7 +55,7 @@
55
55
  relationship: 'has_n',
56
56
  name: '<%= property.name %>',
57
57
  model: '<%= related_model.name %>',
58
- fields: <%= related_model.list_properties.map(&:name).to_json %>,
58
+ fields: <%= related_model.get_list_properties.map(&:name).to_json %>,
59
59
  count: <%= content_count %>,
60
60
  related_ids: <%= related_ids.to_json %>
61
61
  });
@@ -0,0 +1,63 @@
1
+ <% content_count = content.send(property.name.to_sym).size %>
2
+ <% related_ids = content.send(property.name.to_sym).map(&:id) %>
3
+ <% related_content = content.send(property.name.to_sym)[0...10] %>
4
+ <% related_model = property.child_model %>
5
+ <input type="hidden" name="related_<%= property.name %>" class="related_ids" value="unset" />
6
+ <label for="<%= property.name %>"><%= related_model.display_name %></label>
7
+ <div class="search" id="search-<%= related_model.name %>">
8
+ <input type="text" name="search-<%= property.name %>" value="Search..." />
9
+ <div class="paging">
10
+ Page <span class="page-number">1</span> of <span class="page-count"><%= (content_count/10).ceil %></span>
11
+ <a href="#" rel="prev">&laquo; Previous</a> <a href="#" rel="next">Next &raquo;</a>
12
+ </div>
13
+ </div>
14
+ <table>
15
+ <thead>
16
+ <tr>
17
+ <th class="checkbox"></th>
18
+ <% related_model.get_list_properties.each do |p| %>
19
+ <th><%= p.name.to_s.humanize.titleize %></th>
20
+ <% end %>
21
+ </tr>
22
+ </thead>
23
+ <tfoot>
24
+ <tr>
25
+ <td class="checkbox"></td>
26
+ <td>
27
+ <span class="associated-count-display" style="<%= (content_count == 0 or content_count < 10) ? 'display: none;' : '' %>">
28
+ ...and <span class="associated-count"><%= content_count-related_content.size %></span> more associated items
29
+ </span>
30
+ </td>
31
+ <td colspan="<%= related_model.get_form_properties.size-1 %>">
32
+ <button class="association-modify">Modify</button>
33
+ </td>
34
+ </tr>
35
+ </tfoot>
36
+ <tbody>
37
+ <% if related_content.empty? %>
38
+ <tr>
39
+ <td colspan="<%= related_model.get_form_properties.size %>">No Content Associated.</td>
40
+ </tr>
41
+ <% else %>
42
+ <% related_content.each do |c| %>
43
+ <tr>
44
+ <td class="checkbox"><input type="checkbox" name="selection[<%= c.id %>]" value="<%= c.id %>" id="selection_<%= related_model.name %>_<%= c.id %>" checked="checked" /></td>
45
+ <% related_model.get_list_properties.each_with_index do |p,i| %>
46
+ <td><% if i == 0 %><a href="/edit/<%= related_model.name %>/<%= c.id %>"><%= c.send(p.name.to_sym) || '-' %></a><% else %><%= c.send(p.name.to_sym) %><% end %></td>
47
+ <% end %>
48
+ </tr>
49
+ <% end %>
50
+ <% end %>
51
+ </tbody>
52
+ </table>
53
+ <script type="text/javascript">
54
+ new AssociationManager({
55
+ relationship: 'many_to_many',
56
+ name: '<%= property.name %>',
57
+ model: '<%= related_model.name %>',
58
+ fields: <%= related_model.get_list_properties.map(&:name).to_json %>,
59
+ count: <%= content_count %>,
60
+ related_ids: <%= related_ids.to_json %>
61
+ });
62
+ </script>
63
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: togo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt King
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-10 00:00:00 -07:00
18
+ date: 2010-08-16 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -89,6 +89,7 @@ files:
89
89
  - lib/togo/model/types/float.erb
90
90
  - lib/togo/model/types/has_n.erb
91
91
  - lib/togo/model/types/integer.erb
92
+ - lib/togo/model/types/many_to_many.erb
92
93
  - lib/togo/model/types/string.erb
93
94
  - lib/togo/model/types/text.erb
94
95
  - lib/togo/model.rb