Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 1342327c

Von Werner Hahn vor mehr als 8 Jahren hinzugefügt

  • ID 1342327ced23ff6451049e803d885834389b4405
  • Vorgänger 3df63bfe
  • Nachfolger 757b637e

FileUploader: SL/Controller/FileUploader.pm nach SL/Helper/FileUploader.pm verschoben
Shop: typo im Connector und js
ShopPart: Benutzerdefinierte Variablen werden jetzt angeziegt im ShopPartreiter, TODO extra BDV's für Shoppart implementieren

Unterschiede anzeigen:

SL/Controller/FileUploader.pm
1
package SL::Controller::FileUploader;
2

  
3
use strict;
4
use parent qw(SL::Controller::Base);
5

  
6
use SL::DB::File;
7

  
8
use SL::Helper::Flash;
9
use SL::Locale::String;
10

  
11
use Rose::Object::MakeMethods::Generic
12
(
13
  'scalar --get_set_init' => [ qw(file) ],
14
);
15

  
16
#
17
# actions
18
#
19
sub action_test_page{
20
  my ($self) = @_;
21
  $self->render('fileuploader/test_page');
22
}
23

  
24
sub action_upload_form{
25
  my ($self) = @_;
26
  $self->file(SL::DB::File->new);
27
  $self->render('common/file_upload', {header => 0});
28
}
29

  
30
sub action_show_files {
31
  my ($self) = @_;
32
  my $images = SL::DB::Manager::File->get_all( query => [ trans_id => $::form->{id}, modul => $::form->{modul} ] );
33

  
34

  
35
}
36

  
37
sub action_ajax_add_file{
38
  my ($self) = @_;
39
  $self->file(SL::DB::File->new);
40
  $self->render('common/file_upload', { layout => 0}, DATA => $::form);
41
}
42

  
43
sub action_ajax_upload_file{
44
  my ($self, %params) = @_;
45
  my $attributes                  = $::form->{ $::form->{form_prefix} } || die "Missing FormPrefix";
46
  $attributes->{trans_id}         = $::form->{id} || die "Missing ID";
47
  $attributes->{modul}            = $::form->{modul} || die "Missing Modul";
48
  $attributes->{filename}         = $::form->{FILENAME} || die "Missing Filename";
49
  $attributes->{title}            = $::form->{ $::form->{form_prefix} }->{title};
50
  $attributes->{description}      = $::form->{ $::form->{form_prefix} }->{description};
51
  my @image_types = ("jpg","tif","png");
52

  
53
  my @errors = $self->file(SL::DB::File->new(%{ $attributes }))->validate;
54
  return $self->js->error(@errors)->render($self) if @errors;
55

  
56
  $self->file->save;
57

  
58
  # TODO js call
59
  $self->render('fileuploader/test_page');
60
}
61

  
62
#
63
# helpers
64
#
65

  
66
sub init_file {
67
  return SL::DB::File->new(id => $::form->{id})->load;
68
}
69

  
70
1;
71
__END__
72

  
73
=pod
74

  
75
=encoding utf8
76

  
77
=head1 NAME
78

  
79
SL::Controller::FileUploader - Controller to manage fileuploads
80

  
81
=head1 SYNOPSIS
82

  
83
  use SL::Controller::FileUploader;
84

  
85
  # synopsis.. =>
86

  
87
=head1 DESCRIPTION
88

  
89
# longer description...
90

  
91

  
92
=head1 INTERFACE
93

  
94

  
95
=head1 DEPENDENCIES
96

  
97

  
98
=head1 SEE ALSO
99

  
100
=head1 AUTHOR
101

  
102
Werner Hahn E<lt>wh@futureworldsearch.netE<gt>
103

  
104
=cut
SL/Controller/TopQuickSearch.pm
2 2

  
3 3
use strict;
4 4
use parent qw(SL::Controller::Base);
5
our $VERSION = 1;
5 6

  
6 7
use SL::ClientJS;
7 8
use SL::JSON;
8 9
use SL::Locale::String qw(t8);
10
use SL::Helper::UserPreferences;
9 11

  
10 12
use Rose::Object::MakeMethods::Generic (
11
 'scalar --get_set_init' => [ qw(module js) ],
13
 'scalar --get_set_init' => [ qw(module js prefs) ],
12 14
);
13 15

  
14 16
my @available_modules = (
......
66 68
sub enabled_modules {
67 69
  my %enabled_names = map {
68 70
    $_ => 1
69
  } @{ $::instance_conf->get_quick_search_modules };
71
  } @{
72
    $::instance_conf->get_quick_search_modules
73
  };
70 74

  
71 75
  grep {
72 76
    $enabled_names{$_->name}
......
109 113
  }
110 114
}
111 115

  
116
sub init_prefs {
117
  SL::Helper::UserPreferences->new(
118
    namespace         => __PACKAGE__,
119
    upgrade_callbacks => {},
120
  )
121
}
122

  
112 123
1;
113 124

  
114 125
__END__
SL/Helper/FileUploader.pm
1
package SL::Controller::Helper::FileUploader;
2
# Controller will not be used if things for FILES needed they can go in Helpers
3
use strict;
4
use parent qw(SL::Controller::Base);
5

  
6
use SL::DB::File;
7

  
8
use SL::Helper::Flash;
9
use SL::Locale::String;
10

  
11
use Rose::Object::MakeMethods::Generic
12
(
13
  'scalar --get_set_init' => [ qw(file) ],
14
);
15

  
16
#
17
# actions
18
#
19
sub action_test_page{
20
  my ($self) = @_;
21
  $self->render('fileuploader/test_page');
22
}
23

  
24
sub action_upload_form{
25
  my ($self) = @_;
26
  $self->file(SL::DB::File->new);
27
  $self->render('common/file_upload', {header => 0});
28
}
29

  
30
sub action_show_files {
31
  my ($self) = @_;
32
  my $images = SL::DB::Manager::File->get_all( query => [ trans_id => $::form->{id}, modul => $::form->{modul} ] );
33

  
34

  
35
}
36
# this can go in Helpers::Fileuploader
37
sub action_ajax_add_file{
38
  my ($self) = @_;
39
  $self->file(SL::DB::File->new);
40
  $self->render('common/file_upload', { layout => 0}, DATA => $::form);
41
}
42

  
43
sub action_ajax_upload_file{
44
  my ($self, %params) = @_;
45
  my $attributes                  = $::form->{ $::form->{form_prefix} } || die "Missing FormPrefix";
46
  $attributes->{trans_id}         = $::form->{id} || die "Missing ID";
47
  $attributes->{modul}            = $::form->{modul} || die "Missing Modul";
48
  $attributes->{filename}         = $::form->{FILENAME} || die "Missing Filename";
49
  $attributes->{title}            = $::form->{ $::form->{form_prefix} }->{title};
50
  $attributes->{description}      = $::form->{ $::form->{form_prefix} }->{description};
51
  my @image_types = ("jpg","tif","png");
52

  
53
  my @errors = $self->file(SL::DB::File->new(%{ $attributes }))->validate;
54
  return $self->js->error(@errors)->render($self) if @errors;
55

  
56
  $self->file->save;
57

  
58
  # TODO js call
59
  $self->render('fileuploader/test_page');
60
}
61

  
62
#
63
# helpers
64
#
65

  
66
sub init_file {
67
  return SL::DB::File->new(id => $::form->{id})->load;
68
}
69

  
70
1;
71
__END__
72

  
73
=pod
74

  
75
=encoding utf8
76

  
77
=head1 NAME
78

  
79
SL::Controller::FileUploader - Controller to manage fileuploads
80

  
81
=head1 SYNOPSIS
82

  
83
  use SL::Controller::FileUploader;
84

  
85
  # synopsis.. =>
86

  
87
=head1 DESCRIPTION
88

  
89
# longer description...
90

  
91

  
92
=head1 INTERFACE
93

  
94

  
95
=head1 DEPENDENCIES
96

  
97

  
98
=head1 SEE ALSO
99

  
100
=head1 AUTHOR
101

  
102
Werner Hahn E<lt>wh@futureworldsearch.netE<gt>
103

  
104
=cut
SL/Helper/UserPreferences.pm
1
package SL::Helper::UserPreferences;
2

  
3
use strict;
4

  
5
1;
6

  
7
__END__
8

  
9
=encoding utf-8
10

  
11
=head1 NAME
12

  
13
SL::Helper::UserPreferences - user based preferences store
14

  
15
=head1
16

  
17
  use SL::Helper::UserPreferences;
18
  my $user_pref = SL::Helper::UserPreferences->new(
19
    login             => $login,        # defaults to current user
20
    namespace         => $namespace,    # defaults to current package
21
    upgrade_callbacks => $upgrade_callbacks,
22
    current_version   => $version,      # defaults to __PACKAGE__->VERSION
23
    auto_store_back   => 0,             # default 1 
24
  );
25
  # OR
26
  my $user_pref = $::auth->current_user->user_preferences(
27
    namespace         => $namespace,
28
    upgrade_callbacks => $upgrade_callbacks,
29
    current_version   => $version,      # defaults to __PACKAGE__->VERSION
30
    auto_store_back   => 0, # default 1 
31
  );
32

  
33
  $user_pref->store($key, $value);
34
  my $val  = $user_pref->get($key);
35
  my $vals = $user_pref->get_all;
36
  my $keys = $user_pref->get_keys;
37
  $user_pref->delete($key);
38
  $user_pref->delete_all;
39

  
40
=head1 DESCRIPTION
41

  
42

  
43
=head1 BEHAVIOUR
44

  
45
* If a (namepace, key) tuple exists, a store will overwrite the last version
46

  
47
* If the value retrieved from the database is newer than the code version, an
48
  error must be thrown.
49

  
50
* get will check the version against the current version and apply all upgrade
51
  steps.
52

  
53
* if the final step is not the current version, behaviour is undefined
54

  
55
*  
56

  
57
=head1 VERSIONING
58

  
59
Every entry in the user prefs must have a version to be compatible in case of code upgrades.
60

  
61
Code reading user prefs must check if the version is the expected one, and must have upgrade code to upgrade out of date preferences to the current version.
62

  
63
Code SHOULD write the upgraded version back to the store at the earliest time to keep preferences up to date. This should be able to be disabled to have developer versions not overwrite preferences with unsupported versions.
64

  
65
Example:
66

  
67
Initial code dealing with prefs:
68

  
69
  our $VERSION = 1;
70

  
71
  $user_prefs->store("selected tab", $::form->{selected_tab});
72

  
73
And the someone edits the code and removes the tab "Webdav". To ensure favorites with webdav selected are upgraded:
74

  
75
  our $VERSION = 2;
76

  
77
  my $upgrade_callbacks = {
78
    2 => sub { $_[0] eq 'WebDav' ? 'MasterData' : $_[0]; },
79
  };
80

  
81
  my $val = $user_prefs->get("selected tab");
82

  
83
=head1 FUNCTIONS
84

  
85
=head1 SPECIAL CASES
86

  
87
* get must work in both scalar and list context
88

  
89
* version might be integer or version object
90

  
91
* not defined if it should be possible to retrieve the version of a tuple
92

  
93

  
94

  
95
=head1 BUGS
96

  
97
None yet :)
98

  
99
=head1 AUTHOR
100

  
101

  
102

  
103
=cut
SL/ShopConnector/Shopware.pm
102 102
    my @positions = sort { Sort::Naturally::ncmp($a->{"partnumber"}, $b->{"partnumber"}) } @{ $import->{data}->{details} };
103 103
    my $position = 1;
104 104
    foreach my $pos(@positions) {
105
      my %pos_columns = ( description => $pos->{articleName},
106
                          partnumber  => $pos->{articleNumber},
107
                          price       => $pos->{price},
108
                          quantity    => $pos->{quantity},
109
                          position    => $position,
110
                          tax_rate    => $pos->{taxRate},
111
                          shop_trans_id    => $pos->{articleId},
112
                          shop_order_id    => $id,
105
      my %pos_columns = ( description       => $pos->{articleName},
106
                          partnumber        => $pos->{articleNumber},
107
                          price             => $pos->{price},
108
                          quantity          => $pos->{quantity},
109
                          position          => $position,
110
                          tax_rate          => $pos->{taxRate},
111
                          shop_trans_id     => $pos->{articleId},
112
                          shop_order_id     => $id,
113 113
                        );
114 114
      my $pos_insert = SL::DB::ShopOrderItem->new(%pos_columns);
115 115
      $pos_insert->save;
......
118 118
    # Versandkosten als Position am ende einfügen Dreschflegelspezifisch event. konfigurierbar machen
119 119
    if (my $shipping = $import->{data}->{dispatch}->{name}) {
120 120
      my %shipping_partnumbers = (
121
                                  'Auslandsversand Einschreiben' => { 'partnumber' => '900650'},
122
                                  'Auslandsversand'              => { 'partnumber' => '900650'},
123
                                  'Standard Versand'            => { 'partnumber' => '905500'},
124
                                  'Kostenloser Versand'         => { 'partnumber' => '905500'},
121
                                  'Auslandsversand Einschreiben'  => { 'partnumber' => '900650'},
122
                                  'Auslandsversand'               => { 'partnumber' => '900650'},
123
                                  'Standard Versand'              => { 'partnumber' => '905500'},
124
                                  'Kostenloser Versand'           => { 'partnumber' => '905500'},
125 125
                                );
126
      my %shipping_pos = ( description => $import->{data}->{dispatch}->{name},
127
                           partnumber  => $shipping_partnumbers{$shipping}->{partnumber},
128
                           price       => $import->{data}->{invoiceShipping},
129
                           quantity    => 1,
130
                           position    => $position,
131
                           tax_rate    => 7,
126
      my %shipping_pos = ( description    => $import->{data}->{dispatch}->{name},
127
                           partnumber     => $shipping_partnumbers{$shipping}->{partnumber},
128
                           price          => $import->{data}->{invoiceShipping},
129
                           quantity       => 1,
130
                           position       => $position,
131
                           tax_rate       => 7,
132 132
                           shop_trans_id  => 0,
133 133
                           shop_order_id  => $id,
134 134
                         );
......
196 196
  foreach my $img (@{ $images }) {
197 197
    my ($path, $extension) = (split /\./, $img->{filename});
198 198

  
199
    my $temp ={
200
                      ( link        => 'data:' . $img->{file_content_type} . ';base64,' . MIME::Base64::encode($img->{file_content},''),
201
                        description => $img->{title},
202
                        position    => $img->{position},
203
                        extension   => $extension,
204
                        path        => $path,
199
    my $temp ={ ( link        => 'data:' . $img->{file_content_type} . ';base64,' . MIME::Base64::encode($img->{file_content},''),
200
                  description => $img->{title},
201
                  position    => $img->{position},
202
                  extension   => $extension,
203
                  path        => $path,
205 204
                      )}    ;
206 205
    push( @upload_img, $temp);
207 206
  }
......
209 208
  my $data = $self->connector->get("http://$url/api/articles/$part->{partnumber}?useNumberAsId=true");
210 209
  my $data_json = $data->content;
211 210
  my $import = SL::JSON::decode_json($data_json);
212

  
213
  my %shop_data =  (  name          => $part->{description},
214
                      taxId         => 4, # TODO Hardcoded kann auch der taxwert sein zB. tax => 19.00
215
                      mainDetail    => { number   => $part->{partnumber},
211
  # mapping to shopware
212
  my %shop_data =  (  name              => $part->{description},
213
                      taxId             => 4, # TODO Hardcoded kann auch der taxwert sein zB. tax => 19.00
214
                      mainDetail        => { number   => $part->{partnumber},
216 215
                                         inStock  => $part->{onhand},
217 216
                                         prices   =>  [ {          from   => 1,
218 217
                                                                   price  => $part->{sellprice},
......
220 219
                                                      },
221 220
                                                    ],
222 221
                                       },
223
                      supplier      => $cvars->{freifeld_7}->{value},
224
                      description   => $shop_part->{shop_description},
225
                      active        => $shop_part->active,
226
                      images        => [ @upload_img ],
227
                      __options_images => { replace => 1, },
228
                      categories    => [ @cat ], #{ path => 'Deutsch|test2' }, ], #[ $categories ],
222
                      supplier          => $cvars->{freifeld_7}->{value},
223
                      description       => $shop_part->{shop_description},
224
                      active            => $shop_part->active,
225
                      images            => [ @upload_img ],
226
                      __options_images  => { replace => 1, },
227
                      categories        => [ @cat ], #{ path => 'Deutsch|test2' }, ], #[ $categories ],
229 228

  
230 229
                    )
231 230
                  ;
......
234 233

  
235 234
  if($import->{success}){
236 235
    #update
236
    #TODO partnumber escapen slash uri_encode
237 237
    my $upload = $self->connector->put("http://$url/api/articles/$part->{partnumber}?useNumberAsId=true",Content => $dataString);
238 238
    my $data_json = $upload->content;
239 239
    my $upload_content = SL::JSON::decode_json($data_json);
ShopOrder.js
1
namespace('kivi.ShopOrder', function(ns) {
2

  
3
  this.massTransferInitialize = function() {
4
    kivi.popup_dialog({
5
      id: 'status_mass_transfer',
6
      dialog: {
7
        title: kivi.t8('Status Shoptransfer')
8
      }
9
    });
10
  }
11

  
12
  this.massTransferStarted = function() {
13
    $('#status_mass_transfer').data('timerId', setInterval(function() {
14
      $.get("controller.pl", {
15
        action: 'ShopOrderMassTransfer/_transfer_status',
16
        job_id: $('smt_job_id').val()
17
      }, kivi.eval_json_result);
18
    }, 5000));
19
  };
20

  
21
  this.setup = function() {
22
    alert('HALLO');
23
    $('#mass_transfer').click(kivi.ShopOrderMassTransfer.massTransferInitialize);
24
  };
25
});
26

  
27
$(kivi.ShopOrderMassTransfer.setup);
js/kivi.ShopOrder.js
1 1
namespace('kivi.ShopOrder', function(ns) {
2
  this.massTransferInitialize = function() {
2
  ns.massTransferInitialize = function() {
3 3
    kivi.popup_dialog({
4 4
      id: 'status_mass_transfer',
5 5
      dialog: {
......
9 9
    alert('Hallo');
10 10
  };
11 11

  
12
  this.massTransferStarted = function() {
12
  ns.massTransferStarted = function() {
13 13
    $('#status_mass_transfer').data('timerId', setInterval(function() {
14 14
      $.get("controller.pl", {
15 15
        action: 'ShopOrder/transfer_status',
......
18 18
    }, 5000));
19 19
  };
20 20

  
21
  this.massTransferFinished = function() {
21
  ns.massTransferFinished = function() {
22 22
    clearInterval($('#status_mass_transfer').data('timerId'));
23 23
    $('.ui-dialog-titlebar button.ui-dialog-titlebar-close').prop('disabled', '')
24 24
  };
25 25

  
26
  this.setup = function() {
26
  ns.setup = function() {
27 27
    kivi.ShopOrder.massTransferInitialize();
28 28
    kivi.submit_ajax_form('controller.pl?action=ShopOrder/mass_transfer','[name=shop_orders]');
29 29
  };
templates/webpages/common/file_upload.html
62 62
 </table>
63 63

  
64 64
 <p>
65
 <!-- TODO action ändern in übergebene Variable, sodass jede xbelibiege Controller/Action aufgerufen werden kann -->
65 66
  [%- L.ajax_submit_tag('controller.pl?action=FileUploader/ajax_upload_file', '#fileupload_form', LxERP.t8('Save'), no_id=1) %]
66 67
  <a href="#" onclick="$('#jqueryui_popup_dialog').dialog('close');">[%- LxERP.t8("Cancel") %]</a>
67 68
 </p>
templates/webpages/ic/tabs/_shop.html
51 51
        [% # IF !var.partsgroup_filtered %]
52 52
          <td align="right" valign="top">[% HTML.escape(var.description) %]</td>
53 53
        [% # END %]
54
      <td align="right" valign="top">[% var.VALID_BOX %]</td>
54 55
        <td valign="top">[% var.HTML_CODE %]</td>
55 56
       </tr>
56 57
      [%- END %]
templates/webpages/shop_part/_list_images.html
33 33

  
34 34

  
35 35

  
36

  
36
<!-- TODO javascript nach kivi.js id,modul,controller/action -->
37 37
<script type='text/javascript'>
38 38
<!--
39 39
function add_file(id,modul) {

Auch abrufbar als: Unified diff