Commit 1dd259efbc7d060353ec70b9b76f473200c8e795

Authored by Braulio Bhavamitra
1 parent f98862c7

Add delivery plugin

Showing 33 changed files with 663 additions and 0 deletions   Show diff stats
plugins/delivery/controllers/myprofile/delivery_plugin/admin_method_controller.rb 0 → 100644
@@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
  1 +require_dependency 'delivery_plugin/display_helper'
  2 +
  3 +class DeliveryPlugin::AdminMethodController < MyProfileController
  4 +
  5 + protect 'edit_profile', :profile
  6 +
  7 + helper OrdersPlugin::FieldHelper
  8 + helper DeliveryPlugin::DisplayHelper
  9 +
  10 + def new
  11 + @delivery_method = profile.delivery_methods.build
  12 + self.edit
  13 + end
  14 +
  15 + def edit
  16 + @delivery_method ||= profile.delivery_methods.find_by_id params[:id]
  17 + if params[:delivery_method].present? and @delivery_method.update_attributes params[:delivery_method]
  18 + render partial: 'list'
  19 + else
  20 + render partial: 'edit', locals: {delivery_method: @delivery_method}
  21 + end
  22 + end
  23 +
  24 + def destroy
  25 + @delivery_method = profile.delivery_methods.find params[:id]
  26 + @delivery_method.destroy
  27 + render nothing: true
  28 + end
  29 +
  30 + protected
  31 +
  32 +end
plugins/delivery/controllers/myprofile/delivery_plugin/admin_options_controller.rb 0 → 100644
@@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
  1 +class DeliveryPlugin::AdminOptionsController < DeliveryPlugin::AdminMethodController
  2 +
  3 + helper OrdersPlugin::FieldHelper
  4 + helper DeliveryPlugin::DisplayHelper
  5 +
  6 + protect 'edit_profile', :profile
  7 + before_filter :load_context
  8 + before_filter :load_owner
  9 +
  10 + def select
  11 +
  12 + end
  13 +
  14 + def new
  15 + dms = profile.delivery_methods.find Array(params[:method_id])
  16 + (dms - @owner.delivery_methods).each do |dm|
  17 + DeliveryPlugin::Option.create! owner_id: @owner.id, owner_type: @owner.class.name, delivery_method: dm
  18 + end
  19 + end
  20 +
  21 + def destroy
  22 + @delivery_option = @owner.delivery_options.find params[:id]
  23 + @delivery_option.destroy
  24 + end
  25 +
  26 + protected
  27 +
  28 + def load_owner
  29 + @owner_id = params[:owner_id]
  30 + @owner_type = params[:owner_type]
  31 + @owner = @owner_type.constantize.find @owner_id
  32 + end
  33 +
  34 + def load_context
  35 + @delivery_context = 'delivery_plugin/admin_options'
  36 + end
  37 +
  38 +end
plugins/delivery/db/migrate/20130719132252_create_delivery_plugin_tables.rb 0 → 100644
@@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
  1 +class CreateDeliveryPluginTables < ActiveRecord::Migration
  2 + def self.up
  3 + # check if distribution plugin already moved tables
  4 + return if ActiveRecord::Base.connection.table_exists? :delivery_plugin_methods
  5 +
  6 + create_table :delivery_plugin_methods do |t|
  7 + t.integer :profile_id
  8 + t.string :name
  9 + t.text :description
  10 + t.string :recipient
  11 + t.string :address_line1
  12 + t.string :address_line2
  13 + t.string :postal_code
  14 + t.string :state
  15 + t.string :country
  16 + t.string :delivery_type
  17 + t.datetime :created_at
  18 + t.datetime :updated_at
  19 + end
  20 +
  21 + add_index :delivery_plugin_methods, [:profile_id]
  22 + add_index :delivery_plugin_methods, [:delivery_type]
  23 +
  24 + create_table :delivery_plugin_options do |t|
  25 + t.integer :delivery_method_id
  26 + t.integer :owner_id
  27 + t.string :owner_type
  28 + t.datetime :created_at
  29 + t.datetime :updated_at
  30 + end
  31 +
  32 + add_index :delivery_plugin_options, [:delivery_method_id]
  33 + add_index :delivery_plugin_options, [:owner_id, :delivery_method_id], name: :index_delivery_plugin_owner_id_delivery_method_id
  34 + add_index :delivery_plugin_options, [:owner_id]
  35 + add_index :delivery_plugin_options, [:owner_type]
  36 + add_index :delivery_plugin_options, [:owner_id, :owner_type]
  37 +
  38 + end
  39 +
  40 + def self.down
  41 + drop_table :delivery_plugin_methods
  42 + drop_table :delivery_plugin_options
  43 + end
  44 +end
plugins/delivery/db/migrate/20150202122306_add_fixed_cost_to_delivery_plugin_method.rb 0 → 100644
@@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
  1 +class AddFixedCostToDeliveryPluginMethod < ActiveRecord::Migration
  2 + def up
  3 + add_column :delivery_plugin_methods, :fixed_cost, :decimal
  4 + add_column :delivery_plugin_methods, :free_over_price, :decimal
  5 + end
  6 + def down
  7 + remove_column :delivery_plugin_methods, :fixed_cost
  8 + remove_column :delivery_plugin_methods, :free_over_price
  9 + end
  10 +end
plugins/delivery/lib/delivery_plugin.rb 0 → 100644
@@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
  1 +module DeliveryPlugin
  2 +
  3 + extend Noosfero::Plugin::ParentMethods
  4 +
  5 + def self.plugin_name
  6 + I18n.t('delivery_plugin.lib.plugin.name')
  7 + end
  8 +
  9 + def self.plugin_description
  10 + I18n.t('delivery_plugin.lib.plugin.description')
  11 + end
  12 +
  13 +end
plugins/delivery/lib/delivery_plugin/base.rb 0 → 100644
@@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
  1 +class DeliveryPlugin::Base < Noosfero::Plugin
  2 +
  3 + def stylesheet?
  4 + true
  5 + end
  6 +
  7 + def js_files
  8 + ['delivery'].map{ |j| "javascripts/#{j}" }
  9 + end
  10 +
  11 +end
  12 +
  13 +
plugins/delivery/lib/delivery_plugin/display_helper.rb 0 → 100644
@@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
  1 +module DeliveryPlugin::DisplayHelper
  2 +
  3 + def input_group_addon unit
  4 + yield
  5 + end unless defined? ResponsivePlugin
  6 +
  7 + def supplier_delivery_options options = {}
  8 + selected = options[:selected]
  9 + methods = options[:methods] || profile.delivery_methods
  10 +
  11 + options = methods.map do |method|
  12 + cost = if method.fixed_cost.present? and method.fixed_cost > 0 then float_to_currency_cart(method.fixed_cost, environment) else nil end
  13 + text = if cost.present? then "#{method.name} (#{cost})" else method.name end
  14 +
  15 + content_tag :option, text, value: method.id,
  16 + data: {label: method.name, type: method.delivery_type, instructions: method.description.to_s},
  17 + selected: if method == selected then 'selected' else nil end
  18 + end.join
  19 + end
  20 +
  21 + def delivery_context
  22 + @delivery_context || 'delivery_plugin/admin_method'
  23 + end
  24 +
  25 +end
plugins/delivery/lib/ext/profile.rb 0 → 100644
@@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
  1 +require_dependency 'profile'
  2 +
  3 +class Profile
  4 +
  5 + has_many :delivery_methods, class_name: 'DeliveryPlugin::Method', foreign_key: :profile_id, dependent: :destroy, order: 'id ASC'
  6 +
  7 +end
plugins/delivery/locales/en-US.yml 0 → 100644
@@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
  1 +"en-US": &en-US
  2 +
  3 + delivery_plugin:
  4 + lib:
  5 + plugin:
  6 + name: "Delivery"
  7 + description: "Management of delivery's methods and options"
  8 + models:
  9 + method:
  10 + pickup: 'Pickup'
  11 + deliver: 'Deliver'
  12 + delivery_type: 'Type'
  13 + delivery_type_help: 'Pickup: the products will be delivered in the consumption place.<br>Delivery: the products will be delivered in the address asked by the consumer.'
  14 + name: Name
  15 + name_help: Write the name of the Consumption Place or the
  16 + fixed_cost: Fixed cost
  17 + free_over_price: Order's minimum price for free delivery
  18 + instructions: Description
  19 + instructions_help: "Write the address and other important informations about the place of this consumption place.<br> This text will be available"
  20 + views:
  21 + delivery_option:
  22 + select:
  23 + add: Add selected
  24 + _select_content:
  25 + add: Add option
  26 + add_new: "add new"
  27 + are_you_sure_you_want: "Are you sure you want to remove?"
  28 + cancel: cancel
  29 + choose_a_delivery_met: "Choose a delivery method from the list"
  30 + edit_this: "Edit"
  31 + remove_method: "Remover"
  32 + _show:
  33 + x: X
  34 + select:
  35 + add_a_delivery_method: "Add a delivery method to the Orders' Cycle"
  36 + method:
  37 + index:
  38 + new: "New delivery or pickup"
  39 + edit:
  40 + add: Add
  41 + back: back
  42 + save: Save
  43 +
  44 +'en_US':
  45 + <<: *en-US
  46 +'en':
  47 + <<: *en-US
  48 +
plugins/delivery/locales/pt-BR.yml 0 → 100644
@@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
  1 +"pt-BR": &pt-BR
  2 +
  3 + delivery_plugin:
  4 + lib:
  5 + plugin:
  6 + name: "Entrega"
  7 + description: "Gestão de métodos e opções de entrega"
  8 + models:
  9 + method:
  10 + pickup: 'Retirada'
  11 + deliver: 'Entrega'
  12 + delivery_type: "Tipo"
  13 + delivery_type_help: "Retirada: os produtos serão buscados pela(o) consumidor(a), por exemplo, no empreendimento, numa feira ou num Núcleo de Consumo.<br>Entrega: os produtos serão entregues no endereço solicitado pelo(a) consumidor(a)."
  14 + name: Nome
  15 + name_help: "Para opção Retirada: escreva o nome do local onde os produtos deverão ser retirados pela(o) consumidor(a), por exemplo o nome do Núcleo de Consumo, da feira ou do próprio empreendimento.<br>Para a opção Entrega: escreva o nome do local, (uma cidade ou região) ou a forma de entrega (Correios, transportadora)"
  16 + fixed_cost: Custo
  17 + free_over_price: "Preço mínimo do pedido para Entrega Grátis"
  18 + instructions: Descrição
  19 + instructions_help: "Escreva informações importantes sobre esta opção de Retirada ou Entrega.<br>Por exemplo, o endereço completo do Núcleo de Consumo, a abrangência da região de entrega.<br> Este texto estará disponível no \"Finalizar pedido\" e, ao confirmar a compra, o(a) consumidor(a) receberá um email com o pedido realizado e as informações deste campo."
  20 + views:
  21 + delivery_option:
  22 + select:
  23 + add: "Adicionar selecionados"
  24 + _select_content:
  25 + add: Adicionar opção
  26 + add_new: "adicionar novo"
  27 + are_you_sure_you_want: "Tem certeza de que quer remover?"
  28 + cancel: Cancelar
  29 + choose_a_delivery_met: "Escolha um método de entrega da lista"
  30 + edit_this: Editar
  31 + remove_method: "Remover"
  32 + _show:
  33 + x: X
  34 + select:
  35 + add_a_delivery_method: "Adicionar um método de entrega ao ciclo de pedidos"
  36 + method:
  37 + index:
  38 + new: "Nova forma de entrega ou retirada"
  39 + edit:
  40 + add: Adicionar
  41 + back: voltar
  42 + save: Salvar
  43 +
  44 +'pt_BR':
  45 + <<: *pt-BR
  46 +'pt':
  47 + <<: *pt-BR
  48 +
plugins/delivery/models/delivery_plugin/method.rb 0 → 100644
@@ -0,0 +1,53 @@ @@ -0,0 +1,53 @@
  1 +class DeliveryPlugin::Method < ActiveRecord::Base
  2 +
  3 + extend CurrencyHelper::ClassMethods
  4 +
  5 + Types = ['pickup', 'deliver']
  6 +
  7 + # see also: Profile::LOCATION_FIELDS
  8 + AddressFields = %w[
  9 + address address_line2 address_reference district city state country_name zip_code
  10 + ].map(&:to_sym)
  11 +
  12 + attr_accessible :profile, :delivery_type, :name, :description,
  13 + :fixed_cost, :free_over_price
  14 +
  15 + belongs_to :profile
  16 +
  17 + has_many :delivery_options, class_name: 'DeliveryPlugin::Option', foreign_key: :delivery_method_id, dependent: :destroy
  18 +
  19 + validates_presence_of :profile
  20 + validates_presence_of :name
  21 + validates_inclusion_of :delivery_type, in: Types
  22 +
  23 + scope :pickup, conditions: {delivery_type: 'pickup'}
  24 + scope :delivery, conditions: {delivery_type: 'deliver'}
  25 +
  26 + def pickup?
  27 + self.delivery_type == 'pickup'
  28 + end
  29 + def deliver?
  30 + self.delivery_type == 'deliver'
  31 + end
  32 +
  33 + def has_cost? order_price=nil
  34 + if order_price.present? and order_price.nonzero? and self.free_over_price.present? and self.free_over_price.nonzero?
  35 + order_price <= self.free_over_price
  36 + else
  37 + self.fixed_cost.present? and self.fixed_cost.nonzero?
  38 + end
  39 + end
  40 + def free? order_price=nil
  41 + !self.has_cost?
  42 + end
  43 +
  44 + def cost order_price=nil
  45 + if self.has_cost?(order_price) then self.fixed_cost.to_f else 0 end
  46 + end
  47 + has_currency :fixed_cost
  48 + has_currency :free_over_price
  49 + has_currency :cost
  50 +
  51 + protected
  52 +
  53 +end
plugins/delivery/models/delivery_plugin/option.rb 0 → 100644
@@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
  1 +class DeliveryPlugin::Option < ActiveRecord::Base
  2 +
  3 + belongs_to :delivery_method, :class_name => 'DeliveryPlugin::Method'
  4 + belongs_to :owner, :polymorphic => true
  5 +
  6 + validates_presence_of :delivery_method
  7 + validates_presence_of :owner
  8 +
  9 + attr_accessible :owner_id, :owner_type, :delivery_methods, :delivery_method
  10 +
  11 +end
plugins/delivery/public/javascripts/delivery.js 0 → 100644
@@ -0,0 +1,103 @@ @@ -0,0 +1,103 @@
  1 +
  2 +delivery = {
  3 +
  4 + order: {
  5 + select: {
  6 +
  7 + onChange: function(input) {
  8 + var input = jQuery(input)
  9 + var deliverySelect = input.parents('.order-delivery-select')
  10 +
  11 + var option = input.find('option:selected')
  12 + var typeData = option.attr('data-type')
  13 + var isPickup = typeData == 'pickup'
  14 + var instructionsData = option.attr('data-instructions')
  15 + var labelData = option.attr('data-label')
  16 +
  17 + var instructions = deliverySelect.find('.instructions')
  18 + instructions.html(instructionsData)
  19 + var consumerData = deliverySelect.find('.consumer-delivery-data')
  20 + if (isPickup) {
  21 + consumerData.slideUp('fast')
  22 + } else {
  23 + consumerData.slideDown('fast')
  24 + }
  25 + },
  26 +
  27 + },
  28 + },
  29 +
  30 + option: {
  31 + },
  32 +
  33 + method: {
  34 +
  35 + view: {
  36 + edition: function() {
  37 + return jQuery('#delivery-method-edition')
  38 + },
  39 + listing: function() {
  40 + return jQuery('#delivery-method-list')
  41 + },
  42 + toggle: function () {
  43 + jQuery('#delivery-method-list, #delivery-method-edition').fadeToggle();
  44 + },
  45 + },
  46 +
  47 + changeType: function(select) {
  48 + select = jQuery(select)
  49 + },
  50 +
  51 + new: function(newUrl) {
  52 + this.edit(newUrl)
  53 + },
  54 +
  55 + edit: function(editUrl) {
  56 + var listing = this.view.listing()
  57 + var edition = this.view.edition()
  58 +
  59 + loading_overlay.show(listing)
  60 + jQuery.get(editUrl, function(data) {
  61 + edition.html(data)
  62 + delivery.method.view.toggle();
  63 + loading_overlay.hide(listing)
  64 + });
  65 + },
  66 +
  67 + save: function(form) {
  68 + var listing = this.view.listing()
  69 + var edition = this.view.edition()
  70 +
  71 + jQuery(form).ajaxSubmit({
  72 + beforeSubmit: function() {
  73 + loading_overlay.show(edition)
  74 + }, success: function(data) {
  75 + listing.html(data);
  76 + delivery.method.view.toggle();
  77 + loading_overlay.hide(edition)
  78 + },
  79 + })
  80 + return false;
  81 + },
  82 +
  83 + destroy: function(id, confirmText, destroy_url) {
  84 + if (!confirm(confirmText))
  85 + return
  86 + var method = jQuery('#delivery-method-'+id)
  87 + jQuery.post(destroy_url, function() {
  88 + method.fadeOut(function() {
  89 + method.remove()
  90 + })
  91 + })
  92 + },
  93 +
  94 + },
  95 +
  96 + option: {
  97 +
  98 + add: function(newUrl) {
  99 + $.getScript(newUrl)
  100 + },
  101 + },
  102 +
  103 +};
plugins/delivery/public/style.scss 0 → 100644
@@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
  1 +@import 'stylesheets/delivery'
  2 +
plugins/delivery/public/stylesheets/_base.scss 0 → 120000
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +../../../suppliers/public/stylesheets/_base.scss
0 \ No newline at end of file 2 \ No newline at end of file
plugins/delivery/public/stylesheets/_field.scss 0 → 120000
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +../../../suppliers/public/stylesheets/_field.scss
0 \ No newline at end of file 2 \ No newline at end of file
plugins/delivery/public/stylesheets/delivery.scss 0 → 100644
@@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
  1 +@import 'base';
  2 +
  3 +#delivery-method-edition {
  4 + @extend .container-clean;
  5 +
  6 + .field-help {
  7 + font-size: 10px;
  8 + }
  9 +}
  10 +#delivery-method-list {
  11 +}
  12 +
  13 +#delivery-add {
  14 + // to resize popin
  15 + overflow: hidden;
  16 +}
  17 +
  18 +.delivery-method {
  19 + .select {
  20 + width: 20px;
  21 + }
  22 +
  23 +}
  24 +
  25 +.order-delivery-select {
  26 +
  27 +}
  28 +
  29 +#delivery-method-choose {
  30 + height: 235px;
  31 +
  32 + #delivery-menu a {
  33 + text-transform: capitalize;
  34 + }
  35 +}
  36 +
  37 +.cycle-delete-delivery-option {
  38 + font-weight: bold;
  39 +}
  40 +
plugins/delivery/test/test_helper.rb 0 → 100644
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +require File.dirname(__FILE__) + '/../../../test/test_helper'
plugins/delivery/test/unit/delivery_plugin/method_test.rb 0 → 100644
@@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
  1 +require "#{File.dirname(__FILE__)}/../../test_helper"
  2 +
  3 +class DeliveryPlugin::MethodTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @profile = build(Profile)
  7 + end
  8 +
  9 + attr_accessor :profile
  10 +
  11 + should 'have a name and a delivery type' do
  12 + dm = DeliveryPlugin::Method.new :name => 'Delivery Deluxe', :delivery_type => 'deliver', :profile => profile
  13 + assert dm.valid?
  14 + dm = DeliveryPlugin::Method.new :profile => profile
  15 + assert !dm.valid?
  16 + end
  17 +
  18 + should 'accept only pickup and deliver as delivery types' do
  19 + dm = build(DeliveryPlugin::Method, :name => 'Delivery Deluxe', :delivery_type => 'unkown', :profile => profile)
  20 + assert !dm.valid?
  21 + dm = build(DeliveryPlugin::Method, :name => 'Delivery Deluxe', :delivery_type => 'pickup', :profile => profile)
  22 + assert dm.valid?
  23 + dm = build(DeliveryPlugin::Method, :name => 'Delivery Deluxe', :delivery_type => 'deliver', :profile => profile)
  24 + assert dm.valid?
  25 + end
  26 +
  27 + should 'filter by delivery types' do
  28 + dm_deliver = create(DeliveryPlugin::Method, :name => 'Delivery Deluxe', :delivery_type => 'deliver', :profile => profile)
  29 + dm_pickup = create(DeliveryPlugin::Method, :name => 'Delivery Deluxe', :delivery_type => 'pickup', :profile => profile)
  30 + assert_equal [dm_deliver], DeliveryPlugin::Method.delivery
  31 + assert_equal [dm_pickup], DeliveryPlugin::Method.pickup
  32 + end
  33 +
  34 + should 'have many delivery options' do
  35 + dm = create(DeliveryPlugin::Method, :name => 'Delivery Deluxe', :delivery_type => 'deliver', :profile => profile)
  36 + cycle = build(OrdersCyclePlugin::Cycle, :name => 'cycle name', :profile => profile)
  37 + option = create(DeliveryPlugin::Option, :cycle => cycle, :delivery_method => dm)
  38 +
  39 + assert_equal [option], dm.reload.delivery_options
  40 + end
  41 +
  42 +end
plugins/delivery/test/unit/delivery_plugin/option_test.rb 0 → 100644
@@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
  1 +require "#{File.dirname(__FILE__)}/../../test_helper"
  2 +
  3 +class DeliveryPlugin::OptionTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @profile = build(Profile)
  7 + @cycle = build(OrdersCyclePluginCycle, :profile => @profile)
  8 + @delivery_method = build(OrdersCyclePluginMethod, :profile => @profile)
  9 + end
  10 +
  11 + attr_accessor :profile
  12 + attr_accessor :cycle
  13 + attr_accessor :delivery_method
  14 +
  15 + should 'be associated with a cycle and a delivery method' do
  16 + option = OrdersCyclePluginOption.new :cycle => @cycle, :delivery_method => @delivery_method
  17 + assert option.valid?
  18 + option = OrdersCyclePluginOption.new
  19 + :wa
  20 +
  21 + assert !option.valid?
  22 + end
  23 +
  24 +end
plugins/delivery/views/delivery_plugin/_order_select.html.slim 0 → 100644
@@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
  1 +- methods ||= order.delivery_methods
  2 +- edition = true if edition.nil?
  3 +- readonly = !edition
  4 +
  5 +div.order-delivery-select
  6 +
  7 + div.supplier-delivery-data
  8 + = labelled_form_field _('Option'),
  9 + f.select(:supplier_delivery_id, supplier_delivery_options(methods: methods), {}, disabled: readonly,
  10 + onchange: 'delivery.order.select.onChange(this)', onkeyup: 'delivery.order.select.onChange(this)')
  11 + p.instructions
  12 +
  13 + div.consumer-delivery-data
  14 + = f.fields_for :consumer_delivery_data, order.consumer_delivery_data do |ff|
  15 + = labelled_form_field _('Address (street and number)'),
  16 + ff.text_field(:address, value: order.consumer_delivery_data[:address], readonly: readonly)
  17 + = labelled_form_field _('Address completion'),
  18 + ff.text_field(:address_line2, value: order.consumer_delivery_data[:address_line2], readonly: readonly)
  19 + = labelled_form_field _('Address reference'),
  20 + ff.text_field(:address_reference, value: order.consumer_delivery_data[:address_reference], readonly: readonly)
  21 + = labelled_form_field _('District'),
  22 + ff.text_field(:district, value: order.consumer_delivery_data[:district], readonly: readonly)
  23 + = labelled_form_field _('City'),
  24 + ff.text_field(:city, value: order.consumer_delivery_data[:city], readonly: readonly)
  25 + = labelled_form_field _('State'),
  26 + ff.text_field(:state, value: order.consumer_delivery_data[:state], readonly: readonly)
  27 + = labelled_form_field _('ZIP code'),
  28 + ff.text_field(:zip_code, value: order.consumer_delivery_data[:zip_code], readonly: readonly)
  29 +
  30 + javascript:
  31 + delivery.order.select.onChange($('#order_supplier_delivery_id'))
plugins/delivery/views/delivery_plugin/admin_method/_edit.html.slim 0 → 100644
@@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
  1 += form_for delivery_method, as: :delivery_method,
  2 + url: request.GET.merge(controller: delivery_context, action: delivery_method.new_record? ? :new : :edit, id: delivery_method.id),
  3 + html: {onsubmit: 'return delivery.method.save(this)'} do |f|
  4 +
  5 + = error_messages_for :delivery_method
  6 +
  7 + = labelled_field f, :delivery_type, t('delivery_plugin.models.method.delivery_type'),
  8 + f.select(:delivery_type, DeliveryPlugin::Method::Types.map{ |t| [t("delivery_plugin.models.method.#{t}"), t] },
  9 + onchange: 'delivery.method.changeType(this)', onkeyup: 'this.onchange()'),
  10 + help: t('delivery_plugin.models.method.delivery_type_help')
  11 +
  12 + = labelled_field f, :name, t('delivery_plugin.models.method.name'), f.text_field(:name),
  13 + help: t('delivery_plugin.models.method.name_help')
  14 + = labelled_field f, :description, t('delivery_plugin.models.method.instructions'),
  15 + f.text_area(:description, rows: 5), help: t('delivery_plugin.models.method.instructions_help')
  16 +
  17 + = labelled_field f, :fixed_cost, t('delivery_plugin.models.method.fixed_cost'),
  18 + input_group_addon(environment.currency_unit){ f.text_field :fixed_cost, type: :number, step: '0.01', value: number_with_precision(delivery_method.fixed_cost, precision: 2, locale: :en)}
  19 +
  20 + = labelled_field f, :free_over_price, t('delivery_plugin.models.method.free_over_price'),
  21 + input_group_addon(environment.currency_unit){ f.text_field :free_over_price, type: :number, step: '0.01', value: number_with_precision(delivery_method.free_over_price, precision: 2, locale: :en)}
  22 +
  23 + div
  24 + = submit_button :save, if delivery_method.new_record? then t('delivery_plugin.views.method.edit.add') else t('delivery_plugin.views.method.edit.save') end
  25 + = link_to_function t('delivery_plugin.views.method.edit.back'), "delivery.method.view.toggle()"
  26 +
plugins/delivery/views/delivery_plugin/admin_method/_index.html.slim 0 → 100644
@@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
  1 +table#delivery-method-list
  2 + = render 'delivery_plugin/admin_method/list'
  3 +
  4 +#delivery-method-edition style=("display: none")
plugins/delivery/views/delivery_plugin/admin_method/_list.html.slim 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +tr
  2 + td colspan=3
  3 + = button_to_function :add, t('delivery_plugin.views.method.index.new'),
  4 + "delivery.method.new('#{url_for request.GET.merge(controller: 'delivery_plugin/admin_method', action: :new)}')"
  5 +
  6 +- profile.delivery_methods.each do |m|
  7 + tr.delivery-method id="delivery-method-#{m.id}"
  8 + = render "delivery_plugin/admin_method/show", method: m
  9 +
plugins/delivery/views/delivery_plugin/admin_method/_show.html.slim 0 → 100644
@@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
  1 +td.name title="#{method.description}"
  2 + = method.name
  3 +td.actions
  4 + - if request.GET[:select_ids].present? and not method.id.to_s.in? Array(request.GET[:selected_ids])
  5 + = button_to_function :add, t('delivery_plugin.views.delivery_option._select_content.add'),
  6 + "delivery.option.add('#{url_for request.GET.merge(controller: 'delivery_plugin/admin_options', action: :new, method_id: method.id)}')"
  7 +
  8 + = button_to_function :edit, t('delivery_plugin.views.delivery_option._select_content.edit_this'),
  9 + "delivery.method.edit('#{url_for request.GET.merge(controller: delivery_context, action: :edit, id: method.id)}')"
  10 + = button_to_function :remove, t('delivery_plugin.views.delivery_option._select_content.remove_method'),
  11 + "delivery.method.destroy(#{method.id}, '#{t('delivery_plugin.views.delivery_option._select_content.are_you_sure_you_want')}',
  12 + '#{url_for request.GET.merge(controller: delivery_context, action: :destroy, id: method.id)}')"
plugins/delivery/views/delivery_plugin/admin_method/edit.html.slim 0 → 120000
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +_edit.html.slim
0 \ No newline at end of file 2 \ No newline at end of file
plugins/delivery/views/delivery_plugin/admin_method/new.js.erb 0 → 100644
@@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
  1 +$('#delivery-method-edition').replaceWith('<%=j render 'index' %>')
  2 +
plugins/delivery/views/delivery_plugin/admin_options/_index.html.slim 0 → 100644
@@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
  1 +- owner.delivery_options.each do |o|
  2 + = render 'delivery_plugin/admin_options/show', owner: owner, option: o
  3 +
plugins/delivery/views/delivery_plugin/admin_options/_new.js.erb 0 → 100644
@@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
  1 +// FIXME: move to orders_cycle plugin
  2 +jQuery('#cycle-delivery-options').html('<%= j render('index', owner: @owner) %>');
  3 +noosfero.modal.close()
  4 +
plugins/delivery/views/delivery_plugin/admin_options/_show.html.slim 0 → 100644
@@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
  1 +.cycle-delivery-option id="cycle-delivery-option-#{option.id}"
  2 + span= option.delivery_method.name
  3 + = link_to_remote t('delivery_plugin.views.delivery_option._show.x'),
  4 + { url: {controller: 'delivery_plugin/admin_options', action: :destroy, id: option.id, owner_id: owner.id, owner_type: owner.class.name} },
  5 + class: 'cycle-delete-delivery-option'
plugins/delivery/views/delivery_plugin/admin_options/destroy.rjs 0 → 100644
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +page.remove "cycle-delivery-option-#{@delivery_option.id}"
plugins/delivery/views/delivery_plugin/admin_options/new.js.erb 0 → 120000
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +_new.js.erb
0 \ No newline at end of file 2 \ No newline at end of file
plugins/delivery/views/delivery_plugin/admin_options/select.html.slim 0 → 100644
@@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
  1 +#delivery-add.popin
  2 + h1= t('delivery_plugin.views.delivery_option.select.add_a_delivery_method')
  3 +
  4 + / flag to admin_method/show that we want to select an option from methods
  5 + - request.GET[:select_ids] = 'true'
  6 + - request.GET[:selected_ids] = @owner.delivery_methods.map(&:id).map(&:to_s)
  7 + = render 'delivery_plugin/admin_method/index'
  8 +