zones_restrict respected in preview

This commit is contained in:
Emi Matchu 2010-06-07 19:50:49 -04:00
parent 5e5032d671
commit c8f20b2f34
4 changed files with 20 additions and 8 deletions

View file

@ -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

View file

@ -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',

View file

@ -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 {

View file

@ -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