Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 8fe07618

Von Werner Hahn vor mehr als 6 Jahren hinzugefügt

  • ID 8fe0761874361bd21e6f4d190d61eb45bd285b2a
  • Vorgänger 2ef0a962
  • Nachfolger c24f46f5

Shopmodul: ShopPart

Conflicts:
SL/Controller/ShopPart.pm
SL/DB/Manager/ShopPart.pm
SL/DB/ShopPart.pm
js/kivi.shop_part.js
sql/Pg-upgrade2/shop_parts.sql
templates/webpages/shop_part/edit.html

Unterschiede anzeigen:

SL/Controller/ShopPart.pm
1
package SL::Controller::ShopPart;
2
#package SL::Controller::ShopPart;
3

  
4
use strict;
5

  
6
use parent qw(SL::Controller::Base);
7

  
8
use Data::Dumper;
9
use SL::Locale::String qw(t8);
10
use SL::DB::ShopPart;
11
use SL::Helper::Flash;
12

  
13
use Rose::Object::MakeMethods::Generic
14
(
15
  'scalar --get_set_init' => [ qw(shop_part js) ],
16
);
17

  
18
__PACKAGE__->run_before('check_auth');
19
__PACKAGE__->run_before('add_javascripts', only => [ qw(edit_popup) ]);
20
#
21
# actions
22
#
23

  
24
sub action_create_or_edit_popup {
25
  my ($self) = @_;
26

  
27
  $self->render_shop_part_edit_dialog();
28
};
29

  
30
sub action_update_shop {
31
  my ($self, %params) = @_;
32

  
33
  my $shop_part = SL::DB::Manager::ShopPart->find_by(id => $::form->{shop_part_id});
34
  die unless $shop_part;
35
  require SL::Shop;
36
  my $shop = SL::Shop->new( config => $shop_part->shop );
37

  
38
  # TODO: generate data to upload to shop
39
  my $part_hash = $shop_part->part->as_tree;
40
  my $json      = SL::JSON::to_json($part_hash);
41
  my $return    = $shop->connector->update_part($self->shop_part, $json);
42

  
43
  # the connector deals with parsing/result verification, just needs to return success or failure
44
  if ( $return == 1 ) {
45
    # TODO: write update time to DB
46
    my $now = DateTime->now;
47
    $self->js->html('#shop_part_last_update_' . $shop_part->id, $now->to_kivitendo('precision' => 'minute'))
48
           ->flash('info', t8("Updated part [#1] in shop [#2] at #3", $shop_part->part->displayable_name, $shop_part->shop->description, $now->to_kivitendo('precision' => 'minute') ) )
49
           ->render;
50
  } else {
51
    $self->js->flash('error', t8('The shop part wasn\'t updated.'))->render;
52
  };
53

  
54
};
55

  
56

  
57

  
58
# old:
59
# sub action_edit {
60
#   my ($self) = @_;
61
#
62
#   $self->render('shop_part/edit'); #, { output => 0 }); #, price_source => $price_source)
63
# }
64
#
65
# used when saving existing ShopPart
66

  
67
sub action_update {
68
  my ($self) = @_;
69

  
70
  $self->create_or_update;
71
}
72

  
73
sub create_or_update {
74
  my ($self) = @_;
75

  
76
  my $is_new = !$self->shop_part->id;
77

  
78
  # in edit.html all variables start with shop_part
79
  my $params = delete($::form->{shop_part}) || { };
80

  
81
  $self->shop_part->assign_attributes(%{ $params });
82

  
83
  $self->shop_part->save;
84

  
85
  flash('info', $is_new ? t8('The shop part has been created.') : t8('The shop part has been saved.'));
86
  # $self->js->val('#partnumber', 'ladida');
87
  $self->js->html('#shop_part_description_' . $self->shop_part->id, $self->shop_part->shop_description)
88
           ->html('#shop_part_active_' . $self->shop_part->id, $self->shop_part->active)
89
           ->run('kivi.shop_part.close_dialog')
90
           ->flash('info', t8("Updated shop part"))
91
           ->render;
92
}
93

  
94
sub render_shop_part_edit_dialog {
95
  my ($self) = @_;
96

  
97
  # when self->shop_part is called in template, it will be an existing shop_part with id,
98
  # or a new shop_part with only part_id and shop_id set
99
  $self->js
100
    ->run(
101
      'kivi.shop_part.shop_part_dialog',
102
      t8('Shop part'),
103
      $self->render('shop_part/edit', { output => 0 }) #, shop_part => $self->shop_part)
104
    )
105
    ->reinit_widgets;
106

  
107
  $self->js->render;
108
}
109

  
110
sub action_save_categories {
111
  my ($self) = @_;
112

  
113
#
114
# internal stuff
115
#
116
sub add_javascripts  {
117
  # is this needed?
118
  $::request->{layout}->add_javascripts(qw(kivi.shop_part.js));
119
}
120

  
121
sub check_auth {
122
  return 1; # TODO: implement shop rights
123
  # $::auth->assert('shop');
124
}
125

  
126
sub init_shop_part {
127
  if ($::form->{shop_part_id}) {
128
    SL::DB::Manager::ShopPart->find_by(id => $::form->{shop_part_id});
129
  } else {
130
    SL::DB::ShopPart->new(shop_id => $::form->{shop_id}, part_id => $::form->{part_id});
131
  };
132
}
133

  
134
1;
135

  
136
=pod
137

  
138
=encoding utf-8
139

  
140
=head1 NAME
141

  
142
SL::Controller::ShopPart - Controller for managing ShopParts
143

  
144
=head1 SYNOPSIS
145

  
146
ShopParts are configured in a tab of the corresponding part.
147

  
148
=head1 FUNCTIONS
149

  
150
=over 4
151

  
152
=item C<action_update_shop>
153

  
154
To be called from the "Update" button, for manually syncing a part with its
155
shop. Generates a  Calls some ClientJS functions to modifiy original page.
156

  
157
=back
158

  
159
=head1 AUTHORS
160

  
161
G. Richardson E<lt>information@kivitendo-premium.deE<gt>
162

  
163
=cut
164
1;
SL/DB/Manager/ShopPart.pm
1
# This file has been auto-generated only because it didn't exist.
2
# Feel free to modify it at will; it will not be overwritten automatically.
3

  
4
package SL::DB::Manager::ShopPart;
5
#package SL::DB::Manager::ShopPart;
6

  
7
use strict;
8

  
9
use SL::DB::Helper::Manager;
10
use base qw(SL::DB::Helper::Manager);
11

  
12
sub object_class { 'SL::DB::ShopPart' }
13

  
14
__PACKAGE__->make_manager_methods;
15

  
16
1;
SL/DB/MetaSetup/ShopPart.pm
1 1
# This file has been auto-generated. Do not modify it; it will be overwritten
2 2
# by rose_auto_create_model.pl automatically.
3 3
package SL::DB::ShopPart;
4
#package SL::DB::ShopPart;
4 5

  
5 6
use strict;
6 7

  
SL/DB/Part.pm
1 1
package SL::DB::Part;
2
#package SL::DB::Part;
2 3

  
3 4
use strict;
4 5

  
SL/DB/ShopPart.pm
1
# This file has been auto-generated only because it didn't exist.
2
# Feel free to modify it at will; it will not be overwritten automatically.
3

  
4
package SL::DB::ShopPart;
5
#package SL::DB::ShopPart;
6

  
7
use strict;
8

  
9
use SL::DB::MetaSetup::ShopPart;
10
use SL::DB::Manager::ShopPart;
11

  
12
__PACKAGE__->meta->initialize;
13

  
14
1;
bin/mozilla/ic.pl
1
#TMP
1 2
#=====================================================================
2 3
# LX-Office ERP
3 4
# Copyright (C) 2004
js/kivi.shop_part.js
1
//TMP
2
namespace('kivi.shop_part', function(ns) {
3
  var $dialog;
4

  
5
  // this is called by sub render, with a certain prerendered html (edit.html)
6
  ns.shop_part_dialog = function(title, html) {
7
    var id            = 'jqueryui_popup_dialog';
8
    var dialog_params = {
9
      id:     id,
10
      width:  800,
11
      height: 500,
12
      modal:  true,
13
      close: function(event, ui) { $dialog.remove(); },
14
    };
15

  
16
    $('#' + id).remove();
17

  
18
    $dialog = $('<div style="display:none" id="' + id + '"></div>').appendTo('body');
19
    $dialog.attr('title', title);
20
    $dialog.html(html);
21
    $dialog.dialog(dialog_params);
22

  
23
    $('.cancel').click(ns.close_dialog);
24

  
25
    return true;
26
  };
27

  
28
  ns.close_dialog = function() {
29
    $dialog.dialog("close");
30
  }
31

  
32

  
33
    // save existing shop_part_id with new params from form, calls create_or_update and saves to db
34
    ns.save_shop_part = function(shop_part_id) {
35
      var form = $('form').serializeArray();
36
      form.push( { name: 'action', value: 'ShopPart/update' }
37
               , { name: 'shop_part_id',  value: shop_part_id }
38
      );
39

  
40
      $.post('controller.pl', form, function(data) {
41
        kivi.eval_json_result(data);
42
      });
43
    }
44

  
45
    // add part to a shop
46
    ns.add_shop_part = function(part_id,shop_id) {
47
      var form = $('form').serializeArray();
48
      form.push( { name: 'action', value: 'ShopPart/update' }
49
      );
50

  
51
      $.post('controller.pl', form, function(data) {
52
        kivi.eval_json_result(data);
53
      });
54
    }
55

  
56
  // this is called from tabs/_shop.html, opens edit_window (render)
57
  ns.edit_shop_part = function(shop_part_id) {
58
    $.post('controller.pl', { action: 'ShopPart/create_or_edit_popup', shop_part_id: shop_part_id }, function(data) {
59
      kivi.eval_json_result(data);
60
    });
61
  }
62

  
63
  // does the same as edit_shop_part (existing), but with part_id and shop_id, opens edit window (render)
64
  ns.create_shop_part = function(part_id, shop_id) {
65
    $.post('controller.pl', { action: 'ShopPart/create_or_edit_popup', part_id: part_id, shop_id: shop_id }, function(data) {
66
      kivi.eval_json_result(data);
67
    });
68
  }
69

  
70
  // gets all categories from the webshop
71
  ns.get_all_categories = function(shop_part_id) {
72
    var form = $('form').serializeArray();
73
    form.push( { name: 'action', value: 'ShopPart/get_categories' }
74
             , { name: 'shop_part_id', value: shop_part_id }
75
    );
76

  
77
    $.post('controller.pl', form, function(data) {
78
      kivi.eval_json_result(data);
79
    });
80
  }
81
  // write categories in kivi DB not in the shops DB TODO: create new categories in the shops db
82
  ns.save_categories = function(shop_part_id, shop_id) {
83
    var form = $('form').serializeArray();
84
    form.push( { name: 'action', value: 'ShopPart/save_categories' }
85
             , { name: 'shop_id', value: shop_id }
86
             , { name: 'shop_part_id', value: shop_part_id }
87
    );
88

  
89
    $.post('controller.pl', form, function(data) {
90
      kivi.eval_json_result(data);
91
    });
92
  }
93

  
94
  ns.update_shop_part = function(shop_part_id) {
95
    $.post('controller.pl', { action: 'ShopPart/update_shop', shop_part_id: shop_part_id }, function(data) {
96
      kivi.eval_json_result(data);
97
    });
98
  }
99

  
100
  ns.update_discount_source = function(row, source, discount_str) {
101
    $('#active_discount_source_' + row).val(source);
102
    if (discount_str) $('#discount_' + row).val(discount_str);
103
    $('#update_button').click();
104
  }
105
});
sql/Pg-upgrade2/shop_parts.sql
1
-- TMP
2
-- @tag: shop_parts
3
-- @description: Add tables for part information for shop
4
-- @charset: UTF-8
5
-- @depends: release_3_3_0 shops
6
-- @ignore: 0
7

  
8
CREATE TABLE shop_parts (
9
  id               SERIAL PRIMARY KEY,
10
  shop_id          INTEGER NOT NULL REFERENCES shops(id),
11
  part_id          INTEGER NOT NULL REFERENCES parts(id),
12
  shop_description TEXT,
13
  itime            TIMESTAMP DEFAULT now(),
14
  mtime            TIMESTAMP,
15
  last_update      TIMESTAMP,
16
  show_date        DATE,   -- the starting date for displaying part in shop
17
  sortorder        INTEGER,
18
  front_page       BOOLEAN NOT NULL DEFAULT false,
19
  active           BOOLEAN NOT NULL DEFAULT false,  -- rather than obsolete
20
  shop_category    TEXT,
21
  meta_tags        TEXT,
22
  UNIQUE (part_id, shop_id)  -- make sure a shop_part appears only once per shop and part
23
);
24

  
25
CREATE TRIGGER mtime_shop_parts BEFORE UPDATE ON shop_parts
26
    FOR EACH ROW EXECUTE PROCEDURE set_mtime();
27

  
28
-- CREATE TABLE shop_meta_tags (
29
-- id integer NOT NULL DEFAULT nextval('shop_parts_id'),
30
 --  description
31
-- );
32

  
33
-- CREATE TABLE shop_categories (
34
-- );
templates/webpages/ic/tabs/_shop.html
1
<!-- TMP -->
1 2
[%- USE HTML %][%- USE L -%][%- USE P -%][%- USE LxERP -%]
2 3
<<<<<<< HEAD
3 4
[%- USE Dumper %]
templates/webpages/shop_part/edit.html
1
<!-- TMP -->
2
[%- USE HTML %][%- USE L -%][%- USE P -%][%- USE LxERP -%]
3

  
4
[% LxERP.t8("Part") %]: [% HTML.escape(SELF.shop_part.part.displayable_name) %]<br>
5
[% LxERP.t8("Shop") %]: [% HTML.escape(SELF.shop_part.shop.description) %]
6

  
7
<form action="controller.pl" method="post">
8

  
9
[% IF SELF.shop_part.id %]
10
[%- L.hidden_tag("shop_part.id", SELF.shop_part.id) %]
11
[% ELSE %]
12
[%- L.hidden_tag("shop_part.shop_id", FORM.shop_id) %]
13
[%- L.hidden_tag("shop_part.part_id", FORM.part_id) %]
14
[% END %]
15

  
16
 <table>
17
  <tr>
18
   <td>[% LxERP.t8("Description") %]</td>
19
   <td>[% L.textarea_tag("shop_part.shop_description", SELF.shop_part.shop_description) %]</td>
20
  </tr>
21
  <tr>
22
   <td>[% LxERP.t8("Active") %]</td>
23
   <td>[% L.yes_no_tag("shop_part.active", SELF.shop_part.active) %]</td>
24
  </tr>
25
  <tr>
26
   <td>[% LxERP.t8("Sort order") %]</td>
27
   <td>[% L.input_tag("shop_part.sortorder", SELF.shop_part.sortorder, size=2) %]</td>
28
  </tr>
29
  <tr>
30
   <td>[% LxERP.t8("Date") %]</td>
31
   <td>[% L.date_tag("shop_part.show_date", SELF.shop_part.show_date) %]</td>
32
  </tr>
33
  <tr>
34
   <td>[% LxERP.t8("Front page") %]</td>
35
   <td>[% L.yes_no_tag('shop_part.front_page', SELF.shop_part.front_page) %]</td>
36
  </tr>
37
  <tr>
38
   <td>[% LxERP.t8("Meta Tags") %]</td>
39
   <td>[% L.input_tag("shop_part.meta_tags", SELF.shop_part.meta_tags, size=2) %]</td>
40
  </tr>
41
  <tr>
42
   <td>[% LxERP.t8("Shop Category") %]</td>
43
   <td>[% L.input_tag("shop_part.shop_category", SELF.shop_part.category, size=2) %]</td>
44
  </tr>
45
</table>
46
[% # L.dump(SELF.shop_part) %]
47

  
48
[% IF SELF.shop_part.id %]
49
[% L.button_tag("kivi.shop_part.save_shop_part(" _ SELF.shop_part.id _ ")", LxERP.t8("Save"))  %]</td>
50
[% ELSE %]
51
[% L.button_tag("kivi.shop_part.add_shop_part(" _ FORM.part_id _", " _ FORM.shop_id _")", LxERP.t8("Save"))  %]</td>
52
[% END %]
53
[% # L.button_tag("kivi.shop_part.update_partnumber()", LxERP.t8("Update Partnumber"))  %]</td>
54

  
55
[% # L.hidden_tag("action", "ShopPart/dispatch") %]
56
[% # L.submit_tag('action_update', LxERP.t8('Save')) %]
57

  
58
</div>
59
</form>
60
[%- IF SELF.shop_part.part.image && INSTANCE_CONF.get_parts_show_image %]
61
         <a href="[% SELF.shop_part.part.image | html %]" target="_blank"><img style="[% INSTANCE_CONF.get_parts_image_css %]" src="[% SELF.shop_part.part.image | html %]"/></a>
62
[%- END %]
63

  
64
[% # SELF.shop_part.shop_description %]
65
[% # L.dump(SELF.shop_part) %]

Auch abrufbar als: Unified diff