<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>spec/controllers/assets_controller_spec.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -23,7 +23,13 @@ class Vrame::AssetsController &lt; Vrame::VrameController
   # no new action
   
   def create
-    @asset = Asset.create_from_file(params[:Filedata])
+    #TODO Gucken ob vorhanden und eingaben absichern
+    params[:vrame_styles] = JsonObject::Types::Asset.styles_for(params[:schema])
+    params[:file] = params.delete(:Filedata) if params[:Filedata]
+    params[:user] = @current_user
+    
+    @asset = Asset.factory(params)
+    
     
     # Build response hash
     response = { :id =&gt; @asset.id }</diff>
      <filename>app/controllers/vrame/assets_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,6 +6,8 @@ class Asset &lt; ActiveRecord::Base
   belongs_to :user
   belongs_to :assetable, :polymorphic =&gt; true
   
+  attr_accessor :vrame_styles
+  
   has_attached_file :file,
     :path =&gt; &quot;:rails_root/public/system/assets/:class/:id/:style.:extension&quot;,
     :url  =&gt;                   &quot;/system/assets/:class/:id/:style.:extension&quot;
@@ -14,22 +16,12 @@ class Asset &lt; ActiveRecord::Base
     file.url
   end
   
-  def self.create_from_file(file)
-    # Basic attributes
-    attributes = {
-      :file =&gt; file,
-      :user =&gt; @current_user
-    }
-    
-    # Is the file an image?
+  def self.factory(attributes)
+    file = attributes[:file]
     filename = file.respond_to?(:original_filename) ? file.original_filename : file.basename
     is_image = Paperclip::Attachment.is_image?(filename)
-    
-    # Create an Image instance or a generic Asset
     klass = is_image ? Image : Asset
-    
-    # Create asset record and return it
-    klass.create(attributes)
+    klass.create(:file =&gt; file, :user =&gt; attributes[:user], :vrame_styles =&gt; attributes[:vrame_styles])
   end
   
   def initialize_collection(collection_id = nil, parent_type = nil, parent_id = nil)</diff>
      <filename>app/models/asset.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,21 +1,24 @@
 class Image &lt; Asset
   belongs_to :collection
   
+  DEFAULT_STYLES = {
+    :vrame_backend        =&gt; &quot;100x50&quot;,
+    :thumbnail            =&gt; &quot;100x140&quot;,
+    :thumbnail_square     =&gt; &quot;100x100#&quot;,
+    :full                 =&gt; &quot;300x250&quot;,
+    :bg_thumb             =&gt; &quot;392x272&quot;
+  }
+  
   has_attached_file :file,
     :path =&gt; &quot;:rails_root/public/system/assets/:class/:id/:style.:extension&quot;,
     :url  =&gt;                   &quot;/system/assets/:class/:id/:style.:extension&quot;,
-    :styles =&gt; {
-      :menucarddesign_thumb =&gt; &quot;85x57&quot;,
-      :qbus_large           =&gt; [&quot;x506&quot;, :jpg],
-      :qbus_medium          =&gt; [&quot;294x166#&quot;, :jpg],
-      :qbus_thumb           =&gt; [&quot;x124&quot;, :jpg],
-      :qbus_backend         =&gt; [&quot;x57&quot;, :jpg],
-      :vrame_backend      =&gt; &quot;100x50&quot;,
-      :thumbnail          =&gt; &quot;100x140&quot;,
-      :thumbnail_square   =&gt; &quot;100x100#&quot;,
-      :full               =&gt; &quot;300x250&quot;,
-      :bg_thumb           =&gt; &quot;392x272&quot;
-    },
+    :styles =&gt; lambda { |attachment|
+                  if attachment.instance.vrame_styles.is_a? Hash
+                    Image::DEFAULT_STYLES.merge(attachment.instance.vrame_styles)
+                  else
+                    Image::DEFAULT_STYLES
+                  end
+                },
     :convert_options =&gt; { :all =&gt; &quot;-quality 80 -colorspace RGB -strip&quot; }
     
 end
\ No newline at end of file</diff>
      <filename>app/models/image.rb</filename>
    </modified>
    <modified>
      <diff>@@ -43,6 +43,7 @@
 		
 		&lt;%= render :partial =&gt; 'vrame/shared/file_upload', :locals =&gt; {
 			:field_name =&gt; field_name,
+			:uid =&gt; field.uid,
 			:asset =&gt; value,
 			:parent =&gt; document
 		} %&gt;</diff>
      <filename>app/views/vrame/documents/_meta_field.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -17,6 +17,12 @@ end %&gt;
 	data-parent-id    = &quot;&lt;%= parent.id %&gt;&quot;
 	data-parent-type  = &quot;&lt;%= parent_name %&gt;&quot;
 	data-upload-type  = &quot;&lt;%= type %&gt;&quot;
+	&lt;% if defined?(uid)  %&gt; &lt;%# TODO Dirty Hack  %&gt;
+		data-schema-class = &quot;Category&quot;
+		data-schema-id    = &quot;&lt;%= parent.category.id %&gt;&quot;
+		data-schema-attr  = &quot;schema&quot;
+		data-schema-uid   = &quot;&lt;%= uid %&gt;&quot;
+	&lt;% end %&gt;
 	&lt;% if type == 'collection' and id -%&gt;
 		data-collection-id = &quot;&lt;%= id %&gt;&quot;
 	&lt;%- end %&gt;</diff>
      <filename>app/views/vrame/shared/_file_upload.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -40,8 +40,15 @@ function Upload (containerEl) {
 		assetIdInput                : c.find('input.asset-id'),
 		
 		/* Form field(s) for the new collection id (jQuery collection) */
-		collectionIdInput           : c.find('input.collection-id')
-		
+		collectionIdInput           : c.find('input.collection-id'),
+
+		// Information needed for the asset controller to determine the correct styles 
+		schema                      : {
+																	class:     c.attr('data-schema-class'),
+																	id:        c.attr('data-schema-id'),
+																	attribute: c.attr('data-schema-attr'),
+																	uid:       c.attr('data-schema-uid')
+																	}
 	};
 	
 	//console.log('new Upload', o);
@@ -73,11 +80,15 @@ function Upload (containerEl) {
 
 		/* POST parameters with authentication and relation ids */
 		post_params : {
-			user_credentials : o.token,
-			upload_type      : o.uploadType,
-			parent_id        : o.parentId,
-			parent_type      : o.parentType,
-			collection_id    : o.collectionId
+			'user_credentials'  : o.token,
+			'upload_type'       : o.uploadType,
+			'parent_id'         : o.parentId,
+			'parent_type'       : o.parentType,
+			'collection_id'     : o.collectionId,
+			'schema[class]'     : o.schema.class,
+			'schema[id]'        : o.schema.id,
+			'schema[attribute]' : o.schema.attribute,
+			'schema[uid]'       : o.schema.uid
 		},
 
 		/* Pass our settings */</diff>
      <filename>public/vrame/javascripts/upload.js</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>40c24d8e199d082b163761fe7fe42f4b3a076f22</id>
    </parent>
  </parents>
  <author>
    <name>Jan Varwig</name>
    <email>jan@varwig.org</email>
  </author>
  <url>http://github.com/sebastiandeutsch/vrame/commit/400a5e89656df156bfa66d639a1a10a49f3e99e8</url>
  <id>400a5e89656df156bfa66d639a1a10a49f3e99e8</id>
  <committed-date>2009-11-03T09:58:17-08:00</committed-date>
  <authored-date>2009-11-03T09:56:52-08:00</authored-date>
  <message>Rebuilt Assets to support dynamic styles</message>
  <tree>f497621dbfcc4097d4ab0c2c5747f3fa67314459</tree>
  <committer>
    <name>Jan Varwig</name>
    <email>jan@varwig.org</email>
  </committer>
</commit>
