radiant-shop_packages-extension 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/.gitignore +2 -0
  2. data/README +3 -0
  3. data/Rakefile +138 -0
  4. data/VERSION +1 -0
  5. data/app/controllers/.DS_Store +0 -0
  6. data/app/controllers/admin/shop/packages/packings_controller.rb +90 -0
  7. data/app/controllers/admin/shop/packages_controller.rb +63 -0
  8. data/app/datasets/shop_packages.rb +25 -0
  9. data/app/models/shop_package.rb +79 -0
  10. data/app/models/shop_packing.rb +22 -0
  11. data/app/views/admin/shop/packages/edit.html.haml +11 -0
  12. data/app/views/admin/shop/packages/edit/_foot.html.haml +17 -0
  13. data/app/views/admin/shop/packages/edit/_form.html.haml +15 -0
  14. data/app/views/admin/shop/packages/edit/_head.html.haml +4 -0
  15. data/app/views/admin/shop/packages/edit/_inputs.html.haml +2 -0
  16. data/app/views/admin/shop/packages/edit/_meta.html.haml +8 -0
  17. data/app/views/admin/shop/packages/edit/_parts.html.haml +9 -0
  18. data/app/views/admin/shop/packages/edit/_popups.html.haml +4 -0
  19. data/app/views/admin/shop/packages/edit/buttons/_browse_products.html.haml +1 -0
  20. data/app/views/admin/shop/packages/edit/inputs/_name.html.haml +3 -0
  21. data/app/views/admin/shop/packages/edit/inputs/_price.html.haml +3 -0
  22. data/app/views/admin/shop/packages/edit/meta/_sku.html.haml +5 -0
  23. data/app/views/admin/shop/packages/edit/parts/_description.html.haml +1 -0
  24. data/app/views/admin/shop/packages/edit/parts/_products.html.haml +3 -0
  25. data/app/views/admin/shop/packages/edit/popups/_browse_products.html.haml +7 -0
  26. data/app/views/admin/shop/packages/edit/shared/_product.html.haml +8 -0
  27. data/app/views/admin/shop/packages/index.html.haml +13 -0
  28. data/app/views/admin/shop/packages/index/_foot.html.haml +8 -0
  29. data/app/views/admin/shop/packages/index/_head.html.haml +2 -0
  30. data/app/views/admin/shop/packages/index/_package.html.haml +9 -0
  31. data/app/views/admin/shop/packages/index/buttons/_new_package.html.haml +1 -0
  32. data/app/views/admin/shop/packages/new.html.haml +11 -0
  33. data/app/views/admin/shop/packages/remove.html.haml +12 -0
  34. data/config/locales/en.yml +11 -0
  35. data/config/routes.rb +13 -0
  36. data/cucumber.yml +1 -0
  37. data/db/migrate/20101015161749_setup_shop_packages.rb +27 -0
  38. data/lib/shop_packages/interface/packages.rb +34 -0
  39. data/lib/shop_packages/models/shop_packageable.rb +15 -0
  40. data/lib/shop_packages/tags/helpers.rb +41 -0
  41. data/lib/shop_packages/tags/package.rb +94 -0
  42. data/lib/tasks/shop_packages_extension_tasks.rake +55 -0
  43. data/public/javascripts/admin/extensions/shop/packages/edit.js +109 -0
  44. data/public/stylesheets/sass/admin/extensions/shop/packages/edit.sass +162 -0
  45. data/radiant-shop_packages-extension.gemspec +104 -0
  46. data/shop_packages_extension.rb +37 -0
  47. data/spec/controllers/admin/shop/packages/packings_controller_spec.rb +188 -0
  48. data/spec/controllers/admin/shop/packages_controller_spec.rb +32 -0
  49. data/spec/datasets/shop_packages.rb +23 -0
  50. data/spec/lib/shop_packages/tags/package_spec.rb +348 -0
  51. data/spec/models/shop_package_spec.rb +117 -0
  52. data/spec/models/shop_packing_spec.rb +67 -0
  53. data/spec/models/shop_product_spec.rb +25 -0
  54. data/spec/spec.opts +4 -0
  55. data/spec/spec_helper.rb +23 -0
  56. metadata +141 -0
@@ -0,0 +1,17 @@
1
+ - render_region :foot do |foot|
2
+ - foot.buttons do
3
+ %p.buttons
4
+ = save_model_button(@shop_package)
5
+ = save_model_and_continue_editing_button(@shop_package)
6
+ = t('or')
7
+ = link_to t('cancel'), admin_shop_packages_path
8
+ - foot.timestamp do
9
+ = updated_stamp @shop_package
10
+
11
+ - unless @shop_package.new_record?
12
+ :javascript
13
+ if(typeof(ROUTES) === 'undefined') ROUTES = new Array();
14
+
15
+ ROUTES['sort_admin_shop_package_packings_path'] = "#{sort_admin_shop_package_packings_path(@shop_package)}";
16
+ ROUTES['admin_shop_package_packings_path'] = "#{admin_shop_package_packings_path(@shop_package)}";
17
+ ROUTES['admin_shop_package_packing_path'] = "#{admin_shop_package_packing_path(@shop_package,':d')}";
@@ -0,0 +1,15 @@
1
+ - form_for [:admin, @shop_package], :html => {'data-onsubmit_status'=>"Saving Changes…"} do |f|
2
+ = hidden_field_tag 'shop_package_id',@shop_package.id
3
+
4
+ - render_region :form do |form|
5
+ - form.inputs do
6
+ = render :partial => '/admin/shop/packages/edit/inputs', :locals => { :f => f }
7
+
8
+ - form.meta do
9
+ = render :partial => '/admin/shop/packages/edit/meta', :locals => { :f => f }
10
+
11
+ - form.parts do
12
+ = render :partial => '/admin/shop/packages/edit/parts', :locals => { :f => f }
13
+
14
+ - form.foot do
15
+ = render :partial => '/admin/shop/packages/edit/foot', :locals => { :f => f }
@@ -0,0 +1,4 @@
1
+ %h1
2
+ = @page_title
3
+ - @buttons.each do |button|
4
+ = render :partial => "admin/shop/packages/edit/buttons/#{button}"
@@ -0,0 +1,2 @@
1
+ - @inputs.each do |input|
2
+ = render :partial => "admin/shop/packages/edit/inputs/#{input}", :locals => { :f => f }
@@ -0,0 +1,8 @@
1
+ - if @meta.present?
2
+ .drawer
3
+ .drawer_contents#attributes
4
+ %table.fieldset
5
+ - @meta.each do |meta|
6
+ = render :partial => "admin/shop/packages/edit/meta/#{meta}", :locals => { :f => f }
7
+ .drawer_handle
8
+ %a.toggle{:href=>'#attributes', :rel=>"toggle[attributes]", :class=>"#{(meta_errors? ? 'less' : 'more')}"}= meta_label
@@ -0,0 +1,9 @@
1
+ #tab_control
2
+ #tabs.tabs
3
+ #tab_toolbar
4
+ #pages.pages
5
+ = hidden_field_tag 'page_part_index_field' #important
6
+ - @parts.each do |part|
7
+ .page{:id => "package_page_#{part}", 'data-caption'=>h(part)}
8
+ .part{:id => "package_part_#{part}"}
9
+ = render :partial => "admin/shop/packages/edit/parts/#{part}", :locals => { :f => f }
@@ -0,0 +1,4 @@
1
+ #popups
2
+ - @popups.each do |popup|
3
+ .popup{ :id => "#{popup}_popup"}
4
+ = render :partial => "admin/shop/packages/edit/popups/#{popup}"
@@ -0,0 +1 @@
1
+ = link_to "#{image('plus')} #{t('browse_products')}", '#browse_products_popup', :class => 'popup button'
@@ -0,0 +1,3 @@
1
+ %p.title
2
+ = f.label :name
3
+ = f.text_field :name, :class => 'textbox', :maxlenth => 255
@@ -0,0 +1,3 @@
1
+ %p.title
2
+ = f.label :price
3
+ = f.text_field :price, :class => 'textbox', :maxlenth => 255, :value => input_currency(@shop_package.price)
@@ -0,0 +1,5 @@
1
+ %tr
2
+ %th.label
3
+ %label{:for=>"shop_package[sku]"}= t('sku')
4
+ %td.field
5
+ = f.text_field :sku, :class =>'textbox'
@@ -0,0 +1 @@
1
+ ~ f.text_area :description, :class => "textarea large", :style => "width: 100%"
@@ -0,0 +1,3 @@
1
+ %ol#package_products
2
+ - @shop_package.packings.each do |packing|
3
+ = render :partial => 'admin/shop/packages/edit/shared/product', :locals => { :product => packing.product, :packing => packing }
@@ -0,0 +1,7 @@
1
+ %h3.title Available Products
2
+
3
+ %ul#available_products
4
+ - @shop_package.available_products.each do |product|
5
+ = render :partial => 'admin/shop/packages/edit/shared/product', :locals => { :product => product }
6
+
7
+ %a#browse_products_popup_close.close{ :href => '#' }
@@ -0,0 +1,8 @@
1
+ %li.product{ :id => "product_#{packing.id rescue product.id}", :'data-packing_id' => (packing.id rescue nil), :'data-product_id' => product.id }
2
+ .wrapper
3
+ = image_tag(product.images.first.url(:preview)) unless product.images.empty?
4
+ %span.title= product.sku
5
+ %input.quantity{ :id => "packing_#{packing.id rescue nil }_quantity", :value => (packing.quantity rescue nil), :'data-packing_id' => (packing.id rescue nil) }
6
+ %button.save_quantity{ :onclick => 'return false' } save
7
+ .actions
8
+ %span.delete
@@ -0,0 +1,13 @@
1
+ - @page_title = t('packages') + ' - ' + default_page_title
2
+
3
+ .outset
4
+
5
+ #head.min
6
+ = render :partial => '/admin/shop/packages/index/head'
7
+
8
+ #packages_map.map
9
+ %ul#packages
10
+ = render :partial => '/admin/shop/packages/index/package', :collection => @shop_packages
11
+
12
+ #actions
13
+ = render :partial => '/admin/shop/packages/index/foot'
@@ -0,0 +1,8 @@
1
+ %ul
2
+ - render_region :foot do |foot|
3
+ - foot.buttons do
4
+ - @buttons.each do |button|
5
+ %li= render :partial => "admin/shop/packages/index/buttons/#{button}"
6
+
7
+ :javascript
8
+ if(typeof(ROUTES) === 'undefined') ROUTES = new Array();
@@ -0,0 +1,2 @@
1
+ - render_region :head do |head|
2
+ - nil
@@ -0,0 +1,9 @@
1
+ %li.package.object{:id => "package_#{package.id}", :'data-id' => package.id}
2
+ .attributes
3
+ - render_region :body do |body|
4
+ - body.name do
5
+ %span.name.attribute
6
+ = link_to package.name, [:edit_admin, package]
7
+ - body.modify do
8
+ .modify
9
+ %span.remove= link_to t('remove'), [:remove_admin, package]
@@ -0,0 +1 @@
1
+ = link_to image('plus') + " " + t("add_package"), new_admin_shop_package_path
@@ -0,0 +1,11 @@
1
+ - @page_title = t('new_package')
2
+
3
+ - render_region :main do |main|
4
+ - main.head do
5
+ = render 'admin/shop/packages/edit/head'
6
+
7
+ - main.popups do
8
+ = render 'admin/shop/packages/edit/popups'
9
+
10
+ - main.form do
11
+ = render 'admin/shop/packages/edit/form'
@@ -0,0 +1,12 @@
1
+ %h1
2
+ = t('remove_package')
3
+
4
+ %p
5
+ = t('text.remove_package.warning')
6
+
7
+ - form_for [:admin, @shop_package.becomes(ShopPackage)], :html => {:method => :delete, 'data-onsubmit_status'=>"Removing Package…"} do
8
+
9
+ %p.buttons
10
+ %input.button{:type=>"submit", :value => t('delete_package') }/
11
+ = t('or')
12
+ = link_to t('cancel'), admin_shop_packages_path
@@ -0,0 +1,11 @@
1
+ ---
2
+ en:
3
+ shop packages: Shop Packages
4
+ packages: Packages
5
+ add_package: Add Package
6
+ new_package: New Package
7
+ remove_package: Remove Package
8
+ text:
9
+ remove_package:
10
+ warning: Removing a package is irreversible
11
+ delete_package: Delete Package
data/config/routes.rb ADDED
@@ -0,0 +1,13 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+
3
+ map.namespace :admin do |admin|
4
+ admin.namespace :shop, :member => { :remove => :get } do |shop|
5
+
6
+ shop.resources :packages, :member => { :remove => :get } do |packages|
7
+ packages.resources :packings, :controller => 'packages/packings', :only => [:create, :update, :destroy], :collection => { :sort => :put }
8
+ end
9
+
10
+ end
11
+ end
12
+
13
+ end
data/cucumber.yml ADDED
@@ -0,0 +1 @@
1
+ default: --format progress features --tags ~@proposed,~@in_progress
@@ -0,0 +1,27 @@
1
+ class SetupShopPackages < ActiveRecord::Migration
2
+ def self.up
3
+ create_table "shop_packages", :force => true do |t|
4
+ t.string "name"
5
+ t.string "sku"
6
+ t.text "description"
7
+ t.boolean "is_active", :default => true
8
+ t.decimal "price"
9
+ t.integer "created_by"
10
+ t.integer "updated_by"
11
+ t.datetime "created_at"
12
+ t.datetime "updated_at"
13
+ end
14
+
15
+ create_table "shop_packings", :force => true do |t|
16
+ t.integer "quantity", :default => 1
17
+ t.integer "position"
18
+ t.integer "product_id"
19
+ t.integer "package_id"
20
+ end
21
+ end
22
+
23
+ def self.down
24
+ remove_table 'shop_packages'
25
+ remove_table 'shop_packings'
26
+ end
27
+ end
@@ -0,0 +1,34 @@
1
+ module ShopPackages
2
+ module Interface
3
+ module Packages
4
+
5
+ def self.included(base)
6
+ base.send :include, InstanceMethods
7
+ end
8
+
9
+ module InstanceMethods
10
+ attr_accessor :packages
11
+
12
+ protected
13
+
14
+ def load_default_shop_packages_regions
15
+ returning OpenStruct.new do |packages|
16
+ packages.edit = Radiant::AdminUI::RegionSet.new do |edit|
17
+ edit.main.concat %w{head form popups}
18
+ edit.form.concat %w{inputs meta parts foot}
19
+ edit.foot.concat %w{buttons timestamp}
20
+ end
21
+ packages.new = packages.edit
22
+ packages.index = Radiant::AdminUI::RegionSet.new do |index|
23
+ index.head.concat %w{}
24
+ index.body.concat %w{name modify}
25
+ index.foot.concat %w{buttons}
26
+ end
27
+ packages.remove = packages.index
28
+ end
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,15 @@
1
+ module ShopPackages
2
+ module Models
3
+ module ShopPackageable
4
+
5
+ def self.included(base)
6
+ base.class_eval do
7
+ has_many :packings, :class_name => 'ShopPacking', :foreign_key => :product_id
8
+ has_many :packages, :class_name => 'ShopPackage', :foreign_key => :package_id, :through => :packings, :source => :package
9
+ has_many :related, :class_name => 'ShopProduct', :through => :packings, :source => :product, :uniq => true
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,41 @@
1
+ module ShopPackages
2
+ module Tags
3
+ class Helpers
4
+ class << self
5
+ include ActionView::Helpers::NumberHelper
6
+
7
+ def current_packages(tag)
8
+ result = nil
9
+
10
+ if tag.locals.shop_product.present?
11
+ result = tag.locals.shop_product.packages
12
+
13
+ elsif tag.attr['key'] and tag.attr['value']
14
+ result = ShopPackage.all(:conditions => { tag.attr['key'].downcase.to_sym => tag.attr['value']})
15
+
16
+ else
17
+ result = ShopPackage.all
18
+
19
+ end
20
+
21
+ result
22
+ end
23
+
24
+ def current_package(tag)
25
+ result = nil
26
+
27
+ if tag.locals.shop_package.present?
28
+ result = tag.locals.shop_package
29
+
30
+ elsif tag.attr['key'] and tag.attr['value']
31
+ result = ShopPackage.first(:conditions => { tag.attr['key'].downcase.to_sym => tag.attr['value']})
32
+
33
+ end
34
+
35
+ result
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,94 @@
1
+ module ShopPackages
2
+ module Tags
3
+ module Package
4
+ include Radiant::Taggable
5
+ include ActionView::Helpers::NumberHelper
6
+
7
+ tag 'shop:packages' do |tag|
8
+ tag.locals.shop_packages = Helpers.current_packages(tag)
9
+ tag.expand
10
+ end
11
+
12
+ desc %{ expands if there are packages within the context }
13
+ tag 'shop:packages:if_packages' do |tag|
14
+ tag.expand if tag.locals.shop_packages.present?
15
+ end
16
+
17
+ desc %{ expands if there are no packages within the context }
18
+ tag 'shop:packages:unless_packages' do |tag|
19
+ tag.expand unless tag.locals.shop_packages.present?
20
+ end
21
+
22
+ desc %{ iterates through each package within the scope }
23
+ tag 'shop:packages:each' do |tag|
24
+ content = ''
25
+
26
+ tag.locals.shop_packages.each do |package|
27
+ tag.locals.shop_package = package
28
+ content << tag.expand
29
+ end
30
+
31
+ content
32
+ end
33
+
34
+ tag 'shop:package' do |tag|
35
+ tag.locals.shop_package = Helpers.current_package(tag)
36
+ tag.expand unless tag.locals.shop_package.nil?
37
+ end
38
+
39
+ [:id, :name, :sku].each do |symbol|
40
+ desc %{ outputs the #{symbol} of the current package }
41
+ tag "shop:package:#{symbol}" do |tag|
42
+ tag.locals.shop_package.send(symbol)
43
+ end
44
+ end
45
+
46
+ desc %{ outputs the description of the current packaage}
47
+ tag "shop:package:description" do |tag|
48
+ parse(TextileFilter.filter(tag.locals.shop_package.description))
49
+ end
50
+
51
+ [:price, :value].each do |symbol|
52
+ desc %{ output #{symbol} of product }
53
+ tag "shop:package:#{symbol}" do |tag|
54
+ attr = tag.attr.symbolize_keys
55
+
56
+ Shop::Tags::Helpers.currency(tag.locals.shop_package.send(symbol),attr)
57
+ end
58
+ end
59
+
60
+ desc %{ expands if the package has products }
61
+ tag 'shop:package:if_products' do |tag|
62
+ tag.expand unless tag.locals.shop_package.products.empty?
63
+ end
64
+
65
+ desc %{ expands if the package do not have products }
66
+ tag 'shop:package:unless_products' do |tag|
67
+ tag.expand if tag.locals.shop_package.products.empty?
68
+ end
69
+
70
+ tag 'shop:package:products' do |tag|
71
+ tag.expand
72
+ end
73
+
74
+ desc %{ iterates through each of the products images }
75
+ tag 'shop:package:products:each' do |tag|
76
+ content = ''
77
+
78
+ tag.locals.shop_package.packings.each do |packing|
79
+ tag.locals.shop_product = packing.product
80
+ tag.locals.shop_packing = packing
81
+ content << tag.expand
82
+ end
83
+
84
+ content
85
+ end
86
+
87
+ desc %{ outputs the quantity of the current packing }
88
+ tag 'shop:package:product:quantity' do |tag|
89
+ tag.locals.shop_packing.quantity
90
+ end
91
+
92
+ end
93
+ end
94
+ end