ImageUpload: erste Version
authorSven Schöling <s.schoeling@googlemail.com>
Fri, 26 Mar 2021 18:26:04 +0000 (19:26 +0100)
committerSven Schöling <s.schoeling@googlemail.com>
Fri, 25 Jun 2021 13:51:32 +0000 (15:51 +0200)
SL/Controller/ImageUpload.pm [new file with mode: 0644]
menus/mobile/00-erp.yaml
templates/mobile_webpages/image_upload/form.html [new file with mode: 0644]

diff --git a/SL/Controller/ImageUpload.pm b/SL/Controller/ImageUpload.pm
new file mode 100644 (file)
index 0000000..173c5da
--- /dev/null
@@ -0,0 +1,57 @@
+package SL::Controller::ImageUpload;
+
+use strict;
+use parent qw(SL::Controller::Base);
+
+use SL::DB::Part;
+use SL::DB::Order;
+use SL::DB::DeliveryOrder;
+
+use Rose::Object::MakeMethods::Generic
+(
+  scalar => [ qw() ],
+  'scalar --get_set_init' => [ qw(object_type object) ],
+);
+
+my %object_loader = (
+  part            => [ "SL::DB::Part" ],
+  sales_order     => [ "SL::DB::Order", [ sales => 1, quotation => 0 ] ],
+  sales_quotation => [ "SL::DB::Order", [ sales => 1, quotation => 1 ] ],
+  purchase_order  => [ "SL::DB::Order", [ sales => 0, quotation => 1 ] ],
+  sales_delivery_order => [ "SL::DB::DeliveryOrder", [ is_sales => 1 ] ],
+);
+
+
+################ actions #################
+
+sub action_upload_image {
+  my ($self) = @_;
+
+  $::request->layout->add_javascripts('kivi.File.js');
+
+  $self->render('image_upload/form');
+}
+
+################# internal ###############
+
+sub init_object_type {
+  $::form->{object_type} or die "need object type"
+}
+
+sub init_object {
+  my ($self) = @_;
+
+  return unless $self->object_type;
+
+  my $loader = $object_loader{ $self->object_type } or die "unknown object type";
+  my $manager = $loader->[0]->_get_manager_class;
+
+  return $manager->find_by(id => $::form->{object_id}*1) if $::form->{object_id};
+
+  return $manager->find_by(donumber => $::form->{object_number}, @{ $loader->[1] // [] }) if $::form->{object_number};
+}
+
+
+1;
+
+
index e510d08..62231c8 100644 (file)
@@ -8,8 +8,8 @@
   order: 100
   access: sales_delivery_order_edit
   params:
-    action: ImageUpload/search_delivery_order
-    sales: 1
+    action: ImageUpload/upload_image
+    object_type: sales_delivery_order
 - id: component_test
   name: Component Test
   order: 200
diff --git a/templates/mobile_webpages/image_upload/form.html b/templates/mobile_webpages/image_upload/form.html
new file mode 100644 (file)
index 0000000..428f6b9
--- /dev/null
@@ -0,0 +1,31 @@
+[% USE HTML %]
+[% USE T8 %]
+[% USE P %]
+[% USE LxERP %]
+
+<h1>[% title | html %]</h1>
+
+<form action="controller.pl">
+
+[% IF !SELF.object.id %]
+
+  <p>[% 'Input delivery order number (picker NYI)' | $T8 %]</p>
+
+  [% P.M.input_tag("object_number", "", label=LxERP.t8("Number")) %]
+  [% P.M.submit_tag("submit", LxERP.t8("Update")) %]
+[% ELSE %]
+  <h2>[% SELF.object.displayable_name | html %]</h2>
+
+  [% P.hidden_tag("object_id", SELF.object.id) %]
+[% END %]
+
+[% P.hidden_tag("object_type", SELF.object_type) %]
+[% P.hidden_tag("action", "ImageUpload/upload_image") %]
+</form>
+
+[%# IF SELF.object.id %]
+  <div id="image_list_[% SELF.object_type | html %]"></div>
+  <script>
+    $(function() { $.get('controller.pl', { action: "File/list", "file_type": "image", "object_type": "[% SELF.object_type %]", "object_id": "[% SELF.object.id %]", "json": "1"}, kivi.eval_json_result) });
+  </script>
+[%# END %]