typus 0.9.18 → 0.9.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. data/README.rdoc +50 -1
  2. data/VERSION +1 -1
  3. data/app/helpers/admin/table_helper.rb +40 -40
  4. data/generators/typus/templates/config/initializers/typus.rb +1 -1
  5. data/generators/typus/templates/config/typus/README +0 -1
  6. data/generators/typus/templates/config/typus/typus.yml +1 -3
  7. data/generators/typus/templates/public/images/admin/fancyzoom/bl.gif +0 -0
  8. data/generators/typus/templates/public/images/admin/fancyzoom/bl.png +0 -0
  9. data/generators/typus/templates/public/images/admin/fancyzoom/bm.gif +0 -0
  10. data/generators/typus/templates/public/images/admin/fancyzoom/bm.png +0 -0
  11. data/generators/typus/templates/public/images/admin/fancyzoom/br.gif +0 -0
  12. data/generators/typus/templates/public/images/admin/fancyzoom/br.png +0 -0
  13. data/generators/typus/templates/public/images/admin/fancyzoom/closebox.gif +0 -0
  14. data/generators/typus/templates/public/images/admin/fancyzoom/closebox.png +0 -0
  15. data/generators/typus/templates/public/images/admin/fancyzoom/ml.gif +0 -0
  16. data/generators/typus/templates/public/images/admin/fancyzoom/ml.png +0 -0
  17. data/generators/typus/templates/public/images/admin/fancyzoom/mr.gif +0 -0
  18. data/generators/typus/templates/public/images/admin/fancyzoom/mr.png +0 -0
  19. data/generators/typus/templates/public/images/admin/fancyzoom/tl.gif +0 -0
  20. data/generators/typus/templates/public/images/admin/fancyzoom/tl.png +0 -0
  21. data/generators/typus/templates/public/images/admin/fancyzoom/tm.gif +0 -0
  22. data/generators/typus/templates/public/images/admin/fancyzoom/tm.png +0 -0
  23. data/generators/typus/templates/public/images/admin/fancyzoom/tr.gif +0 -0
  24. data/generators/typus/templates/public/images/admin/fancyzoom/tr.png +0 -0
  25. data/generators/typus/templates/public/images/admin/ui-icons.png +0 -0
  26. data/generators/typus/templates/public/javascripts/admin/builder.js +136 -0
  27. data/generators/typus/templates/public/javascripts/admin/controls.js +963 -0
  28. data/generators/typus/templates/public/javascripts/admin/dragdrop.js +973 -0
  29. data/generators/typus/templates/public/javascripts/admin/effects.js +1128 -0
  30. data/generators/typus/templates/public/javascripts/admin/fancyzoom.js +221 -0
  31. data/generators/typus/templates/public/javascripts/admin/prototype.js +4320 -0
  32. data/generators/typus/templates/public/javascripts/admin/scriptaculous.js +58 -0
  33. data/generators/typus/templates/public/javascripts/admin/slider.js +275 -0
  34. data/generators/typus/templates/public/javascripts/admin/sound.js +55 -0
  35. data/generators/typus/templates/public/stylesheets/admin/screen.css +163 -524
  36. data/generators/typus/typus_generator.rb +10 -4
  37. data/generators/typus_update_schema_to_01/templates/config/typus.yml +1 -3
  38. data/lib/typus/configuration.rb +1 -1
  39. data/lib/typus/generator.rb +9 -9
  40. data/lib/typus/preview.rb +13 -0
  41. data/lib/typus.rb +1 -0
  42. data/test/config/default/typus.yml +1 -3
  43. data/test/config/working/typus.yml +1 -3
  44. data/test/functional/admin/comments_controller_test.rb +2 -2
  45. data/test/helpers/admin/form_helper_test.rb +2 -2
  46. data/test/helpers/admin/table_helper_test.rb +14 -14
  47. data/test/lib/configuration_test.rb +1 -1
  48. data/typus.gemspec +31 -8
  49. metadata +31 -8
  50. data/generators/typus/templates/public/images/admin/arrow_down.gif +0 -0
  51. data/generators/typus/templates/public/images/admin/arrow_up.gif +0 -0
  52. data/generators/typus/templates/public/images/admin/spinner.gif +0 -0
  53. data/generators/typus/templates/public/images/admin/status_false.gif +0 -0
  54. data/generators/typus/templates/public/images/admin/status_true.gif +0 -0
  55. data/generators/typus/templates/public/images/admin/trash.gif +0 -0
data/README.rdoc CHANGED
@@ -56,6 +56,55 @@ mailing list.
56
56
  Tell everybody about Typus, tell your friends and colleagues about
57
57
  Typus and blog about Typus.
58
58
 
59
+ == Fancyzoom for assets
60
+
61
+ This feature is a work in progress. It currently works if the attached file is
62
+ named asset and only previews images.
63
+
64
+ # db/migrate/create_photos.rb
65
+
66
+ class CreatePhotos < ActiveRecord::Migration
67
+
68
+ def self.up
69
+ create_table :photos do |t|
70
+ t.string :asset_file_name
71
+ t.string :asset_content_type
72
+ t.integer :asset_file_size
73
+ t.datetime :asset_updated_at
74
+ end
75
+ end
76
+
77
+ def self.down
78
+ drop_table :photos
79
+ end
80
+
81
+ end
82
+
83
+ # app/models/photo.rb
84
+
85
+ class Photo < ActiveRecord::Base
86
+ has_attached_file :asset, :styles => { :typus => "692x461" }
87
+ end
88
+
89
+ # app/views/admin/photos/_index.html.erb
90
+
91
+ <%- content_for :javascripts do -%>
92
+
93
+ <%= javascript_include_tag 'admin/prototype' %>
94
+ <%= javascript_include_tag 'admin/scriptaculous' %>
95
+ <%= javascript_include_tag 'admin/fancyzoom' %>
96
+
97
+ <script type="text/javascript">
98
+ FancyZoomBox.directory = '/images/admin/fancyzoom';
99
+ $(document).observe('dom:loaded', function() {
100
+ <%- @items.each do |item| -%>
101
+ new FancyZoom('<%= item.to_dom %>');
102
+ <%- end -%>
103
+ });
104
+ </script>
105
+
106
+ <%- end -%>
107
+
59
108
  == Contributors
60
109
 
61
110
  - Laia Gargallo (Lover and tea provider) http://azotacalles.net
@@ -68,7 +117,7 @@ Typus and blog about Typus.
68
117
  - Erik Tigerholm (Code) http://github.com/eriktigerholm
69
118
  - George Guimarães (Portuguese translation and code) http://github.com/georgeguimaraes
70
119
  - José Valim (Code) http://github.com/josevalim
71
- - Luqman Amjad (Code) http://github.com/snake
120
+ - Luqman Amjad (Code) http://github.com/luqman
72
121
  - Alexey Noskov (Russian translation and code) http://github.com/alno
73
122
  - Andres Gutierres (Bugfixes & feedback) http://github.com/andresgutgon
74
123
  - Komzák Nándor (Code, bugfixes & feedback) http://github.com/rubymood
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.18
1
+ 0.9.19
@@ -21,6 +21,7 @@ module Admin::TableHelper
21
21
  when :boolean then html << typus_table_boolean_field(key, item)
22
22
  when :datetime then html << typus_table_datetime_field(key, item, fields.keys.first, link_options)
23
23
  when :date then html << typus_table_datetime_field(key, item, fields.keys.first, link_options)
24
+ when :file then html << typus_table_file_field(key, item, fields.keys.first, link_options)
24
25
  when :time then html << typus_table_datetime_field(key, item, fields.keys.first, link_options)
25
26
  when :belongs_to then html << typus_table_belongs_to_field(key, item)
26
27
  when :tree then html << typus_table_tree_field(key, item)
@@ -30,8 +31,15 @@ module Admin::TableHelper
30
31
  else
31
32
  html << typus_table_string_field(key, item, fields.keys.first, link_options)
32
33
  end
34
+
33
35
  end
34
36
 
37
+ action = item.class.typus_options_for(:default_action_on_item)
38
+ content = link_to _(action.capitalize), :controller => "admin/#{item.class.name.tableize}", :action => action, :id => item.id
39
+ html << <<-HTML
40
+ <td width="10px">#{content}</td>
41
+ HTML
42
+
35
43
  ##
36
44
  # This controls the action to perform. If we are on a model list we
37
45
  # will remove the entry, but if we inside a model we will remove the
@@ -39,24 +47,25 @@ module Admin::TableHelper
39
47
  #
40
48
  # Only shown is the user can destroy items.
41
49
  #
42
-
43
50
  if @current_user.can_perform?(model, 'delete')
44
51
 
52
+ trash = "<div class=\"sprite trash\">Trash</div>"
53
+
45
54
  case params[:action]
46
55
  when 'index'
47
- perform = link_to image_tag('admin/trash.gif'), { :action => 'destroy',
48
- :id => item.id },
49
- :confirm => _("Remove entry?"),
50
- :method => :delete
56
+ perform = link_to trash, { :action => 'destroy',
57
+ :id => item.id },
58
+ :confirm => _("Remove entry?"),
59
+ :method => :delete
51
60
  else
52
- perform = link_to image_tag('admin/trash.gif'), { :action => 'unrelate',
53
- :id => params[:id],
54
- :association => association,
55
- :resource => model,
56
- :resource_id => item.id },
57
- :confirm => _("Unrelate {{unrelate_model}} from {{unrelate_model_from}}?",
58
- :unrelate_model => model.typus_human_name,
59
- :unrelate_model_from => @resource[:class].typus_human_name)
61
+ perform = link_to trash, { :action => 'unrelate',
62
+ :id => params[:id],
63
+ :association => association,
64
+ :resource => model,
65
+ :resource_id => item.id },
66
+ :confirm => _("Unrelate {{unrelate_model}} from {{unrelate_model_from}}?",
67
+ :unrelate_model => model.typus_human_name,
68
+ :unrelate_model_from => @resource[:class].typus_human_name)
60
69
  end
61
70
 
62
71
  html << <<-HTML
@@ -90,13 +99,15 @@ module Admin::TableHelper
90
99
 
91
100
  if (model.model_fields.map(&:first).collect { |i| i.to_s }.include?(key) || model.reflect_on_all_associations(:belongs_to).map(&:name).include?(key.to_sym)) && params[:action] == 'index'
92
101
  sort_order = case params[:sort_order]
93
- when 'asc' then 'desc'
94
- when 'desc' then 'asc'
102
+ when 'asc' then ['desc', '&darr;']
103
+ when 'desc' then ['asc', '&uarr;']
104
+ else
105
+ [nil, nil]
95
106
  end
96
107
  order_by = model.reflect_on_association(key.to_sym).primary_key_name rescue key
97
- switch = (params[:order_by] == key) ? sort_order : ''
98
- options = { :order_by => order_by, :sort_order => sort_order }
99
- content = (link_to "<div class=\"#{switch}\">#{content}</div>", params.merge(options))
108
+ switch = (params[:order_by] == key) ? sort_order.last : ''
109
+ options = { :order_by => order_by, :sort_order => sort_order.first }
110
+ content = (link_to "#{content} #{switch}", params.merge(options))
100
111
  end
101
112
 
102
113
  headers << "<th>#{content}</th>"
@@ -131,22 +142,16 @@ module Admin::TableHelper
131
142
  HTML
132
143
  end
133
144
 
134
- ##
135
- # When detection of the attributes is made a default attribute
136
- # type is set. From the string_field we display other content
137
- # types.
138
- #
139
145
  def typus_table_string_field(attribute, item, first_field, link_options = {})
146
+ <<-HTML
147
+ <td>#{item.send(attribute)}</td>
148
+ HTML
149
+ end
140
150
 
141
- action = item.class.typus_options_for(:default_action_on_item)
142
-
143
- content = if first_field == attribute
144
- link_to item.send(attribute) || item.class.typus_options_for(:nil), link_options.merge(:controller => "admin/#{item.class.name.tableize}", :action => action, :id => item.id)
145
- else
146
- item.send(attribute)
147
- end
151
+ def typus_table_file_field(attribute, item, first_field, link_options = {})
148
152
  <<-HTML
149
- <td>#{content}</td>
153
+ <td><a href="##{item.to_dom(:suffix => 'zoom')}" id="#{item.to_dom}" title="Click to preview">#{item.send(attribute)}</a></td>
154
+ <div id="#{item.to_dom(:suffix => 'zoom')}">#{item.typus_preview}</div>
150
155
  HTML
151
156
  end
152
157
 
@@ -199,21 +204,16 @@ module Admin::TableHelper
199
204
 
200
205
  def typus_table_boolean_field(attribute, item)
201
206
 
202
- boolean_icon = item.class.typus_options_for(:icon_on_boolean)
203
207
  boolean_hash = item.class.typus_boolean(attribute)
204
-
205
208
  status = item.send(attribute)
206
-
207
- link_text = unless item.send(attribute).nil?
208
- (boolean_icon) ? image_tag("admin/status_#{status}.gif") : boolean_hash["#{status}".to_sym]
209
- else
210
- item.class.typus_options_for(:nil) # Content is nil, so we show nil.
211
- end
209
+ link_text = !item.send(attribute).nil? ? boolean_hash["#{status}".to_sym] : item.class.typus_options_for(:nil)
212
210
 
213
211
  options = { :controller => item.class.name.tableize, :action => 'toggle', :field => attribute.gsub(/\?$/,''), :id => item.id }
214
212
 
215
213
  content = if item.class.typus_options_for(:toggle) && !item.send(attribute).nil?
216
- link_to link_text, params.merge(options), :confirm => _("Change {{attribute}}?", :attribute => item.class.human_attribute_name(attribute).downcase)
214
+ link_to link_text, params.merge(options),
215
+ :confirm => _("Change {{attribute}}?",
216
+ :attribute => item.class.human_attribute_name(attribute).downcase)
217
217
  else
218
218
  link_text
219
219
  end
@@ -5,6 +5,7 @@
5
5
  Typus::Configuration.options[:app_name] = '<%= application %>'
6
6
  # Typus::Configuration.options[:config_folder] = 'config/typus'
7
7
  # Typus::Configuration.options[:email] = 'admin@example.com'
8
+ # Typus::Configuration.options[:image_preview_size] = :typus
8
9
  # Typus::Configuration.options[:locales] = [ [ "English", :en ], [ "Español", :es ] ]
9
10
  # Typus::Configuration.options[:recover_password] = true
10
11
  # Typus::Configuration.options[:root] = 'admin'
@@ -18,7 +19,6 @@ Typus::Configuration.options[:app_name] = '<%= application %>'
18
19
  # Typus::Configuration.options[:default_action_on_item] = 'edit'
19
20
  # Typus::Configuration.options[:end_year] = Time.now.year + 1
20
21
  # Typus::Configuration.options[:form_rows] = 10
21
- # Typus::Configuration.options[:icon_on_boolean] = false
22
22
  # Typus::Configuration.options[:index_after_save] = true
23
23
  # Typus::Configuration.options[:minute_step] = 5
24
24
  # Typus::Configuration.options[:nil] = 'nil'
@@ -39,7 +39,6 @@ only have set the most common settings.
39
39
  default_action_on_item: show
40
40
  end_year: 2015
41
41
  form_rows: 25
42
- icon_on_boolean: true
43
42
  index_after_save: false
44
43
  minute_step: 15
45
44
  nil: 'nil'
@@ -9,6 +9,4 @@ TypusUser:
9
9
  filters: status, role
10
10
  search: first_name, last_name, email, role
11
11
  application: Typus
12
- description: System Users Administration
13
- options:
14
- icon_on_boolean: false
12
+ description: System Users Administration
@@ -0,0 +1,136 @@
1
+ // script.aculo.us builder.js v1.8.2, Tue Nov 18 18:30:58 +0100 2008
2
+
3
+ // Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
4
+ //
5
+ // script.aculo.us is freely distributable under the terms of an MIT-style license.
6
+ // For details, see the script.aculo.us web site: http://script.aculo.us/
7
+
8
+ var Builder = {
9
+ NODEMAP: {
10
+ AREA: 'map',
11
+ CAPTION: 'table',
12
+ COL: 'table',
13
+ COLGROUP: 'table',
14
+ LEGEND: 'fieldset',
15
+ OPTGROUP: 'select',
16
+ OPTION: 'select',
17
+ PARAM: 'object',
18
+ TBODY: 'table',
19
+ TD: 'table',
20
+ TFOOT: 'table',
21
+ TH: 'table',
22
+ THEAD: 'table',
23
+ TR: 'table'
24
+ },
25
+ // note: For Firefox < 1.5, OPTION and OPTGROUP tags are currently broken,
26
+ // due to a Firefox bug
27
+ node: function(elementName) {
28
+ elementName = elementName.toUpperCase();
29
+
30
+ // try innerHTML approach
31
+ var parentTag = this.NODEMAP[elementName] || 'div';
32
+ var parentElement = document.createElement(parentTag);
33
+ try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
34
+ parentElement.innerHTML = "<" + elementName + "></" + elementName + ">";
35
+ } catch(e) {}
36
+ var element = parentElement.firstChild || null;
37
+
38
+ // see if browser added wrapping tags
39
+ if(element && (element.tagName.toUpperCase() != elementName))
40
+ element = element.getElementsByTagName(elementName)[0];
41
+
42
+ // fallback to createElement approach
43
+ if(!element) element = document.createElement(elementName);
44
+
45
+ // abort if nothing could be created
46
+ if(!element) return;
47
+
48
+ // attributes (or text)
49
+ if(arguments[1])
50
+ if(this._isStringOrNumber(arguments[1]) ||
51
+ (arguments[1] instanceof Array) ||
52
+ arguments[1].tagName) {
53
+ this._children(element, arguments[1]);
54
+ } else {
55
+ var attrs = this._attributes(arguments[1]);
56
+ if(attrs.length) {
57
+ try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
58
+ parentElement.innerHTML = "<" +elementName + " " +
59
+ attrs + "></" + elementName + ">";
60
+ } catch(e) {}
61
+ element = parentElement.firstChild || null;
62
+ // workaround firefox 1.0.X bug
63
+ if(!element) {
64
+ element = document.createElement(elementName);
65
+ for(attr in arguments[1])
66
+ element[attr == 'class' ? 'className' : attr] = arguments[1][attr];
67
+ }
68
+ if(element.tagName.toUpperCase() != elementName)
69
+ element = parentElement.getElementsByTagName(elementName)[0];
70
+ }
71
+ }
72
+
73
+ // text, or array of children
74
+ if(arguments[2])
75
+ this._children(element, arguments[2]);
76
+
77
+ return $(element);
78
+ },
79
+ _text: function(text) {
80
+ return document.createTextNode(text);
81
+ },
82
+
83
+ ATTR_MAP: {
84
+ 'className': 'class',
85
+ 'htmlFor': 'for'
86
+ },
87
+
88
+ _attributes: function(attributes) {
89
+ var attrs = [];
90
+ for(attribute in attributes)
91
+ attrs.push((attribute in this.ATTR_MAP ? this.ATTR_MAP[attribute] : attribute) +
92
+ '="' + attributes[attribute].toString().escapeHTML().gsub(/"/,'&quot;') + '"');
93
+ return attrs.join(" ");
94
+ },
95
+ _children: function(element, children) {
96
+ if(children.tagName) {
97
+ element.appendChild(children);
98
+ return;
99
+ }
100
+ if(typeof children=='object') { // array can hold nodes and text
101
+ children.flatten().each( function(e) {
102
+ if(typeof e=='object')
103
+ element.appendChild(e);
104
+ else
105
+ if(Builder._isStringOrNumber(e))
106
+ element.appendChild(Builder._text(e));
107
+ });
108
+ } else
109
+ if(Builder._isStringOrNumber(children))
110
+ element.appendChild(Builder._text(children));
111
+ },
112
+ _isStringOrNumber: function(param) {
113
+ return(typeof param=='string' || typeof param=='number');
114
+ },
115
+ build: function(html) {
116
+ var element = this.node('div');
117
+ $(element).update(html.strip());
118
+ return element.down();
119
+ },
120
+ dump: function(scope) {
121
+ if(typeof scope != 'object' && typeof scope != 'function') scope = window; //global scope
122
+
123
+ var tags = ("A ABBR ACRONYM ADDRESS APPLET AREA B BASE BASEFONT BDO BIG BLOCKQUOTE BODY " +
124
+ "BR BUTTON CAPTION CENTER CITE CODE COL COLGROUP DD DEL DFN DIR DIV DL DT EM FIELDSET " +
125
+ "FONT FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HR HTML I IFRAME IMG INPUT INS ISINDEX "+
126
+ "KBD LABEL LEGEND LI LINK MAP MENU META NOFRAMES NOSCRIPT OBJECT OL OPTGROUP OPTION P "+
127
+ "PARAM PRE Q S SAMP SCRIPT SELECT SMALL SPAN STRIKE STRONG STYLE SUB SUP TABLE TBODY TD "+
128
+ "TEXTAREA TFOOT TH THEAD TITLE TR TT U UL VAR").split(/\s+/);
129
+
130
+ tags.each( function(tag){
131
+ scope[tag] = function() {
132
+ return Builder.node.apply(Builder, [tag].concat($A(arguments)));
133
+ };
134
+ });
135
+ }
136
+ };