refinerycms-image-gallery 0.1.0

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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.4"
12
+ gem "rcov", ">= 0"
13
+ gem "rdoc", ">= 0"
14
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Vinicius Zago
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Dynamic Image gallery for Refinery CMS
2
+
3
+ This gem is based on refinerycms-page-images gem, with this gem is simple to create a more then one gallery tab in your engines with dynamic columns.
4
+
5
+ ## Requirements
6
+
7
+ * refinerycms >= 1.0.8
8
+
9
+ ## Features
10
+
11
+ * Select multiple images from the image picker and insert on your engine.
12
+ * Include dynamic fields in gallery for each engine, this is editable in each image.
13
+ * Reordering images with a simple drag into order.
14
+
15
+ ## Install
16
+
17
+ Add this line to your applications `Gemfile`
18
+
19
+ gem 'refinerycms-image-gallery'
20
+
21
+ Run:
22
+
23
+ bundle install
24
+
25
+ ## Usage
26
+
27
+ Creating new gallery for your engine:
28
+
29
+ rails g refinerycms_image_gallery singular_engine_name:gallery_name attribute:type
30
+
31
+ For example, if you wanna create new gallery called Top for Post engine:
32
+
33
+ rails g refinerycms_image_gallery post:top caption:string photographer:string
34
+
35
+ This generate a new tab Top Gallery in Posts engine.
36
+
37
+
38
+ But if you wanna generate a new gallery for a engine that already have a gallery, only do this:
39
+
40
+ rails g refinerycms_image_gallery post:bottom
41
+
42
+ This generate a new tab Bottom gallery in Posts engine with the same attributes.
43
+
44
+ Note: When you run this line, automaticly generate models, views and run a migrate with relationship between engine and images.
45
+
46
+ ## TODO
47
+
48
+ * CSS
49
+ * Implement refinery Modules in generator
data/Rakefile ADDED
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+
3
+ require 'psych'
4
+ require 'rubygems'
5
+ require 'bundler'
6
+
7
+ begin
8
+ Bundler.setup(:default, :development)
9
+ rescue Bundler::BundlerError => e
10
+ $stderr.puts e.message
11
+ $stderr.puts "Run `bundle install` to install missing gems"
12
+ exit e.status_code
13
+ end
14
+ require 'rake'
15
+
16
+ require 'jeweler'
17
+ Jeweler::Tasks.new do |gem|
18
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
19
+ gem.name = "refinerycms-image-gallery"
20
+ gem.homepage = "http://github.com/ginga/refinerycms-image-gallery"
21
+ gem.license = "MIT"
22
+ gem.summary = "Multi-purpose image-gallery for RefineryCMS."
23
+ gem.description = "Image Gallery for RefineryCMS that supports another fields like author, subtitles etc."
24
+ gem.email = "mvinicius.zago@gmail.com"
25
+ gem.authors = ["Vinicius Zago"]
26
+ gem.executables = ["refinerycms_image_gallery"]
27
+ gem.files.include 'lib/templates/**/*'
28
+ # dependencies defined in Gemfile
29
+ end
30
+ Jeweler::RubygemsDotOrgTasks.new
31
+
32
+ require 'rake/testtask'
33
+ Rake::TestTask.new(:test) do |test|
34
+ test.libs << 'lib' << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+
39
+ require 'rcov/rcovtask'
40
+ Rcov::RcovTask.new do |test|
41
+ test.libs << 'test'
42
+ test.pattern = 'test/**/test_*.rb'
43
+ test.verbose = true
44
+ test.rcov_opts << '--exclude "gems/*"'
45
+ end
46
+
47
+ task :default => :test
48
+
49
+ require 'rdoc/task'
50
+ RDoc::Task.new do |rdoc|
51
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
52
+
53
+ rdoc.rdoc_dir = 'rdoc'
54
+ rdoc.title = "refinerycms-image-gallery #{version}"
55
+ rdoc.rdoc_files.include('README*')
56
+ rdoc.rdoc_files.include('lib/**/*.rb')
57
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'refinerycms-image-gallery.rb'
@@ -0,0 +1,275 @@
1
+ class RefinerycmsImageGalleryGenerator < ::Refinery::Generators::EngineInstaller
2
+ attr_accessor :attributes, :name, :plural_class_name, :plural_name, :file_path
3
+
4
+ source_root Pathname.new(File.expand_path('../templates', __FILE__))
5
+
6
+ ######### Initialize generator with params #########
7
+ def initialize(*args)
8
+ super
9
+ @args = @_initializer.first
10
+
11
+ @title = @args.first.split(":")
12
+ @name = @title[0]
13
+ @chunk = @title[1]
14
+ @attributes = []
15
+ @column_name = []
16
+
17
+ # For each param include in migration a new column
18
+ @args.each do |arg|
19
+ unless @args.first == arg
20
+ name = arg.split(":")[0]
21
+ type = arg.split(":")[1]
22
+ @column_name << name
23
+ @attributes << Rails::Generators::GeneratedAttribute.new(name, type)
24
+ end
25
+ end
26
+
27
+ # Pluralize and camelize the class name
28
+ @plural_name = @name.pluralize
29
+ @plural_class_name = @name.pluralize.camelize
30
+
31
+ # Check if migration already exists
32
+ @check_migration = ActiveRecord::Base.connection.table_exists?("#{@plural_name}_images")
33
+
34
+ # Create @attributes variable for new gallery
35
+ if @attributes.empty? && @check_migration
36
+ @columns_exc = ["id", "#{@name}_id", "image_id", "position", "chunk", "created_at", "updated_at"]
37
+ "#{@plural_class_name}Image".constantize.column_names.each_with_index do |name, i|
38
+ type = "#{@plural_class_name}Image".constantize.columns[i].type
39
+ if @columns_exc.index("#{name}").nil?
40
+ @attributes << Rails::Generators::GeneratedAttribute.new(name, type)
41
+ end
42
+ end
43
+ end
44
+
45
+ # Define view class path
46
+ @file_path = "app/views/admin/#{@plural_name}/"
47
+ end
48
+
49
+ ##############################################################################
50
+ ############################# GENERATE MIGRATION #############################
51
+ ##############################################################################
52
+
53
+ ######### Create a migration relationsheep beetween model and images #########
54
+ def self.next_migration_number(path)
55
+ ActiveRecord::Generators::Base.next_migration_number(path)
56
+ end
57
+
58
+ def generate_migration
59
+ unless @check_migration
60
+ migration_template 'migration.rb', "db/migrate/create_#{plural_name}_images"
61
+ run "rake db:migrate"
62
+ end
63
+ end
64
+
65
+ ##############################################################################
66
+ ######################## OVERRIDE FILES IF NECESSARY #########################
67
+ ##############################################################################
68
+
69
+ ######### Override the image model if not exists #########
70
+ def override_image_model
71
+ run "rake refinery:override model=image"
72
+ end unless File.exists?("app/models/image.rb")
73
+
74
+ ######### Override the class model if not exists #########
75
+ def override_class_model
76
+ unless File.exists?("app/models/#{@name}.rb")
77
+ run "rake refinery:override model=#{@name}"
78
+ end
79
+ end
80
+
81
+ ######### Override your class admin/_form item if not exists #########
82
+ def override_class_form
83
+ unless File.exists?("app/views/admin/#{@plural_name}/_form.html.erb")
84
+ run "rake refinery:override view=admin/#{plural_name}/_form"
85
+ end
86
+ end
87
+
88
+ ######### Override inset image view if not exists #########
89
+ def override_insert_image
90
+ run "rake refinery:override view=admin/images/insert"
91
+ end unless File.exists?("app/views/admin/images/insert.html.erb")
92
+
93
+ ######### Override refinery admin javascript #########
94
+ def override_javascripts
95
+ run "rake refinery:override javascript=refinery/admin"
96
+ end unless File.exists?("public/javascripts/refinery/admin.js")
97
+
98
+ ##############################################################################
99
+ ############################## GENERATE MODELS ###############################
100
+ ##############################################################################
101
+
102
+ ######### Create relationsheep model #########
103
+ def create_model
104
+ unless @check_migration
105
+ template 'models/model.rb', File.join('app/models', "#{plural_name}_image.rb")
106
+ end
107
+ end
108
+
109
+ ######### Insert into models new relations #########
110
+ def insert_into_model
111
+ unless @check_migration
112
+ @columns = []
113
+ @column_name.each do |column|
114
+ @columns << ":" + column.to_s + " => image_data['#{column}']"
115
+ end
116
+
117
+ # Insert into image model
118
+ insert_into_file "app/models/image.rb", :after => "image_accessor :image\n" do
119
+ "\thas_many :#{plural_name}_images\n" +
120
+ "\thas_many :#{plural_name}, :through => :#{plural_name}_images\n"
121
+ end
122
+
123
+ # Insert into object model
124
+ insert_into_file "app/models/#{@name}.rb", :after => "ActiveRecord::Base\n" do
125
+ "\n\thas_many :#{plural_name}_images\n" +
126
+ "\thas_many :images, :through => :#{plural_name}_images\n" +
127
+ "\n\tdef images_attributes=(data)
128
+ #{plural_class_name}Image.delete_all(:#{@name}_id => self.id)
129
+ data.each_with_index do | ( k, image_data ), i |
130
+ if image_data['id'].present?
131
+ image_gallery = self.#{plural_name}_images.new(
132
+ :image_id => image_data['id'].to_i,
133
+ :position => i,
134
+ :chunk => image_data['chunk'],
135
+ #{@columns.join(', ')}
136
+ )
137
+ self.#{plural_name}_images << image_gallery
138
+ end
139
+ self.touch
140
+ end
141
+ end\n"
142
+ end
143
+ end
144
+ end
145
+
146
+ ##############################################################################
147
+ ########################## GENERATE VIEWS TEMPLATES ##########################
148
+ ##############################################################################
149
+
150
+ ######### Insert into view image gallery tab #########
151
+ def add_tab_to_form
152
+ unless File.exists?("#{file_path}/_images_field_#{@chunk}.html.erb")
153
+ page_parts = open("app/views/admin/#{@plural_name}/_form.html.erb").grep(/page_parts/)
154
+
155
+ if page_parts.empty?
156
+ insert_into_file "app/views/admin/#{@plural_name}/_form.html.erb",
157
+ :before => '<%= render :partial => "/shared/admin/form_actions",' do
158
+ "\n\t<div class='field'>" +
159
+ "\n\t\t<div id='page-tabs' class='clearfix ui-tabs ui-widget ui-widget-content ui-corner-all'>" +
160
+ "\n\t\t\t<ul id='page_parts'>" +
161
+ "\n\t\t\t\t<li class='ui-state-default'>" +
162
+ "\n\t\t\t\t\t<%= link_to '#{@chunk.camelize} Gallery', '##{@chunk}_gallery' %>" +
163
+ "\n\t\t\t</li>"+
164
+ "\n\t\t\t</ul>" +
165
+
166
+ "\n\n\t\t\t<div id='page_part_editors'>" +
167
+ "\n\t\t\t\t<div class='page_part' id='#{@chunk}_gallery'>" +
168
+ "\n\t\t\t\t\t<%= render :partial => 'images', :locals => { :f => f, :chunk_name => '#{@chunk}' } -%>" +
169
+ "\n\t\t\t\t</div>" +
170
+ "\n\t\t\t</div>" +
171
+ "\n\t\t</div>" +
172
+ "\n\t</div>\n"
173
+ end
174
+ else
175
+ insert_into_file "app/views/admin/#{@plural_name}/_form.html.erb",
176
+ :after => "<ul id='page_parts'>" do
177
+ "\n\t\t<li class='ui-state-default'>" +
178
+ "\n\t\t\t<%= link_to '#{@chunk.camelize} Gallery', '##{@chunk}_gallery' %>" +
179
+ "\n\t\t</li>"
180
+ end
181
+
182
+ insert_into_file "app/views/admin/#{@plural_name}/_form.html.erb",
183
+ :after => "<div id='page_part_editors'>" do
184
+ "\n\t\t<div class='page_part' id='#{@chunk}_gallery'>" +
185
+ "\n\t\t\t<%= render :partial => 'images', :locals => { :f => f, :chunk_name => '#{@chunk}' } -%>" +
186
+ "\n\t\t</div>"
187
+ end
188
+ end
189
+ end
190
+ end
191
+
192
+ ######### Insert into form partial the javascripts and css #########
193
+ def add_js_and_css_to_form
194
+ unless @check_migration
195
+ page_options = open("app/views/admin/#{@plural_name}/_form.html.erb").grep(/content_for :javascripts/)
196
+
197
+ if page_options.empty?
198
+ insert_into_file "app/views/admin/#{@plural_name}/_form.html.erb",
199
+ :before => "<%= form_for" do
200
+ "<% content_for :javascripts do %>" +
201
+ "\n\t<script>" +
202
+ "\n\t\t$(document).ready(function(){" +
203
+ "\n\t\t\tpage_options.init(false, '', '');" +
204
+ "\n\t\t});" +
205
+ "\n\t</script>"+
206
+ "\n\t<%= javascript_include_tag 'gallery' %>" +
207
+ "\n<% end %>" +
208
+
209
+ "\n\n<% content_for :stylesheets do %>" +
210
+ "\n\t<%= stylesheet_link_tag 'gallery' %>" +
211
+ "\n<% end %>\n\n"
212
+ end
213
+ else
214
+ insert_into_file "app/views/admin/#{@plural_name}/_form.html.erb",
215
+ :after => "<% content_for :javascripts do %>" do
216
+ "\n\t<%= javascript_include_tag 'gallery' %>"
217
+ end
218
+
219
+ insert_into_file "app/views/admin/#{@plural_name}/_form.html.erb",
220
+ :before => "<% content_for :javascripts do %>" do
221
+ "\n<% content_for :stylesheets do %>" +
222
+ "\n\t<%= stylesheet_link_tag 'gallery' %>" +
223
+ "\n<% end %>\n"
224
+ end
225
+ end
226
+ end
227
+ end
228
+
229
+ ######### Insert into insert image template new params #########
230
+ def insert_image_params
231
+ unless @check_migration
232
+ insert_into_file "app/views/admin/images/insert.html.erb",
233
+ :after => 'image_dialog.init(<%= @callback.present? ? "self.parent.#{@callback}" : "null" %>' do
234
+ ", '<%= params[:chunk] %>'"
235
+ end
236
+ end
237
+ end
238
+
239
+ ######### Create view partial templates for images in gallery #########
240
+ def create_view_templates
241
+ unless @check_migration
242
+ template 'views/images.html.erb', File.join(file_path, "_images.html.erb")
243
+ template 'views/image.html.erb', File.join(file_path, "_image.html.erb")
244
+ template 'views/images_field.html.erb', File.join(file_path, "_images_field_#{@chunk}.html.erb")
245
+ else
246
+ unless File.exists?("#{file_path}/_images_field_#{@chunk}.html.erb")
247
+ template 'views/images_field.html.erb', File.join(file_path, "_images_field_#{@chunk}.html.erb")
248
+ end
249
+ end
250
+ end
251
+
252
+ ##############################################################################
253
+ ########################## GENERATE JAVASCRIPTS/CSS ##########################
254
+ ##############################################################################
255
+
256
+ ######### Inserto into admin javascript chunk params #########
257
+ def insert_chunk_admin_js
258
+ js_admin_path = "public/javascripts/refinery/admin.js"
259
+ unless @check_migration
260
+ insert_into_file "#{js_admin_path}","\n, chunk: null", :after => ", callback: null"
261
+ insert_into_file "#{js_admin_path}", ",chunk", :after => ", init: function(callback"
262
+ insert_into_file "#{js_admin_path}","\n\t\tthis.chunk = chunk;", :after => "this.callback = callback;"
263
+ insert_into_file "#{js_admin_path}", ", this.chunk", :after => "this.callback(img_selected"
264
+ end
265
+ end
266
+
267
+ def copy_javascript
268
+ template "javascripts/gallery.js", File.join("public/javascripts", "gallery.js") unless @check_migration
269
+ end unless File.exists?("public/javascripts/gallery.js")
270
+
271
+ def copy_css
272
+ template "stylesheets/gallery.css", File.join("public/stylesheets", "gallery.css") unless @check_migration
273
+ end unless File.exists?("public/stylesheets/gallery.css")
274
+
275
+ end
@@ -0,0 +1,91 @@
1
+ # Function to Add New Image
2
+ image_added = (image, chunk) ->
3
+ image_id = $(image).attr('id').replace 'image_', '' # Get image id for new list item id
4
+ new_list = $("li.empty_#{chunk}").clone() # Clone empty li to new list
5
+ new_list.find('input').next().val image_id # Set input image_id value = image_id
6
+ new_list.find('span').html($(image).attr('alt'))
7
+
8
+ # Set random values items id/name
9
+ id = parseInt(image_id + Math.random() * 101)
10
+ $('input', new_list).each (i,input) ->
11
+ input = $(input)
12
+ input.attr('name', input.attr('name').replace(/images_attributes\]\[[\d]+/, "images_attributes][" + id))
13
+ input.attr('id', input.attr('id').replace(/images_attributes_[\d]+/, "images_attributes_" + id))
14
+
15
+ # Append thumb to new list
16
+ img = $("<img />").attr({
17
+ title: $(image).attr('title')
18
+ , alt: $(image).attr('alt')
19
+ , src: $(image).attr('data-grid')
20
+ }).appendTo(new_list)
21
+
22
+ # Get dynamic items and set id/val
23
+ dynamic_items = new_list.find "#dynamic_items"
24
+ dynamic_items.attr 'id', "dynamic_items_#{image_id}"
25
+ dynamic_items.find("input").val ""
26
+
27
+ # Remove class and show new list
28
+ new_list.attr('id', "image_#{image_id}").removeClass 'empty'
29
+ new_list.attr('id', "image_#{image_id}").removeClass "empty_#{chunk}"
30
+ new_list.show()
31
+
32
+ # Append new list to correct gallery
33
+ target = "#page_images_#{chunk}"
34
+ new_list.appendTo target
35
+
36
+ # Function to edit image fields
37
+ jQuery ->
38
+ # Edit image fields
39
+ $('.edit_image').live 'click', ->
40
+ image_id = $(this).parents().parents().attr('id').replace 'image_', '' # Get image id
41
+ items = $(this).parents().parents().find("#dynamic_items_#{image_id}")[0] # Get dynamic items of this list
42
+ open_edit_image items, image_id # Call function open modal
43
+
44
+ # Delete image from gallery
45
+ $('.delete_image').live 'click', ->
46
+ rm = confirm "Are you sure delete this image?"
47
+ if(rm == true)
48
+ $(this).parents('li').first().remove()
49
+ else
50
+ return false
51
+
52
+ # Reoder images
53
+ $('li.image_field').live 'hover', ->
54
+ chunk = $(this).find('input').first().val()
55
+ $("#page_images_#{chunk}").sortable()
56
+
57
+ # Dialog dynamic items
58
+ open_edit_image = (items, image_id) ->
59
+ # Clone dynamic fields for modal
60
+ fields = $(items).clone()
61
+ input = fields.find('input')
62
+
63
+ # For each input create a textarea for edit
64
+ input.each (i, inp) ->
65
+ title = $(inp).attr('class').replace 'edit_items_', ''
66
+ value = $(inp).val()
67
+ $(inp).after $("<div id='image#{image_id}_title_#{title}'><span class='ui-dialog-title' id='ui-dialog-title-1' style='width: 300px; background: #22A7F2;float:left;'>#{title}</span><textarea style='width: 290px; height: 30px;'>#{value}</textarea></div>")
68
+
69
+ # Input a submit button
70
+ input.after($("<div class='form-actions'><div class='form-actions-left'><a class='button' id='insert_fields'>Insert<a></div></div>"))
71
+
72
+ # Open the dialog modal
73
+ fields.dialog({
74
+ title: "Edit Image Fields",
75
+ modal: true,
76
+ resizable: false,
77
+ autoOpen: true,
78
+ height:300
79
+ })
80
+
81
+ # Insert click function
82
+ $('a#insert_fields').click ->
83
+ # For each input get the textarea value and change input value
84
+ input.each (i, inp) ->
85
+ title = $(inp).attr('class').replace 'edit_items_', ''
86
+ input_val = $(items).find("input.edit_items_#{title}")
87
+ input_val.val $("div#image#{image_id}_title_#{title}").find("textarea").val()
88
+ fields.dialog('close')
89
+
90
+ # Remove cloned div after close
91
+ fields.remove()
@@ -0,0 +1,82 @@
1
+ /* DO NOT MODIFY. This file was compiled Thu, 22 Sep 2011 19:50:13 GMT from
2
+ * /Users/vinicius/workspace/gem-gallery-image/app/coffeescripts/gallery.coffee
3
+ */
4
+
5
+ var image_added, open_edit_image;
6
+ image_added = function(image, chunk) {
7
+ var dynamic_items, id, image_id, img, new_list, target;
8
+ image_id = $(image).attr('id').replace('image_', '');
9
+ new_list = $("li.empty_" + chunk).clone();
10
+ new_list.find('input').next().val(image_id);
11
+ new_list.find('span').html($(image).attr('alt'));
12
+ id = parseInt(image_id + Math.random() * 101);
13
+ $('input', new_list).each(function(i, input) {
14
+ input = $(input);
15
+ input.attr('name', input.attr('name').replace(/images_attributes\]\[[\d]+/, "images_attributes][" + id));
16
+ return input.attr('id', input.attr('id').replace(/images_attributes_[\d]+/, "images_attributes_" + id));
17
+ });
18
+ img = $("<img />").attr({
19
+ title: $(image).attr('title'),
20
+ alt: $(image).attr('alt'),
21
+ src: $(image).attr('data-grid')
22
+ }).appendTo(new_list);
23
+ dynamic_items = new_list.find("#dynamic_items");
24
+ dynamic_items.attr('id', "dynamic_items_" + image_id);
25
+ dynamic_items.find("input").val("");
26
+ new_list.attr('id', "image_" + image_id).removeClass('empty');
27
+ new_list.attr('id', "image_" + image_id).removeClass("empty_" + chunk);
28
+ new_list.show();
29
+ target = "#page_images_" + chunk;
30
+ return new_list.appendTo(target);
31
+ };
32
+ jQuery(function() {
33
+ $('.edit_image').live('click', function() {
34
+ var image_id, items;
35
+ image_id = $(this).parents().parents().attr('id').replace('image_', '');
36
+ items = $(this).parents().parents().find("#dynamic_items_" + image_id)[0];
37
+ return open_edit_image(items, image_id);
38
+ });
39
+ $('.delete_image').live('click', function() {
40
+ var rm;
41
+ rm = confirm("Are you sure delete this image?");
42
+ if (rm === true) {
43
+ return $(this).parents('li').first().remove();
44
+ } else {
45
+ return false;
46
+ }
47
+ });
48
+ return $('li.image_field').live('hover', function() {
49
+ var chunk;
50
+ chunk = $(this).find('input').first().val();
51
+ return $("#page_images_" + chunk).sortable();
52
+ });
53
+ });
54
+ open_edit_image = function(items, image_id) {
55
+ var fields, input;
56
+ fields = $(items).clone();
57
+ input = fields.find('input');
58
+ input.each(function(i, inp) {
59
+ var title, value;
60
+ title = $(inp).attr('class').replace('edit_items_', '');
61
+ value = $(inp).val();
62
+ return $(inp).after($("<div id='image" + image_id + "_title_" + title + "'><span class='ui-dialog-title' id='ui-dialog-title-1' style='width: 300px; background: #22A7F2;float:left;'>" + title + "</span><textarea style='width: 290px; height: 30px;'>" + value + "</textarea></div>"));
63
+ });
64
+ input.after($("<div class='form-actions'><div class='form-actions-left'><a class='button' id='insert_fields'>Insert<a></div></div>"));
65
+ fields.dialog({
66
+ title: "Edit Image Fields",
67
+ modal: true,
68
+ resizable: false,
69
+ autoOpen: true,
70
+ height: 300
71
+ });
72
+ return $('a#insert_fields').click(function() {
73
+ input.each(function(i, inp) {
74
+ var input_val, title;
75
+ title = $(inp).attr('class').replace('edit_items_', '');
76
+ input_val = $(items).find("input.edit_items_" + title);
77
+ input_val.val($("div#image" + image_id + "_title_" + title).find("textarea").val());
78
+ return fields.dialog('close');
79
+ });
80
+ return fields.remove();
81
+ });
82
+ };