diff options
| author | hukl <contact@smyck.org> | 2009-09-04 22:34:55 +0200 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-09-04 22:34:55 +0200 |
| commit | 96a928cdfd6854a168d6328bcf29096403e556db (patch) | |
| tree | 4ccdabb8f5186d355bf395772addfbd6afabc8ef | |
| parent | fed65d37b7894d7cccbe44757148c5441af90cc3 (diff) | |
moved the image sorting into the model and wrapped it into a transaction
| -rw-r--r-- | app/controllers/pages_controller.rb | 8 | ||||
| -rw-r--r-- | app/models/page.rb | 20 |
2 files changed, 21 insertions, 7 deletions
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 4b3b541..6e826c0 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb | |||
| @@ -16,13 +16,7 @@ class PagesController < ApplicationController | |||
| 16 | 16 | ||
| 17 | def sort_images | 17 | def sort_images |
| 18 | page = Page.find(params[:id]) | 18 | page = Page.find(params[:id]) |
| 19 | 19 | page.update_assets(params[:images]) | |
| 20 | page.related_assets.destroy_all | ||
| 21 | |||
| 22 | params[:images].each_with_index do |id, index| | ||
| 23 | asset = Asset.find(id) | ||
| 24 | page.related_assets.create(:asset_id => asset.id, :position => index+1) | ||
| 25 | end | ||
| 26 | 20 | ||
| 27 | render :nothing => true, :status => 200 | 21 | render :nothing => true, :status => 200 |
| 28 | end | 22 | end |
diff --git a/app/models/page.rb b/app/models/page.rb index 6b3799b..8583071 100644 --- a/app/models/page.rb +++ b/app/models/page.rb | |||
| @@ -172,6 +172,19 @@ class Page < ActiveRecord::Base | |||
| 172 | end | 172 | end |
| 173 | end | 173 | end |
| 174 | 174 | ||
| 175 | def update_assets image_ids | ||
| 176 | |||
| 177 | transaction do | ||
| 178 | self.related_assets.delete_all | ||
| 179 | |||
| 180 | image_ids.each_with_index do |id, index| | ||
| 181 | asset = Asset.find(id) | ||
| 182 | self.related_assets.create!(:asset_id => asset.id, :position => index+1) | ||
| 183 | end | ||
| 184 | end | ||
| 185 | |||
| 186 | end | ||
| 187 | |||
| 175 | private | 188 | private |
| 176 | 189 | ||
| 177 | def set_page_title | 190 | def set_page_title |
| @@ -188,6 +201,13 @@ class Page < ActiveRecord::Base | |||
| 188 | xml_doc = xml_string.parse | 201 | xml_doc = xml_string.parse |
| 189 | links = xml_doc.find("//a[not(starts-with(@href, 'http://'))]") | 202 | links = xml_doc.find("//a[not(starts-with(@href, 'http://'))]") |
| 190 | locales = I18n.available_locales.reject {|l| l == :root} | 203 | locales = I18n.available_locales.reject {|l| l == :root} |
| 204 | |||
| 205 | if xml_doc.find("//p/aggregate")[0] | ||
| 206 | aggregate_tags = xml_doc.find("//aggregate") | ||
| 207 | aggregate_tags[0].parent.replace_with aggregate_tags[0] | ||
| 208 | end | ||
| 209 | |||
| 210 | |||
| 191 | 211 | ||
| 192 | links.each do |link| | 212 | links.each do |link| |
| 193 | unless locales.include? link[:href].slice(1,2).to_sym | 213 | unless locales.include? link[:href].slice(1,2).to_sym |
