radiant-shop_packages-extension 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/README +3 -0
- data/Rakefile +138 -0
- data/VERSION +1 -0
- data/app/controllers/.DS_Store +0 -0
- data/app/controllers/admin/shop/packages/packings_controller.rb +90 -0
- data/app/controllers/admin/shop/packages_controller.rb +63 -0
- data/app/datasets/shop_packages.rb +25 -0
- data/app/models/shop_package.rb +79 -0
- data/app/models/shop_packing.rb +22 -0
- data/app/views/admin/shop/packages/edit.html.haml +11 -0
- data/app/views/admin/shop/packages/edit/_foot.html.haml +17 -0
- data/app/views/admin/shop/packages/edit/_form.html.haml +15 -0
- data/app/views/admin/shop/packages/edit/_head.html.haml +4 -0
- data/app/views/admin/shop/packages/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/packages/edit/_meta.html.haml +8 -0
- data/app/views/admin/shop/packages/edit/_parts.html.haml +9 -0
- data/app/views/admin/shop/packages/edit/_popups.html.haml +4 -0
- data/app/views/admin/shop/packages/edit/buttons/_browse_products.html.haml +1 -0
- data/app/views/admin/shop/packages/edit/inputs/_name.html.haml +3 -0
- data/app/views/admin/shop/packages/edit/inputs/_price.html.haml +3 -0
- data/app/views/admin/shop/packages/edit/meta/_sku.html.haml +5 -0
- data/app/views/admin/shop/packages/edit/parts/_description.html.haml +1 -0
- data/app/views/admin/shop/packages/edit/parts/_products.html.haml +3 -0
- data/app/views/admin/shop/packages/edit/popups/_browse_products.html.haml +7 -0
- data/app/views/admin/shop/packages/edit/shared/_product.html.haml +8 -0
- data/app/views/admin/shop/packages/index.html.haml +13 -0
- data/app/views/admin/shop/packages/index/_foot.html.haml +8 -0
- data/app/views/admin/shop/packages/index/_head.html.haml +2 -0
- data/app/views/admin/shop/packages/index/_package.html.haml +9 -0
- data/app/views/admin/shop/packages/index/buttons/_new_package.html.haml +1 -0
- data/app/views/admin/shop/packages/new.html.haml +11 -0
- data/app/views/admin/shop/packages/remove.html.haml +12 -0
- data/config/locales/en.yml +11 -0
- data/config/routes.rb +13 -0
- data/cucumber.yml +1 -0
- data/db/migrate/20101015161749_setup_shop_packages.rb +27 -0
- data/lib/shop_packages/interface/packages.rb +34 -0
- data/lib/shop_packages/models/shop_packageable.rb +15 -0
- data/lib/shop_packages/tags/helpers.rb +41 -0
- data/lib/shop_packages/tags/package.rb +94 -0
- data/lib/tasks/shop_packages_extension_tasks.rake +55 -0
- data/public/javascripts/admin/extensions/shop/packages/edit.js +109 -0
- data/public/stylesheets/sass/admin/extensions/shop/packages/edit.sass +162 -0
- data/radiant-shop_packages-extension.gemspec +104 -0
- data/shop_packages_extension.rb +37 -0
- data/spec/controllers/admin/shop/packages/packings_controller_spec.rb +188 -0
- data/spec/controllers/admin/shop/packages_controller_spec.rb +32 -0
- data/spec/datasets/shop_packages.rb +23 -0
- data/spec/lib/shop_packages/tags/package_spec.rb +348 -0
- data/spec/models/shop_package_spec.rb +117 -0
- data/spec/models/shop_packing_spec.rb +67 -0
- data/spec/models/shop_product_spec.rb +25 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +23 -0
- 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,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 @@
|
|
1
|
+
= link_to "#{image('plus')} #{t('browse_products')}", '#browse_products_popup', :class => 'popup button'
|
@@ -0,0 +1 @@
|
|
1
|
+
~ f.text_area :description, :class => "textarea large", :style => "width: 100%"
|
@@ -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,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,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
|
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
|