Revision cfe73453
Von Kivitendo Admin vor mehr als 8 Jahren hinzugefügt
SL/Controller/ShopPart.pm | ||
---|---|---|
1 |
package SL::Controller::ShopPart; |
|
2 |
|
|
3 |
use strict; |
|
4 |
|
|
5 |
use parent qw(SL::Controller::Base); |
|
6 |
|
|
7 |
use Data::Dumper; |
|
8 |
use SL::Locale::String qw(t8); |
|
9 |
use SL::DB::ShopPart; |
|
10 |
use SL::Helper::Flash; |
|
11 |
|
|
12 |
use Rose::Object::MakeMethods::Generic |
|
13 |
( |
|
14 |
'scalar --get_set_init' => [ qw(shop_part js) ], |
|
15 |
); |
|
16 |
|
|
17 |
__PACKAGE__->run_before('check_auth'); |
|
18 |
__PACKAGE__->run_before('add_javascripts', only => [ qw(edit_popup) ]); |
|
19 |
# |
|
20 |
# actions |
|
21 |
# |
|
22 |
|
|
23 |
sub action_create_or_edit_popup { |
|
24 |
my ($self) = @_; |
|
25 |
|
|
26 |
$self->render_shop_part_edit_dialog(); |
|
27 |
}; |
|
28 |
|
|
29 |
|
|
30 |
# old: |
|
31 |
sub action_edit { |
|
32 |
my ($self) = @_; |
|
33 |
|
|
34 |
$self->render('shop_part/edit'); #, { output => 0 }); #, price_source => $price_source) |
|
35 |
} |
|
36 |
|
|
37 |
# used when saving existing ShopPart |
|
38 |
sub action_update { |
|
39 |
my ($self) = @_; |
|
40 |
|
|
41 |
$self->create_or_update; |
|
42 |
} |
|
43 |
|
|
44 |
sub create_or_update { |
|
45 |
my ($self) = @_; |
|
46 |
|
|
47 |
my $is_new = !$self->shop_part->id; |
|
48 |
|
|
49 |
# in edit.html all variables start with shop_part |
|
50 |
my $params = delete($::form->{shop_part}) || { }; |
|
51 |
|
|
52 |
$self->shop_part->assign_attributes(%{ $params }); |
|
53 |
|
|
54 |
$self->shop_part->save; |
|
55 |
|
|
56 |
flash('info', $is_new ? t8('The shop part has been created.') : t8('The shop part has been saved.')); |
|
57 |
# $self->js->val('#partnumber', 'ladida'); |
|
58 |
$self->js->html('#shop_part_description_' . $self->shop_part->id, $self->shop_part->shop_description) |
|
59 |
->html('#shop_part_active_' . $self->shop_part->id, $self->shop_part->active) |
|
60 |
->run('kivi.shop_part.close_dialog') |
|
61 |
->flash('info', t8("Updated shop part")) |
|
62 |
->render; |
|
63 |
} |
|
64 |
|
|
65 |
sub render_shop_part_edit_dialog { |
|
66 |
my ($self) = @_; |
|
67 |
|
|
68 |
# when self->shop_part is called in template, it will be an existing shop_part with id, |
|
69 |
# or a new shop_part with only part_id and shop_id set |
|
70 |
$self->js |
|
71 |
->run( |
|
72 |
'kivi.shop_part.shop_part_dialog', |
|
73 |
t8('Shop part'), |
|
74 |
$self->render('shop_part/edit', { output => 0 }) #, shop_part => $self->shop_part) |
|
75 |
) |
|
76 |
->reinit_widgets; |
|
77 |
|
|
78 |
$self->js->render; |
|
79 |
} |
|
80 |
|
|
81 |
|
|
82 |
# |
|
83 |
# internal stuff |
|
84 |
# |
|
85 |
sub add_javascripts { |
|
86 |
$::request->{layout}->add_javascripts(qw(kivi.shop_part.js)); |
|
87 |
} |
|
88 |
|
|
89 |
sub check_auth { |
|
90 |
return 1; # TODO: implement shop rights |
|
91 |
# $::auth->assert('shop'); |
|
92 |
} |
|
93 |
|
|
94 |
sub init_shop_part { |
|
95 |
if ($::form->{shop_part_id}) { |
|
96 |
SL::DB::ShopPart->new(id => $::form->{shop_part_id})->load; |
|
97 |
} else { |
|
98 |
SL::DB::ShopPart->new(shop_id => $::form->{shop_id}, part_id => $::form->{part_id}); |
|
99 |
}; |
|
100 |
} |
|
101 |
|
|
102 |
1; |
|
103 |
|
bin/mozilla/ic.pl | ||
---|---|---|
1641 | 1641 |
if (scalar @{ $form->{CUSTOM_VARIABLES} }); |
1642 | 1642 |
|
1643 | 1643 |
my $active_shops = SL::DB::Manager::Shop->get_all(query => [ obsolete => 0 ], sort_by => 'sortkey'); |
1644 |
$form->{ACTIVE_SHOPS} = $active_shops; |
|
1645 |
foreach my $shop ( @$active_shops ) { |
|
1646 |
my ($shop_part) = $part->find_shop_parts( { shop_id => $shop->id } ); |
|
1647 |
push( @{ $form->{SHOP_PARTS} }, $shop_part ); |
|
1648 |
}; |
|
1644 |
$form->{SHOP_PARTS} = SL::DB::Manager::ShopPart->get_all( query => [ part_id => $part->id , 'shop.obsolete' => 0 ], with_objects => ['shop'] ); |
|
1645 |
|
|
1646 |
# $form->{ACTIVE_SHOPS} = $active_shops; |
|
1647 |
# foreach my $shop ( @$active_shops ) { |
|
1648 |
# my ($shop_part) = $part->find_shop_parts( { shop_id => $shop->id } ); |
|
1649 |
# push( @{ $form->{SHOP_PARTS} }, $shop_part ); |
|
1650 |
# }; |
|
1651 |
my @used_shop_ids = map { $_->shop->id } @{ $form->{SHOP_PARTS} }; |
|
1652 |
$form->{SHOPS_NOT_ASSIGNED} = SL::DB::Manager::Shop->get_all( query => [ obsolete => 0, '!id' => \@used_shop_ids ], sort_by => 'sortkey' ); |
|
1649 | 1653 |
|
1650 |
$::request->layout->use_javascript("${_}.js") for qw(ckeditor/ckeditor ckeditor/adapters/jquery kivi.PriceRule); |
|
1654 |
$::request->layout->use_javascript("${_}.js") for qw(ckeditor/ckeditor ckeditor/adapters/jquery kivi.PriceRule kivi.shop_part);
|
|
1651 | 1655 |
$::request->layout->add_javascripts_inline("\$(function(){kivi.PriceRule.load_price_rules_for_part(@{[ $::form->{id} * 1 ]})});") if $::form->{id}; |
1652 | 1656 |
$form->header; |
1653 | 1657 |
#print $form->parse_html_template('ic/form_header', { ALL_PRICE_FACTORS => $form->{ALL_PRICE_FACTORS}, |
js/kivi.shop_part.js | ||
---|---|---|
1 |
namespace('kivi.shop_part', function(ns) { |
|
2 |
var $dialog; |
|
3 |
|
|
4 |
// this is called by sub render, with a certain prerendered html (edit.html) |
|
5 |
ns.shop_part_dialog = function(title, html) { |
|
6 |
var id = 'jqueryui_popup_dialog'; |
|
7 |
var dialog_params = { |
|
8 |
id: id, |
|
9 |
width: 800, |
|
10 |
height: 500, |
|
11 |
modal: true, |
|
12 |
close: function(event, ui) { $dialog.remove(); }, |
|
13 |
}; |
|
14 |
|
|
15 |
$('#' + id).remove(); |
|
16 |
|
|
17 |
$dialog = $('<div style="display:none" id="' + id + '"></div>').appendTo('body'); |
|
18 |
$dialog.attr('title', title); |
|
19 |
$dialog.html(html); |
|
20 |
$dialog.dialog(dialog_params); |
|
21 |
|
|
22 |
$('.cancel').click(ns.close_dialog); |
|
23 |
|
|
24 |
return true; |
|
25 |
}; |
|
26 |
|
|
27 |
ns.close_dialog = function() { |
|
28 |
$dialog.dialog("close"); |
|
29 |
} |
|
30 |
|
|
31 |
|
|
32 |
// save existing shop_part_id with new params from form, calls create_or_update and saves to db |
|
33 |
ns.save_shop_part = function(shop_part_id) { |
|
34 |
var form = $('form').serializeArray(); |
|
35 |
// alert(form); |
|
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 |
// alert(shop_part_id); |
|
59 |
var form = $('form').serializeArray(); |
|
60 |
form.push( { name: 'action', value: 'ShopPart/create_or_edit_popup' } |
|
61 |
, { name: 'shop_part_id', value: shop_part_id } |
|
62 |
); |
|
63 |
|
|
64 |
$.post('controller.pl', form, function(data) { |
|
65 |
kivi.eval_json_result(data); |
|
66 |
}); |
|
67 |
} |
|
68 |
|
|
69 |
// does the same as edit_shop_part (existing), but with part_id and shop_id, opens edit window (render) |
|
70 |
ns.create_shop_part = function(part_id, shop_id) { |
|
71 |
var form = $('form').serializeArray(); |
|
72 |
form.push( { name: 'action', value: 'ShopPart/create_or_edit_popup' } |
|
73 |
, { name: 'part_id', value: part_id } |
|
74 |
, { name: 'shop_id', value: shop_id } |
|
75 |
); |
|
76 |
|
|
77 |
$.post('controller.pl', form, function(data) { |
|
78 |
kivi.eval_json_result(data); |
|
79 |
}); |
|
80 |
} |
|
81 |
|
|
82 |
// ns.update_partnumber = function() { |
|
83 |
// $('#partnumber').val('barfoo'); |
|
84 |
// $('#update_button').click(); |
|
85 |
// // $dialog.dialog("close"); |
|
86 |
// } |
|
87 |
|
|
88 |
ns.update_discount_source = function(row, source, discount_str) { |
|
89 |
$('#active_discount_source_' + row).val(source); |
|
90 |
if (discount_str) $('#discount_' + row).val(discount_str); |
|
91 |
$('#update_button').click(); |
|
92 |
} |
|
93 |
}); |
templates/webpages/ic/tabs/_shop.html | ||
---|---|---|
2 | 2 |
|
3 | 3 |
<div id="shop_variables"> |
4 | 4 |
[% LxERP.t8("Active shops:") %] |
5 |
<table> |
|
6 |
<thead> |
|
7 |
<tr> |
|
8 |
<th>[% LxERP.t8("Description") %]</th> |
|
9 |
<th>[% LxERP.t8("Description") %]</th> |
|
10 |
</tr> |
|
11 |
</thead> |
|
12 |
[%- FOREACH shop = ACTIVE_SHOPS %] |
|
13 |
<tr> |
|
14 |
<td>[% HTML.escape( shop.description ) %]</td> |
|
15 |
<td>[% HTML.escape( shop.description ) %]</td> |
|
16 |
</tr> |
|
17 |
[%- END %] |
|
18 |
</table> |
|
19 |
|
|
20 | 5 |
<table> |
21 | 6 |
<thead> |
22 | 7 |
<tr> |
23 | 8 |
<th>[% LxERP.t8("Shop") %]</th> |
9 |
<th>[% LxERP.t8("Active") %]</th> |
|
24 | 10 |
<th>[% LxERP.t8("Shop part") %]</th> |
25 | 11 |
<th>[% LxERP.t8("Last update") %]</th> |
12 |
<th>[% LxERP.t8("Action") %]</th> |
|
26 | 13 |
</tr> |
27 | 14 |
</thead> |
28 | 15 |
[%- FOREACH shop_part = SHOP_PARTS %] |
29 | 16 |
<tr> |
30 | 17 |
<td>[% HTML.escape( shop_part.shop.description ) %]</td> |
31 |
<td>[% HTML.escape( shop_part.shop_description ) %]</td> |
|
18 |
<td>[% L.html_tag('span', shop_part.active, id => 'shop_part_active_' _ shop_part.id ) %]</td> |
|
19 |
<td>[% L.html_tag('span', shop_part.shop_description, id => 'shop_part_description_' _ shop_part.id ) %]</td> |
|
32 | 20 |
<td>[% HTML.escape( shop_part.last_update.to_kivitendo('precision' => 'minute') ) %]</td> |
21 |
<td>[% L.button_tag("kivi.shop_part.edit_shop_part(" _ shop_part.id _ ")", LxERP.t8("Edit")) %]</td> |
|
33 | 22 |
</tr> |
34 | 23 |
[%- END %] |
35 |
</table> |
|
36 |
|
|
37 |
<br><br> |
|
38 |
|
|
39 |
<table> |
|
40 |
<tr> |
|
41 |
<td>[% LxERP.t8("Description") %]</td> |
|
42 |
<td>[% L.textarea_tag("shop_description", shop_part.shop_description) %]</td> |
|
43 |
</tr> |
|
24 |
[%- FOREACH shop = SHOPS_NOT_ASSIGNED %] |
|
44 | 25 |
<tr> |
45 |
<td>[% LxERP.t8("Sort order") %]</td> |
|
46 |
<td>[% L.input_tag("shop_sortorder", shop_part.sortorder, size=2) %]</td> |
|
47 |
</tr> |
|
48 |
<tr> |
|
49 |
<td>[% LxERP.t8("Date") %]</td> |
|
50 |
<td>[% L.date_tag("shop_show_date", shop_part.show_date) %]</td> |
|
51 |
</tr> |
|
52 |
<tr> |
|
53 |
<td>[% LxERP.t8("Front page") %]</td> |
|
54 |
<td>[% L.yes_no_tag('shop_front_page', shop_part.front_page) %]</td> |
|
55 |
</tr> |
|
26 |
<td>[% HTML.escape( shop.description ) %]</td> |
|
27 |
<td></td> |
|
28 |
<td></td> |
|
29 |
<td></td> |
|
30 |
<td>[% L.button_tag("kivi.shop_part.create_shop_part(" _ id _ ", " _ shop.id _ ")", LxERP.t8("Add")) %]</td> |
|
56 | 31 |
</tr> |
57 |
|
|
32 |
[%- END %] |
|
58 | 33 |
</table> |
34 |
|
|
35 |
|
|
59 | 36 |
[% # L.dump(shop_part) %] |
60 | 37 |
</div> |
61 | 38 |
|
Auch abrufbar als: Unified diff
ShopPart - editing and adding in jquery ui dialog
from shop tab in part tab.