Revision 8fe07618
Von Werner Hahn vor mehr als 7 Jahren hinzugefügt
SL/Controller/ShopPart.pm | ||
---|---|---|
package SL::Controller::ShopPart;
|
||
#package SL::Controller::ShopPart;
|
||
|
||
use strict;
|
||
|
||
use parent qw(SL::Controller::Base);
|
||
|
||
use Data::Dumper;
|
||
use SL::Locale::String qw(t8);
|
||
use SL::DB::ShopPart;
|
||
use SL::Helper::Flash;
|
||
|
||
use Rose::Object::MakeMethods::Generic
|
||
(
|
||
'scalar --get_set_init' => [ qw(shop_part js) ],
|
||
);
|
||
|
||
__PACKAGE__->run_before('check_auth');
|
||
__PACKAGE__->run_before('add_javascripts', only => [ qw(edit_popup) ]);
|
||
#
|
||
# actions
|
||
#
|
||
|
||
sub action_create_or_edit_popup {
|
||
my ($self) = @_;
|
||
|
||
$self->render_shop_part_edit_dialog();
|
||
};
|
||
|
||
sub action_update_shop {
|
||
my ($self, %params) = @_;
|
||
|
||
my $shop_part = SL::DB::Manager::ShopPart->find_by(id => $::form->{shop_part_id});
|
||
die unless $shop_part;
|
||
require SL::Shop;
|
||
my $shop = SL::Shop->new( config => $shop_part->shop );
|
||
|
||
# TODO: generate data to upload to shop
|
||
my $part_hash = $shop_part->part->as_tree;
|
||
my $json = SL::JSON::to_json($part_hash);
|
||
my $return = $shop->connector->update_part($self->shop_part, $json);
|
||
|
||
# the connector deals with parsing/result verification, just needs to return success or failure
|
||
if ( $return == 1 ) {
|
||
# TODO: write update time to DB
|
||
my $now = DateTime->now;
|
||
$self->js->html('#shop_part_last_update_' . $shop_part->id, $now->to_kivitendo('precision' => 'minute'))
|
||
->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') ) )
|
||
->render;
|
||
} else {
|
||
$self->js->flash('error', t8('The shop part wasn\'t updated.'))->render;
|
||
};
|
||
|
||
};
|
||
|
||
|
||
|
||
# old:
|
||
# sub action_edit {
|
||
# my ($self) = @_;
|
||
#
|
||
# $self->render('shop_part/edit'); #, { output => 0 }); #, price_source => $price_source)
|
||
# }
|
||
#
|
||
# used when saving existing ShopPart
|
||
|
||
sub action_update {
|
||
my ($self) = @_;
|
||
|
||
$self->create_or_update;
|
||
}
|
||
|
||
sub create_or_update {
|
||
my ($self) = @_;
|
||
|
||
my $is_new = !$self->shop_part->id;
|
||
|
||
# in edit.html all variables start with shop_part
|
||
my $params = delete($::form->{shop_part}) || { };
|
||
|
||
$self->shop_part->assign_attributes(%{ $params });
|
||
|
||
$self->shop_part->save;
|
||
|
||
flash('info', $is_new ? t8('The shop part has been created.') : t8('The shop part has been saved.'));
|
||
# $self->js->val('#partnumber', 'ladida');
|
||
$self->js->html('#shop_part_description_' . $self->shop_part->id, $self->shop_part->shop_description)
|
||
->html('#shop_part_active_' . $self->shop_part->id, $self->shop_part->active)
|
||
->run('kivi.shop_part.close_dialog')
|
||
->flash('info', t8("Updated shop part"))
|
||
->render;
|
||
}
|
||
|
||
sub render_shop_part_edit_dialog {
|
||
my ($self) = @_;
|
||
|
||
# when self->shop_part is called in template, it will be an existing shop_part with id,
|
||
# or a new shop_part with only part_id and shop_id set
|
||
$self->js
|
||
->run(
|
||
'kivi.shop_part.shop_part_dialog',
|
||
t8('Shop part'),
|
||
$self->render('shop_part/edit', { output => 0 }) #, shop_part => $self->shop_part)
|
||
)
|
||
->reinit_widgets;
|
||
|
||
$self->js->render;
|
||
}
|
||
|
||
sub action_save_categories {
|
||
my ($self) = @_;
|
||
|
||
#
|
||
# internal stuff
|
||
#
|
||
sub add_javascripts {
|
||
# is this needed?
|
||
$::request->{layout}->add_javascripts(qw(kivi.shop_part.js));
|
||
}
|
||
|
||
sub check_auth {
|
||
return 1; # TODO: implement shop rights
|
||
# $::auth->assert('shop');
|
||
}
|
||
|
||
sub init_shop_part {
|
||
if ($::form->{shop_part_id}) {
|
||
SL::DB::Manager::ShopPart->find_by(id => $::form->{shop_part_id});
|
||
} else {
|
||
SL::DB::ShopPart->new(shop_id => $::form->{shop_id}, part_id => $::form->{part_id});
|
||
};
|
||
}
|
||
|
||
1;
|
||
|
||
=pod
|
||
|
||
=encoding utf-8
|
||
|
||
=head1 NAME
|
||
|
||
SL::Controller::ShopPart - Controller for managing ShopParts
|
||
|
||
=head1 SYNOPSIS
|
||
|
||
ShopParts are configured in a tab of the corresponding part.
|
||
|
||
=head1 FUNCTIONS
|
||
|
||
=over 4
|
||
|
||
=item C<action_update_shop>
|
||
|
||
To be called from the "Update" button, for manually syncing a part with its
|
||
shop. Generates a Calls some ClientJS functions to modifiy original page.
|
||
|
||
=back
|
||
|
||
=head1 AUTHORS
|
||
|
||
G. Richardson E<lt>information@kivitendo-premium.deE<gt>
|
||
|
||
=cut
|
||
1;
|
SL/DB/Manager/ShopPart.pm | ||
---|---|---|
# This file has been auto-generated only because it didn't exist.
|
||
# Feel free to modify it at will; it will not be overwritten automatically.
|
||
|
||
package SL::DB::Manager::ShopPart;
|
||
#package SL::DB::Manager::ShopPart;
|
||
|
||
use strict;
|
||
|
||
use SL::DB::Helper::Manager;
|
||
use base qw(SL::DB::Helper::Manager);
|
||
|
||
sub object_class { 'SL::DB::ShopPart' }
|
||
|
||
__PACKAGE__->make_manager_methods;
|
||
|
||
1;
|
SL/DB/MetaSetup/ShopPart.pm | ||
---|---|---|
# This file has been auto-generated. Do not modify it; it will be overwritten
|
||
# by rose_auto_create_model.pl automatically.
|
||
package SL::DB::ShopPart;
|
||
#package SL::DB::ShopPart;
|
||
|
||
use strict;
|
||
|
SL/DB/Part.pm | ||
---|---|---|
package SL::DB::Part;
|
||
#package SL::DB::Part;
|
||
|
||
use strict;
|
||
|
SL/DB/ShopPart.pm | ||
---|---|---|
# This file has been auto-generated only because it didn't exist.
|
||
# Feel free to modify it at will; it will not be overwritten automatically.
|
||
|
||
package SL::DB::ShopPart;
|
||
#package SL::DB::ShopPart;
|
||
|
||
use strict;
|
||
|
||
use SL::DB::MetaSetup::ShopPart;
|
||
use SL::DB::Manager::ShopPart;
|
||
|
||
__PACKAGE__->meta->initialize;
|
||
|
||
1;
|
bin/mozilla/ic.pl | ||
---|---|---|
#TMP
|
||
#=====================================================================
|
||
# LX-Office ERP
|
||
# Copyright (C) 2004
|
js/kivi.shop_part.js | ||
---|---|---|
//TMP
|
||
namespace('kivi.shop_part', function(ns) {
|
||
var $dialog;
|
||
|
||
// this is called by sub render, with a certain prerendered html (edit.html)
|
||
ns.shop_part_dialog = function(title, html) {
|
||
var id = 'jqueryui_popup_dialog';
|
||
var dialog_params = {
|
||
id: id,
|
||
width: 800,
|
||
height: 500,
|
||
modal: true,
|
||
close: function(event, ui) { $dialog.remove(); },
|
||
};
|
||
|
||
$('#' + id).remove();
|
||
|
||
$dialog = $('<div style="display:none" id="' + id + '"></div>').appendTo('body');
|
||
$dialog.attr('title', title);
|
||
$dialog.html(html);
|
||
$dialog.dialog(dialog_params);
|
||
|
||
$('.cancel').click(ns.close_dialog);
|
||
|
||
return true;
|
||
};
|
||
|
||
ns.close_dialog = function() {
|
||
$dialog.dialog("close");
|
||
}
|
||
|
||
|
||
// save existing shop_part_id with new params from form, calls create_or_update and saves to db
|
||
ns.save_shop_part = function(shop_part_id) {
|
||
var form = $('form').serializeArray();
|
||
form.push( { name: 'action', value: 'ShopPart/update' }
|
||
, { name: 'shop_part_id', value: shop_part_id }
|
||
);
|
||
|
||
$.post('controller.pl', form, function(data) {
|
||
kivi.eval_json_result(data);
|
||
});
|
||
}
|
||
|
||
// add part to a shop
|
||
ns.add_shop_part = function(part_id,shop_id) {
|
||
var form = $('form').serializeArray();
|
||
form.push( { name: 'action', value: 'ShopPart/update' }
|
||
);
|
||
|
||
$.post('controller.pl', form, function(data) {
|
||
kivi.eval_json_result(data);
|
||
});
|
||
}
|
||
|
||
// this is called from tabs/_shop.html, opens edit_window (render)
|
||
ns.edit_shop_part = function(shop_part_id) {
|
||
$.post('controller.pl', { action: 'ShopPart/create_or_edit_popup', shop_part_id: shop_part_id }, function(data) {
|
||
kivi.eval_json_result(data);
|
||
});
|
||
}
|
||
|
||
// does the same as edit_shop_part (existing), but with part_id and shop_id, opens edit window (render)
|
||
ns.create_shop_part = function(part_id, shop_id) {
|
||
$.post('controller.pl', { action: 'ShopPart/create_or_edit_popup', part_id: part_id, shop_id: shop_id }, function(data) {
|
||
kivi.eval_json_result(data);
|
||
});
|
||
}
|
||
|
||
// gets all categories from the webshop
|
||
ns.get_all_categories = function(shop_part_id) {
|
||
var form = $('form').serializeArray();
|
||
form.push( { name: 'action', value: 'ShopPart/get_categories' }
|
||
, { name: 'shop_part_id', value: shop_part_id }
|
||
);
|
||
|
||
$.post('controller.pl', form, function(data) {
|
||
kivi.eval_json_result(data);
|
||
});
|
||
}
|
||
// write categories in kivi DB not in the shops DB TODO: create new categories in the shops db
|
||
ns.save_categories = function(shop_part_id, shop_id) {
|
||
var form = $('form').serializeArray();
|
||
form.push( { name: 'action', value: 'ShopPart/save_categories' }
|
||
, { name: 'shop_id', value: shop_id }
|
||
, { name: 'shop_part_id', value: shop_part_id }
|
||
);
|
||
|
||
$.post('controller.pl', form, function(data) {
|
||
kivi.eval_json_result(data);
|
||
});
|
||
}
|
||
|
||
ns.update_shop_part = function(shop_part_id) {
|
||
$.post('controller.pl', { action: 'ShopPart/update_shop', shop_part_id: shop_part_id }, function(data) {
|
||
kivi.eval_json_result(data);
|
||
});
|
||
}
|
||
|
||
ns.update_discount_source = function(row, source, discount_str) {
|
||
$('#active_discount_source_' + row).val(source);
|
||
if (discount_str) $('#discount_' + row).val(discount_str);
|
||
$('#update_button').click();
|
||
}
|
||
});
|
sql/Pg-upgrade2/shop_parts.sql | ||
---|---|---|
-- TMP
|
||
-- @tag: shop_parts
|
||
-- @description: Add tables for part information for shop
|
||
-- @charset: UTF-8
|
||
-- @depends: release_3_3_0 shops
|
||
-- @ignore: 0
|
||
|
||
CREATE TABLE shop_parts (
|
||
id SERIAL PRIMARY KEY,
|
||
shop_id INTEGER NOT NULL REFERENCES shops(id),
|
||
part_id INTEGER NOT NULL REFERENCES parts(id),
|
||
shop_description TEXT,
|
||
itime TIMESTAMP DEFAULT now(),
|
||
mtime TIMESTAMP,
|
||
last_update TIMESTAMP,
|
||
show_date DATE, -- the starting date for displaying part in shop
|
||
sortorder INTEGER,
|
||
front_page BOOLEAN NOT NULL DEFAULT false,
|
||
active BOOLEAN NOT NULL DEFAULT false, -- rather than obsolete
|
||
shop_category TEXT,
|
||
meta_tags TEXT,
|
||
UNIQUE (part_id, shop_id) -- make sure a shop_part appears only once per shop and part
|
||
);
|
||
|
||
CREATE TRIGGER mtime_shop_parts BEFORE UPDATE ON shop_parts
|
||
FOR EACH ROW EXECUTE PROCEDURE set_mtime();
|
||
|
||
-- CREATE TABLE shop_meta_tags (
|
||
-- id integer NOT NULL DEFAULT nextval('shop_parts_id'),
|
||
-- description
|
||
-- );
|
||
|
||
-- CREATE TABLE shop_categories (
|
||
-- );
|
templates/webpages/ic/tabs/_shop.html | ||
---|---|---|
<!-- TMP -->
|
||
[%- USE HTML %][%- USE L -%][%- USE P -%][%- USE LxERP -%]
|
||
<<<<<<< HEAD
|
||
[%- USE Dumper %]
|
templates/webpages/shop_part/edit.html | ||
---|---|---|
<!-- TMP -->
|
||
[%- USE HTML %][%- USE L -%][%- USE P -%][%- USE LxERP -%]
|
||
|
||
[% LxERP.t8("Part") %]: [% HTML.escape(SELF.shop_part.part.displayable_name) %]<br>
|
||
[% LxERP.t8("Shop") %]: [% HTML.escape(SELF.shop_part.shop.description) %]
|
||
|
||
<form action="controller.pl" method="post">
|
||
|
||
[% IF SELF.shop_part.id %]
|
||
[%- L.hidden_tag("shop_part.id", SELF.shop_part.id) %]
|
||
[% ELSE %]
|
||
[%- L.hidden_tag("shop_part.shop_id", FORM.shop_id) %]
|
||
[%- L.hidden_tag("shop_part.part_id", FORM.part_id) %]
|
||
[% END %]
|
||
|
||
<table>
|
||
<tr>
|
||
<td>[% LxERP.t8("Description") %]</td>
|
||
<td>[% L.textarea_tag("shop_part.shop_description", SELF.shop_part.shop_description) %]</td>
|
||
</tr>
|
||
<tr>
|
||
<td>[% LxERP.t8("Active") %]</td>
|
||
<td>[% L.yes_no_tag("shop_part.active", SELF.shop_part.active) %]</td>
|
||
</tr>
|
||
<tr>
|
||
<td>[% LxERP.t8("Sort order") %]</td>
|
||
<td>[% L.input_tag("shop_part.sortorder", SELF.shop_part.sortorder, size=2) %]</td>
|
||
</tr>
|
||
<tr>
|
||
<td>[% LxERP.t8("Date") %]</td>
|
||
<td>[% L.date_tag("shop_part.show_date", SELF.shop_part.show_date) %]</td>
|
||
</tr>
|
||
<tr>
|
||
<td>[% LxERP.t8("Front page") %]</td>
|
||
<td>[% L.yes_no_tag('shop_part.front_page', SELF.shop_part.front_page) %]</td>
|
||
</tr>
|
||
<tr>
|
||
<td>[% LxERP.t8("Meta Tags") %]</td>
|
||
<td>[% L.input_tag("shop_part.meta_tags", SELF.shop_part.meta_tags, size=2) %]</td>
|
||
</tr>
|
||
<tr>
|
||
<td>[% LxERP.t8("Shop Category") %]</td>
|
||
<td>[% L.input_tag("shop_part.shop_category", SELF.shop_part.category, size=2) %]</td>
|
||
</tr>
|
||
</table>
|
||
[% # L.dump(SELF.shop_part) %]
|
||
|
||
[% IF SELF.shop_part.id %]
|
||
[% L.button_tag("kivi.shop_part.save_shop_part(" _ SELF.shop_part.id _ ")", LxERP.t8("Save")) %]</td>
|
||
[% ELSE %]
|
||
[% L.button_tag("kivi.shop_part.add_shop_part(" _ FORM.part_id _", " _ FORM.shop_id _")", LxERP.t8("Save")) %]</td>
|
||
[% END %]
|
||
[% # L.button_tag("kivi.shop_part.update_partnumber()", LxERP.t8("Update Partnumber")) %]</td>
|
||
|
||
[% # L.hidden_tag("action", "ShopPart/dispatch") %]
|
||
[% # L.submit_tag('action_update', LxERP.t8('Save')) %]
|
||
|
||
</div>
|
||
</form>
|
||
[%- IF SELF.shop_part.part.image && INSTANCE_CONF.get_parts_show_image %]
|
||
<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>
|
||
[%- END %]
|
||
|
||
[% # SELF.shop_part.shop_description %]
|
||
[% # L.dump(SELF.shop_part) %]
|
Auch abrufbar als: Unified diff
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