pettanr_public_domain_v01_licenses 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,28 +5,37 @@ module PettanrPublicDomainV01Licenses
5
5
  before_filter :authenticate_user, :only => [:new, :create]
6
6
  before_filter :authenticate_artist, :only => [:new, :create]
7
7
 
8
+ def self.my_module
9
+ PettanrPublicDomainV01Licenses
10
+ end
11
+
12
+ def self.my_model
13
+ PettanrPublicDomainV01Licenses::Attribute
14
+ end
15
+
8
16
  def new
9
17
  @original_picture, @original_picture_license_group, @license_group =
10
- PettanrPublicDomainV01Licenses::Attribute.remember_params params, @operators
11
- @public_domain_license = PettanrPublicDomainV01Licenses::Attribute.new
12
- @public_domain_license.supply_default @operators
18
+ self.class.my_model.remember_params params, @operators
19
+ @attr = @license_group.my_engine.new_attribute {}
20
+ # rare case !
21
+ # Attribute need artist name by @operators
22
+ @attr.supply_default @operators
13
23
 
14
24
  respond_to do |format|
15
- format.html # new.html.erb
16
- # format.js
25
+ format.html
17
26
  end
18
27
  end
19
28
 
20
29
  def create
21
30
  @original_picture, @original_picture_license_group, @license_group =
22
- PettanrPublicDomainV01Licenses::Attribute.remember_params params, @operators
23
- @public_domain_license = PettanrPublicDomainV01Licenses::Attribute.new params[:public_domain_license]
24
- @license = License.show @public_domain_license.license_id, @operators
31
+ self.class.my_model.remember_params params, @operators
32
+ @attr = self.class.my_module.new_attribute params[:attributes]
33
+ @license = License.show @attr.license_id, @operators
25
34
  @resource_picture = @original_picture.resource_picture || ResourcePicture.new
26
- @resource_picture.attributes = @public_domain_license.resource_picture_attributes @original_picture, @license
35
+ @resource_picture.attributes = @attr.resource_picture_attributes @original_picture, @license
27
36
  @resource_picture.overwrite @original_picture
28
37
  respond_to do |format|
29
- if @public_domain_license.valid?
38
+ if @attr.valid?
30
39
  format.html { render main_app.new_resource_picture_path }
31
40
  format.json { render json: @resource_picture.to_json(ResourcePicture.show_json_opt), status: :created }
32
41
  else
@@ -1,9 +1,10 @@
1
1
  module PettanrPublicDomainV01Licenses
2
2
  class Attribute < ActiveRecord::Base
3
- belongs_to :license
4
3
 
5
4
  validates :license_id, :presence => true, :numericality => true #, :existence => true
6
5
  validates :artist_name, :presence => true
6
+ # validates :source_url, :presence => true
7
+ # validates :note, :presence => true
7
8
 
8
9
  def supply_default operators
9
10
  self.artist_name = operators.artist.name
@@ -14,11 +15,14 @@ module PettanrPublicDomainV01Licenses
14
15
  :original_picture_id => op.id,
15
16
  :license_id => ls.id,
16
17
  :artist_name => self.artist_name,
18
+ :system_picture_id => ls.system_picture_id,
17
19
  :license_group_classname => ls.license_group_classname,
18
20
  :license_group_settings => ls.license_group_settings,
19
21
  :credit_picture_settings => ls.credit_picture_settings,
20
22
  :license_settings => {
21
- :system_picture_id => ls.system_picture_id,
23
+ :license_id => ls.id,
24
+ # :system_picture_id => ls.system_picture_id, # no save
25
+ :artist_name => self.artist_name,
22
26
  :source_url => self.source_url,
23
27
  :note => self.note
24
28
  }.to_json
@@ -32,5 +36,25 @@ module PettanrPublicDomainV01Licenses
32
36
  [op, oplg, lg]
33
37
  end
34
38
 
39
+ def engine_name
40
+ "pettanr_public_domain_v01_licenses"
41
+ end
42
+
43
+ def form_name
44
+ self.engine_name + '/attributes'
45
+ end
46
+
47
+ def label_name field_name = nil
48
+ self.class.to_s + (field_name ? '.' + field_name : '')
49
+ end
50
+
51
+ def trans_name field_name = nil
52
+ self.engine_name + '.' + field_name
53
+ end
54
+
55
+ def tag_name field_name
56
+ 'attributes[' + field_name + ']'
57
+ end
58
+
35
59
  end
36
60
  end
@@ -1,9 +1,11 @@
1
1
  <table class="no-border">
2
2
  <tr>
3
3
  <td width="1px">
4
- <%= link_to(
5
- tag(:img, :src => picture.license.system_picture.url, :alt => h(picture.license.caption.to_s), :width => picture.license.system_picture.width, :height => picture.license.system_picture.height),
6
- picture.license.url )
4
+ <%= content_tag(:a,
5
+ tag(:img, :src => picture.system_picture.url,
6
+ :alt => h(picture.alt_name),
7
+ :width => picture.system_picture.width, :height => picture.system_picture.height),
8
+ :href => picture.license.url )
7
9
  %>
8
10
  </td>
9
11
  <td>
@@ -12,17 +14,19 @@
12
14
  <%= h(truncate(picture.artist_name, :length => 12)) %>
13
15
  </div>
14
16
  <div class="md5">
15
- <% picture.license.boosts 'read' %>
16
17
  <% if picture.attribute_extend.source_url.blank? %>
17
- <% source_url_off_btn = SystemPicture.find(picture.license.credit_picture_extend.source_url_off_btn_id) %>
18
+ <% source_url_off_btn = picture.credit_picture_extend.source_url_off_btn %>
18
19
  <%=
19
- tag(:img, :src => source_url_off_btn.url, :alt => 'no source', :width => source_url_off_btn.width, :height => source_url_off_btn.height)
20
+ tag(:img, :src => source_url_off_btn.url, :alt => 'no source',
21
+ :width => source_url_off_btn.width, :height => source_url_off_btn.height
22
+ )
20
23
  %>
21
24
  <% else %>
22
- <% source_url_btn = SystemPicture.find(picture.license.credit_picture_extend.source_url_btn_id) %>
25
+ <% source_url_btn = picture.credit_picture_extend.source_url_btn %>
23
26
  <%= link_to(
24
- tag(:img, :src => source_url_btn.url, :alt => 'source url', :width => source_url_btn.width, :height => source_url_btn.height),
25
- picture.attribute_extend.source_url)
27
+ tag(:img, :src => source_url_btn.url, :alt => 'source url',
28
+ :width => source_url_btn.width, :height => source_url_btn.height
29
+ ), picture.attribute_extend.source_url)
26
30
  %>
27
31
  <% end %>
28
32
  </div>
@@ -1,36 +1,30 @@
1
- <%
2
- unless @public_domain_license
3
- @public_domain_license = PettanrPublicDomainV01Licenses::Attribute.new
4
- @public_domain_license.supply_default @operators
5
- end
6
- %>
7
- <%= form_tag('/pettanr_public_domain_v01_licenses/attributes') do %>
8
- <%= render 'system/error_explanation', :obj => @public_domain_license %>
1
+ <%= form_tag(@attr.form_name) do %>
2
+ <%= render 'system/error_explanation', :obj => @attr %>
9
3
 
10
4
  <table class="no-border">
11
5
  <tr>
12
6
  <td><%= t_m 'LicenseGroup' -%></td>
13
- <td><%= h @license_group.caption -%></td>
14
- <td><%= t('pettanr_public_domain_v01_licenses.selected') -%></td>
7
+ <td><%= t_m @attr.label_name -%></td>
8
+ <td><%= t(@attr.trans_name('selected')) -%></td>
15
9
  </tr>
16
10
  <tr>
17
- <td><%= t_m 'PettanrPublicDomainV01Licenses::Attribute.license_id' -%></td>
18
- <td><%= collection_select :public_domain_license, :license_id, @license_group.licenses.map {|l| [l.caption, l.id] }, :last, :first -%></td>
19
- <td><%= t('pettanr_public_domain_v01_licenses.no_blank') -%></td>
11
+ <td><%= t_m @attr.label_name('license_id') -%></td>
12
+ <td><%= collection_select :attributes, :license_id, @license_group.licenses.map {|l| [l.caption, l.id] }, :last, :first -%></td>
13
+ <td><%= t(@attr.trans_name('no_blank')) -%></td>
20
14
  </tr>
21
15
  <tr>
22
- <td><%= t_m 'PettanrPublicDomainV01Licenses::Attribute.artist_name' -%></td>
23
- <td><%= text_field_tag 'public_domain_license[artist_name]', @public_domain_license.artist_name -%></td>
24
- <td><%= t('pettanr_public_domain_v01_licenses.no_blank') -%></td>
16
+ <td><%= t_m @attr.label_name('artist_name') -%></td>
17
+ <td><%= text_field_tag @attr.tag_name('artist_name'), @attr.artist_name -%></td>
18
+ <td><%= t(@attr.trans_name('no_blank')) -%></td>
25
19
  </tr>
26
20
  <tr>
27
- <td><%= t_m 'PettanrPublicDomainV01Licenses::Attribute.source_url' -%></td>
28
- <td><%= text_field_tag 'public_domain_license[source_url]', @public_domain_license.source_url -%></td>
21
+ <td><%= t_m @attr.label_name('source_url') -%></td>
22
+ <td><%= text_field_tag @attr.tag_name('source_url'), @attr.source_url -%></td>
29
23
  <td></td>
30
24
  </tr>
31
25
  <tr>
32
- <td><%= t_m 'PettanrPublicDomainV01Licenses::Attribute.note' -%></td>
33
- <td><%= text_field_tag 'public_domain_license[note]', @public_domain_license.note -%></td>
26
+ <td><%= t_m @attr.label_name('note') -%></td>
27
+ <td><%= text_field_tag @attr.tag_name('note'), @attr.note -%></td>
34
28
  <td></td>
35
29
  </tr>
36
30
  </table>
@@ -40,6 +34,6 @@
40
34
  <%= hidden_field_tag 'original_picture_license_group[license_group_id]', @original_picture_license_group.license_group_id %>
41
35
 
42
36
  <div class="actions">
43
- <%= submit_tag t('pettanr_public_domain_v01_licenses.next') %>
37
+ <%= submit_tag t(@attr.trans_name('next')) %>
44
38
  </div>
45
39
  <% end %>
@@ -2,7 +2,9 @@
2
2
  <tr>
3
3
  <td colspan="2">
4
4
  <%= link_to(
5
- tag(:img, :src => picture.license.system_picture.url, :alt => h(picture.license.license_group.caption.to_s + '[' + picture.license.caption.to_s + ']'), :width => picture.license.system_picture.width, :height => picture.license.system_picture.height),
5
+ tag(:img, :src => picture.license.system_picture.url,
6
+ :alt => h(picture.alt_name),
7
+ :width => picture.system_picture.width, :height => picture.system_picture.height),
6
8
  picture.license.url )
7
9
  %>
8
10
  </td>
@@ -13,19 +15,19 @@
13
15
  </td>
14
16
  </tr>
15
17
  <tr>
16
- <td><%= t_m 'PettanrPublicDomainV01Licenses::Attribute' -%></td>
18
+ <td><%= t_m picture.attribute_extend.label_name() -%></td>
17
19
  <td><%= link_to(h(picture.license.license_group.caption), picture.license.license_group.url) -%></td>
18
20
  </tr>
19
21
  <tr>
20
- <td><%= t_m 'PettanrPublicDomainV01Licenses::Attribute.license_id' -%></td>
22
+ <td><%= t_m picture.attribute_extend.label_name('license_id') -%></td>
21
23
  <td><%= link_to(h(picture.license.caption), picture.license.url) -%></td>
22
24
  </tr>
23
25
  <tr>
24
- <td><%= t_m 'PettanrPublicDomainV01Licenses::Attribute.artist_name' -%></td>
26
+ <td><%= t_m picture.attribute_extend.label_name('artist_name') -%></td>
25
27
  <td><%= h(picture.artist_name) -%></td>
26
28
  </tr>
27
29
  <tr>
28
- <td><%= t_m 'PettanrPublicDomainV01Licenses::Attribute.source_url' -%></td>
30
+ <td><%= t_m picture.attribute_extend.label_name('source_url') -%></td>
29
31
  <td>
30
32
  <% if picture.attribute_extend.source_url.blank? %>
31
33
  <% else %>
@@ -34,7 +36,7 @@
34
36
  </td>
35
37
  </tr>
36
38
  <tr>
37
- <td><%= t_m 'PettanrPublicDomainV01Licenses::Attribute.note' -%></td>
39
+ <td><%= t_m picture.attribute_extend.label_name('note') -%></td>
38
40
  <td><%= h picture.attribute_extend.note -%></td>
39
41
  </tr>
40
42
  </table>
@@ -54,21 +54,23 @@ module PettanrPublicDomainV01Licenses
54
54
  end
55
55
 
56
56
  def attribute_extend
57
- self.new_attribute unless @attribute_extend
58
- @attribute_extend ||= PettanrPublicDomainV01Licenses::Attribute.new
57
+ @attribute_extend
59
58
  end
60
59
 
61
60
  def attribute_extend= params
62
61
  # load attributes
63
- @attribute_extend = PettanrPublicDomainV01Licenses::Attribute.new params
62
+ @attribute_extend = PettanrPublicDomainV01Licenses.new_attribute params
64
63
  # no supply default params
65
64
  end
66
65
 
67
- def new_attribute params = {}
68
- @attribute_extend = PettanrPublicDomainV01Licenses::Attribute.new params
69
- # Attribute's supply_default need operators
70
- # @attribute_extend.supply_default operators
66
+ end
67
+
68
+ module ModuleMethods
69
+ def new_attribute params = {}
70
+ PettanrPublicDomainV01Licenses::Attribute.new params
71
71
  end
72
72
 
73
73
  end
74
+
75
+ extend ModuleMethods
74
76
  end
@@ -1,3 +1,3 @@
1
1
  module PettanrPublicDomainV01Licenses
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pettanr_public_domain_v01_licenses
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-15 00:00:00.000000000 Z
12
+ date: 2014-04-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -61,9 +61,7 @@ files:
61
61
  - app/models/pettanr_public_domain_v01_licenses/attribute.rb
62
62
  - app/models/pettanr_public_domain_v01_licenses/credit_picture.rb
63
63
  - app/models/pettanr_public_domain_v01_licenses/license.rb
64
- - app/views/layouts/pettanr_public_domain_v01_licenses/application.html.erb
65
64
  - app/views/pettanr_public_domain_v01_licenses/attributes/new.html.erb
66
- - app/views/pettanr_public_domain_v01_licenses/attributes/new.js.erb
67
65
  - app/views/pettanr_public_domain_v01_licenses/attributes/_confirm.html.erb
68
66
  - app/views/pettanr_public_domain_v01_licenses/attributes/_credit.html.erb
69
67
  - app/views/pettanr_public_domain_v01_licenses/attributes/_form.html.erb
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>PettanrPublicDomainV01Licenses</title>
5
- <%= stylesheet_link_tag "pettanr_public_domain_v01_licenses/application", :media => "all" %>
6
- <%= javascript_include_tag "pettanr_public_domain_v01_licenses/application" %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>
@@ -1 +0,0 @@
1
- $("#oplg").html("<%= escape_javascript(render('form')) -%>");