From 1e5624ce063498153745a4305b27021b54da2b74 Mon Sep 17 00:00:00 2001 From: did Date: Sun, 20 Mar 2011 11:21:07 +0100 Subject: [PATCH] fix js bugs --- Gemfile | 3 ++- Gemfile.lock | 14 +++++++++----- app/helpers/admin/content_types_helper.rb | 11 +++++++++++ app/models/content_type.rb | 1 - public/javascripts/admin/custom_fields.js | 4 ++-- public/javascripts/admin/custom_fields/category.js | 2 +- public/javascripts/admin/utils.js | 10 +++++++++- 7 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index b1fa2d95..5813c25d 100644 --- a/Gemfile +++ b/Gemfile @@ -20,7 +20,8 @@ gem 'inherited_resources', '~> 1.1.2' gem 'rmagick', '2.12.2' gem 'locomotive_carrierwave', '0.5.0.1.beta3', :require => 'carrierwave' -gem 'custom_fields', '1.0.0.beta.6' +# gem 'custom_fields', '1.0.0.beta.7' +gem 'custom_fields', '1.0.0.beta.7', :path => '../gems/custom_fields' gem 'fog', '0.3.7' gem 'mimetype-fu' gem 'actionmailer-with-request' diff --git a/Gemfile.lock b/Gemfile.lock index 47572cb6..05ba83d7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,6 +11,14 @@ GIT xpath (0.1.2) nokogiri (~> 1.4) +PATH + remote: ../gems/custom_fields + specs: + custom_fields (1.0.0.beta.7) + activesupport (>= 3.0.4) + locomotive_carrierwave + mongoid (~> 2.0.0.rc.7) + GEM remote: http://rubygems.org/ specs: @@ -77,10 +85,6 @@ GEM cucumber-rails (0.3.2) cucumber (>= 0.8.0) culerity (0.2.15) - custom_fields (1.0.0.beta.6) - activesupport (>= 3.0.4) - locomotive_carrierwave - mongoid (~> 2.0.0.rc.7) daemons (1.1.0) database_cleaner (0.6.6) delayed_job (2.1.4) @@ -261,7 +265,7 @@ DEPENDENCIES capybara cucumber (= 0.8.5) cucumber-rails - custom_fields (= 1.0.0.beta.6) + custom_fields (= 1.0.0.beta.7)! database_cleaner delayed_job (= 2.1.4) delayed_job_mongoid (= 1.0.2) diff --git a/app/helpers/admin/content_types_helper.rb b/app/helpers/admin/content_types_helper.rb index f3f35681..d62ba726 100644 --- a/app/helpers/admin/content_types_helper.rb +++ b/app/helpers/admin/content_types_helper.rb @@ -8,12 +8,23 @@ module Admin::ContentTypesHelper @content_types = current_site.content_types.ordered. limit(:contents => Locomotive.config.lastest_items_nb). only(:name, :slug, :highlighted_field_name, :updated_at).to_a + # only(:name, :slug, :highlighted_field_name, :content_custom_fields_updated_at).to_a if @content_type && @content_type.persisted? && @content_types.index(@content_type) >= MAX_DISPLAYED_CONTENTS @content_types.delete(@content_type) @content_types.insert(0, @content_type) end + # # be sure, we've got the custom klass up-to-date, otherwise it will fail miserably + # @content_types.each do |content_type| + # # puts "content_type custom_fields !!! ? #{content_type.name} / #{content_type.content_klass.try(:built_at).inspect} / #{content_type.content_custom_fields_updated_at.try(:utc)}" + # if content_type.content_klass_out_of_date? + # puts "RELOADED #{content_type.name}" + # content_type.reload + # content_type.invalidate_content_klass + # end + # end + @content_types end diff --git a/app/models/content_type.rb b/app/models/content_type.rb index 51bc4d80..b41ce53a 100644 --- a/app/models/content_type.rb +++ b/app/models/content_type.rb @@ -24,7 +24,6 @@ class ContentType ## named scopes ## scope :ordered, :order_by => :updated_at.desc - ## indexes ## index [[:site_id, Mongo::ASCENDING], [:slug, Mongo::ASCENDING]] diff --git a/public/javascripts/admin/custom_fields.js b/public/javascripts/admin/custom_fields.js index 91047b98..0b7715b2 100644 --- a/public/javascripts/admin/custom_fields.js +++ b/public/javascripts/admin/custom_fields.js @@ -57,7 +57,7 @@ $(document).ready(function() { content: $(link.attr('href')).parent().html(), padding: 0, onComplete: function() { - $('#fancybox-wrap .actions button[type=submit]').click(function(e) { + $('#fancybox-wrap .popup-actions button[type=submit]').click(function(e) { $.each(attributes, function(index, name) { var val = domBoxAttrVal(name).trim(); if (val != '') domFieldVal(domField, name, val); @@ -148,7 +148,7 @@ $(document).ready(function() { field = $.extend({ behaviour_flag: function() { return options.is_template ? 'template' : 'added' }, new_record_flag: function() { return this.new_record == true && options.is_template == false ? 'new' : '' }, - errors_flag: function() { return this.errors.length > 0 ? 'error' : '' }, + errors_flag: function() { return Object.size(this.errors) > 0 ? 'error' : '' }, required_flag: function() { return this.required ? 'required' : ''; }, base_name: function() { return options.is_template ? '' : baseInputName + "[" + index + "]"; }, base_dom_id: function() { return options.is_template ? 'custom_field_template' : 'custom_field_' + index; }, diff --git a/public/javascripts/admin/custom_fields/category.js b/public/javascripts/admin/custom_fields/category.js index 44a467ff..8191e395 100644 --- a/public/javascripts/admin/custom_fields/category.js +++ b/public/javascripts/admin/custom_fields/category.js @@ -108,7 +108,7 @@ var SetupCustomFieldCategoryEditor = function(target) { category = $.extend({ behaviour_flag: function() { return options.is_template ? 'template' : 'added' }, new_record_flag: function() { return this.new_record == true && options.is_template == false ? 'new' : '' }, - errors_flag: function() { return this.errors && this.errors.length > 0 ? 'error' : '' }, + errors_flag: function() { return this.errors && Object.size(this.errors) > 0 ? 'error' : '' }, base_name: function() { return options.is_template ? '' : baseInputName + "[" + index + "]"; }, base_dom_id: function() { return options.is_template ? 'category_template' : 'category_' + index; }, if_existing_record: function() { return this.new_record == false } diff --git a/public/javascripts/admin/utils.js b/public/javascripts/admin/utils.js index ce2322f9..0a06b06d 100644 --- a/public/javascripts/admin/utils.js +++ b/public/javascripts/admin/utils.js @@ -13,4 +13,12 @@ function makeSlug(val, sep) { // code largely inspired by http://www.thewebsitet String.prototype.trim = function() { return this.replace(/^\s+/g, '').replace(/\s+$/g, ''); } -})(); \ No newline at end of file +})(); + +Object.size = function(obj) { + var size = 0, key; + for (key in obj) { + if (obj.hasOwnProperty(key)) size++; + } + return size; +}; \ No newline at end of file