card 1.16.8 → 1.16.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/db/migrate_core_cards/{20150611203506_rails_inflection_updates.rb → 20120611203506_rails_inflection_updates.rb} +0 -0
  4. data/db/migrate_core_cards/20150326205655_bootswatch_themes.rb +0 -1
  5. data/db/migrate_core_cards/20150429090551_search_card_context.rb +1 -1
  6. data/db/migrate_core_cards/20150708224756_add_list_cards.rb +22 -0
  7. data/db/seed/new/card_actions.yml +789 -509
  8. data/db/seed/new/card_acts.yml +1 -1
  9. data/db/seed/new/card_changes.yml +2618 -1920
  10. data/db/seed/new/card_references.yml +1034 -901
  11. data/db/seed/new/cards.yml +2303 -1675
  12. data/db/seed/test/fixtures/card_actions.yml +1926 -1606
  13. data/db/seed/test/fixtures/card_acts.yml +354 -324
  14. data/db/seed/test/fixtures/card_changes.yml +5950 -5175
  15. data/db/seed/test/fixtures/card_references.yml +1861 -1630
  16. data/db/seed/test/fixtures/cards.yml +3768 -3048
  17. data/db/seed/test/seed.rb +121 -107
  18. data/lib/card.rb +2 -3
  19. data/lib/card/active_record_helper.rb +44 -0
  20. data/lib/card/auth.rb +51 -47
  21. data/lib/card/cache.rb +7 -3
  22. data/lib/card/codename.rb +7 -7
  23. data/lib/card/format.rb +2 -1
  24. data/lib/card/migration.rb +17 -16
  25. data/lib/card/name.rb +71 -20
  26. data/lib/card/set.rb +202 -166
  27. data/lib/card/simplecov_helper.rb +11 -7
  28. data/lib/card/subcards.rb +249 -0
  29. data/mod/01_core/set/all/collection.rb +1 -2
  30. data/mod/01_core/set/all/fetch.rb +167 -92
  31. data/mod/01_core/set/all/initialize.rb +8 -22
  32. data/mod/01_core/set/all/name.rb +128 -79
  33. data/mod/01_core/set/all/phases.rb +93 -95
  34. data/mod/01_core/set/all/subcards.rb +70 -0
  35. data/mod/01_core/set/all/tracked_attributes.rb +83 -59
  36. data/mod/01_core/set/all/trash.rb +14 -12
  37. data/mod/01_core/set/all/type.rb +3 -24
  38. data/mod/01_core/spec/set/all/initialize_spec.rb +44 -14
  39. data/mod/01_core/spec/set/all/permissions_spec.rb +206 -185
  40. data/mod/01_core/spec/set/all/tracked_attributes_spec.rb +0 -10
  41. data/mod/01_core/spec/set/all/trash_spec.rb +38 -13
  42. data/mod/01_core/spec/set/all/type_spec.rb +0 -19
  43. data/mod/01_history/set/all/content_history.rb +5 -3
  44. data/mod/01_history/set/all/history.rb +117 -82
  45. data/mod/02_basic_types/set/all/base.rb +50 -49
  46. data/mod/03_machines/lib/card/machine.rb +2 -1
  47. data/mod/03_machines/lib/javascript/wagn_mod.js.coffee +55 -17
  48. data/mod/03_machines/spec/set/type/javascript_spec.rb +18 -12
  49. data/mod/05_email/set/right/followers.rb +5 -5
  50. data/mod/05_email/set/right/following.rb +1 -1
  51. data/mod/05_email/set/type_plus_right/user/follow.rb +1 -1
  52. data/mod/05_standard/lib/carrier_wave/cardmount.rb +19 -11
  53. data/mod/05_standard/lib/file_uploader.rb +1 -1
  54. data/mod/05_standard/set/abstract/attachment.rb +20 -8
  55. data/mod/05_standard/set/all/list_changes.rb +43 -0
  56. data/mod/05_standard/set/all/rich_html/form.rb +21 -11
  57. data/mod/05_standard/set/all/rich_html/menu.rb +1 -1
  58. data/mod/05_standard/set/right/account.rb +5 -5
  59. data/mod/05_standard/set/self/head.rb +0 -1
  60. data/mod/05_standard/set/self/signin.rb +43 -35
  61. data/mod/05_standard/set/type/file.rb +9 -2
  62. data/mod/05_standard/set/type/list.rb +134 -0
  63. data/mod/05_standard/set/type/listed_by.rb +94 -0
  64. data/mod/05_standard/set/type/search_type.rb +62 -61
  65. data/mod/05_standard/set/type/signup.rb +94 -63
  66. data/mod/05_standard/set/type/user.rb +48 -39
  67. data/mod/05_standard/spec/set/all/account_spec.rb +1 -1
  68. data/mod/05_standard/spec/set/all/rich_html/form_spec.rb +2 -2
  69. data/mod/05_standard/spec/set/self/signin_spec.rb +23 -27
  70. data/mod/05_standard/spec/set/type/email_template_spec.rb +0 -2
  71. data/mod/05_standard/spec/set/type/list_spec.rb +140 -0
  72. data/mod/05_standard/spec/set/type/listed_by_spec.rb +157 -0
  73. data/mod/05_standard/spec/set/type/signup_spec.rb +38 -32
  74. data/spec/lib/card/subcards_spec.rb +126 -0
  75. metadata +14 -3
@@ -7,38 +7,37 @@ format do
7
7
 
8
8
  # NAME VIEWS
9
9
 
10
- view :name, closed: true, perms: :none do |args| card.name end
11
- view :key, closed: true, perms: :none do |args| card.key end
12
- view :title, closed: true, perms: :none do |args| args[:title] || card.name end
13
-
14
- view :linkname, closed: true, perms: :none do |args| card.cardname.url_key end
15
- view :url, closed: true, perms: :none do |args| card_url _render_linkname end
16
- view :url_link, closed: true, perms: :none do |args| web_link card_url(_render_linkname) end
10
+ simple_args = { closed: true, perms: :none }
11
+ view(:name, simple_args) { card.name }
12
+ view(:key, simple_args) { card.key }
13
+ view(:title, simple_args) { |args| args[:title] || card.name }
14
+ view(:linkname, simple_args) { card.cardname.url_key }
15
+ view(:url, simple_args) { card_url _render_linkname }
16
+ view(:url_link, simple_args) { web_link card_url(_render_linkname) }
17
17
 
18
18
  view :link, closed: true, perms: :none do |args|
19
- card_link( card.name,
20
- text: showname( args[:title] ),
19
+ card_link(
20
+ card.name,
21
+ text: showname(args[:title]),
21
22
  known: card.known?,
22
23
  path_opts: { type: args[:type] }
23
24
  )
24
25
  end
25
26
 
26
- view :codename, closed: true do |args| card.codename.to_s end
27
- view :id, closed: true do |args| card.id end
28
- view :type, closed: true do |args| card.type_name end
29
-
27
+ view(:codename, closed: true) { card.codename.to_s }
28
+ view(:id, closed: true) { card.id }
29
+ view(:type, closed: true) { card.type_name }
30
30
 
31
31
  # DATE VIEWS
32
32
 
33
- view :created_at, closed: true do |args| time_ago_in_words card.created_at end
34
- view :updated_at, closed: true do |args| time_ago_in_words card.updated_at end
35
- view :acted_at, closed: true do |args| time_ago_in_words card.acted_at end
36
-
33
+ view(:created_at, closed: true) { time_ago_in_words card.created_at }
34
+ view(:updated_at, closed: true) { time_ago_in_words card.updated_at }
35
+ view(:acted_at, closed: true) { time_ago_in_words card.acted_at }
37
36
 
38
37
  # CONTENT VIEWS
39
38
 
40
39
  view :raw do |args|
41
- scard = args[:structure] ? Card[ args[:structure] ] : card
40
+ scard = args[:structure] ? Card[args[:structure]] : card
42
41
  scard ? scard.raw_content : _render_blank
43
42
  end
44
43
 
@@ -55,32 +54,30 @@ format do
55
54
  end
56
55
 
57
56
  view :closed_content, closed: true do |args|
58
- Card::Content.truncatewords_with_closing_tags _render_core(args) #{ yield }
57
+ Card::Content.truncatewords_with_closing_tags _render_core(args)
59
58
  end
60
59
 
61
- view :blank, closed: true, perms: :none do |args|
60
+ view :blank, closed: true, perms: :none do
62
61
  ''
63
62
  end
64
63
 
65
-
66
- # note: content and open_content may look like they should be aliased to core, but it's important that they render
67
- # core explicitly so that core view overrides work. the titled and labeled views below, however, are not intended
68
- # for frequent override, so this shortcut is fine.
69
-
64
+ # note: content and open_content may look like they should be aliased to
65
+ # core, but it's important that they render core explicitly so that core view
66
+ # overrides work. the titled and labeled views below, however, are not
67
+ # intended for frequent override, so this shortcut is fine.
70
68
 
71
69
  # NAME + CONTENT VIEWS
72
70
 
73
71
  view :titled do |args|
74
- "#{ card.name }\n\n#{ _render_core args }"
72
+ "#{card.name}\n\n#{_render_core args}"
75
73
  end
76
74
  view :open, :titled
77
75
 
78
76
  view :labeled do |args|
79
- "#{ card.name }: #{ _render_closed_content args }"
77
+ "#{card.name}: #{_render_closed_content args}"
80
78
  end
81
79
  view :closed, :labeled
82
80
 
83
-
84
81
  # SPECIAL VIEWS
85
82
 
86
83
  view :array do |args|
@@ -89,34 +86,38 @@ format do
89
86
  end.inspect
90
87
  end
91
88
 
92
-
93
-
94
- #none of the below belongs here!!
95
-
89
+ # none of the below belongs here!!
96
90
 
97
91
  view :template_rule, tags: :unknown_ok do |args|
98
- #FIXME - relativity should be handled in smartname
92
+ # FIXME: - relativity should be handled in smartname
93
+ return '' unless args[:inc_name]
94
+ name = args[:inc_name].to_name
95
+ stripped_name = name.stripped.to_name
99
96
 
100
- name = args[:inc_name] or return ''
101
- regexp = /\b_(left|right|whole|self|user|main|\d+|L*R?)\b/
102
- absolute = name !~ regexp && name !~ /^\+/
103
-
104
- tname = name.gsub regexp, ''
105
- if tname !~ /^\+/ and !absolute
97
+ if name.relative? && !stripped_name.starts_with_joint?
98
+ # not a simple relative name; just return the original syntax
106
99
  "{{#{args[:inc_syntax]}}}"
107
100
  else
108
- set_name = if absolute # find the most appropriate set to use as prototype for inclusion
109
- "#{name}+#{Card[:self].name}"
110
- else
111
- tmpl_set_name = parent.card.cardname.trunk_name
112
- if tmpl_set_class_name = tmpl_set_name.tag_name and Card[tmpl_set_class_name].codename == 'type'
113
- "#{tmpl_set_name.left_name}#{name}+#{Card[:type_plus_right].name}" # *type plus right
101
+ set_name =
102
+ case
103
+ when name.absolute?
104
+ "#{name}+#{Card[:self].name}" # *self set
105
+ when type = on_type_set
106
+ "#{type}#{name}+#{Card[:type_plus_right].name}" # *type plus right
114
107
  else
115
- "#{tname.gsub /^\+/,''}+#{Card[:right].name}" # *right
108
+ "#{stripped_name.gsub(/^\+/, '')}+#{Card[:right].name}" # *right
116
109
  end
117
- end
118
-
119
- subformat( Card.fetch(set_name) ).render_template_link args
110
+ subformat(Card.fetch set_name).render_template_link args
120
111
  end
121
112
  end
113
+
114
+ def on_type_set
115
+ return unless
116
+ (tmpl_set_name = parent.card.cardname.trunk_name) &&
117
+ (tmpl_set_class_name = tmpl_set_name.tag_name) &&
118
+ (tmpl_set_class_card = Card[tmpl_set_class_name]) &&
119
+ (tmpl_set_class_card.codename == 'type')
120
+
121
+ tmpl_set_name.left_name
122
+ end
122
123
  end
@@ -116,7 +116,8 @@ class Card
116
116
  event_suffix = host_class.name.gsub ':', '_'
117
117
  host_class.event(
118
118
  "reset_machine_output_#{ event_suffix }".to_sym,
119
- after: :store_subcards, on: :save
119
+ after: :expire_related, on: :save
120
+ #after: :store_subcards, on: :save
120
121
  ) do
121
122
  reset_machine_output!
122
123
  end
@@ -4,27 +4,65 @@ window.wagn ||= {} #needed to run w/o *head. eg. jasmine
4
4
 
5
5
  $.extend wagn,
6
6
  editorContentFunctionMap: {
7
- '.ace-editor-textarea' : -> ace_editor_content this[0]
8
- '.tinymce-textarea' : -> tinyMCE.get(@[0].id).getContent()
9
- '.pointer-select' : -> pointerContent @val()
10
- '.pointer-multiselect' : -> pointerContent @val()
11
- '.pointer-radio-list' : -> pointerContent @find('input:checked').val()
12
- '.pointer-list-ul' : -> pointerContent @find('input' ).map( -> $(this).val() )
13
- '.pointer-checkbox-list' : -> pointerContent @find('input:checked').map( -> $(this).val() )
14
- '.pointer-select-list' : -> pointerContent @find('.pointer-select select').map( -> $(this).val() )
15
- '.pointer-mixed' : -> pointerContent @find('.pointer-checkbox-sublist input:checked, .pointer-sublist-ul input').map( -> $(this).val() )
16
- '.perm-editor' : -> permissionsContent this # must happen after pointer-list-ul, I think
7
+ '.ace-editor-textarea' : -> ace_editor_content this[0]
8
+ '.tinymce-textarea' : -> tinyMCE.get(@[0].id).getContent()
9
+ '.pointer-select' : -> pointerContent @val()
10
+ '.pointer-multiselect' : -> pointerContent @val()
11
+ '.pointer-radio-list' : -> pointerContent @find('input:checked').val()
12
+ '.pointer-list-ul' : ->
13
+ pointerContent @find('input').map( -> $(this).val() )
14
+ '.pointer-checkbox-list' : ->
15
+ pointerContent @find('input:checked').map( -> $(this).val() )
16
+ '.pointer-select-list' : ->
17
+ pointerContent @find('.pointer-select select').map( -> $(this).val() )
18
+ '.pointer-mixed' : ->
19
+ element = '.pointer-checkbox-sublist input:checked,\
20
+ .pointer-sublist-ul input'
21
+ pointerContent @find(element).map( -> $(this).val() )
22
+ # must happen after pointer-list-ul, I think
23
+ '.perm-editor' : -> permissionsContent this
17
24
  }
18
25
 
19
26
  editorInitFunctionMap: {
20
- '.date-editor' : -> @datepicker { dateFormat: 'yy-mm-dd' }
21
- 'textarea' : -> $(this).autosize()
22
- '.ace-editor-textarea' : -> wagn.initAce $(this)
23
- '.tinymce-textarea' : -> wagn.initTinyMCE @[0].id
24
- '.pointer-list-editor' : -> @sortable({handle: '.handle', cancel: ''}); wagn.initPointerList @find('input')
25
- '.file-upload' : -> @fileupload( dataType: 'html', done: wagn.doneFile, add: wagn.chooseFile, progressall: wagn.progressallFile )#, forceIframeTransport: true )
26
- '.etherpad-textarea' : -> $(this).closest('form').find('.edit-submit-button').attr('class', 'etherpad-submit-button')
27
+ '.date-editor' : -> @datepicker { dateFormat : 'yy-mm-dd' }
28
+ 'textarea' : -> $(this).autosize()
29
+ '.ace-editor-textarea' : -> wagn.initAce $(this)
30
+ '.tinymce-textarea' : -> wagn.initTinyMCE @[0].id
31
+ '.pointer-list-editor' : ->
32
+ @sortable({handle : '.handle', cancel : ''})
33
+ wagn.initPointerList @find('input')
34
+ '.file-upload' : -> wagn.upload_file(this)
35
+ '.etherpad-textarea' : ->
36
+ $(this).closest('form')
37
+ .find('.edit-submit-button')
38
+ .attr('class', 'etherpad-submit-button')
27
39
  }
40
+ upload_file: (fileupload) ->
41
+ # for file as a subcard in a form,
42
+ # excess parameters are inlcuded in the request which cause errors.
43
+ # only the file, type_id and attachment_card_name are needed
44
+ # attachment_card_name is the original card name,
45
+ # ex: card[subcards][+logo][image], card[file]
46
+ $(fileupload).bind 'fileuploadsubmit', (e,data) ->
47
+ $_this = $(this)
48
+ card_name = $_this.siblings(".attachment_card_name:first").attr("name")
49
+ type_id = $_this.siblings("#attachment_type_id").val()
50
+ data.formData = {
51
+ "card[type_id]" : type_id,
52
+ "attachment_upload" : card_name
53
+ }
54
+ $_fileupload = $(fileupload)
55
+ if $_fileupload.closest("form").attr("action").indexOf("update") > -1
56
+ url = "/card/update/"+$(fileupload).siblings("#file_card_name").val()
57
+ else
58
+ url = "/card/create"
59
+ $(fileupload).fileupload(
60
+ url : url,
61
+ dataType : 'html',
62
+ done : wagn.doneFile,
63
+ add : wagn.chooseFile,
64
+ progressall : wagn.progressallFile
65
+ )#, forceIframeTransport: true )
28
66
 
29
67
  initPointerList: (input)->
30
68
  optionsCard = input.closest('ul').data('options-card')
@@ -6,23 +6,29 @@ describe Card::Set::Type::JavaScript do
6
6
  let(:changed_js) { 'alert( "Hello" );' }
7
7
  let(:compressed_changed_js) { 'alert("Hello");' }
8
8
 
9
-
10
9
  it_should_behave_like 'content machine', that_produces_js do
11
- let(:machine_card) { Card.gimme! "test javascript", type: :java_script, content: js}
10
+ let(:machine_card) do
11
+ Card.gimme! 'test javascript', type: :java_script, content: js
12
+ end
12
13
  let(:card_content) do
13
- { in: js, out: compressed_js,
14
- changed_in: changed_js, changed_out: compressed_changed_js }
14
+ { in: js, out: compressed_js,
15
+ changed_in: changed_js, changed_out: compressed_changed_js }
15
16
  end
16
17
  end
17
18
 
18
- it_behaves_like "machine input" do
19
- let(:create_machine_input_card) { Card.gimme! "test javascript", type: :java_script, content: js }
20
- let(:create_another_machine_input_card) { Card.gimme! "more javascript", type: :java_script, content: js }
21
- let(:create_machine_card) { Card.gimme! "script with js+*script", type: :pointer }
19
+ it_behaves_like 'machine input' do
20
+ let(:create_machine_input_card) do
21
+ Card.gimme! 'test javascript', type: :java_script, content: js
22
+ end
23
+ let(:create_another_machine_input_card) do
24
+ Card.gimme! 'more javascript', type: :java_script, content: js
25
+ end
26
+ let(:create_machine_card) do
27
+ Card.gimme! 'script with js+*script', type: :pointer
28
+ end
22
29
  let(:card_content) do
23
- { in: js, out: compressed_js,
24
- changed_in: changed_js, changed_out: compressed_changed_js }
30
+ { in: js, out: compressed_js,
31
+ changed_in: changed_js, changed_out: compressed_changed_js }
25
32
  end
26
33
  end
27
-
28
- end
34
+ end
@@ -7,8 +7,8 @@ def raw_content
7
7
  items = if (left.type_id == SetID) || (left.type_id == CardtypeID)
8
8
  left.default_follow_set_card.all_user_ids_with_rule_for(:follow).map do |user_id|
9
9
  if left.followed_by?(user_id) && (user = Card.find(user_id))
10
- user.name
11
- else
10
+ user.name
11
+ else
12
12
  nil
13
13
  end
14
14
  end.compact
@@ -21,10 +21,10 @@ def raw_content
21
21
  end
22
22
  end
23
23
 
24
- def virtual?; true end
24
+ def virtual?; !real? end
25
25
 
26
- format() do
27
- include Card::Set::Type::Pointer::Format
26
+ format() do
27
+ include Card::Set::Type::Pointer::Format
28
28
  end
29
29
 
30
30
  format(:html) { include Card::Set::Type::Pointer::HtmlFormat }
@@ -1,5 +1,5 @@
1
1
 
2
- def virtual?; true end
2
+ def virtual?; !real? end
3
3
 
4
4
 
5
5
  format :html do
@@ -13,7 +13,7 @@ def raw_content
13
13
  end
14
14
  end
15
15
 
16
- def virtual?; true end
16
+ def virtual?; !real? end
17
17
 
18
18
 
19
19
 
@@ -4,7 +4,6 @@ module CarrierWave
4
4
  module CardMount
5
5
  include CarrierWave::Mount
6
6
 
7
-
8
7
  def uploaders
9
8
  Card.uploaders ||= {}
10
9
  end
@@ -13,26 +12,33 @@ module CarrierWave
13
12
  Card.uploader_options ||= {}
14
13
  end
15
14
 
16
- def mount_uploader(column, uploader=nil, options={}, &block)
15
+ def mount_uploader column, uploader=nil, options={}, &block
17
16
  options[:mount_on] ||= :db_content
18
17
  super
19
18
 
20
- class_eval <<-RUBY, __FILE__, __LINE__+1
19
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
21
20
  event :store_#{column}_event, on: :save, after: :store do
22
21
  store_#{column}!
23
22
  end
24
23
 
25
24
  # remove files only if card has no history
26
- event :remove_#{column}_event, on: :delete, after: :stored, when: proc { |c| !c.history? } do
25
+ event :remove_#{column}_event,
26
+ on: :delete, after: :stored, when: proc { |c| !c.history? } do
27
27
  remove_#{column}!
28
28
  end
29
- event :mark_remove_#{column}_false_event, on: :update, after: :stored do
29
+ event :mark_remove_#{column}_false_event,
30
+ on: :update, after: :stored do
30
31
  mark_remove_#{column}_false
31
32
  end
32
- event :store_previous_model_for_#{column}_event, on: :update, before: :store, when: proc { |c| !c.history? } do
33
+ event :store_previous_model_for_#{column}_event,
34
+ on: :update, before: :store, when: proc { |c| !c.history? } do
33
35
  store_previous_model_for_#{column}
34
36
  end
35
- event :remove_previously_stored_#{column}_event, on: :update, after: :store, when: proc { |c| !c.history?} do
37
+ event :remove_previously_stored_#{column}_event,
38
+ on: :update, after: :store, when: proc { |c| !c.history?} do
39
+ if @previous_model_for_#{column}
40
+ @previous_model_for_#{column}.include_set_modules
41
+ end
36
42
  remove_previously_stored_#{column}
37
43
  end
38
44
 
@@ -87,11 +93,14 @@ module CarrierWave
87
93
  def serializable_hash(options=nil)
88
94
  hash = {}
89
95
 
90
- except = options && options[:except] && Array.wrap(options[:except]).map(&:to_s)
91
- only = options && options[:only] && Array.wrap(options[:only]).map(&:to_s)
96
+ except = options && options[:except] &&
97
+ Array.wrap(options[:except]).map(&:to_s)
98
+ only = options && options[:only] &&
99
+ Array.wrap(options[:only]).map(&:to_s)
92
100
 
93
101
  self.class.uploaders.each do |column, uploader|
94
- if (!only && !except) || (only && only.include?(column.to_s)) || (!only && except && !except.include?(column.to_s))
102
+ if (!only && !except) || (only && only.include?(column.to_s)) ||
103
+ (!only && except && !except.include?(column.to_s))
95
104
  hash[column.to_s] = _mounter(column).uploader.serializable_hash
96
105
  end
97
106
  end
@@ -99,6 +108,5 @@ module CarrierWave
99
108
  end
100
109
  RUBY
101
110
  end
102
-
103
111
  end
104
112
  end
@@ -146,7 +146,7 @@ class FileUploader < CarrierWave::Uploader::Base
146
146
  end
147
147
 
148
148
  def mod_file?
149
- @mod ||= model.mod_file?
149
+ model.mod_file?
150
150
  end
151
151
 
152
152
  def action_id
@@ -24,15 +24,16 @@ event :upload_attachment, before: :validate_name, on: :save, when: proc { |c| c.
24
24
  end
25
25
 
26
26
  event :assign_attachment_on_create, after: :prepare, on: :create, when: proc { |c| c.save_preliminary_upload? } do
27
- if (action = Card::Action.fetch(Card::Env.params[:cached_upload]))
27
+ if (action = Card::Action.fetch(@cached_upload))
28
28
  upload_cache_card.selected_action_id = action.id
29
29
  upload_cache_card.select_file_revision
30
30
  assign_attachment upload_cache_card.attachment.file, action.comment
31
31
  end
32
32
  end
33
33
 
34
- event :assign_attachment_on_update, after: :prepare, on: :update, when: proc { |c| c.save_preliminary_upload? } do
35
- if (action = Card::Action.fetch(Card::Env.params[:cached_upload]))
34
+ event :assign_attachment_on_update, after: :prepare, on: :update,
35
+ when: proc { |c| c.save_preliminary_upload? } do
36
+ if (action = Card::Action.fetch(@cached_upload))
36
37
  uploaded_file =
37
38
  with_selected_action_id(action.id) do
38
39
  attachment.file
@@ -53,15 +54,15 @@ event :correct_identifier, after: :store, on: :create do
53
54
  update_column(:db_content,attachment.db_content(mod: load_from_mod))
54
55
  expire
55
56
  end
56
-
57
57
  event :save_original_filename, after: :validate_name, when: proc {|c| !c.preliminary_upload? && !c.save_preliminary_upload? && c.attachment_changed?} do
58
+
58
59
  if @current_action
59
60
  @current_action.update_attributes! comment: original_filename
60
61
  end
61
62
  end
62
63
 
63
64
  event :delete_cached_upload_file_on_create, after: :extend, on: :create, when: proc { |c| c.save_preliminary_upload? } do
64
- if (action = Card::Action.fetch(Card::Env.params[:cached_upload]))
65
+ if (action = Card::Action.fetch(@cached_upload))
65
66
  upload_cache_card.delete_files_for_action action
66
67
  action.delete
67
68
  end
@@ -69,7 +70,7 @@ event :delete_cached_upload_file_on_create, after: :extend, on: :create, when: p
69
70
  end
70
71
 
71
72
  event :delete_cached_upload_file_on_update, after: :extend, on: :update, when: proc { |c| c.save_preliminary_upload? } do
72
- if (action = Card::Action.fetch(Card::Env.params[:cached_upload]))
73
+ if (action = Card::Action.fetch(@cached_upload))
73
74
  delete_files_for_action action
74
75
  action.delete
75
76
  end
@@ -89,12 +90,16 @@ def original_filename
89
90
  attachment.original_filename
90
91
  end
91
92
 
93
+ def unfilled?
94
+ !attachment.present? && !save_preliminary_upload? && super
95
+ end
96
+
92
97
  def preliminary_upload?
93
98
  Card::Env && Card::Env.params[:attachment_upload]
94
99
  end
95
100
 
96
101
  def save_preliminary_upload?
97
- Card::Env.params[:cached_upload].present?
102
+ @cached_upload.present?
98
103
  end
99
104
 
100
105
  def attachment_changed?
@@ -110,6 +115,14 @@ def upload_cache_card
110
115
  @upload_cache_card ||= Card["new_#{attachment_name}".to_sym ]
111
116
  end
112
117
 
118
+ # action id of the cached upload
119
+ def cached_upload= value
120
+ @cached_upload = value
121
+ end
122
+
123
+ def cached_upload
124
+ @cached_upload
125
+ end
113
126
 
114
127
  def load_from_mod= value
115
128
  @mod = value
@@ -164,7 +177,6 @@ def mod_dir
164
177
  end
165
178
  end
166
179
 
167
-
168
180
  def mod_file?
169
181
  if @store_in_mod
170
182
  return @mod