refinerycms-portfolio 0.9.8.rc2 → 0.9.8.rc3

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.
@@ -1,6 +1,9 @@
1
1
  class Admin::PortfolioController < Admin::BaseController
2
2
 
3
- crudify :portfolio_entry, :order => 'lft ASC', :conditions => "parent_id IS NULL", :sortable => true
3
+ crudify :portfolio_entry,
4
+ :order => 'lft ASC',
5
+ :conditions => {:parent_id => nil},
6
+ :sortable => true
4
7
 
5
8
  def emancipate
6
9
  if (entry = PortfolioEntry.find(params[:id])).present?
@@ -0,0 +1,10 @@
1
+ class ImagesPortfolioEntry < ActiveRecord::Base
2
+
3
+ belongs_to :image
4
+ belongs_to :portfolio_entry
5
+
6
+ before_save do |image_portfolio_entry|
7
+ image_portfolio_entry.position = (ImagesPortfolioEntry.maximum(:position) || -1) + 1
8
+ end
9
+
10
+ end
@@ -7,14 +7,20 @@ class PortfolioEntry < ActiveRecord::Base
7
7
  acts_as_nested_set
8
8
  default_scope :order => 'lft ASC'
9
9
 
10
- has_and_belongs_to_many :images
10
+ has_many :images_portfolio_entries
11
+ has_many :images, :through => :images_portfolio_entries, :order => 'images_portfolio_entries.position ASC'
12
+ accepts_nested_attributes_for :images, :allow_destroy => false
11
13
 
12
- alias_attribute :content, :body
14
+ def images_attributes=(data)
15
+ self.images.clear
13
16
 
14
- def image_ids=(ids)
15
- self.images = ids.reject{|id| id.blank?}.collect {|image_id|
16
- Image.find(image_id.to_i) rescue nil
17
+ self.images = (0..(data.length-1)).collect { |i|
18
+ unless (image_id = data[i.to_s]['id'].to_i) == 0
19
+ Image.find(image_id) rescue nil
20
+ end
17
21
  }.compact
18
22
  end
19
23
 
24
+ alias_attribute :content, :body
25
+
20
26
  end
@@ -9,40 +9,51 @@
9
9
  :object => f.object,
10
10
  :include_object_name => true
11
11
  } %>
12
- <div class='field'>
12
+ <div id='portfolio_body' class='field clearfix'>
13
13
  <%= f.required_label t('.title') %>
14
14
  <%= f.text_field :title, :class => "larger widest" %>
15
15
  </div>
16
- <div class='field images_field'>
17
- <span class='clearfix label_inline_with_link'>
18
- <%= label_tag('portfolio_entry_image_ids', t('.images')) %>
19
- <%= link_to "#{refinery_icon_tag "add.png"} #{t('.add')}".html_safe,
20
- insert_admin_images_url(
21
- :dialog => true,
22
- :width => 866,
23
- :height => 510,
24
- :callback => "image_added"
25
- ),
26
- :name => t('.add_another_image'),
27
- :id => "add_image_link" %>
28
- </span>
29
- <ul id='portfolio_images' class='clearfix portfolio_entry_images'>
30
- <% @portfolio_entry.images.each do |image| %>
31
- <li id='image_<%= image.id %>'>
32
- <%= image_fu image, '135x135#c' %>
33
- <%= hidden_field_tag 'portfolio_entry[image_ids][]', image.id,
34
- :id => "portfolio_entry_image_id_#{image.id}" %>
16
+ <div class='field clearfix'>
17
+ <div id='page-tabs' class='clearfix ui-tabs ui-widget ui-widget-content'>
18
+ <ul id='page_parts'>
19
+ <li class='ui-state-default ui-state-active'>
20
+ <%= link_to t('.content'), '#page_part_content'%>
35
21
  </li>
36
- <% end %>
37
- <li class='empty'>
38
- <img id="current_portfolio_entry_image" src="" alt="" style='display: none' />
39
- <input type='hidden' id='portfolio_entry_image_id' name='portfolio_entry[image_ids][]' />
40
- </li>
41
- </ul>
42
- </div>
43
- <div id='portfolio_body' class='field clearfix'>
44
- <%= f.label :body, t('.content') %>
45
- <%= f.text_area :body, :class => "wymeditor widest", :rows => 7 %>
22
+ <li class='ui-state-default'>
23
+ <%= link_to t('.images'), '#portfolio_image_picker'%>
24
+ </li>
25
+ </ul>
26
+ </div>
27
+ <div id='page_part_editors'>
28
+ <div id='page_part_content' class='page_part'>
29
+ <%= f.text_area :body, :class => "wymeditor widest", :rows => 7 %>
30
+ </div>
31
+ <div class='page_part wym_skin_refinery' id='portfolio_image_picker'>
32
+ <div class='wym_area_top'>
33
+ <span class='clearfix label_inline_with_link'>
34
+ <%= link_to t('.add_another_image').html_safe,
35
+ insert_admin_images_url(:dialog => true,
36
+ :width => 866,
37
+ :height => 510,
38
+ :callback => "image_added"),
39
+ :id => "add_image_link" %>
40
+ </span>
41
+ </div>
42
+ <div class='wym_box field images_field'>
43
+ <ul id='portfolio_images' class='clearfix portfolio_entry_images'>
44
+ <%= f.fields_for :images do |image_form| %>
45
+ <li id='image_<%= image_form.object.id %>'>
46
+ <%= image_form.hidden_field :id %>
47
+ <%= image_fu image_form.object, '135x135#c' %>
48
+ </li>
49
+ <% end %>
50
+ <li class='empty'>
51
+ <%= hidden_field_tag "portfolio_entry[images_attributes][#{@portfolio_entry.images.size}][id]" %>
52
+ </li>
53
+ </ul>
54
+ </div>
55
+ </div>
56
+ </div>
46
57
  </div>
47
58
  <% if (nested_portfolios = nested_set_options(PortfolioEntry, @portfolio_entry) {|i| "#{'-' * i.level} #{i.title}" }).present? %>
48
59
  <div class='field'>
@@ -27,4 +27,4 @@
27
27
  <% end %>
28
28
  </div>
29
29
  <%= render :partial => "/shared/admin/make_sortable",
30
- :locals => { :tree => ::Refinery::Portfolio.multi_level? } if PortfolioEntry.count > 1 %>
30
+ :locals => { :tree => ::Refinery::Portfolio.multi_level? } if PortfolioEntry.count > 1 %>
@@ -2,7 +2,7 @@ lv:
2
2
  plugins:
3
3
  portfolio:
4
4
  title: Portfolio
5
- description: Pārvaldīt portfeļa izmanto Refinery CMS
5
+ description: Portfolio pārvaldīšana iekš Refinery CMS
6
6
  admin:
7
7
  portfolio:
8
8
  index:
data/lib/gemspec.rb CHANGED
@@ -30,4 +30,4 @@ Gem::Specification.new do |s|
30
30
  end
31
31
  EOF
32
32
 
33
- File.open(File.expand_path("../../refinerycms-portfolio.gemspec", __FILE__), 'w').puts(gemspec)
33
+ File.open(File.expand_path("../../refinerycms-portfolio.gemspec", __FILE__), 'w').puts(gemspec)
@@ -56,4 +56,4 @@ module ActiveRecord
56
56
  end
57
57
  end
58
58
  end
59
- end
59
+ end
@@ -27,4 +27,4 @@ if RefinerySetting.methods.map(&:to_sym).include?(:set)
27
27
  RefinerySetting.set(:image_thumbnails, new_thumbnails)
28
28
  else
29
29
  RefinerySetting[:image_thumbnails] = new_thumbnails
30
- end
30
+ end
@@ -1,7 +1,7 @@
1
1
  module Refinery
2
2
  module Portfolio
3
3
  def self.version
4
- %q{0.9.8.rc2}
4
+ %q{0.9.8.rc3}
5
5
  end
6
6
  end
7
- end
7
+ end
data/lib/portfolio.rb CHANGED
@@ -2,4 +2,4 @@ require 'portfolio/version'
2
2
 
3
3
  unless defined?(::Refinery::Portfolio::Engine)
4
4
  require File.expand_path('../refinerycms-portfolio.rb', __FILE__)
5
- end
5
+ end
@@ -31,4 +31,4 @@ module Refinery
31
31
  end
32
32
  end
33
33
 
34
- require File.expand_path('../portfolio', __FILE__)
34
+ require File.expand_path('../portfolio', __FILE__)
@@ -6,6 +6,7 @@ reset_functionality = function() {
6
6
  , 'placeholder': 'placeholder'
7
7
  , 'cursor': 'drag'
8
8
  , 'items': 'li'
9
+ , stop: reindex_images
9
10
  });
10
11
 
11
12
  $('#content #portfolio_images li:not(.empty)').each(function(index, li) {
@@ -16,6 +17,7 @@ reset_functionality = function() {
16
17
  img_delete.appendTo(image_actions);
17
18
  img_delete.click(function() {
18
19
  $(this).parents('li[id*=image_]').remove();
20
+ reindex_images();
19
21
  });
20
22
 
21
23
  image_actions.appendTo($(li));
@@ -26,19 +28,56 @@ reset_functionality = function() {
26
28
  $(this).find('.image_actions').hide();
27
29
  });
28
30
  });
31
+
32
+ reindex_images();
33
+ }
34
+
35
+ reindex_images = function() {
36
+ $('#portfolio_images li input:hidden').each(function(i, input){
37
+ // make the image's name consistent with its position.
38
+ parts = $(input).attr('name').split(']');
39
+ parts[1] = ('[' + i)
40
+ $(input).attr('name', parts.join(']'));
41
+
42
+ // make the image's id consistent with its position.
43
+ $(input).attr('id', $(input).attr('id').replace(/_\d_/, '_'+i+'_').replace(/_\d/, '_'+i));
44
+ });
29
45
  }
30
46
 
31
47
  image_added = function(image) {
32
48
  last_portfolio_entry_image_id = "";
49
+ new_list_item = (current_list_item = $('li.empty')).clone();
33
50
  image_id = $(image).attr('id').replace('image_', '');
34
- hidden_identifier = $('li.empty').find('input:hidden');
35
- hidden_identifier.attr('id', '').val(image_id);
36
- $('li.empty').find('img').css('display', '').attr({'id': '', 'src': $(image).attr('src').replace('_dialog_thumb', '_grid'), 'title': $(image).attr('title'), 'alt': $(image).attr('alt')});
37
- $('li.empty').attr('id', 'image_' + image_id).removeClass('empty');
51
+ current_list_item.find('input:hidden').val(image_id);
52
+ $.ajax({
53
+ async: false,
54
+ url: '/refinery/images/'+image_id+'/url',
55
+ data: {size: '135x135#c'},
56
+ success: function (result, status, xhr) {
57
+ if (result.error) {
58
+ if (console && console.log) {
59
+ console.log("Something went wrong with the image insertion!");
60
+ console.log(result);
61
+ }
62
+ } else {
63
+ (img = $("<img />")).attr({
64
+ title: $(image).attr('title')
65
+ , alt: $(image).attr('alt')
66
+ , src: result.url
67
+ }).appendTo(current_list_item);
68
+ }
69
+ },
70
+ error: function(xhr, txt, status) {
71
+ if (console && console.log) {
72
+ console.log("Something went wrong with the image insertion!");
73
+ console.log(xhr);
74
+ console.log(txt);
75
+ console.log(status);
76
+ }
77
+ }
78
+ });
38
79
 
39
- new_list_item = $("<li class='empty'></li>");
40
- $("<img id='current_portfolio_entry_image' src='' alt='' style='display:none;' />").appendTo(new_list_item);
41
- $("<input type='hidden' id='portfolio_entry_image_id' name='portfolio_entry[image_ids][]' />").appendTo(new_list_item);
80
+ current_list_item.attr('id', 'image_' + image_id).removeClass('empty');
42
81
 
43
82
  new_list_item.appendTo($('#portfolio_images'));
44
83
  reset_functionality();
@@ -54,8 +93,30 @@ $(document).ready(function() {
54
93
  window.location = portfolio_entry_url + this.value;
55
94
  });
56
95
 
96
+ if ((tabs = $('.edit_portfolio_entry #page-tabs, .new_portfolio_entry #page-tabs')).length > 0) {
97
+ page_options.init(false, '', '');
98
+ $('a[href*=portfolio_image_picker]').click(function(){
99
+ if (!(picker = $('#portfolio_image_picker')).data('size-applied')){
100
+ wym_box = $('.page_part:first .wym_box');
101
+ iframe = $('.page_part:first iframe');
102
+ picker.css({
103
+ height: wym_box.height()
104
+ , width: wym_box.width()
105
+ }).data('size-applied', true).corner('tr 5px').corner('bottom 5px').find('.wym_box').css({
106
+ backgroundColor: 'white'
107
+ , height: iframe.height() + $('.page_part:first .wym_area_top').height() - parseInt($('.wym_area_top .label_inline_with_link a').css('lineHeight'))
108
+ , width: iframe.width() - 20
109
+ , 'border-color': iframe.css('border-top-color')
110
+ , 'border-style': iframe.css('border-top-style')
111
+ , 'border-width': iframe.css('border-top-width')
112
+ , padding: '0px 10px 0px 10px'
113
+ });
114
+ }
115
+ });
116
+ }
117
+
57
118
  var clicked_on = null;
58
- $("ul#portfolio_images li a").click(function(event) {
119
+ $("ul#portfolio_images li a").click(function(e) {
59
120
  if (!$(this).hasClass('selected')) {
60
121
  clicked_on = $(this);
61
122
  $.get($(this).attr('href'), function(data, textStatus) {
@@ -72,6 +133,6 @@ $(document).ready(function() {
72
133
  });
73
134
  }
74
135
 
75
- return false;
136
+ e.preventDefault();
76
137
  });
77
138
  });
@@ -72,4 +72,11 @@
72
72
  #content #portfolio_images.ui-sortable li.placeholder {
73
73
  width: 135px;
74
74
  height: 135px;
75
+ }
76
+ .wym_area_top .label_inline_with_link a, #content .wym_area_top .label_inline_with_link a {
77
+ margin-top: 0px;
78
+ line-height: 29px;
79
+ background: url('/images/refinery/icons/add.png') no-repeat 0px 6px;
80
+ padding-left: 20px;
81
+ border-bottom: 0px none;
75
82
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refinerycms-portfolio
3
3
  version: !ruby/object:Gem::Version
4
- hash: 977940519
4
+ hash: 977940516
5
5
  prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
9
  - 8
10
- - rc2
11
- version: 0.9.8.rc2
10
+ - rc3
11
+ version: 0.9.8.rc3
12
12
  platform: ruby
13
13
  authors:
14
14
  - Resolve Digital
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-09-20 00:00:00 +12:00
19
+ date: 2010-09-27 00:00:00 +13:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -49,6 +49,7 @@ files:
49
49
  - app/controllers/admin/portfolio_controller.rb
50
50
  - app/controllers/portfolio_controller.rb
51
51
  - app/helpers/portfolio_helper.rb
52
+ - app/models/images_portfolio_entry.rb
52
53
  - app/models/portfolio_entry.rb
53
54
  - app/views/admin/portfolio/_form.html.erb
54
55
  - app/views/admin/portfolio/_list.html.erb