spiderfw 0.5.7 → 0.5.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. data/Rakefile +17 -6
  2. data/apps/cas_server/controllers/mixins/cas_login_mixin.rb +18 -5
  3. data/apps/cas_server/lib/cas.rb +1 -1
  4. data/apps/cms/models/content.rb +16 -0
  5. data/apps/cms/models/news_item.rb +7 -0
  6. data/apps/cms/models/translation.rb +14 -0
  7. data/apps/cms/views/admin/admin.shtml +16 -0
  8. data/apps/cms/views/admin/content.shtml +4 -0
  9. data/apps/core/acl/_init.rb +10 -0
  10. data/apps/core/acl/controllers/acl_controller.rb +14 -0
  11. data/apps/core/acl/models/permission.rb +11 -0
  12. data/apps/core/acl/views/acl.layout.shtml +8 -0
  13. data/apps/core/acl/views/index.shtml +3 -0
  14. data/apps/core/auth/controllers/mixins/auth_helper.rb +3 -3
  15. data/apps/core/auth/lib/authenticable.rb +4 -0
  16. data/apps/core/auth/models/super_user.rb +1 -0
  17. data/apps/core/auth/po/it/spider_auth.po +18 -10
  18. data/apps/core/auth/po/spider_auth.pot +13 -1
  19. data/apps/core/components/_init.rb +2 -1
  20. data/apps/core/components/po/it/spider_components.po +3 -3
  21. data/apps/core/components/po/spider_components.pot +3 -3
  22. data/apps/core/components/public/css/month_calendar.css +24 -0
  23. data/apps/core/components/public/js/jquery/jquery-1.4.2-min.js +154 -0
  24. data/apps/core/components/public/js/jquery/jquery-1.4.2.js +6240 -0
  25. data/apps/core/components/public/js/jquery/plugins/jquery.form.js +1 -1
  26. data/apps/core/components/public/js/spider.js +26 -20
  27. data/apps/core/components/widgets/admin/admin.rb +1 -1
  28. data/apps/core/components/widgets/crud/crud.rb +1 -1
  29. data/apps/core/components/widgets/list/list.rb +2 -2
  30. data/apps/core/components/widgets/month_calendar/month_calendar.rb +67 -0
  31. data/apps/core/components/widgets/month_calendar/month_calendar.shtml +21 -0
  32. data/apps/core/components/widgets/table/table.rb +4 -2
  33. data/apps/core/components/widgets/table/table.shtml +37 -31
  34. data/apps/core/forms/_init.rb +2 -1
  35. data/apps/core/forms/po/it/spider_forms.po +14 -2
  36. data/apps/core/forms/po/spider_forms.pot +13 -1
  37. data/apps/core/forms/public/css/file_input.css +15 -0
  38. data/apps/core/forms/public/{form.css → css/form.css} +8 -0
  39. data/apps/core/forms/public/file_input.js +37 -0
  40. data/apps/core/forms/tags/element_label.erb +4 -1
  41. data/apps/core/forms/tags/element_row.erb +7 -2
  42. data/apps/core/forms/tags/row.erb +10 -1
  43. data/apps/core/forms/widgets/form/form.rb +43 -10
  44. data/apps/core/forms/widgets/form/form.shtml +12 -5
  45. data/apps/core/forms/widgets/inputs/date_time/date_time.shtml +1 -0
  46. data/apps/core/forms/widgets/inputs/file_input/file_input.rb +43 -0
  47. data/apps/core/forms/widgets/inputs/file_input/file_input.shtml +12 -0
  48. data/apps/core/forms/widgets/inputs/input/input.rb +23 -1
  49. data/apps/core/forms/widgets/inputs/password/password.rb +1 -0
  50. data/apps/core/forms/widgets/inputs/text/text.shtml +1 -1
  51. data/apps/core/forms/widgets/inputs/text_area/text_area.shtml +2 -2
  52. data/apps/git_model_versioning/models/mixins/git_versioned.rb +91 -0
  53. data/apps/hippo/models/mixins/hippo_struct.rb +42 -26
  54. data/apps/master/controllers/git.rb +32 -0
  55. data/apps/messenger/_init.rb +1 -1
  56. data/apps/messenger/config/options.rb +2 -0
  57. data/apps/messenger/config/worker/queue.rb +3 -0
  58. data/apps/messenger/controllers/mixins/{messenger_controller_mixin.rb → messenger_helper.rb} +8 -6
  59. data/apps/messenger/messenger.rb +10 -3
  60. data/apps/messenger/models/message.rb +2 -2
  61. data/apps/messenger/po/it/spider_messenger.po +1 -1
  62. data/apps/messenger/po/spider_messenger.pot +1 -1
  63. data/apps/saml/_init.rb +13 -0
  64. data/apps/saml/controllers/saml2idp.rb +18 -0
  65. data/apps/saml/lib/bindings/http_redirect_binding.rb +14 -0
  66. data/apps/saml/lib/messages/authn_request.rb +52 -0
  67. data/apps/saml/lib/saml.rb +10 -0
  68. data/apps/soap/controllers/soap_controller.rb +12 -2
  69. data/apps/soap/lib/soap.rb +16 -1
  70. data/apps/soap/soap.gemspec +10 -0
  71. data/apps/webdav/lib/locking.rb +2 -2
  72. data/apps/worker/_init.rb +2 -0
  73. data/apps/worker/config/options.rb +1 -0
  74. data/apps/worker/worker.rb +17 -4
  75. data/blueprints/app/__APP__.appspec +4 -0
  76. data/blueprints/app/_init.rb +5 -8
  77. data/blueprints/app/controllers/__APP___controller.rb +2 -1
  78. data/blueprints/app/views/__APP__.layout.shtml +4 -1
  79. data/blueprints/install/config/config.yml +2 -4
  80. data/blueprints/model.rb +15 -0
  81. data/data/locale/it/LC_MESSAGES/spider.mo +0 -0
  82. data/data/locale/it/LC_MESSAGES/spider_auth.mo +0 -0
  83. data/data/locale/it/LC_MESSAGES/spider_components.mo +0 -0
  84. data/data/locale/it/LC_MESSAGES/spider_forms.mo +0 -0
  85. data/data/locale/it/LC_MESSAGES/spider_messenger.mo +0 -0
  86. data/lib/spiderfw/app.rb +93 -31
  87. data/lib/spiderfw/autoload.rb +1 -0
  88. data/lib/spiderfw/cmd/cmd.rb +8 -1
  89. data/lib/spiderfw/cmd/commands/config.rb +54 -0
  90. data/lib/spiderfw/config/configuration.rb +30 -0
  91. data/lib/spiderfw/config/options/spider.rb +18 -6
  92. data/lib/spiderfw/controller/controller.rb +12 -11
  93. data/lib/spiderfw/controller/dispatcher.rb +5 -4
  94. data/lib/spiderfw/controller/http_controller.rb +16 -2
  95. data/lib/spiderfw/controller/mixins/http_mixin.rb +3 -2
  96. data/lib/spiderfw/controller/mixins/static_content.rb +8 -2
  97. data/lib/spiderfw/controller/mixins/visual.rb +72 -52
  98. data/lib/spiderfw/controller/request.rb +7 -3
  99. data/lib/spiderfw/controller/scene.rb +6 -0
  100. data/lib/spiderfw/controller/session.rb +12 -8
  101. data/lib/spiderfw/env.rb +1 -1
  102. data/lib/spiderfw/http/adapters/mongrel.rb +1 -1
  103. data/lib/spiderfw/http/http.rb +48 -19
  104. data/lib/spiderfw/i18n/cldr.rb +53 -3
  105. data/lib/spiderfw/i18n/i18n.rb +52 -2
  106. data/lib/spiderfw/i18n/provider.rb +24 -0
  107. data/lib/spiderfw/i18n/rails.rb +24 -0
  108. data/lib/spiderfw/model/active_record.rb +3 -3
  109. data/lib/spiderfw/model/base_model.rb +45 -14
  110. data/lib/spiderfw/model/condition.rb +11 -2
  111. data/lib/spiderfw/model/data_type.rb +15 -7
  112. data/lib/spiderfw/model/datatypes/decimal.rb +15 -3
  113. data/lib/spiderfw/model/datatypes/file_path.rb +50 -0
  114. data/lib/spiderfw/model/datatypes/serialized_object.rb +0 -4
  115. data/lib/spiderfw/model/datatypes/uuid.rb +3 -3
  116. data/lib/spiderfw/model/datatypes.rb +1 -0
  117. data/lib/spiderfw/model/extended_models/managed.rb +11 -2
  118. data/lib/spiderfw/model/mappers/db_mapper.rb +116 -52
  119. data/lib/spiderfw/model/mappers/mapper.rb +36 -14
  120. data/lib/spiderfw/model/mixins/state_machine.rb +45 -9
  121. data/lib/spiderfw/model/mixins/versioned.rb +1 -1
  122. data/lib/spiderfw/model/model.rb +2 -1
  123. data/lib/spiderfw/model/query_set.rb +21 -3
  124. data/lib/spiderfw/model/request.rb +7 -0
  125. data/lib/spiderfw/model/storage/db/adapters/mssql.rb +2 -1
  126. data/lib/spiderfw/model/storage/db/adapters/mysql.rb +4 -1
  127. data/lib/spiderfw/model/storage/db/adapters/oci8.rb +35 -18
  128. data/lib/spiderfw/model/storage/db/adapters/sqlite.rb +68 -34
  129. data/lib/spiderfw/model/storage/db/connectors/odbc.rb +1 -1
  130. data/lib/spiderfw/model/storage/db/db_schema.rb +33 -4
  131. data/lib/spiderfw/model/storage/db/db_storage.rb +27 -8
  132. data/lib/spiderfw/requires.rb +2 -0
  133. data/lib/spiderfw/tag/tag.rb +1 -1
  134. data/lib/spiderfw/templates/blocks/attr_if.rb +7 -1
  135. data/lib/spiderfw/templates/blocks/each.rb +8 -3
  136. data/lib/spiderfw/templates/blocks/html.rb +12 -22
  137. data/lib/spiderfw/templates/blocks/render.rb +3 -3
  138. data/lib/spiderfw/templates/blocks/run.rb +47 -11
  139. data/lib/spiderfw/templates/blocks/tag_if.rb +2 -2
  140. data/lib/spiderfw/templates/blocks/text.rb +2 -1
  141. data/lib/spiderfw/templates/blocks/widget.rb +5 -3
  142. data/lib/spiderfw/templates/blocks/yield.rb +1 -1
  143. data/lib/spiderfw/templates/template.rb +27 -24
  144. data/lib/spiderfw/templates/template_blocks.rb +37 -14
  145. data/lib/spiderfw/utils/monkey/exception.rb +1 -1
  146. data/lib/spiderfw/utils/monkey/nil_class.rb +7 -0
  147. data/lib/spiderfw/utils/monkey/numeric.rb +15 -0
  148. data/lib/spiderfw/version.rb +1 -1
  149. data/lib/spiderfw/widget/widget.rb +36 -33
  150. data/lib/spiderfw/widget/widget_attributes.rb +1 -1
  151. data/lib/spiderfw.rb +18 -5
  152. data/spider.gemspec +5 -5
  153. metadata +44 -18
  154. data/apps/core/components/public/js/jquery/plugins/jtree/jquery.jtree.1.0.js +0 -187
  155. data/apps/core/components/public/js/jquery/plugins/jtree/jquery.jtree.1.0.min.js +0 -1
  156. data/apps/core/components/public/js/jquery/plugins/jtree/jquery.jtree.spider.1.0.js +0 -193
  157. data/apps/core/forms/widgets/inputs/subform/subform.rb +0 -10
  158. data/apps/core/forms/widgets/inputs/subform/subform.shtml +0 -5
  159. data/apps/messenger/config/worker.rb +0 -3
  160. data/lib/spiderfw/controller/app_controller.rb +0 -14
  161. data/lib/spiderfw/utils/test_case.rb +0 -24
@@ -54,11 +54,11 @@ $.fn.ajaxSubmit = function(options) {
54
54
  options = { success: options };
55
55
 
56
56
  var url = $.trim(this.attr('action'));
57
+ url = url || window.location.href || '';
57
58
  if (url) {
58
59
  // clean url (don't include hash vaue)
59
60
  url = (url.match(/^([^#]+)/)||[])[1];
60
61
  }
61
- url = url || window.location.href || '';
62
62
 
63
63
  options = $.extend({
64
64
  url: url,
@@ -97,23 +97,7 @@ Spider.Widget = Class.extend({
97
97
  el.each(function(){
98
98
  var $this = $(this);
99
99
  if (this.tagName == 'FORM'){
100
- $('input[type=submit]', $this).click(function(e){
101
- e.preventDefault();
102
- w.setLoading();
103
- var submitName = $(this).attr('name');
104
- var submitValue = $(this).val();
105
- $this.ajaxSubmit({
106
- dataType: 'html',
107
- beforeSubmit: function(data, form, options){
108
- data.push({name: submitName, value: submitValue});
109
- data.push({name: '_wt', value: w.path});
110
- },
111
- success: function(res){
112
- w.replaceHTML(res);
113
- w.removeLoading();
114
- }
115
- });
116
- });
100
+ w.ajaxifyForm($(this));
117
101
  }
118
102
  else if (this.tagName == 'A'){
119
103
  $this.click(function(e){
@@ -145,6 +129,29 @@ Spider.Widget = Class.extend({
145
129
 
146
130
  },
147
131
 
132
+ ajaxifyForm: function(form){
133
+ var w = this;
134
+ var isForm = form.get(0).tagName == 'FORM';
135
+ $('input[type=submit]', form).click(function(e){
136
+ e.preventDefault();
137
+ w.setLoading();
138
+ var submitName = $(this).attr('name');
139
+ var submitValue = $(this).val();
140
+ form.ajaxSubmit({
141
+ dataType: 'html',
142
+ semantic: !isForm,
143
+ beforeSubmit: function(data, form, options){
144
+ data.push({name: submitName, value: submitValue});
145
+ data.push({name: '_wt', value: w.path});
146
+ },
147
+ success: function(res){
148
+ w.replaceHTML(res);
149
+ w.removeLoading();
150
+ }
151
+ });
152
+ });
153
+ },
154
+
148
155
  setLoading: function(){
149
156
  if (this.el.is(':empty')){
150
157
  this.el.addClass('loading-empty');
@@ -217,7 +224,7 @@ Spider.Widget.initFromEl = function(el){
217
224
  var path = Spider.Widget.pathFromId(el.attr('id'));
218
225
  if (Spider.widgets[path]){
219
226
  var widget = Spider.widgets[path];
220
- widget.replaceEl(el);
227
+ if (el.get(0) != widget.el.get(0)) widget.replaceEl(el);
221
228
  return widget;
222
229
  }
223
230
  var cl = el.attr('class');
@@ -257,9 +264,8 @@ Spider.WidgetBackend = Class.extend({
257
264
 
258
265
  init: function(widget){
259
266
  this.widget = widget;
260
- this.baseUrl = document.location.href;
267
+ this.baseUrl = document.location.href.split('#')[0];
261
268
  this.urlParts = this.baseUrl.split('?');
262
- this.urlParts[0] = this.urlParts[0].split('#')[0];
263
269
  this.wUrl = this.urlParts[0]+'?';
264
270
  if (this.urlParts[1]) this.wUrl += this.urlParts[1]+'&';
265
271
  this.wUrl += '_wt='+this.widget.path;
@@ -18,7 +18,7 @@ module Spider; module Components
18
18
  tag 'admin'
19
19
 
20
20
  i_attribute :models, :process => lambda{ |models| models.split(/,[\s\n]*/).map{|m| const_get_full(m) } }
21
- is_attr_accessor :title, :default => _("Administration")
21
+ is_attr_accessor :title, :default => lambda{ _("Administration") }
22
22
  is_attr_accessor :logout_url, :default => Spider::Auth.request_url+'/login/logout'
23
23
 
24
24
  def init
@@ -104,7 +104,7 @@ module Spider; module Components
104
104
  links = {}
105
105
  table_rows = @widgets[:table].scene.data
106
106
  table_rows.each_index do |i|
107
- links[i] = "#{widget_request_path}/#{table_rows[i][@key_element]}"
107
+ links[i] = "#{widget_request_path}/#{Spider::HTTP.urlencode(table_rows[i][@key_element])}"
108
108
  end
109
109
  @widgets[:table].scene.links_to_form = links
110
110
  end
@@ -170,7 +170,7 @@ module Spider; module Components
170
170
  end
171
171
 
172
172
  def create_requested_sublist(sbl, row, cnt)
173
- attributes = sbl.attributes.clone
173
+ attributes = sbl.attributes.to_hash.clone
174
174
  if (attributes['element'])
175
175
  el = @model.elements[attributes['element'].to_sym]
176
176
  #next unless el # may be ok if the query is polymorphic
@@ -228,7 +228,7 @@ module Spider; module Components
228
228
 
229
229
  def parse_runtime_content(doc, src_path='')
230
230
  doc = super
231
- return doc if doc.children.empty?
231
+ return doc if !doc.children || doc.children.empty?
232
232
  doc.root.children_of_type('sublist').each do |sl|
233
233
  raise ArgumentError, "Sublist of #{@id} does not have an id" unless sl['id']
234
234
  @requested_sublists ||= []
@@ -0,0 +1,67 @@
1
+ module Spider; module Components
2
+
3
+ class MonthCalendar < Spider::Widget
4
+ tag 'month_calendar'
5
+
6
+ attribute :start_month, :type => Fixnum
7
+ attribute :start_year, :type => Fixnum
8
+ attr_accessor :busy
9
+
10
+ def prepare
11
+ super
12
+ today = Date.today
13
+ start_month = attributes[:start_month] || today.month
14
+ start_year = attributes[:start_year] || today.year
15
+ if params['d'] && params['d'] =~ /(\d{4})\/(\d{1,2})/
16
+ @month = $2.to_i
17
+ @year = $1.to_i
18
+ else
19
+ @month = start_month
20
+ @year = start_year
21
+ end
22
+ @busy ||= {}
23
+ end
24
+
25
+ def run
26
+ month = @month; year = @year
27
+ @scene.month = month
28
+ @scene.year = year
29
+ @scene.first_week_day = Spider.i18n.week_start
30
+ @scene.weekend_start = Spider.i18n.weekend_start
31
+ @scene.weekend_end = Spider.i18n.weekend_end
32
+ @scene.days_short_names = Spider.i18n.day_names(:narrow)
33
+ @scene.week_days = (0..6).map{ |i| (@scene.first_week_day + i) % 7 }
34
+ @scene.current_month_name = Spider.i18n.month_names[month]
35
+ @scene.first_day = Date.civil(year, month, 1)
36
+ @scene.first_day_wday = @scene.first_day.wday
37
+ @scene.last_day = Date.civil(year, month, -1)
38
+ @scene.days_in_month = @scene.last_day.day
39
+ @scene.last_day_wday = @scene.last_day.wday
40
+ @scene.prev_month = (@scene.first_day - 1)
41
+ @scene.prev_month_last_day = @scene.prev_month.day
42
+ @scene.next_month = (@scene.first_day + 31)
43
+ @scene.prev_link = "#{@scene.prev_month.year}/#{@scene.prev_month.month}"
44
+ @scene.next_link = "#{@scene.next_month.year}/#{@scene.next_month.month}"
45
+ @scene.rows = [[]]
46
+ row = 0
47
+ col = ((@scene.first_day_wday - @scene.first_week_day) % 7) - 1
48
+ 0.upto(col){ |i| @scene.rows[0][i] = {:day => @scene.prev_month_last_day - col + i, :classes => ['prev-month'] } }
49
+ 1.upto(@scene.days_in_month) do |i|
50
+ col += 1
51
+ if (col == 7)
52
+ col = 0
53
+ row += 1
54
+ @scene.rows[row] = []
55
+ end
56
+ classes = []
57
+ classes << 'busy' if @busy[year] && @busy[year][month] && @busy[year][month][i]
58
+ @scene.rows[row][col] = {:day => i, :classes => classes}
59
+ end
60
+ (col+1).upto(6){ |i| @scene.rows[row][i] = {:day => i - col, :classes => ['next-month'] } }
61
+ end
62
+
63
+
64
+
65
+ end
66
+
67
+ end; end
@@ -0,0 +1,21 @@
1
+ <table class="{ @widget[:css_class] }">
2
+ <tpl:asset type="css" src="css/month_calendar.css" />
3
+ <thead>
4
+ <tr>
5
+ <th colspan="7">
6
+ <a href="{ @request[:path] }?_w{ @widget[:param] }[d]={ @prev_link }"><span>&lt;&lt;</span></a>
7
+ { @current_month_name } { @year }
8
+ <a href="{ @request[:path] }?_w{ @widget[:param] }[d]={ @next_link }"><span>&gt;&gt;</span></a>
9
+ </th>
10
+ <tr>
11
+ <th sp:each="@week_days |i|">{ @days_short_names[i] }</th>
12
+ </tr>
13
+ </thead>
14
+ <tbody>
15
+ <tr sp:each="@rows |row|">
16
+ <td sp:each="row |col|" class="{ col[:classes] }">
17
+ { col[:day] }
18
+ </td>
19
+ </tr>
20
+ </tbody>
21
+ </table>
@@ -125,8 +125,10 @@ module Spider; module Components
125
125
  else
126
126
  if (!row[el])
127
127
  res_row[el] = ''
128
- elsif (element.type < Date || element.type < Time)
129
- res_row[el] = Spider::I18n.localize(@request.locale, row[el])
128
+ elsif (element.type <= Date || element.type <= Time)
129
+ res_row[el] = Spider::I18n.localize_date_time(@request.locale, row[el], :short)
130
+ elsif (element.type <= Float || element.type <= BigDecimal)
131
+ res_row[el] = Spider::I18n.localize_number(@request.locale, row[el])
130
132
  elsif (row[el].respond_to?(:format))
131
133
  res_row[el] = row[el].format(:short)
132
134
  else
@@ -5,37 +5,43 @@
5
5
  Nessun elemento
6
6
  </div>
7
7
  <table sp:if="@rows && @rows.length > 0" class="{ @widget[:css_class] }">
8
- <tr class="heading_row">
9
- <th sp:each="@elements |element|">
10
- <a sp:tag-if="@sortable[element]" href="{ @request[:path] }?_w{ @widget[:param] }[sort]={ element }">
11
- { @labels[element] }
12
- </a>
13
- </th>
14
- </tr>
15
- <tr sp:each_index="@rows |row_i|" class="row { (row_i%2==0) ? 'odd' : 'even' }">
16
- <td sp:each="@elements |element|">
17
- <a sp:tag-if="@link_el && element == @link_el" href="{ @link }{ @rows[row_i][element] }">
18
- { @rows[row_i][element] }
19
- </a>
20
- </td>
21
- </tr>
22
- <tr class="paginator" sp:if="@paginate && @pages > 1">
23
- <td colspan="{ @elements.size }" >
24
- <a sp:if="@page > 1" href="{ @request[:path] }?_w{ @widget[:param] }[page]={ @page-1 }">Indietro</a>
25
- <sp:pass sp:if="@paginate_first > 1">
26
- <a href="{ @request[:path] }?_w{ @widget[:param] }[page]=1" class="page">1</a> ...
27
- </sp:pass>
28
- <sp:pass sp:each="(@paginate_first..@paginate_last) |i|" >
29
- <a sp:if="i != @page" href="{ @request[:path] }?_w{ @widget[:param] }[page]={ i }" class="page">
30
- { i }
8
+ <thead>
9
+ <tr class="heading_row">
10
+ <th sp:each="@elements |element|">
11
+ <a sp:tag-if="@sortable[element]" href="{ @request[:path] }?_w{ @widget[:param] }[sort]={ element }">
12
+ { @labels[element] }
31
13
  </a>
32
- <span sp:if="i == @page" class="current">{ i }</span>
33
- </sp:pass>
34
- <sp:pass sp:if="@paginate_last < @pages-1">
35
- ... <a href="{ @request[:path] }?_w{ @widget[:param] }[page]={ @pages }" class="page">{ @pages }</a>
36
- </sp:pass>
37
- <a sp:if="@has_more" href="{ @request[:path] }?_w{ @widget[:param] }[page]={ @page+1 }">Avanti</a>
38
- </td>
39
- </tr>
14
+ </th>
15
+ </tr>
16
+ </thead>
17
+ <tbody>
18
+ <tr sp:each_index="@rows |row_i|" class="row { (row_i%2==0) ? 'odd' : 'even' }">
19
+ <td sp:each="@elements |element|">
20
+ <a sp:tag-if="@link_el && element == @link_el" href="{ @link }{ Spider::HTTP.urlencode(@rows[row_i][element]) }">
21
+ { @rows[row_i][element] }
22
+ </a>
23
+ </td>
24
+ </tr>
25
+ </tbody>
26
+ <tfoot>
27
+ <tr class="paginator" sp:if="@paginate && @pages > 1">
28
+ <td colspan="{ @elements.size }" >
29
+ <a sp:if="@page > 1" href="{ @request[:path] }?_w{ @widget[:param] }[page]={ @page-1 }">Indietro</a>
30
+ <sp:pass sp:if="@paginate_first > 1">
31
+ <a href="{ @request[:path] }?_w{ @widget[:param] }[page]=1" class="page">1</a> ...
32
+ </sp:pass>
33
+ <sp:pass sp:each="(@paginate_first..@paginate_last) |i|" >
34
+ <a sp:if="i != @page" href="{ @request[:path] }?_w{ @widget[:param] }[page]={ i }" class="page">
35
+ { i }
36
+ </a>
37
+ <span sp:if="i == @page" class="current">{ i }</span>
38
+ </sp:pass>
39
+ <sp:pass sp:if="@paginate_last < @pages-1">
40
+ ... <a href="{ @request[:path] }?_w{ @widget[:param] }[page]={ @pages }" class="page">{ @pages }</a>
41
+ </sp:pass>
42
+ <a sp:if="@has_more" href="{ @request[:path] }?_w{ @widget[:param] }[page]={ @page+1 }">Avanti</a>
43
+ </td>
44
+ </tr>
45
+ </tfoot>
40
46
  </table>
41
47
  </div>
@@ -19,4 +19,5 @@ require 'apps/core/forms/widgets/inputs/date_time/date_time'
19
19
  require 'apps/core/forms/widgets/inputs/select/select'
20
20
  require 'apps/core/forms/widgets/inputs/search_select/search_select'
21
21
  require 'apps/core/forms/widgets/inputs/password/password'
22
- require 'apps/core/forms/widgets/inputs/checkbox/checkbox'
22
+ require 'apps/core/forms/widgets/inputs/checkbox/checkbox'
23
+ require 'apps/core/forms/widgets/inputs/file_input/file_input'
@@ -6,8 +6,8 @@
6
6
  msgid ""
7
7
  msgstr ""
8
8
  "Project-Id-Version: Spider::Forms 0.1\n"
9
- "POT-Creation-Date: 2009-10-27 14:38+0100\n"
10
- "PO-Revision-Date: 2009-10-07 19:35+0100\n"
9
+ "POT-Creation-Date: 2010-04-22 18:59+0200\n"
10
+ "PO-Revision-Date: 2010-03-11 11:36+0100\n"
11
11
  "Last-Translator: Ivan Pirlik <ivan.pirlik@soluzionipa.it>\n"
12
12
  "Language-Team: LANGUAGE <LL@li.org>\n"
13
13
  "MIME-Version: 1.0\n"
@@ -34,3 +34,15 @@ msgstr "%s e rimani"
34
34
  #: widgets/inputs/date_time/date_time.rb:17
35
35
  msgid "%s is not a valid date"
36
36
  msgstr "%s non è una data valida"
37
+
38
+ #: widgets/inputs/input/input.rb:94
39
+ msgid "%s is required"
40
+ msgstr "Il campo %s è obbligatorio"
41
+
42
+ #: widgets/inputs/file_input/file_input.shtml:6
43
+ msgid "Clear"
44
+ msgstr "Pulisci"
45
+
46
+ #: widgets/inputs/file_input/file_input.shtml:8
47
+ msgid "Change"
48
+ msgstr "Cambia"
@@ -7,7 +7,7 @@
7
7
  msgid ""
8
8
  msgstr ""
9
9
  "Project-Id-Version: Spider::Forms 0.1\n"
10
- "POT-Creation-Date: 2009-10-27 14:38+0100\n"
10
+ "POT-Creation-Date: 2010-04-22 18:59+0200\n"
11
11
  "PO-Revision-Date: 2009-06-30 17:03+0200\n"
12
12
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
13
  "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -35,3 +35,15 @@ msgstr ""
35
35
  #: widgets/inputs/date_time/date_time.rb:17
36
36
  msgid "%s is not a valid date"
37
37
  msgstr ""
38
+
39
+ #: widgets/inputs/input/input.rb:94
40
+ msgid "%s is required"
41
+ msgstr ""
42
+
43
+ #: widgets/inputs/file_input/file_input.shtml:6
44
+ msgid "Clear"
45
+ msgstr ""
46
+
47
+ #: widgets/inputs/file_input/file_input.shtml:8
48
+ msgid "Change"
49
+ msgstr ""
@@ -0,0 +1,15 @@
1
+ .wdgt-Spider-Forms-FileInput .change{
2
+ margin: 5px 0;
3
+ }
4
+
5
+ .wdgt-Spider-Forms-FileInput .js-change-link{
6
+ margin-left: 10px;
7
+ }
8
+
9
+ .wdgt-Spider-Forms-FileInput .js-change-link.open{
10
+ color: #AAAAFF;
11
+ }
12
+
13
+ .wdgt-Spider-Forms-FileInput .file-link.deleted{
14
+ text-decoration: line-through;
15
+ }
@@ -8,17 +8,25 @@
8
8
  list-style-position:outside;
9
9
  }
10
10
 
11
+
12
+
11
13
  .spider.forms.form .fields{
12
14
  padding: 10px;
13
15
  margin: 20px;
14
16
  }
15
17
 
16
18
  .spider.forms.form label{
19
+ position: relative;
17
20
  display: block;
18
21
  float: left;
19
22
  width: 8em;
20
23
  }
21
24
 
25
+ .spider.forms.form label .form_required_symbol{
26
+ position: absolute;
27
+ right: 8px;
28
+ }
29
+
22
30
  .spider.forms.form .row.error label{
23
31
  padding-left: 4px;
24
32
  }
@@ -0,0 +1,37 @@
1
+ Spider.defineWidget('Spider.Forms.FileInput', 'Spider.Forms.Input', {
2
+
3
+ autoInit: true,
4
+
5
+ ready: function(){
6
+ var self = this;
7
+ var fileLink = $('.file-link', this.el);
8
+ if (fileLink.size() == 1){
9
+ var changeLabel = $('.change-label', this.el).text();
10
+ var changeDiv = $('.change', this.el);
11
+ changeDiv.hide();
12
+ $('.clear', this.el).hide();
13
+ var clearCheckBox = $('.clear input:checkbox', this.el);
14
+ var fileInput = $('.change input', this.el);
15
+
16
+ var link = $('<a href="#" class="js-change-link"/>');
17
+ link.text(changeLabel+'...')
18
+ .insertAfter(fileLink)
19
+ .click(function(e){
20
+ e.preventDefault();
21
+ if (clearCheckBox.is(':checked')){
22
+ link.removeClass('open');
23
+ fileLink.removeClass('deleted');
24
+ clearCheckBox.attr('checked', false);
25
+ changeDiv.hide();
26
+ }
27
+ else{
28
+ fileLink.addClass('deleted');
29
+ clearCheckBox.attr('checked', true);
30
+ link.addClass('open');
31
+ changeDiv.show();
32
+ }
33
+ });
34
+ }
35
+
36
+ }
37
+ });
@@ -1 +1,4 @@
1
- <label for="{ @inputs[<%=@attributes['element']%>].full_id }">{ @inputs[<%=@attributes['element']%>].label }</label>
1
+ <label for="{ @inputs[<%=@attributes['element']%>].full_id }">
2
+ { @inputs[<%=@attributes['element']%>].label }
3
+ <em class="form_required_symbol" sp:if="<%=@attributes['required']%>">*</em>
4
+ </label>
@@ -1,4 +1,9 @@
1
- <forms:row error_condition="<%=@attributes['error_condition']%>">
2
- <forms:element_label element="<%=@attributes['element']%>" />
1
+ <%
2
+ error_condition = @attributes['error_condition'] ? @attributes['error_condition'] : "@inputs[#{@attributes['element']}].error?"
3
+ required = @attributes['required'] ? @attributes['required'] : "@inputs[#{@attributes['element']}].required?"
4
+ %>
5
+ <forms:row error_condition="<%=error_condition%>" required="<%=required%>">
6
+ <forms:element_label element="<%=@attributes['element']%>" required="<%=required%>"/>
3
7
  <sp:run obj="@inputs[<%=@attributes['element']%>]" />
8
+ <sp:attribute widget="<%=@attributes['element'][1..-1]%>" name="required" value="<%=(@attributes['required']=='true')? 'true' : ''%>" />
4
9
  </forms:row>
@@ -1,4 +1,13 @@
1
- <div class="row { (<%= (@attributes['error_condition'])%>) ? 'error' : '' }">
1
+ <%
2
+ if @attributes['element']
3
+ error_condition = @attributes['error_condition'] ? @attributes['error_condition'] : "@inputs[#{@attributes['element']}].error?"
4
+ required = @attributes['required'] ? @attributes['required'] : "@inputs[#{@attributes['element']}].required?"
5
+ else
6
+ error_condition = @attributes['error_condition']
7
+ required = @attributes['required']
8
+ end
9
+ %>
10
+ <div class="row { (<%=error_condition%>) ? ' error' : '' }{ (<%=required%>) ? ' required' : '' }">
2
11
  <%=@content%>
3
12
  <div style="clear: both"></div>
4
13
  </div>
@@ -38,6 +38,7 @@ module Spider; module Forms
38
38
  attr_to_scene :inputs, :names, :hidden_inputs, :labels, :error, :errors, :sub_links
39
39
  attribute :show_related, :type => TrueClass, :default => false
40
40
  i_attribute :auto_redirect, :default => false
41
+ is_attribute :multipart, :default => false
41
42
  attr_accessor :save_actions
42
43
  attr_accessor :fixed
43
44
  attr_accessor :before_save, :after_save
@@ -71,6 +72,7 @@ module Spider; module Forms
71
72
  @pk ||= @_action_local
72
73
  @pk ||= params['pk']
73
74
  @pk = nil if @pk == 'new'
75
+ @pk = Spider::HTTP.urldecode(@pk) if @pk && @pk.is_a?(String) && !@pk.empty?
74
76
  @model = const_get_full(@model) if @model.is_a?(String)
75
77
  if (@elements.is_a?(String))
76
78
  @elements = @elements.split(',').map{ |e| @model.elements[e.strip.to_sym] }.reject{ |i| i.nil? }
@@ -143,8 +145,14 @@ module Spider; module Forms
143
145
  @scene.crud = @crud
144
146
  @obj = load
145
147
  cond = {}
146
- @model.primary_keys.each do |key|
147
- cond[@sub_element.reverse.to_s+'.'+key.name.to_s] = @obj.get(key)
148
+ if @sub_element.integrated?
149
+ @sub_element.integrated_from.model.primary_keys.each do |key|
150
+ cond[@sub_element.reverse.to_s+'.'+key.name.to_s] = @obj.get("#{@sub_element.integrated_from.name}.#{key.name}")
151
+ end
152
+ else
153
+ @model.primary_keys.each do |key|
154
+ cond[@sub_element.reverse.to_s+'.'+key.name.to_s] = @obj.get(key)
155
+ end
148
156
  end
149
157
  @crud.fixed = cond
150
158
  sub_elements = []
@@ -174,6 +182,7 @@ module Spider; module Forms
174
182
  @scene.submit_and_new_text = @attributes[:submit_and_new_text] % @scene.submit_text
175
183
  @scene.submit_and_stay_text = @attributes[:submit_and_stay_text] % @scene.submit_text
176
184
  @scene.submit_buttons = @save_actions.keys
185
+ @scene.enctype = 'multipart/form-data' if @multipart
177
186
  super
178
187
  end
179
188
 
@@ -215,6 +224,15 @@ module Spider; module Forms
215
224
  widget_type = Password
216
225
  elsif (el.type == Spider::DataTypes::Bool)
217
226
  widget_type = Checkbox
227
+ elsif (el.type == Spider::DataTypes::FilePath)
228
+ if el.attributes[:uploadable]
229
+ widget_type = FileInput
230
+ input_attributes = {:save_path => el.attributes[:base_path]}
231
+ input_attributes[:save_path] = input_attributes[:save_path].call if input_attributes[:save_path].is_a?(Proc)
232
+ else
233
+ widget_type = Text
234
+ input_attributes = {:size => 50}
235
+ end
218
236
  elsif (el.model?)
219
237
  if ([:choice, :multiple_choice, :state, :multiple_state].include?(el.association) && !el.extended?)
220
238
  widget_type = el.type.attributes[:estimated_size] && el.type.attributes[:estimated_size] > 30 ?
@@ -256,6 +274,7 @@ module Spider; module Forms
256
274
  input.model = el.type if input.respond_to?(:model)
257
275
  input.condition = el.condition if el.condition
258
276
  end
277
+ @multipart = true if input.needs_multipart?
259
278
  return input
260
279
  end
261
280
 
@@ -267,8 +286,8 @@ module Spider; module Forms
267
286
  end
268
287
 
269
288
  def instantiate_obj
270
- if (@pk && !@pk.empty?)
271
- parts = @pk.split(':')
289
+ if (@pk && !@pk.to_s.empty?)
290
+ parts = @pk.to_s.split(':')
272
291
  h = {}
273
292
  @model.primary_keys.each{ |k| h[k.name] = parts.shift }
274
293
  return @model.new(h)
@@ -294,6 +313,7 @@ module Spider; module Forms
294
313
  input = @inputs[element_name]
295
314
  next unless input
296
315
  next if input.read_only?
316
+ input.check
297
317
  # debug("SETTING #{element_name} TO #{@inputs[element_name].prepare_value(@data[element_name.to_s])}")
298
318
  if (input.error?)
299
319
  @error = true
@@ -311,7 +331,7 @@ module Spider; module Forms
311
331
  # obj.set(element_name, @inputs[element_name].prepare_value(@data[element_name.to_s]))
312
332
  rescue FormatError => exc
313
333
  # debugger
314
- add_error(exc, exc.message, element_name)
334
+ add_error(exc.message, element_name, exc)
315
335
  end
316
336
  end
317
337
  if (@fixed)
@@ -339,15 +359,20 @@ module Spider; module Forms
339
359
  if exc.is_a?(Spider::Model::MapperElementError)
340
360
  Spider::Logger.error(exc)
341
361
  exc_element = exc.element.name
342
- add_error(exc, exc.message, exc_element)
362
+ add_error(exc.message, exc_element, exc)
343
363
  else
344
364
  raise
345
365
  end
346
366
  end
347
367
  @after_save.call(obj, save_mode) if @after_save
348
368
  after_save(obj, save_mode)
349
- if (@auto_redirect)
350
- redirect(@request.path)
369
+ @auto_redirect = true if @auto_redirect.is_a?(String) && @auto_redirect.strip == 'true'
370
+ if @auto_redirect
371
+ if @auto_redirect.is_a?(String)
372
+ redirect(@auto_redirect)
373
+ else
374
+ redirect(@request.path)
375
+ end
351
376
  end
352
377
  end
353
378
  if (action == 'submit_and_new')
@@ -364,7 +389,7 @@ module Spider; module Forms
364
389
  def after_save(obj, save_mode)
365
390
  end
366
391
 
367
- def add_error(exception, message, element_name=nil)
392
+ def add_error(message, element_name=nil, exception=nil)
368
393
  @error = true
369
394
  @errors[element_name] ||= []
370
395
  @errors[element_name] << message
@@ -413,12 +438,20 @@ module Spider; module Forms
413
438
  end
414
439
 
415
440
  def self.parse_override(el)
441
+
416
442
  if (el.name == 'form:fields')
417
443
  el.name = 'tpl:override-content'
418
444
  el['search'] = '.fields'
419
445
  end
420
446
  el.search('form:input').each do |input|
421
- new_input = "<sp:run obj=\"@inputs[:#{input['id']}]\" />"
447
+ input_attributes = input.attributes.to_hash
448
+ widget_id = input_attributes.delete('id')
449
+ new_input = "<sp:run obj=\"@inputs[:#{widget_id}]\" widget=\":#{widget_id}\">"
450
+
451
+ input_attributes.each do |key, value|
452
+ new_input += "<sp:attribute name=\"#{key}\" value=\"#{value}\" />"
453
+ end
454
+ new_input += "</sp:run>"
422
455
  input.swap(new_input)
423
456
  end
424
457
  return el