diff --git a/app/models/swf_asset.rb b/app/models/swf_asset.rb index ffeced9f..d767ca9d 100644 --- a/app/models/swf_asset.rb +++ b/app/models/swf_asset.rb @@ -25,7 +25,8 @@ class SwfAsset < ActiveRecord::Base :id => id, :depth => depth, :local_url => local_url, - :body_id => body_id + :body_id => body_id, + :zone_id => zone_id } end end diff --git a/app/views/items/show.html.haml b/app/views/items/show.html.haml index 03e40673..1e7fefd7 100644 --- a/app/views/items/show.html.haml +++ b/app/views/items/show.html.haml @@ -12,6 +12,9 @@ #item-preview-swf{'data-impress-host' => RemoteImpressHost} Javascript and Flash are required to preview wearables. Sorry! +:javascript + var CURRENT_ITEM_ZONES_RESTRICT = #{@item.zones_restrict.inspect}; + - content_for :javascripts do = javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js', 'http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js', diff --git a/public/javascripts/items/show.js b/public/javascripts/items/show.js index 7b6ac026..fe6979cf 100644 --- a/public/javascripts/items/show.js +++ b/public/javascripts/items/show.js @@ -1,5 +1,3 @@ -// TODO: zones_restrict - var PREVIEW_SWF_ID = 'item-preview-swf', PREVIEW_SWF = document.getElementById(PREVIEW_SWF_ID), IMPRESS_HOST = PREVIEW_SWF.getAttribute('data-impress-host'), @@ -163,7 +161,14 @@ function Item(id) { Item.LOAD_ERROR = new LoadError("$species_article $species wear a $item"); Item.createFromLocation = function () { - var item = new Item(parseInt(document.location.pathname.substr(1))); + var item = new Item(parseInt(document.location.pathname.substr(1))), + z = CURRENT_ITEM_ZONES_RESTRICT, zl = z.length; + item.restricted_zones = []; + for(i = 0; i < zl; i++) { + if(z.charAt(i) == '1') { + item.restricted_zones.push(i + 1); + } + } return item; } @@ -184,8 +189,10 @@ Preview = new function Preview() { $.each(asset_sources, function () { assets = assets.concat(this); }); - $.each(assets, function () { - this.local_path = this.local_url; + assets = $.grep(assets, function (asset) { + var visible = $.inArray(asset.zone_id, Item.current.restricted_zones) == -1; + if(visible) asset.local_path = asset.local_url; + return visible; }); swf.setAssets(assets); } else { diff --git a/spec/models/swf_asset_spec.rb b/spec/models/swf_asset_spec.rb index e4c63bab..9a92b7b3 100644 --- a/spec/models/swf_asset_spec.rb +++ b/spec/models/swf_asset_spec.rb @@ -20,7 +20,7 @@ describe SwfAsset do asset.local_url.should == 'http://impress.openneo.net/assets/swf/outfit/items/000/000/012/12211_9969430b3a.swf' end - it "should contain id, depth, and local_url as JSON" do + it "should contain id, depth, zone ID, and local_url as JSON" do zone = Factory.create :zone, :depth => 12 asset = Factory.create :swf_asset, :id => 123, @@ -31,7 +31,8 @@ describe SwfAsset do :id => 123, :depth => 12, :body_id => 234, - :local_url => 'http://impress.openneo.net/assets/swf/outfit/items/000/000/012/12211_9969430b3a.swf' + :local_url => 'http://impress.openneo.net/assets/swf/outfit/items/000/000/012/12211_9969430b3a.swf', + :zone_id => 1 } end end