pettanr_pettan_protected_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 PettanrPettanProtectedV01Licenses
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
+ PettanrPettanProtectedV01Licenses
10
+ end
11
+
12
+ def self.my_model
13
+ PettanrPettanProtectedV01Licenses::Attribute
14
+ end
15
+
8
16
  def new
9
17
  @original_picture, @original_picture_license_group, @license_group =
10
- PettanrPettanProtectedV01Licenses::Attribute.remember_params params, @operators
11
- @pettan_protected_license = PettanrPettanProtectedV01Licenses::Attribute.new
12
- @pettan_protected_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
- PettanrPettanProtectedV01Licenses::Attribute.remember_params params, @operators
23
- @pettan_protected_license = PettanrPettanProtectedV01Licenses::Attribute.new params[:pettan_protected_license]
24
- @license = License.show @pettan_protected_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 = @pettan_protected_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 @pettan_protected_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 PettanrPettanProtectedV01Licenses
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 :caption, :presence => true
7
+ # validates :sources, :presence => true
7
8
 
8
9
  def supply_default operators
9
10
  self.artist_name = operators.artist.name
@@ -14,11 +15,14 @@ module PettanrPettanProtectedV01Licenses
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
  :caption => self.caption,
23
27
  :sources => self.sources
24
28
  }.to_json
@@ -32,5 +36,25 @@ module PettanrPettanProtectedV01Licenses
32
36
  [op, oplg, lg]
33
37
  end
34
38
 
39
+ def engine_name
40
+ "pettanr_pettan_protected_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.license_group.caption.to_s + '[' + 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>
@@ -15,13 +17,13 @@
15
17
  <%= h(truncate(picture.attribute_extend.caption, :length => 12)) %>
16
18
  </div>
17
19
  <div class="md5">
18
- <% picture.license.boosts 'read' %>
19
- <% source_url_btn = SystemPicture.find(picture.license.credit_picture_extend.source_url_btn_id) %>
20
+ <% source_url_btn = picture.credit_picture_extend.source_url_btn %>
20
21
  <% urls = picture.attribute_extend.sources.to_s.gsub(/\r/, '').split(/\n/) -%>
21
22
  <% urls[0..2].compact.each do |url| -%>
22
23
  <%= link_to(
23
- tag(:img, :src => source_url_btn.url, :alt => 'source url', :width => source_url_btn.width, :height => source_url_btn.height),
24
- url )
24
+ tag(:img, :src => source_url_btn.url, :alt => 'source url',
25
+ :width => source_url_btn.width, :height => source_url_btn.height
26
+ ), url )
25
27
  %>
26
28
  <% end -%>
27
29
  <%= urls.size > 2 ? '...' : '' -%>
@@ -1,36 +1,30 @@
1
- <%
2
- unless @pettan_protected_license
3
- @pettan_protected_license = PettanrPettanProtectedV01Licenses::Attribute.new
4
- @pettan_protected_license.supply_default @operators
5
- end
6
- %>
7
- <%= form_tag('/pettanr_pettan_protected_v01_licenses/attributes') do %>
8
- <%= render 'system/error_explanation', :obj => @pettan_protected_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><%= t_m 'PettanrPettanProtectedV01Licenses::Attribute' -%></td>
7
+ <td><%= t_m @attr.label_name -%></td>
14
8
  <td><%= t('pettanr_pettan_protected_v01_licenses.selected') -%></td>
15
9
  </tr>
16
10
  <tr>
17
- <td><%= t_m 'PettanrPettanProtectedV01Licenses::Attribute.license_id' -%></td>
18
- <td><%= collection_select :pettan_protected_license, :license_id, @license_group.licenses.map {|l| [l.caption, l.id] }, :last, :first -%></td>
19
- <td><%= t('pettanr_pettan_protected_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 'PettanrPettanProtectedV01Licenses::Attribute.artist_name' -%></td>
23
- <td><%= text_field_tag 'pettan_protected_license[artist_name]', @pettan_protected_license.artist_name -%></td>
24
- <td><%= t('pettanr_pettan_protected_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 'PettanrPettanProtectedV01Licenses::Attribute.caption' -%></td>
28
- <td><%= text_field_tag 'pettan_protected_license[caption]', @pettan_protected_license.caption -%></td>
21
+ <td><%= t_m @attr.label_name('caption') -%></td>
22
+ <td><%= text_field_tag @attr.tag_name('caption'), @attr.caption -%></td>
29
23
  <td></td>
30
24
  </tr>
31
25
  <tr>
32
- <td><%= t_m 'PettanrPettanProtectedV01Licenses::Attribute.sources' -%></td>
33
- <td><%= text_area_tag 'pettan_protected_license[sources]', @pettan_protected_license.sources -%></td>
26
+ <td><%= t_m @attr.label_name('sources') -%></td>
27
+ <td><%= text_area_tag @attr.tag_name('sources'), @attr.sources -%></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_pettan_protected_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,23 +15,23 @@
13
15
  </td>
14
16
  </tr>
15
17
  <tr>
16
- <td><%= t_m 'PettanrPettanProtectedV01Licenses::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 'PettanrPettanProtectedV01Licenses::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 'PettanrPettanProtectedV01Licenses::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 'PettanrPettanProtectedV01Licenses::Attribute.caption' -%></td>
30
+ <td><%= t_m picture.attribute_extend.label_name('caption') -%></td>
29
31
  <td><%= h picture.attribute_extend.caption -%></td>
30
32
  </tr>
31
33
  <tr>
32
- <td><%= t_m 'PettanrPettanProtectedV01Licenses::Attribute.sources' -%></td>
34
+ <td><%= t_m picture.attribute_extend.label_name('sources') -%></td>
33
35
  <td>
34
36
  <% picture.attribute_extend.sources.to_s.gsub(/\r/, '').split(/\n/).each do |url| -%>
35
37
  <div><%= link_to(h(url), url) -%></div>
@@ -60,15 +60,18 @@ module PettanrPettanProtectedV01Licenses
60
60
 
61
61
  def attribute_extend= params
62
62
  # load attributes
63
- @attribute_extend = PettanrPettanProtectedV01Licenses::Attribute.new params
63
+ @attribute_extend = PettanrPettanProtectedV01Licenses.new_attribute params
64
64
  # no supply default params
65
65
  end
66
66
 
67
- def new_attribute params = {}
68
- @attribute_extend = PettanrPettanProtectedV01Licenses::Attribute.new params
69
- # Attribute's supply_default need operators
70
- # @attribute_extend.supply_default operators
67
+ end
68
+
69
+ module ModuleMethods
70
+ def new_attribute params = {}
71
+ PettanrPettanProtectedV01Licenses::Attribute.new params
71
72
  end
72
73
 
73
74
  end
75
+
76
+ extend ModuleMethods
74
77
  end
@@ -1,3 +1,3 @@
1
1
  module PettanrPettanProtectedV01Licenses
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_pettan_protected_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-25 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_pettan_protected_v01_licenses/attribute.rb
62
62
  - app/models/pettanr_pettan_protected_v01_licenses/credit_picture.rb
63
63
  - app/models/pettanr_pettan_protected_v01_licenses/license.rb
64
- - app/views/layouts/pettanr_pettan_protected_v01_licenses/application.html.erb
65
64
  - app/views/pettanr_pettan_protected_v01_licenses/attributes/new.html.erb
66
- - app/views/pettanr_pettan_protected_v01_licenses/attributes/new.js.erb
67
65
  - app/views/pettanr_pettan_protected_v01_licenses/attributes/_confirm.html.erb
68
66
  - app/views/pettanr_pettan_protected_v01_licenses/attributes/_credit.html.erb
69
67
  - app/views/pettanr_pettan_protected_v01_licenses/attributes/_form.html.erb
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>PettanrPettanProtectedV01Licenses</title>
5
- <%= stylesheet_link_tag "pettanr_pettan_protected_v01_licenses/application", :media => "all" %>
6
- <%= javascript_include_tag "pettanr_pettan_protected_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')) -%>");